Skip to content

File tree

4 files changed

+115
-45
lines changed

4 files changed

+115
-45
lines changed
 

‎CMakeLists.txt

+2-16
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,6 @@ add_maintenance_targets()
607607
add_windows_deploy_target()
608608
add_macos_deploy_target()
609609

610-
611-
include(GetTargetInterface)
612-
get_target_interface(definitions core_interface COMPILE_DEFINITIONS)
613-
get_target_interface(definitions_RELWITHDEBINFO core_interface_relwithdebinfo COMPILE_DEFINITIONS)
614-
get_target_interface(definitions_DEBUG core_interface_debug COMPILE_DEFINITIONS)
615-
616610
message("\n")
617611
message("Configure summary")
618612
message("=================")
@@ -658,18 +652,10 @@ else()
658652
set(cross_status "FALSE")
659653
endif()
660654
message("Cross compiling ....................... ${cross_status}")
661-
message("Preprocessor defined macros ........... ${definitions}")
662655
message("C compiler ............................ ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}, ${CMAKE_C_COMPILER}")
663-
message("CFLAGS ................................ ${CMAKE_C_FLAGS} ${APPEND_CPPFLAGS} ${APPEND_CFLAGS}")
664656
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, ${CMAKE_CXX_COMPILER}")
665-
message("CXXFLAGS .............................. ${CMAKE_CXX_FLAGS} ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}")
666-
get_target_interface(common_compile_options core_interface COMPILE_OPTIONS)
667-
message("Common compile options ................ ${common_compile_options}")
668-
get_target_interface(common_link_options core_interface LINK_OPTIONS)
669-
message("Common link options ................... ${common_link_options}")
670-
message("Linker flags for executables .......... ${CMAKE_EXE_LINKER_FLAGS} ${APPEND_LDFLAGS}")
671-
message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS} ${APPEND_LDFLAGS}")
672-
print_config_flags()
657+
include(FlagsSummary)
658+
flags_summary()
673659
message("Attempt to harden executables ......... ${ENABLE_HARDENING}")
674660
message("Treat compiler warnings as errors ..... ${WERROR}")
675661
message("Use ccache for compiling .............. ${WITH_CCACHE}")

‎cmake/module/FlagsSummary.cmake

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright (c) 2024-present The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or https://opensource.org/license/mit/.
4+
5+
include_guard(GLOBAL)
6+
7+
function(indent_message header content indent_num)
8+
if(indent_num GREATER 0)
9+
string(REPEAT " " ${indent_num} indentation)
10+
string(REPEAT "." ${indent_num} tail)
11+
string(REGEX REPLACE "${tail}$" "" header "${header}")
12+
endif()
13+
message("${indentation}${header} ${content}")
14+
endfunction()
15+
16+
# Print tools' flags on best-effort. Include the abstracted
17+
# CMake flags that we touch ourselves.
18+
function(print_flags_per_config config indent_num)
19+
string(TOUPPER "${config}" config_uppercase)
20+
21+
include(GetTargetInterface)
22+
get_target_interface(definitions ${config} core_interface COMPILE_DEFINITIONS)
23+
indent_message("Preprocessor defined macros ..........." "${definitions}" ${indent_num})
24+
25+
string(STRIP "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${config_uppercase}}" combined_c_flags)
26+
string(STRIP "${combined_c_flags} ${CMAKE_C${CMAKE_C_STANDARD}_STANDARD_COMPILE_OPTION}" combined_c_flags)
27+
if(CMAKE_POSITION_INDEPENDENT_CODE)
28+
string(JOIN " " combined_c_flags ${combined_c_flags} ${CMAKE_C_COMPILE_OPTIONS_PIC})
29+
endif()
30+
get_target_interface(core_c_flags ${config} core_base_interface COMPILE_OPTIONS)
31+
string(STRIP "${combined_c_flags} ${core_c_flags}" combined_c_flags)
32+
string(STRIP "${combined_c_flags} ${APPEND_CPPFLAGS}" combined_c_flags)
33+
string(STRIP "${combined_c_flags} ${APPEND_CFLAGS}" combined_c_flags)
34+
indent_message("C compiler flags ......................" "${combined_c_flags}" ${indent_num})
35+
36+
string(STRIP "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${config_uppercase}}" combined_cxx_flags)
37+
string(STRIP "${combined_cxx_flags} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}" combined_cxx_flags)
38+
if(CMAKE_POSITION_INDEPENDENT_CODE)
39+
string(JOIN " " combined_cxx_flags ${combined_cxx_flags} ${CMAKE_CXX_COMPILE_OPTIONS_PIC})
40+
endif()
41+
get_target_interface(core_cxx_flags ${config} core_interface COMPILE_OPTIONS)
42+
string(STRIP "${combined_cxx_flags} ${core_cxx_flags}" combined_cxx_flags)
43+
string(STRIP "${combined_cxx_flags} ${APPEND_CPPFLAGS}" combined_cxx_flags)
44+
string(STRIP "${combined_cxx_flags} ${APPEND_CXXFLAGS}" combined_cxx_flags)
45+
indent_message("C++ compiler flags ...................." "${combined_cxx_flags}" ${indent_num})
46+
47+
string(STRIP "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${config_uppercase}}" combined_linker_flags)
48+
string(STRIP "${combined_linker_flags} ${CMAKE_EXE_LINKER_FLAGS}" combined_linker_flags)
49+
get_target_interface(common_link_options ${config} core_interface LINK_OPTIONS)
50+
string(STRIP "${combined_linker_flags} ${common_link_options}" combined_linker_flags)
51+
if(CMAKE_CXX_LINK_PIE_SUPPORTED)
52+
string(JOIN " " combined_linker_flags ${combined_linker_flags} ${CMAKE_CXX_LINK_OPTIONS_PIE})
53+
endif()
54+
string(STRIP "${combined_linker_flags} ${APPEND_LDFLAGS}" combined_linker_flags)
55+
indent_message("Linker flags .........................." "${combined_linker_flags}" ${indent_num})
56+
endfunction()
57+
58+
function(flags_summary)
59+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
60+
if(is_multi_config)
61+
list(JOIN CMAKE_CONFIGURATION_TYPES ", " configs)
62+
message("Available build configurations ........ ${configs}")
63+
if(CMAKE_GENERATOR MATCHES "Visual Studio")
64+
set(default_config "Debug")
65+
else()
66+
list(GET CMAKE_CONFIGURATION_TYPES 0 default_config)
67+
endif()
68+
message("Default build configuration ........... ${default_config}")
69+
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
70+
message("")
71+
message("'${config}' build configuration:")
72+
print_flags_per_config(${config} 2)
73+
endforeach()
74+
else()
75+
message("CMAKE_BUILD_TYPE ...................... ${CMAKE_BUILD_TYPE}")
76+
print_flags_per_config(${CMAKE_BUILD_TYPE} 0)
77+
endif()
78+
message("")
79+
message([=[
80+
NOTE: The summary above may not exactly match the final applied build flags
81+
if any additional CMAKE_* or environment variables have been modified.
82+
To see the exact flags applied, build with the --verbose option.
83+
]=])
84+
endfunction()

