Reputation: 4816
I'm trying to set multiple compile definitions for one of the executables I'm trying to compile in CMake (in order to activate macros used for debugging). Here's what I tried:
add_executable (trie_io_test trie_io_test.c trie.c word_list.c)
set_target_properties(
trie_io_test
PROPERTIES
COMPILE_DEFINITIONS UNIT_TESTING=1)
set_target_properties(
trie_io_test
PROPERTIES
COMPILE_DEFINITIONS IO_TEST=1)
Unfortunately this causes only the IO_TEST to be defined.
I also tried the following:
add_executable (trie_io_test trie_io_test.c trie.c word_list.c)
set_target_properties(
trie_io_test
PROPERTIES
COMPILE_DEFINITIONS UNIT_TESTING=1 IO_TEST=1)
But this, on the other hand, causes CMake error.
How to set both of these definitions for the executable I'm trying to build?
Upvotes: 35
Views: 67570
Reputation: 11
This does work:
add_executable (trie_io_test trie_io_test.c trie.c word_list.c)
set_target_properties(
trie_io_test
PROPERTIES
COMPILE_DEFINITIONS "UNIT_TESTING=1;IO_TEST=1"
)
No clue why this makes a difference. It was my understanding that in cmake, white space separated lists are equivalent to semicolon separated strings.
Upvotes: 1
Reputation: 104
I find this can work for you:
add_executable (trie_io_test trie_io_test.c trie.c word_list.c)
set_target_properties(
trie_io_test
PROPERTIES
COMPILE_DEFINITIONS UNIT_TESTING=1
COMPILE_DEFINITIONS IO_TEST=1
)
Just by adding another COMPILE_DEFINITIONS
:P
Upvotes: 3
Reputation: 78320
You want target_compile_definitions
instead of set_target_properties
:
target_compile_definitions(trie_io_test PRIVATE UNIT_TESTING=1 IO_TEST=1)
Upvotes: 71