Hey guys I read that in modern Cmake we should avoid add_compile_definitions and use target_compile_definitions instead
at the moment I'm using add_compile_definitions() in my root CmakeLists
if()
add_compile_definitions(SOME_TARGET_A_SPECIFIC_DEFINE)
else if()
add_compile_definitions(SOME_TARGET_B_SPECIFIC_DEFINE)
endif()
Now I'm trying to replace this with target_compile_definitions. My project structure looks like this
- CMakeLists.txt
- app
- app/TargetA/CMakeLists.txt
- app/TargetB/CMakeLists.txt
- modules
- modules/SomeModule/CMakeLists.txt
Now when i move add_compile_definitions(SOME_TARGET_A_SPECIFIC_DEFINE) from root to app/TargetA/CMakeLists.txt my Module (which depends on SOME_TARGET_A_SPECIFIC_DEFINE) the module will not build. From my understanding if would have to add add_compile_definitions(SOME_TARGET_A_SPECIFIC_DEFINE) to each module like this
add_library("${module_name}"
${MODULE_SOURCES})
target_link_libraries("${module_name}" ${MyLibs})
if()
target_compile_definitions("${module_name}" SOME_TARGET_A_SPECIFIC_DEFINE)
else if()
target_compile_definitions("${module_name}" SOME_TARGET_B_SPECIFIC_DEFINE)
endif()
So my Point here to summarise: if I use add_compile_defintions() in the root folder I'd only have to map the proper defines once. If would like to move to target_compile_definitions I'd have to add this the EVERY module?
Or is there a better way to pass Target Specific defines to multiple libs?