Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set GDB debug flag with cmake?

Tags:

c++

cmake

I have tried setting the debug flags using the

set 

command in cmake but I cam unsure what to add. I have been told things like DEBUG=true but so far i am unable to find the correct flag to set.

like image 954
Fantastic Mr Fox Avatar asked Apr 04 '12 06:04

Fantastic Mr Fox


People also ask

How do I add a debug flag to CMake?

How to enable debugging with cmake? If we use cmake to build the project, we may want to enabling the debuging mode that cmake invoke gcc with the -g so that we can debug the compiled program with gdb. This can be enabled by adding the CMAKE_BUILD_TYPE parameter to cmake: cmake -DCMAKE_BUILD_TYPE=Debug .

How do I set CMake debug mode?

We can use CMAKE_BUILD_TYPE to set the configuration type: cd debug cmake -DCMAKE_BUILD_TYPE=Debug .. cmake --build . cd ../release cmake -DCMAKE_BUILD_TYPE=Release ..


2 Answers

If you want to build for debug (including source information, i.e. -g) when compiling, use

cmake -DCMAKE_BUILD_TYPE=Debug <path> 

If you want to build a release build, you can use

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo <path> 
like image 121
Fredrik Jansson Avatar answered Sep 17 '22 13:09

Fredrik Jansson


Alternatively you can use the CMAKE GUI to make this change. Doing ccmake with the project will yield a screen similar to this:

enter image description here

Entering Debug in the CMAKE_BUILD_TYPE field will allow you to build with debug flags.

like image 32
Fantastic Mr Fox Avatar answered Sep 20 '22 13:09

Fantastic Mr Fox