forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXUP] cmake: Rework compile/link flags summary
- Loading branch information
Showing
4 changed files
with
121 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (c) 2024-present The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or https://opensource.org/license/mit/. | ||
|
||
include_guard(GLOBAL) | ||
|
||
function(indent_message header content indent_num) | ||
if(indent_num GREATER 0) | ||
string(REPEAT " " ${indent_num} indentation) | ||
string(REPEAT "\\." ${indent_num} dots) | ||
string(REGEX REPLACE "${dots}$" "" header "${header}") | ||
endif() | ||
message("${indentation}" "${header} ${content}") | ||
endfunction() | ||
|
||
function(print_flags_per_config config indent_num) | ||
string(TOUPPER "${config}" config_uppercase) | ||
|
||
include(GetTargetInterface) | ||
get_target_interface(definitions ${config} core_interface COMPILE_DEFINITIONS) | ||
indent_message("Preprocessor defined macros ..........." "${definitions}" ${indent_num}) | ||
|
||
string(STRIP "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${config_uppercase}}" combined_c_flags) | ||
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION) | ||
string(JOIN " " combined_c_flags ${combined_c_flags} ${CMAKE_C_COMPILE_OPTIONS_IPO}) | ||
endif() | ||
if(CMAKE_POSITION_INDEPENDENT_CODE) | ||
string(JOIN " " combined_c_flags ${combined_c_flags} ${CMAKE_C_COMPILE_OPTIONS_PIC}) | ||
endif() | ||
get_target_interface(core_c_flags ${config} core_base_interface COMPILE_OPTIONS) | ||
string(STRIP "${combined_c_flags} ${core_c_flags}" combined_c_flags) | ||
string(STRIP "${combined_c_flags} ${APPEND_CPPFLAGS}" combined_c_flags) | ||
string(STRIP "${combined_c_flags} ${APPEND_CFLAGS}" combined_c_flags) | ||
indent_message("C flags ..............................." "${combined_c_flags}" ${indent_num}) | ||
|
||
string(STRIP "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${config_uppercase}}" combined_cxx_flags) | ||
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION) | ||
string(JOIN " " combined_cxx_flags ${combined_cxx_flags} ${CMAKE_CXX_COMPILE_OPTIONS_IPO}) | ||
endif() | ||
if(CMAKE_POSITION_INDEPENDENT_CODE) | ||
string(JOIN " " combined_cxx_flags ${combined_cxx_flags} ${CMAKE_CXX_COMPILE_OPTIONS_PIC}) | ||
endif() | ||
get_target_interface(core_cxx_flags ${config} core_interface COMPILE_OPTIONS) | ||
string(STRIP "${combined_cxx_flags} ${core_cxx_flags}" combined_cxx_flags) | ||
string(STRIP "${combined_cxx_flags} ${APPEND_CPPFLAGS}" combined_cxx_flags) | ||
string(STRIP "${combined_cxx_flags} ${APPEND_CXXFLAGS}" combined_cxx_flags) | ||
indent_message("C++ flags ............................." "${combined_cxx_flags}" ${indent_num}) | ||
|
||
string(STRIP "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${config_uppercase}}" combined_linker_flags) | ||
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION) | ||
string(JOIN " " combined_linker_flags ${combined_linker_flags} ${CMAKE_CXX_COMPILE_OPTIONS_IPO}) | ||
endif() | ||
string(STRIP "${combined_linker_flags} ${CMAKE_EXE_LINKER_FLAGS}" combined_linker_flags) | ||
get_target_interface(common_link_options ${config} core_interface LINK_OPTIONS) | ||
string(STRIP "${combined_linker_flags} ${common_link_options}" combined_linker_flags) | ||
if(CMAKE_CXX_LINK_PIE_SUPPORTED) | ||
string(JOIN " " combined_linker_flags ${combined_linker_flags} ${CMAKE_CXX_LINK_OPTIONS_PIE}) | ||
endif() | ||
string(STRIP "${combined_linker_flags} ${APPEND_LDFLAGS}" combined_linker_flags) | ||
indent_message("Linker flags .........................." "${combined_linker_flags}" ${indent_num}) | ||
endfunction() | ||
|
||
function(flags_summary) | ||
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) | ||
if(is_multi_config) | ||
list(JOIN CMAKE_CONFIGURATION_TYPES ", " configs) | ||
message("Available build configurations ........ ${configs}") | ||
if(CMAKE_GENERATOR MATCHES "Visual Studio") | ||
set(default_config "Debug") | ||
else() | ||
list(GET CMAKE_CONFIGURATION_TYPES 0 default_config) | ||
endif() | ||
message("Default build configuration ........... ${default_config}") | ||
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES) | ||
message("\n'${config}' build configuration:") | ||
print_flags_per_config(${config} 2) | ||
endforeach() | ||
message("") | ||
else() | ||
message("CMAKE_BUILD_TYPE ...................... ${CMAKE_BUILD_TYPE}") | ||
print_flags_per_config(${CMAKE_BUILD_TYPE} 0) | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters