Preprocessor macro Debug flag Clion Linux

Completed

I've been trying to figure out how to get CLion to only run certain bits of code if I'm debugging. I tried setting debug flags for cmake in my CMakeLists.txt, but that doesn't seem to work.  I tried setting it in CMakeLists.txt without luck

I have :

set(CMAKE_CXX_FLAGS_DEBUG "-DEBUG")

But, don't think that's right. I currently have a macro defined that I can change manually for debugging, but that isn't ideal.  How would I go about setting a debug flag correctly on Linux?

2 comments
Comment actions Permalink

Figured out how to do it.

if(CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(XML_Parser PUBLIC DEBUG=1)
elseif(CMAKE_BUILD_TYPE MATCHES Release)
target_compile_definitions(XML_Parser PUBLIC DEBUG=0)
endif()
0
Comment actions Permalink

This worked for me after I tried lots of other CMake options to do this. Replace XML_parser in the above answer with your executable/target name.

0

Please sign in to leave a comment.