0

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

Dano
  • 7
  • 1
  • `NDEBUG` is already defined in Release, MinSizeRel, and RelWithDebInfo configuration types. Warning flags are best added by setting CMAKE_CXX_FLAGS in a preset / the CLion settings, rather than hardcoding it. – Alex Reinking Aug 20 '21 at 16:04
  • You should not set CMAKE_CXX_STANDARD, either. Instead write `target_compile_features(DS_WET1_PART1 PRIVATE cxx_std_11)`. – Alex Reinking Aug 20 '21 at 16:06
  • Does this answer your question? [Modern way to set compiler flags in cross-platform cmake project](https://stackoverflow.com/questions/45955272/modern-way-to-set-compiler-flags-in-cross-platform-cmake-project) – Alex Reinking Aug 20 '21 at 16:33

1 Answers1

0

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)
Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122