diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e3465a75b..93b59c802d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -334,34 +334,11 @@ endif() message("Cross compiling ....................... ${cross_status}") message("Valgrind .............................. ${SECP256K1_VALGRIND}") get_directory_property(definitions COMPILE_DEFINITIONS) -string(REPLACE ";" " " definitions "${definitions}") +list(JOIN definitions " " definitions) message("Preprocessor defined macros ........... ${definitions}") message("C compiler ............................ ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}, ${CMAKE_C_COMPILER}") -message("CFLAGS ................................ ${CMAKE_C_FLAGS}") -get_directory_property(compile_options COMPILE_OPTIONS) -string(REPLACE ";" " " compile_options "${compile_options}") -message("Compile options ....................... " ${compile_options}) -if(NOT is_multi_config) - message("Build type:") - message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}") - string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type) - message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_${build_type}}") - message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_${build_type}}") - message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_${build_type}}") -else() - message("Supported configurations .............. ${CMAKE_CONFIGURATION_TYPES}") - message("RelWithDebInfo configuration:") - message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_RELWITHDEBINFO}") - message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") - message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}") - message("Debug configuration:") - message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_DEBUG}") - message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}") - message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") -endif() -if(SECP256K1_APPEND_CFLAGS) - message("SECP256K1_APPEND_CFLAGS ............... ${SECP256K1_APPEND_CFLAGS}") -endif() +include(FlagsSummary) +flags_summary() message("") if(print_msan_notice) message( diff --git a/cmake/FlagsSummary.cmake b/cmake/FlagsSummary.cmake new file mode 100644 index 0000000000..2cb68fcacc --- /dev/null +++ b/cmake/FlagsSummary.cmake @@ -0,0 +1,70 @@ +include_guard(GLOBAL) + +function(indent_message header content indent_num) + if(indent_num GREATER 0) + string(REPEAT " " ${indent_num} indentation) + string(REPEAT "." ${indent_num} tail) + string(REGEX REPLACE "${tail}$" "" header "${header}") + endif() + message("${indentation}${header} ${content}") +endfunction() + +# Print tools' flags on best-effort. Include the abstracted +# CMake flags that we touch ourselves. +function(print_flags_per_config config indent_num) + string(TOUPPER "${config}" config_uppercase) + + string(STRIP "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${config_uppercase}}" c_language_flags) + string(STRIP "${c_language_flags} ${CMAKE_C${CMAKE_C_STANDARD}_STANDARD_COMPILE_OPTION}" c_compiler_flags) + get_target_property(pic secp256k1 POSITION_INDEPENDENT_CODE) + if(pic AND CMAKE_C_COMPILE_OPTIONS_PIC) + string(APPEND c_compiler_flags " ${CMAKE_C_COMPILE_OPTIONS_PIC}") + endif() + if(CMAKE_C_COMPILE_OPTIONS_VISIBILITY AND CMAKE_C_VISIBILITY_PRESET) + string(APPEND c_compiler_flags " ${CMAKE_C_COMPILE_OPTIONS_VISIBILITY}${CMAKE_C_VISIBILITY_PRESET}") + endif() + get_directory_property(compile_options COMPILE_OPTIONS) + list(JOIN compile_options " " compile_options) + string(STRIP "${c_compiler_flags} ${compile_options}" c_compiler_flags) + string(STRIP "${c_compiler_flags} ${SECP256K1_APPEND_CFLAGS}" c_compiler_flags) + indent_message("C compiler flags ......................" "${c_compiler_flags}" ${indent_num}) + + if(BUILD_SHARED_LIBS) + string(STRIP "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_${config_uppercase}}" linker_flags) + if(NOT MSVC) + string(STRIP "${c_language_flags} ${linker_flags}" linker_flags) + endif() + indent_message("Linker flags .........................." "${linker_flags}" ${indent_num}) + else() + string(STRIP "${CMAKE_STATIC_LINKER_FLAGS} ${CMAKE_STATIC_LINKER_FLAGS_${config_uppercase}}" archiver_options) + indent_message("Archiver options ......................" "${archiver_options}" ${indent_num}) + endif() +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("") + message("'${config}' build configuration:") + print_flags_per_config(${config} 2) + endforeach() + else() + message("CMAKE_BUILD_TYPE ...................... ${CMAKE_BUILD_TYPE}") + print_flags_per_config(${CMAKE_BUILD_TYPE} 0) + endif() + message("") + message([=[ +NOTE: The summary above may not exactly match the final applied build flags + if any additional CMAKE_* or environment variables have been modified. + To see the exact flags applied, build with the --verbose option. +]=]) +endfunction()