Search code examples
c++c++11debuggingcmakeclion

Clion How to Add Debug Flags?


I used to compile my program like this:

g++ -std=c++11 –DNDEBUG –Wall *.cpp

Now I moved to use Clion, where it has the following CMakeLists.txt, can someone kindly help me on how to add the above flags to it? (Already added C++11 flag):

cmake_minimum_required(VERSION 3.20)
project(DS_WET1_PART1)

set(CMAKE_CXX_STANDARD 11)

add_executable(DS_WET1_PART1 main1.cpp library1.cpp library1.h linked_list.h node.h)

If related I'm working on macOS


Solution

  • Globally, you can use :

    add_compile_definitions(NDEBUG)
    add_compile_options(-Wall)
    

    Otherwise, use the target specific calls:

    target_compile_definitions(DS_WET1_PART1 PUBLIC NDEBUG)
    target_compile_options(DS_WET1_PART1 PUBLIC -Wall)