Skip to content

Commit a3a3d10

Browse files
committed
[FIXUP] cmake: Rework compile/link flags summary
1 parent efd3267 commit a3a3d10

File tree

4 files changed

+85
-46
lines changed

4 files changed

+85
-46
lines changed

CMakeLists.txt

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,6 @@ setup_split_debug_script()
462462
add_maintenance_targets()
463463
add_windows_deploy_target()
464464

465-
include(GetTargetInterface)
466-
get_target_interface(definitions core_interface COMPILE_DEFINITIONS)
467-
separate_by_configs(definitions)
468-
469465
message("\n")
470466
message("Configure summary")
471467
message("=================")
@@ -494,28 +490,17 @@ message(" test_bitcoin-qt ..................... ${BUILD_GUI_TESTS}")
494490
message(" bench_bitcoin ....................... ${BUILD_BENCH}")
495491
message(" fuzz binary ......................... ${BUILD_FUZZ_BINARY}")
496492
message("")
493+
497494
if(CMAKE_CROSSCOMPILING)
498495
set(cross_status "TRUE, for ${CMAKE_SYSTEM_NAME}, ${CMAKE_SYSTEM_PROCESSOR}")
499496
else()
500497
set(cross_status "FALSE")
501498
endif()
502499
message("Cross compiling ....................... ${cross_status}")
503-
message("Preprocessor defined macros ........... ${definitions_ALL}")
504-
message("C compiler ............................ ${CMAKE_C_COMPILER}")
505-
list(JOIN DEPENDS_C_COMPILER_FLAGS " " depends_c_flags)
506-
string(STRIP "${CMAKE_C_FLAGS} ${depends_c_flags}" combined_c_flags)
507-
message("CFLAGS ................................ ${combined_c_flags}")
508-
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER}")
509-
list(JOIN DEPENDS_CXX_COMPILER_FLAGS " " depends_cxx_flags)
510-
string(STRIP "${CMAKE_CXX_FLAGS} ${depends_cxx_flags}" combined_cxx_flags)
511-
message("CXXFLAGS .............................. ${combined_cxx_flags}")
512-
get_target_interface(common_compile_options core_interface COMPILE_OPTIONS)
513-
message("Common compile options ................ ${common_compile_options}")
514-
get_target_interface(common_link_options core_interface LINK_OPTIONS)
515-
message("Common link options ................... ${common_link_options}")
516-
message("Linker flags for executables .......... ${CMAKE_EXE_LINKER_FLAGS}")
517-
message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}")
518-
print_config_flags()
500+
message("C compiler ............................ ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}, ${CMAKE_C_COMPILER}")
501+
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, ${CMAKE_CXX_COMPILER}")
502+
include(FlagsSummary)
503+
flags_summary()
519504
message("Attempt to harden executables ......... ${HARDENING}")
520505
message("Treat compiler warnings as errors ..... ${WERROR}")
521506
message("Use ccache for compiling .............. ${CCACHE}")

