CMake - how to set multiple compile definitions fo

2019-02-21 14:17发布

问题:

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?

回答1:

You want target_compile_definitions instead of set_target_properties:

target_compile_definitions(trie_io_test PRIVATE UNIT_TESTING=1 IO_TEST=1)


标签: cmake