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?
Add -D define flags to the compilation of source files. Adds definitions to the compiler command line for targets in the current directory, whether added before or after this command is invoked, and for the ones in sub-directories added after.
Specifies compile definitions to use when compiling a given <target> . The named <target> must have been created by a command such as add_executable() or add_library() and must not be an ALIAS target. The INTERFACE , PUBLIC and PRIVATE keywords are required to specify the scope of the following arguments.
A CMake-based buildsystem is organized as a set of high-level logical targets. Each target corresponds to an executable or library, or is a custom target containing custom commands.
In the C/C++ ecosystem, the best tool for project configuration is CMake. CMake allows you to specify the build of a project, in files named CMakeLists. txt, with a simple syntax (much simpler than writing Makefiles).
You want target_compile_definitions
instead of set_target_properties
:
target_compile_definitions(trie_io_test PRIVATE UNIT_TESTING=1 IO_TEST=1)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With