cmake/module/FlagsSummary.cmake

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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(normalize_preprocessor_definitions definitions)
8+
if(MSVC)
9+
set(flag "/D")
10+
else()
11+
set(flag "-D")
12+
endif()
13+
separate_arguments(${definitions})
14+
set(result "")
15+
foreach(d IN LISTS ${definitions})
16+
if(NOT d)
17+
continue()
18+
endif()
19+
if(NOT d MATCHES "${flag}.*")
20+
string(PREPEND d "${flag}")
21+
endif()
22+
string(STRIP "${result} ${d}" result)
23+
endforeach()
24+
set(${definitions} "${result}" PARENT_SCOPE)
25+
endfunction()
26+
27+
macro(print_flags_per_config config indent dots)
28+
string(TOUPPER "${config}" config_uppercase)
29+
30+
string(STRIP "${definitions_ALL} ${definitions_${config_uppercase}}" combined_cpp_flags)
31+
normalize_preprocessor_definitions(combined_cpp_flags)
32+
message("${indent}" "Preprocessor defined macros .........${dots} ${combined_cpp_flags}")
33+
34+
string(STRIP "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${config_uppercase}}" combined_c_flags)
35+
string(STRIP "${combined_c_flags} ${depends_c_flags}" combined_c_flags)
36+
string(STRIP "${combined_c_flags} ${common_compile_options}" combined_c_flags)
37+
message("${indent}" "C compiler flags ....................${dots} ${combined_c_flags}")
38+
39+
string(STRIP "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${config_uppercase}}" combined_cxx_flags)
40+
string(STRIP "${combined_cxx_flags} ${depends_cxx_flags}" combined_cxx_flags)
41+
string(STRIP "${combined_cxx_flags} ${common_compile_options}" combined_cxx_flags)
42+
message("${indent}" "C++ compiler flags ..................${dots} ${combined_cxx_flags}")
43+
endmacro()
44+
45+
function(flags_summary)
46+
include(GetTargetInterface)
47+
get_target_interface(definitions core_interface COMPILE_DEFINITIONS)
48+
include(ProcessConfigurations)
49+
separate_by_configs(definitions)
50+
51+
list(JOIN DEPENDS_C_COMPILER_FLAGS " " depends_c_flags)
52+
list(JOIN DEPENDS_CXX_COMPILER_FLAGS " " depends_cxx_flags)
53+
get_target_interface(common_compile_options core_interface COMPILE_OPTIONS)
54+
55+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
56+
if(is_multi_config)
57+
list(JOIN CMAKE_CONFIGURATION_TYPES ", " configs)
58+
message("Available build configurations ........ ${configs}")
59+
if(CMAKE_GENERATOR MATCHES "Visual Studio")
60+
set(default_config "Debug")
61+
else()
62+
list(GET CMAKE_CONFIGURATION_TYPES 0 default_config)
63+
endif()
64+
message("Default build configuration ........... ${default_config}")
65+
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
66+
message("'${config}' build configuration:")
67+
print_flags_per_config(${config} " " "")
68+
endforeach()
69+
else()
70+
message("Build configuration ................... ${CMAKE_BUILD_TYPE}")
71+
print_flags_per_config(${CMAKE_BUILD_TYPE} "" "..")
72+
endif()
73+
74+
get_target_interface(common_link_options core_interface LINK_OPTIONS)
75+
string(STRIP "${CMAKE_EXE_LINKER_FLAGS} ${common_link_options}" combined_linker_flags)
76+
message("Linker flags .......................... ${combined_linker_flags}")
77+
endfunction()

cmake/module/ProcessConfigurations.cmake

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,3 @@ function(separate_by_configs options)
106106
set(${options}_${conf_upper} "${match}" PARENT_SCOPE)
107107
endforeach()
108108
endfunction()
109-
110-
function(print_config_flags)
111-
macro(print_flags config)
112-
string(TOUPPER "${config}" config_uppercase)
113-
message(" - Preprocessor defined macros ........ ${definitions_${config_uppercase}}")
114-
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_${config_uppercase}}")
115-
message(" - CXXFLAGS ........................... ${CMAKE_CXX_FLAGS_${config_uppercase}}")
116-
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_${config_uppercase}}")
117-
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_${config_uppercase}}")
118-
endmacro()
119-
120-
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
121-
if(is_multi_config)
122-
list(JOIN CMAKE_CONFIGURATION_TYPES " " configs)
123-
message("Available build types (configurations) ${configs}")
124-
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
125-
message("'${config}' build type (configuration):")
126-
print_flags(${config})
127-
endforeach()
128-
else()
129-
message("Build type (configuration):")
130-
message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}")
131-
print_flags(${CMAKE_BUILD_TYPE})
132-
endif()
133-
endfunction()

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ include(GNUInstallDirs)
66
include(AddWindowsResources)
77

88
configure_file(${CMAKE_SOURCE_DIR}/cmake/bitcoin-config.h.in config/bitcoin-config.h @ONLY)
9-
add_compile_definitions(HAVE_CONFIG_H)
9+
target_compile_definitions(core_interface INTERFACE
10+
HAVE_CONFIG_H
11+
)
1012
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
1113

1214
# After the transition from Autotools to CMake, the obj/ subdirectory

0 commit comments

Comments
 (0)