|
| 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() |
0 commit comments