47

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.

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175

2 Answers2

78

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>
Fredrik Jansson
  • 3,764
  • 3
  • 30
  • 33
2

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.

Community
  • 1
  • 1
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
  • For a person new to using CMake, ccmake is an excellent solution. I'd suggest that `RelWithDebInfo` might be more helpful than `Debug` for the CMAKE_BUILD_TYPE. It would also be good to mention that they should hit `g` to generate after editing. If you wanted to go the extra mile, you could include all the keystrokes (`/` to start searching `type` to find BUILD_TYPE, `Enter` to start editing the field...) – hackerb9 Sep 13 '21 at 02:01