[cmake] refactor configuration

* Split common stuff to reusable files
* Disable INTERPROCEDURAL_OPTIMIZATION for SDL2/3 resource targets
This commit is contained in:
akallabeth
2024-11-12 09:36:25 +01:00
parent 2bb75c195b
commit 0ae7c4b52d
19 changed files with 181 additions and 277 deletions

View File

@@ -0,0 +1,46 @@
include(CheckAndSetFlag)
option(ENABLE_WARNING_VERBOSE "enable -Weveryting (and some exceptions) for compile" OFF)
option(ENABLE_WARNING_ERROR "enable -Werror for compile" OFF)
set(COMMON_COMPILER_FLAGS "")
if(ENABLE_WARNING_VERBOSE)
if(MSVC)
list(APPEND COMMON_COMPILER_FLAGS /W4 /wo4324)
else()
list(
APPEND
COMMON_COMPILER_FLAGS
-Weverything
-Wall
-Wpedantic
-Wno-padded
-Wno-switch-enum
-Wno-cast-align
-Wno-unsafe-buffer-usage
-Wno-reserved-identifier
-Wno-covered-switch-default
-Wno-disabled-macro-expansion
)
endif()
endif()
if(ENABLE_WARNING_ERROR)
list(APPEND COMMON_COMPILER_FLAGS -Werror)
endif()
list(APPEND COMMON_COMPILER_FLAGS -fno-omit-frame-pointer -Wredundant-decls)
include(ExportAllSymbols)
include(CompilerSanitizerOptions)
if(CMAKE_C_COMPILER_ID MATCHES ".*Clang.*" OR (CMAKE_C_COMPILER_ID MATCHES "GNU" AND CMAKE_C_COMPILER_VERSION
VERSION_GREATER_EQUAL 10)
)
add_compile_options($<$<NOT:$<CONFIG:Debug>>:-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.>)
add_compile_options($<$<NOT:$<CONFIG:Debug>>:-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=.>)
add_compile_options($<$<NOT:$<CONFIG:Debug>>:-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.>)
add_compile_options($<$<NOT:$<CONFIG:Debug>>:-fdebug-prefix-map=${CMAKE_BINARY_DIR}=./build>)
add_compile_options($<$<NOT:$<CONFIG:Debug>>:-fmacro-prefix-map=${CMAKE_BINARY_DIR}=./build>)
add_compile_options($<$<NOT:$<CONFIG:Debug>>:-ffile-prefix-map=${CMAKE_BINARY_DIR}=./build>)
endif()