From 6fac1abac493363b4d403fc06856608996ef7060 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Mon, 21 Dec 2020 18:04:46 -0700 Subject: [PATCH] CMake: Use add_compile_options instead of appending to CMAKE_CXX_FLAGS Problem: - Appending to CMAKE_CXX_FLAGS for everything is cumbersome. Solution: - Use the `add_compile_options` built-in function to handle adding compiler options (and even de-duplicating). --- CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8939f81b87d..382d794146e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,11 +46,12 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -ftls-model=initial-exec") +add_compile_options(-Wno-unknown-warning-option -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -ftls-model=initial-exec) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fconcepts") + add_compile_options(-fconcepts) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-overloaded-virtual") + add_compile_options(-Wno-overloaded-virtual) endif() if (ALL_THE_DEBUG_MACROS) @@ -264,10 +265,10 @@ set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-shared") #FIXME: -fstack-protector -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -g1 -fno-exceptions -fno-rtti -Wno-address-of-packed-member -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -Wno-nonnull-compare -Wno-deprecated-copy -Wno-expansion-to-defined") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffile-prefix-map=${CMAKE_SOURCE_DIR}=.") +add_compile_options(-Os -g1 -fno-exceptions -fno-rtti -Wno-address-of-packed-member -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -Wno-nonnull-compare -Wno-deprecated-copy -Wno-expansion-to-defined) +add_compile_options(-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -DSANITIZE_PTRS") +add_compile_definitions(DEBUG SANITIZE_PTRS) set(CMAKE_CXX_FLAGS_STATIC "${CMAKE_CXX_FLAGS} -static") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostartfiles -pie -fpic")