-
Notifications
You must be signed in to change notification settings - Fork 1.1k
cmake: Rework flags summary #1558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hebasto
wants to merge
2
commits into
bitcoin-core:master
Choose a base branch
from
hebasto:240628-cmake-summary
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,87 @@ | ||
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() | ||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
string(STRIP "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${linker_flags}" linker_flags) | ||
get_target_property(soversion secp256k1 SOVERSION) | ||
string(STRIP "${linker_flags} ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG}${PROJECT_NAME}.so.${soversion}" linker_flags) | ||
endif() | ||
if(APPLE) | ||
get_target_property(compatibility_version secp256k1 MACHO_COMPATIBILITY_VERSION) | ||
if(compatibility_version) | ||
string(STRIP "${linker_flags} ${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}${compatibility_version}" linker_flags) | ||
endif() | ||
get_target_property(current_version secp256k1 MACHO_CURRENT_VERSION) | ||
if(compatibility_version) | ||
string(STRIP "${linker_flags} ${CMAKE_C_OSX_CURRENT_VERSION_FLAG}${current_version}" linker_flags) | ||
endif() | ||
endif() | ||
indent_message("Linker flags .........................." "${linker_flags}" ${indent_num}) | ||
else() | ||
string(REGEX REPLACE "(^| )<[^ ]*>( |$)" "" archiver_options "${CMAKE_C_ARCHIVE_CREATE}") | ||
string(STRIP "${archiver_options} ${CMAKE_STATIC_LINKER_FLAGS}" archiver_options) | ||
string(STRIP "${archiver_options} ${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() |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.