Skip to content

Commit

Permalink
fixup! cmake: Redefine configuration flags
Browse files Browse the repository at this point in the history
Reorder `CMAKE_<LANG>_FLAGS` and `CMAKE_<LANG>_FLAGS_<CONFIG>`.
  • Loading branch information
hebasto committed Jan 27, 2024
1 parent 4d96b6f commit b834740
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ else()
unset(debug_flags)
endif()

reorder_flags_for_all_configs()

include(cmake/optional_qt.cmake)

include(cmake/optional.cmake)
Expand Down Expand Up @@ -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}")
Expand Down
21 changes: 21 additions & 0 deletions cmake/module/ProcessConfigurations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ function(set_default_config config)
endif()
endfunction()

#[=[
By default, CMake passes flags in the CMAKE_<LANG>_FLAGS variable before
those in the per-configuration CMAKE_<LANG>_FLAGS_<CONFIG> variable.
Such a behaviour breaks our integration with the depends build system.
Therefore, we _append_ flags from the CMAKE_<LANG>_FLAGS variable to
the CMAKE_<LANG>_FLAGS_<CONFIG> 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)
Expand Down

0 comments on commit b834740

Please sign in to comment.