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

Gregor Jasny gjasny at googlemail.com
Thu Jul 9 00:00:42 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


More information about the CMake mailing list