[CMake] Building arguments to target_comple_definitions()

Chuck Atkins chuck.atkins at kitware.com
Mon Oct 15 13:18:56 EDT 2018


Hi Rob,

How would one set a variable containing multiple definitions to be passed
> to target_compile_definitions()  ?
>

The example you gave works (adjusting for typos, PIC, and adding visibility
specifier):
...
set(COMMON_DEFINITIONS SOME_DEFINE_1 SOME_DEFINE_2 SOME_DEFINE_3)
...
target_compile_definitions(CHUNK1 PRIVATE ${COMMON_DEFINITIONS}
CHUNK1_STUFF CHUNK_NAME=\"One\")
target_compile_definitions(CHUNK2 PRIVATE ${COMMON_DEFINITIONS}
CHUNK2_STUFF CHUNK_NAME=\"Two\")
target_compile_definitions(FooBar PRIVATE ${COMMON_DEFINITIONS})
...
results in the following:
...
/usr/bin/c++  -DCHUNK1_STUFF -DCHUNK_NAME=\"One\" -DSOME_DEFINE_1
-DSOME_DEFINE_2 -DSOME_DEFINE_3  -fPIC   -o
CMakeFiles/CHUNK1.dir/chunk_one.cpp.o -c
/home/chuck/Code/tmp/source/chunk_one.cpp
...
/usr/bin/c++  -DCHUNK2_STUFF -DCHUNK_NAME=\"Two\" -DSOME_DEFINE_1
-DSOME_DEFINE_2 -DSOME_DEFINE_3  -fPIC   -o
CMakeFiles/CHUNK2.dir/chunk_two.cpp.o -c
/home/chuck/Code/tmp/source/chunk_two.cpp
...
/usr/bin/c++  -DFooBar_EXPORTS -DSOME_DEFINE_1 -DSOME_DEFINE_2
-DSOME_DEFINE_3  -fPIC   -o CMakeFiles/FooBar.dir/foobar.cpp.o -c
/home/chuck/Code/tmp/source/foobar.cpp
...

Here you can see the common definitions make it to all targets.

- Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181015/22975bf7/attachment.html>


More information about the CMake mailing list