[CMake] Building arguments to target_comple_definitions()

Rob Boehne robb at datalogics.com
Mon Oct 15 15:19:05 EDT 2018


Ok, Thanks!  I guess I have to get better at reading error messages ☺


From: Chuck Atkins <chuck.atkins at kitware.com>
Date: Monday, October 15, 2018 at 12:19 PM
To: Rob Boehne <robb at datalogics.com>
Cc: CMake Mail List <cmake at cmake.org>
Subject: Re: [CMake] Building arguments to target_comple_definitions()

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/9f293e7b/attachment.html>


More information about the CMake mailing list