Skip to content

Commit d693ad9

Browse files
committed
fixup! cmake: Redefine configuration flags
Reorder `CMAKE_<LANG>_FLAGS` and `CMAKE_<LANG>_FLAGS_<CONFIG>`.
1 parent 60c1c69 commit d693ad9

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

CMakeLists.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ else()
234234
unset(debug_flags)
235235
endif()
236236

237+
reorder_flags_for_all_configs()
238+
237239
include(cmake/optional.cmake)
238240

239241
# Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review.
@@ -354,19 +356,18 @@ else()
354356
set(cross_status "FALSE")
355357
endif()
356358
message("Cross compiling ....................... ${cross_status}")
357-
message("Preprocessor defined macros ........... ${definitions_ALL}")
358359
message("C compiler ............................ ${CMAKE_C_COMPILER}")
359-
message("CFLAGS ................................ ${CMAKE_C_FLAGS}")
360360
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER}")
361-
message("CXXFLAGS .............................. ${CMAKE_CXX_FLAGS}")
362361
include(GetTargetInterface)
362+
print_config_flags()
363+
message("Preprocessor defined macros ........... ${definitions_ALL}")
363364
get_target_interface(common_compile_options core_interface COMPILE_OPTIONS)
364365
message("Common compile options ................ ${common_compile_options}")
365366
get_target_interface(common_link_options core_interface LINK_OPTIONS)
366367
message("Common link options ................... ${common_link_options}")
367368
message("Linker flags for executables .......... ${CMAKE_EXE_LINKER_FLAGS}")
368369
message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}")
369-
print_config_flags()
370+
message("")
370371
message("Use assembly routines ................. ${ASM}")
371372
message("Attempt to harden executables ......... ${HARDENING}")
372373
message("Treat compiler warnings as errors ..... ${WERROR}")

cmake/module/ProcessConfigurations.cmake

+21
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@ function(set_default_config config)
5454
endif()
5555
endfunction()
5656

57+
#[=[
58+
By default, CMake passes flags in the CMAKE_<LANG>_FLAGS variable before
59+
those in the per-configuration CMAKE_<LANG>_FLAGS_<CONFIG> variable.
60+
Such a behaviour breaks our integration with the depends build system.
61+
Therefore, we _append_ flags from the CMAKE_<LANG>_FLAGS variable to
62+
the CMAKE_<LANG>_FLAGS_<CONFIG> ones explicitly, while clearing the former.
63+
]=]
64+
function(reorder_flags_for_all_configs)
65+
get_all_configs(all_configs)
66+
foreach(config IN LISTS all_configs)
67+
string(TOUPPER "${config}" config_uppercase)
68+
string(STRIP "${CMAKE_C_FLAGS_${config_uppercase}} ${CMAKE_C_FLAGS}" CMAKE_C_FLAGS_${config_uppercase})
69+
set(CMAKE_C_FLAGS_${config_uppercase} "${CMAKE_C_FLAGS_${config_uppercase}}" PARENT_SCOPE)
70+
string(STRIP "${CMAKE_CXX_FLAGS_${config_uppercase}} ${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS_${config_uppercase})
71+
set(CMAKE_CXX_FLAGS_${config_uppercase} "${CMAKE_CXX_FLAGS_${config_uppercase}}" PARENT_SCOPE)
72+
set(CMAKE_OBJCXX_FLAGS_${config_uppercase} "${CMAKE_CXX_FLAGS_${config_uppercase}}" PARENT_SCOPE)
73+
endforeach()
74+
set(CMAKE_C_FLAGS PARENT_SCOPE)
75+
set(CMAKE_CXX_FLAGS PARENT_SCOPE)
76+
endfunction()
77+
5778
function(remove_c_flag_from_all_configs flag)
5879
get_all_configs(all_configs)
5980
foreach(config IN LISTS all_configs)

0 commit comments

Comments
 (0)