|
| 1 | +include_guard(GLOBAL) |
| 2 | + |
| 3 | +function(indent_message header content indent_num) |
| 4 | + if(indent_num GREATER 0) |
| 5 | + string(REPEAT " " ${indent_num} indentation) |
| 6 | + string(REPEAT "." ${indent_num} tail) |
| 7 | + string(REGEX REPLACE "${tail}$" "" header "${header}") |
| 8 | + endif() |
| 9 | + message("${indentation}${header} ${content}") |
| 10 | +endfunction() |
| 11 | + |
| 12 | +# Print tools' flags on best-effort. Include the abstracted |
| 13 | +# CMake flags that we touch ourselves. |
| 14 | +function(print_flags_per_config config indent_num) |
| 15 | + string(TOUPPER "${config}" config_uppercase) |
| 16 | + |
| 17 | + string(STRIP "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${config_uppercase}}" c_language_flags) |
| 18 | + string(STRIP "${c_language_flags} ${CMAKE_C${CMAKE_C_STANDARD}_STANDARD_COMPILE_OPTION}" c_compiler_flags) |
| 19 | + get_target_property(pic secp256k1 POSITION_INDEPENDENT_CODE) |
| 20 | + if(pic AND CMAKE_C_COMPILE_OPTIONS_PIC) |
| 21 | + string(APPEND c_compiler_flags " ${CMAKE_C_COMPILE_OPTIONS_PIC}") |
| 22 | + endif() |
| 23 | + if(CMAKE_C_COMPILE_OPTIONS_VISIBILITY AND CMAKE_C_VISIBILITY_PRESET) |
| 24 | + string(APPEND c_compiler_flags " ${CMAKE_C_COMPILE_OPTIONS_VISIBILITY}${CMAKE_C_VISIBILITY_PRESET}") |
| 25 | + endif() |
| 26 | + get_directory_property(compile_options COMPILE_OPTIONS) |
| 27 | + list(JOIN compile_options " " compile_options) |
| 28 | + string(STRIP "${c_compiler_flags} ${compile_options}" c_compiler_flags) |
| 29 | + string(STRIP "${c_compiler_flags} ${SECP256K1_APPEND_CFLAGS}" c_compiler_flags) |
| 30 | + indent_message("C compiler flags ......................" "${c_compiler_flags}" ${indent_num}) |
| 31 | + |
| 32 | + if(BUILD_SHARED_LIBS) |
| 33 | + string(STRIP "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_${config_uppercase}}" linker_flags) |
| 34 | + if(NOT MSVC) |
| 35 | + string(STRIP "${c_language_flags} ${linker_flags}" linker_flags) |
| 36 | + endif() |
| 37 | + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 38 | + string(STRIP "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${linker_flags}" linker_flags) |
| 39 | + get_target_property(soversion secp256k1 SOVERSION) |
| 40 | + string(STRIP "${linker_flags} ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG}${PROJECT_NAME}.so.${soversion}" linker_flags) |
| 41 | + endif() |
| 42 | + if(APPLE) |
| 43 | + get_target_property(compatibility_version secp256k1 MACHO_COMPATIBILITY_VERSION) |
| 44 | + if(compatibility_version) |
| 45 | + string(STRIP "${linker_flags} ${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}${compatibility_version}" linker_flags) |
| 46 | + endif() |
| 47 | + get_target_property(current_version secp256k1 MACHO_CURRENT_VERSION) |
| 48 | + if(compatibility_version) |
| 49 | + string(STRIP "${linker_flags} ${CMAKE_C_OSX_CURRENT_VERSION_FLAG}${current_version}" linker_flags) |
| 50 | + endif() |
| 51 | + endif() |
| 52 | + indent_message("Linker flags .........................." "${linker_flags}" ${indent_num}) |
| 53 | + else() |
| 54 | + string(REGEX REPLACE "(^| )<[^ ]*>( |$)" "" archiver_options "${CMAKE_C_ARCHIVE_CREATE}") |
| 55 | + string(STRIP "${archiver_options} ${CMAKE_STATIC_LINKER_FLAGS}" archiver_options) |
| 56 | + string(STRIP "${archiver_options} ${CMAKE_STATIC_LINKER_FLAGS_${config_uppercase}}" archiver_options) |
| 57 | + indent_message("Archiver options ......................" "${archiver_options}" ${indent_num}) |
| 58 | + endif() |
| 59 | +endfunction() |
| 60 | + |
| 61 | +function(flags_summary) |
| 62 | + get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) |
| 63 | + if(is_multi_config) |
| 64 | + list(JOIN CMAKE_CONFIGURATION_TYPES ", " configs) |
| 65 | + message("Available build configurations ........ ${configs}") |
| 66 | + if(CMAKE_GENERATOR MATCHES "Visual Studio") |
| 67 | + set(default_config "Debug") |
| 68 | + else() |
| 69 | + list(GET CMAKE_CONFIGURATION_TYPES 0 default_config) |
| 70 | + endif() |
| 71 | + message("Default build configuration ........... ${default_config}") |
| 72 | + foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES) |
| 73 | + message("") |
| 74 | + message("'${config}' build configuration:") |
| 75 | + print_flags_per_config("${config}" 2) |
| 76 | + endforeach() |
| 77 | + else() |
| 78 | + message("CMAKE_BUILD_TYPE ...................... ${CMAKE_BUILD_TYPE}") |
| 79 | + print_flags_per_config("${CMAKE_BUILD_TYPE}" 0) |
| 80 | + endif() |
| 81 | + message("") |
| 82 | + message([=[ |
| 83 | +NOTE: The summary above may not exactly match the final applied build flags |
| 84 | + if any additional CMAKE_* or environment variables have been modified. |
| 85 | + To see the exact flags applied, build with the --verbose option. |
| 86 | +]=]) |
| 87 | +endfunction() |
0 commit comments