CMAKE_BUILD_TYPE

Hello,

I have an existing cmake and Jetbrains has a problem because I will add some new executables and cxx_test as well.

For example. When developing I would use:

cmake ../ -DCMAKE_BUILD_TYPE=DEBUG


Then in my CMakeLists.txt I have

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") if(CMAKE_BUILD_TYPE MATCHES "RELEASE")      set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_RELEASE} -O2") elseif(CMAKE_BUILD_TYPE MATCHES "DEBUG")      set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")      add_subdirectory(examples)      enable_testing()      ... add unit tests here endif(CMAKE_BUILD_TYPE MATCHES "RELEASE")


So I was confused, in CLion "Edit Configurations" I have the build mode on "DEBUG", but it is not setting the CMAKE_BUILD_TYPES.

So I'm wondering if I should be changing my CMakeLists.txt structure to use CMAKE_CXX_FLAGS_<configuration> instead? I notice in the IDE, theres a CMakeCache, which I could just override these with the values I want in the configuration mode?

Basically I'm open to tweaking my CMakeLists.txt to play nicely with CLion and follow better standards, so should I throw away using the CMAKE_BUILD_TYPES?

2 comments
Avatar
Alexander Kirillin
Comment actions Permalink

Yes, you better update CMakeLists.txt, because currently you cannot provide "CMAKE_BUILD_TYPE=DEBUG" option to cmake under CLion.

0
Comment actions Permalink

CLion automatically detects build flags from all build types in the project.
After project opening, you can choose build type in Run Configuration - it will only affect compilation. Also you can select build type as a resolving context for any given file on the status bar:
Screenshot 2014-11-05 13.06.45.png

0

Please sign in to leave a comment.