forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXUP] cmake: Rework compile/link flags summary
- Loading branch information
Showing
4 changed files
with
163 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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 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,137 @@ | ||
# Copyright (c) 2024-present The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or https://opensource.org/license/mit/. | ||
|
||
include_guard(GLOBAL) | ||
|
||
function(get_flags_unix_makefiles preprocessor_defines_variable compiler_flags_variable linker_flags_variable) | ||
file(STRINGS ${CMAKE_BINARY_DIR}/${internal_binary_dir}/CMakeFiles/mock.dir/flags.make preprocessor_defines REGEX "^CXX_DEFINES( +)=") | ||
string(REGEX REPLACE "^CXX_DEFINES( +)=( +)" "" preprocessor_defines "${preprocessor_defines}") | ||
set(${preprocessor_defines_variable} "${preprocessor_defines}" PARENT_SCOPE) | ||
|
||
file(STRINGS ${CMAKE_BINARY_DIR}/${internal_binary_dir}/CMakeFiles/mock.dir/flags.make compiler_flags REGEX "^CXX_FLAGS( +)=") | ||
string(REGEX REPLACE "^CXX_FLAGS( +)=( +)" "" compiler_flags "${compiler_flags}") | ||
string(STRIP "${compiler_flags} ${APPEND_CPPFLAGS}" compiler_flags) | ||
string(STRIP "${compiler_flags} ${APPEND_CXXFLAGS}" compiler_flags) | ||
set(${compiler_flags_variable} "${compiler_flags}" PARENT_SCOPE) | ||
|
||
file(STRINGS ${CMAKE_BINARY_DIR}/${internal_binary_dir}/CMakeFiles/mock.dir/link.txt linker_flags LIMIT_COUNT 1) | ||
string(REPLACE "${CMAKE_CXX_COMPILER} " "" linker_flags "${linker_flags}") | ||
string(REPLACE " CMakeFiles/mock.dir/mock.cpp.o -o mock" "" linker_flags "${linker_flags}") | ||
set(${linker_flags_variable} "${linker_flags}" PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(get_flags_ninja preprocessor_defines_variable compiler_flags_variable linker_flags_variable config) | ||
if(config) | ||
cmake_path(APPEND CMAKE_BINARY_DIR ${internal_binary_dir} CMakeFiles impl-${config}.ninja OUTPUT_VARIABLE build_file) | ||
set(object_build_statement_re "^build CMakeFiles/mock\\.dir/${config}/mock\\.cpp\\.o: ") | ||
set(link_build_statement_re "^build ${config}/mock: ") | ||
else() | ||
cmake_path(APPEND CMAKE_BINARY_DIR ${internal_binary_dir} build.ninja OUTPUT_VARIABLE build_file) | ||
set(object_build_statement_re "^build CMakeFiles/mock\\.dir/mock\\.cpp\\.o: ") | ||
set(link_build_statement_re "^build mock: ") | ||
endif() | ||
file(STRINGS ${build_file} build_content) | ||
|
||
set(is_object_build_statement FALSE) | ||
foreach(line IN LISTS build_content) | ||
if(is_object_build_statement) | ||
if(line MATCHES "^( +)DEFINES( +)=") | ||
string(REGEX REPLACE "^( +)DEFINES( +)=( +)" "" preprocessor_defines "${line}") | ||
elseif(line MATCHES "^( +)FLAGS( +)=") | ||
string(REGEX REPLACE "^( +)FLAGS( +)=( +)" "" compiler_flags "${line}") | ||
elseif(line STREQUAL "") | ||
break() | ||
endif() | ||
elseif(line MATCHES ${object_build_statement_re}) | ||
set(is_object_build_statement TRUE) | ||
endif() | ||
endforeach() | ||
set(${preprocessor_defines_variable} "${preprocessor_defines}" PARENT_SCOPE) | ||
string(STRIP "${compiler_flags} ${APPEND_CPPFLAGS}" compiler_flags) | ||
string(STRIP "${compiler_flags} ${APPEND_CXXFLAGS}" compiler_flags) | ||
set(${compiler_flags_variable} "${compiler_flags}" PARENT_SCOPE) | ||
|
||
set(is_link_build_statement FALSE) | ||
foreach(line IN LISTS build_content) | ||
if(is_link_build_statement) | ||
if(line MATCHES "^( +)FLAGS( +)=") | ||
string(REGEX REPLACE "^( +)FLAGS( +)=( +)" "" flags "${line}") | ||
elseif(line MATCHES "^( +)LINK_FLAGS( +)=") | ||
string(REGEX REPLACE "^( +)LINK_FLAGS( +)=( +)" "" link_flags "${line}") | ||
elseif(line STREQUAL "") | ||
break() | ||
endif() | ||
elseif(line MATCHES ${link_build_statement_re}) | ||
set(is_link_build_statement TRUE) | ||
endif() | ||
endforeach() | ||
string(STRIP "${flags} ${link_flags}" linker_flags) | ||
string(STRIP "${linker_flags} ${APPEND_LDFLAGS}" linker_flags) | ||
set(${linker_flags_variable} "${linker_flags}" PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(flags_summary) | ||
if(INTERNAL_BUILD) | ||
file(WRITE ${PROJECT_BINARY_DIR}/mock.cpp "") | ||
add_executable(mock ${PROJECT_BINARY_DIR}/mock.cpp) | ||
target_link_libraries(mock PRIVATE core_interface) | ||
else() | ||
file(WRITE ${CMAKE_BINARY_DIR}/internal_build_cache "set(INTERNAL_BUILD ON CACHE BOOL \"\" FORCE)\n") | ||
get_cmake_property(cache_variable_names CACHE_VARIABLES) | ||
foreach (v ${cache_variable_names}) | ||
get_property(type CACHE ${v} PROPERTY TYPE) | ||
if(NOT type MATCHES "^(INTERNAL|STATIC)$") | ||
file(APPEND ${CMAKE_BINARY_DIR}/internal_build_cache "set(${v} \"$CACHE{${v}}\" CACHE ${type} \"\" FORCE)\n") | ||
endif() | ||
endforeach() | ||
|
||
string(RANDOM internal_binary_dir) | ||
|
||
# DEBUG ONLY | ||
set(internal_binary_dir "internal") | ||
|
||
execute_process( | ||
COMMAND ${CMAKE_COMMAND} -S${CMAKE_SOURCE_DIR} -B${CMAKE_BINARY_DIR}/${internal_binary_dir} -C${CMAKE_BINARY_DIR}/internal_build_cache -G${CMAKE_GENERATOR} | ||
OUTPUT_QUIET | ||
ERROR_QUIET | ||
) | ||
|
||
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:") | ||
if(CMAKE_GENERATOR STREQUAL "Ninja Multi-Config") | ||
get_flags_ninja(preprocessor_defines compiler_flags linker_flags ${config}) | ||
else() | ||
message("Printing build options is not supported for the generator \"${CMAKE_GENERATOR}\"") | ||
endif() | ||
message(" Preprocessor defined macros ......... ${preprocessor_defines}") | ||
message(" C++ flags ........................... ${compiler_flags}") | ||
message(" Linker flags ........................ ${linker_flags}") | ||
endforeach() | ||
message("") | ||
else() | ||
message("CMAKE_BUILD_TYPE ...................... ${CMAKE_BUILD_TYPE}") | ||
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") | ||
get_flags_unix_makefiles(preprocessor_defines compiler_flags linker_flags) | ||
elseif(CMAKE_GENERATOR STREQUAL "Ninja") | ||
get_flags_ninja(preprocessor_defines compiler_flags linker_flags "") | ||
else() | ||
message("Printing build options is not supported for the generator \"${CMAKE_GENERATOR}\"") | ||
endif() | ||
message("Preprocessor defined macros ........... ${preprocessor_defines}") | ||
message("C++ flags ............................. ${compiler_flags}") | ||
message("Linker flags .......................... ${linker_flags}") | ||
endif() | ||
endif() | ||
endfunction() |
This file was deleted.
Oops, something went wrong.
This file contains 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