From b83474096ad74fb30d1fb9e924396b9b6d8ebc2b Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:32:10 +0000 Subject: [PATCH] fixup! cmake: Redefine configuration flags Reorder `CMAKE__FLAGS` and `CMAKE__FLAGS_`. --- CMakeLists.txt | 9 +++++---- cmake/module/ProcessConfigurations.cmake | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72e8a4b31f112..10335175851dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -288,6 +288,8 @@ else() unset(debug_flags) endif() +reorder_flags_for_all_configs() + include(cmake/optional_qt.cmake) include(cmake/optional.cmake) @@ -412,19 +414,18 @@ else() set(cross_status "FALSE") endif() message("Cross compiling ....................... ${cross_status}") -message("Preprocessor defined macros ........... ${definitions_ALL}") message("C compiler ............................ ${CMAKE_C_COMPILER}") -message("CFLAGS ................................ ${CMAKE_C_FLAGS}") message("C++ compiler .......................... ${CMAKE_CXX_COMPILER}") -message("CXXFLAGS .............................. ${CMAKE_CXX_FLAGS}") include(GetTargetInterface) +print_config_flags() +message("Preprocessor defined macros ........... ${definitions_ALL}") get_target_interface(common_compile_options core_interface COMPILE_OPTIONS) message("Common compile options ................ ${common_compile_options}") get_target_interface(common_link_options core_interface LINK_OPTIONS) message("Common link options ................... ${common_link_options}") message("Linker flags for executables .......... ${CMAKE_EXE_LINKER_FLAGS}") message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}") -print_config_flags() +message("") message("Use assembly routines ................. ${ASM}") message("Attempt to harden executables ......... ${HARDENING}") message("Treat compiler warnings as errors ..... ${WERROR}") diff --git a/cmake/module/ProcessConfigurations.cmake b/cmake/module/ProcessConfigurations.cmake index c8cd0635220d9..b0c3c04daa9ed 100644 --- a/cmake/module/ProcessConfigurations.cmake +++ b/cmake/module/ProcessConfigurations.cmake @@ -54,6 +54,27 @@ function(set_default_config config) endif() endfunction() +#[=[ +By default, CMake passes flags in the CMAKE__FLAGS variable before +those in the per-configuration CMAKE__FLAGS_ variable. +Such a behaviour breaks our integration with the depends build system. +Therefore, we _append_ flags from the CMAKE__FLAGS variable to +the CMAKE__FLAGS_ ones explicitly, while clearing the former. +]=] +function(reorder_flags_for_all_configs) + get_all_configs(all_configs) + foreach(config IN LISTS all_configs) + string(TOUPPER "${config}" config_uppercase) + string(STRIP "${CMAKE_C_FLAGS_${config_uppercase}} ${CMAKE_C_FLAGS}" CMAKE_C_FLAGS_${config_uppercase}) + set(CMAKE_C_FLAGS_${config_uppercase} "${CMAKE_C_FLAGS_${config_uppercase}}" PARENT_SCOPE) + string(STRIP "${CMAKE_CXX_FLAGS_${config_uppercase}} ${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS_${config_uppercase}) + set(CMAKE_CXX_FLAGS_${config_uppercase} "${CMAKE_CXX_FLAGS_${config_uppercase}}" PARENT_SCOPE) + set(CMAKE_OBJCXX_FLAGS_${config_uppercase} "${CMAKE_CXX_FLAGS_${config_uppercase}}" PARENT_SCOPE) + endforeach() + set(CMAKE_C_FLAGS PARENT_SCOPE) + set(CMAKE_CXX_FLAGS PARENT_SCOPE) +endfunction() + function(remove_c_flag_from_all_configs flag) get_all_configs(all_configs) foreach(config IN LISTS all_configs)