I have several build profiles in CLion -> Settings -> Build, Execution, Deployment -> CMake. How can I set the preprocessor definitions for each profile, regardless of which compiler I use?
How to define preprocessor definition for each configuration in CLion?
6.1k Views Asked by volodya7292 At
2
There are 2 best solutions below
4
On
I didn't try this but this should work
if (CMAKE_CONFIGURATION_TYPES)
string(TOLOWER "${CMAKE_CONFIGURATION_TYPES}" CMAKE_CONFIGURATION_TYPES_LOWER)
else()
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_CONFIGURATION_TYPES_LOWER)
endif()
foreach(config ${CMAKE_CONFIGURATION_TYPES_LOWER})
if (${config} MATCHES "debug")
#add preprocessor definition something like this bellow
add_definitions(-DFOO -DBAR ...)
elseif(${config} MATCHES "release")
#and so on...
endif()
endforeach()
So, to correctly check strings, we convert build configuration types to lower case, and then we check if config from the type matches this custom configuration types. if it does, then we can add some preprocessor definitions, etc (
Settings -> Build, Execution, Deployment -> CMake.CMake optionsfield:-DYOUR_DEFINE_VARIABLE=1