‎cmake/module/GetTargetInterface.cmake

+29-4
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,46 @@
44

55
include_guard(GLOBAL)
66

7-
# Get target's interface properties recursively.
8-
function(get_target_interface var target property)
7+
# Evaluates config-specific generator expressions in a list.
8+
# Recognizable patterns are:
9+
# - $<$<CONFIG:[config]>:[value]>
10+
# - $<$<NOT:$<CONFIG:[config]>>:[value]>
11+
function(evaluate_generator_expressions list config)
12+
set(input ${${list}})
13+
set(result)
14+
foreach(token IN LISTS input)
15+
if(token MATCHES "\\$<\\$<CONFIG:([^>]+)>:([^>]+)>")
16+
if(CMAKE_MATCH_1 STREQUAL config)
17+
list(APPEND result ${CMAKE_MATCH_2})
18+
endif()
19+
elseif(token MATCHES "\\$<\\$<NOT:\\$<CONFIG:([^>]+)>>:([^>]+)>")
20+
if(NOT CMAKE_MATCH_1 STREQUAL config)
21+
list(APPEND result ${CMAKE_MATCH_2})
22+
endif()
23+
else()
24+
list(APPEND result ${token})
25+
endif()
26+
endforeach()
27+
set(${list} ${result} PARENT_SCOPE)
28+
endfunction()
29+
30+
31+
# Gets target's interface properties recursively.
32+
function(get_target_interface var config target property)
933
get_target_property(result ${target} INTERFACE_${property})
1034
if(result)
11-
string(GENEX_STRIP "${result}" result)
35+
evaluate_generator_expressions(result "${config}")
1236
list(JOIN result " " result)
1337
else()
1438
set(result)
1539
endif()
1640

1741
get_target_property(dependencies ${target} INTERFACE_LINK_LIBRARIES)
1842
if(dependencies)
43+
evaluate_generator_expressions(dependencies "${config}")
1944
foreach(dependency IN LISTS dependencies)
2045
if(TARGET ${dependency})
21-
get_target_interface(dep_result ${dependency} ${property})
46+
get_target_interface(dep_result "${config}" ${dependency} ${property})
2247
string(STRIP "${result} ${dep_result}" result)
2348
endif()
2449
endforeach()

‎cmake/module/ProcessConfigurations.cmake

-25
Original file line numberDiff line numberDiff line change
@@ -139,28 +139,3 @@ function(replace_cxx_flag_in_config config old_flag new_flag)
139139
FORCE
140140
)
141141
endfunction()
142-
143-
function(print_config_flags)
144-
macro(print_flags config)
145-
string(TOUPPER "${config}" config_uppercase)
146-
message(" - Preprocessor defined macros ........ ${definitions_${config_uppercase}}")
147-
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_${config_uppercase}}")
148-
message(" - CXXFLAGS ........................... ${CMAKE_CXX_FLAGS_${config_uppercase}}")
149-
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_${config_uppercase}}")
150-
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_${config_uppercase}}")
151-
endmacro()
152-
153-
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
154-
if(is_multi_config)
155-
list(JOIN CMAKE_CONFIGURATION_TYPES " " configs)
156-
message("Available build types (configurations) ${configs}")
157-
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
158-
message("'${config}' build type (configuration):")
159-
print_flags(${config})
160-
endforeach()
161-
else()
162-
message("Build type (configuration):")
163-
message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}")
164-
print_flags(${CMAKE_BUILD_TYPE})
165-
endif()
166-
endfunction()

0 commit comments

Comments
 (0)
Please sign in to comment.