|
| 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) |
| 21 | + string(APPEND c_compiler_flags " ${CMAKE_C_COMPILE_OPTIONS_PIC}") |
| 22 | + endif() |
| 23 | + if(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 "${c_language_flags} ${CMAKE_SHARED_LINKER_FLAGS}" linker_flags) |
| 34 | + string(STRIP "${linker_flags} ${CMAKE_SHARED_LINKER_FLAGS_${config_uppercase}}" linker_flags) |
| 35 | + if(pic) |
| 36 | + string(PREPEND linker_flags "${CMAKE_C_COMPILE_OPTIONS_PIC} ") |
| 37 | + endif() |
| 38 | + indent_message("Linker flags .........................." "${linker_flags}" ${indent_num}) |
| 39 | + else() |
| 40 | + string(STRIP "${CMAKE_STATIC_LINKER_FLAGS} ${CMAKE_STATIC_LINKER_FLAGS_${config_uppercase}}" archiver_options) |
| 41 | + indent_message("Archiver options ......................" "${archiver_options}" ${indent_num}) |
| 42 | + endif() |
| 43 | +endfunction() |
| 44 | + |
| 45 | +function(flags_summary) |
| 46 | + get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) |
| 47 | + if(is_multi_config) |
| 48 | + list(JOIN CMAKE_CONFIGURATION_TYPES ", " configs) |
| 49 | + message("Available build configurations ........ ${configs}") |
| 50 | + if(CMAKE_GENERATOR MATCHES "Visual Studio") |
| 51 | + set(default_config "Debug") |
| 52 | + else() |
| 53 | + list(GET CMAKE_CONFIGURATION_TYPES 0 default_config) |
| 54 | + endif() |
| 55 | + message("Default build configuration ........... ${default_config}") |
| 56 | + foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES) |
| 57 | + message("") |
| 58 | + message("'${config}' build configuration:") |
| 59 | + print_flags_per_config(${config} 2) |
| 60 | + endforeach() |
| 61 | + else() |
| 62 | + message("CMAKE_BUILD_TYPE ...................... ${CMAKE_BUILD_TYPE}") |
| 63 | + print_flags_per_config(${CMAKE_BUILD_TYPE} 0) |
| 64 | + endif() |
| 65 | + message("") |
| 66 | + message([=[ |
| 67 | +NOTE: The summary above may not exactly match the final applied build flags |
| 68 | + if any additional CMAKE_* or environment variables have been modified. |
| 69 | + To see the exact flags applied, build with the --verbose option. |
| 70 | +]=]) |
| 71 | +endfunction() |
0 commit comments