Skip to content

Commit

Permalink
Don't set global compilation flags on CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Nov 11, 2023
1 parent 0720b06 commit 09840af
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,42 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_C_STANDARD 11)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
add_compile_options(
-Wall
-Werror
)
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-variable -Wno-unused-but-set-variable -funsigned-char")
add_compile_options(
-Wextra
-Wno-sign-compare
-Wno-missing-field-initializers
-Wno-unused-parameter
-Wno-unused-variable
-Wno-unused-but-set-variable
-funsigned-char
)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds -Wno-format-truncation -Wno-unused-variable -Wno-unused-but-set-variable")
add_compile_options(
-Wno-array-bounds
-Wno-format-truncation
-Wno-unused-variable
-Wno-unused-but-set-variable
)
endif()

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()

set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -g")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -O0 -fno-omit-frame-pointer")
string(REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")

message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode")
message(STATUS "Building with ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} on ${CMAKE_SYSTEM}")
if(CMAKE_BUILD_TYPE MATCHES "Debug")
message(STATUS "Building with flags ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
else()
message(STATUS "Building with flags ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}")
add_compile_options(
-ggdb
-O0
-fno-omit-frame-pointer
)
endif()

set(CMAKE_VERBOSE_MAKEFILE TRUE)
Expand Down

0 comments on commit 09840af

Please sign in to comment.