[CMake] Create space delimited string with $<JOIN:> genex

Ed Branch branch at arlut.utexas.edu
Fri Jul 10 18:12:12 EDT 2015


> Hello,
>
> in my build process I need to call a compiler like tool with the same
> include directories as a certain target.
>
> I tried the following:
>
>
> cmake_minimum_required(VERSION 3.2)
> project(cmake-genex C)
> add_library(dummy dummy.c foo.c)
> target_include_directories(dummy PUBLIC foo bar)
>
> set(prop "$<TARGET_PROPERTY:dummy,INCLUDE_DIRECTORIES>")
> set(lst "$<$<BOOL:${prop}>:-I$<JOIN:${prop}, -I>>")
>
> add_custom_command(OUTPUT foo.c
>   COMMAND echo ${lst}
> )
>
> Unfortunately this results in an escaped space before the -I :
> echo -I/Users/gjasny/src/cmake-genex/foo\
> -I/Users/gjasny/src/cmake-genex/bar
>
> Is there a way to convince CMake not to escape the space? It looks like
> whatever I do, the generator expression is handled like a single string.
>
> Thanks,
> Gregor

A bug related to this problem is on the backlog [1]. A workaround is 
attached to the bug report [2], and an example usage of the workaround 
is in the comments.

[1] http://public.kitware.com/Bug/view.php?id=14353
[2] http://public.kitware.com/Bug/file_download.php?file_id=5436&type=bug


More information about the CMake mailing list