Search code examples
c++clionbuild-definition

How to define preprocessor definition for each configuration in CLion?


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?


Solution

    1. Go to Settings -> Build, Execution, Deployment -> CMake.
    2. Select the profile for which you want to set preprocessor definition.
    3. Write in the CMake options field: -DYOUR_DEFINE_VARIABLE=1
    4. In your CMakeLists.txt write the following:
    if (YOUR_DEFINE_VARIABLE)
        add_definitions(-DYOUR_DEFINE_VARIABLE=1)
    endif (YOUR_DEFINE_VARIABLE)