[CMake] addprefix macro?
Michael Wild
themiwi at gmail.com
Wed May 5 10:22:36 EDT 2010
On 5. May, 2010, at 16:14 , Marc Weber wrote:
> Hi, I'm new to cmake.
>
> I asked at #cmake how to prefix a string to a list of paths.
> I got the reply that I should use a foreach loop which worked.
>
> Can I abstract this pattern using a macro such as this?
>
>
> # prefix and suffix each element of list by ${prefix}elemnt${suffix}
> macro(PREFIXSUFFIX list_name prefix suffix)
> # create empty list - necessary?
> SET(${list_name}_TMP)
>
> # prefix and suffix elements
> foreach(l ${list_name})
> list(APPEND ${list_name}_TMP ${prefix}${l}${suffix} )
> endforeach()
>
> # replace list by tmp list
> SET(${list_name} ${list_name}_TMP)
> UNSET(${list_name}_TMP)
> endmacro(PREFIXSUFFIX)
>
>
> When running make I get something like:
>
> make[2]: *** No rule to make target
> `/pr/tasks/terraView_trunk/build/cmake/UI_FILES_TMP', needed by
> `UI_FILES_TMP.h'. Stop.
>
>
> So what's the missing piece I don't understand yet?
>
> Sincerely
> Marc Weber
In your last SET your setting the variable to the temporary list name, not its contents. Use this instead:
SET(${list_name} "${${list_name}_TMP}")
Also, you might consider turning the whole thing into a function instead. This has the advantage of having a local scope. You pass the result back by using PARENT_SCOPE in the last SET command.
HTH
Michael
More information about the CMake
mailing list