[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

@@ -1,4 +1,5 @@
include(CheckCCompilerFlag)
include(CommonCompilerFlags)
macro(checkCFlag FLAG)
check_c_compiler_flag("${FLAG}" CFLAG${FLAG})
@@ -9,9 +10,6 @@ macro(checkCFlag FLAG)
endif()
endmacro()
option(ENABLE_WARNING_VERBOSE "enable -Weveryting (and some exceptions) for compile" OFF)
option(ENABLE_WARNING_ERROR "enable -Werror for compile" OFF)
if(ENABLE_WARNING_VERBOSE)
if(MSVC)
# Remove previous warning definitions,
@@ -21,45 +19,25 @@ if(ENABLE_WARNING_VERBOSE)
)
string(REGEX REPLACE "(^| )[/-]W[ ]*[1-9]" " " "${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
endforeach()
set(C_WARNING_FLAGS /W4 /wo4324)
else()
set(C_WARNING_FLAGS
-Weverything
-Wall
-Wpedantic
-Wno-padded
-Wno-switch-enum
-Wno-cast-align
-Wno-declaration-after-statement
-Wno-unsafe-buffer-usage
-Wno-reserved-identifier
-Wno-covered-switch-default
-Wno-disabled-macro-expansion
-Wno-pre-c11-compat
-Wno-gnu-zero-variadic-macro-arguments
list(APPEND COMMON_COMPILER_FLAGS -Wno-declaration-after-statement -Wno-pre-c11-compat
-Wno-gnu-zero-variadic-macro-arguments
)
endif()
foreach(FLAG ${C_WARNING_FLAGS})
checkcflag(${FLAG})
endforeach()
endif()
if(ENABLE_WARNING_ERROR)
checkcflag(-Werror)
endif()
list(APPEND COMMON_COMPILER_FLAGS -Wimplicit-function-declaration)
checkcflag(-fno-omit-frame-pointer)
foreach(FLAG ${COMMON_COMPILER_FLAGS})
checkcflag(${FLAG})
endforeach()
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU")
if(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>)
# Android profiling
if(ANDROID)
if(WITH_GPROF)
checkandsetflag(-pg)
set(PROFILER_LIBRARIES "${FREERDP_EXTERNAL_PROFILER_PATH}/obj/local/${ANDROID_ABI}/libandroid-ndk-profiler.a")
include_directories(SYSTEM "${FREERDP_EXTERNAL_PROFILER_PATH}")
endif()
endif()