Cartesius00 Cartesius00 - 1 year ago 314
C Question

Debug vs Release in CMAKE

In a GCC compiled project,

  • how to run
    for each target type (debug/release)?

  • how to specify debug and release C/C++ flags using

  • how to express that the main executable will be compiled with
    and one nested library with

Answer Source

It's generally best to do an "out of source" build. Create your CMakeLists.txt in the root of your project. Then from the root of your project:

mkdir Release
cd Release
cmake -DCMAKE_BUILD_TYPE=Release ..

And for Debug (again from the root of your project):

mkdir Debug
cd Debug
cmake -DCMAKE_BUILD_TYPE=Debug ..

Debug will add the debug flags appropriate for your compiler. See this FAQ for more details.

You can modify/add to the flags in your CMakeLists.txt via CMAKE_C_FLAGS_DEBUG and CMAKE_C_FLAGS_RELEASE variables, e.g.:


See this link under CMAKE_BUILD_TYPE for more details.

As for your 3rd question, I'm not sure what you are asking exactly. CMake should automatically detect and use the compiler appropriate for your different source files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download