How to set multiple compilation definitions for a target executable?

I am trying to set several compilation definitions for one of the executables that I am trying to compile in CMake (to activate the macros used for debugging). Here is 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 leads to the determination of only IO_TEST.

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 a CMake error.

How to set both of these definitions for the executable that I am trying to build?

+8
cmake
source share
1 answer

You want target_compile_definitions instead of set_target_properties :

 target_compile_definitions(trie_io_test PRIVATE UNIT_TESTING=1 IO_TEST=1) 
+21
source share

All Articles