From cec86cfc7d3cd9ea906f0d01ec4e268625b28828 Mon Sep 17 00:00:00 2001 From: William Robinet Date: Mon, 11 Sep 2023 11:20:40 +0200 Subject: [PATCH 1/2] Add compilation options to CMakeLists.txt --- CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index aeaa1ba..8d3b7d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,22 @@ project( LANGUAGES C ) +######## User defined options +option(DEBUG_BUILD "Build with debug facilities" OFF) +option(DISABLE_OPTIMIZATION "Build without compiler optimizations" OFF) +################ + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") +if(DEBUG_BUILD) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3 -DDEBUG") +endif() + +if(DISABLE_OPTIMIZATION) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0") +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2") +endif() + include(CheckSymbolExists) include(GNUInstallDirs) From bd730f31c49138afc06de3c716ad1f78d9648511 Mon Sep 17 00:00:00 2001 From: William Robinet Date: Mon, 11 Sep 2023 11:24:17 +0200 Subject: [PATCH 2/2] Enable DEBUG flag differently --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d3b7d8..a5ac0ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,8 @@ option(DISABLE_OPTIMIZATION "Build without compiler optimizations" OFF) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") if(DEBUG_BUILD) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3 -DDEBUG") + add_definitions(-DDEBUG) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3") endif() if(DISABLE_OPTIMIZATION)