Skip to content

Commit 92e4391

Browse files
committed
Merge #18: build: Add CMake-based build system (8 of N)
a65da0d cmake: Redefine configuration flags (Hennadii Stepanov) 1a1dda5 [FIXUP] Evaluate flags set in depends _after_ config-specific flags (Hennadii Stepanov) 482e844 cmake: Warn about not encapsulated build properties (Hennadii Stepanov) 3736470 cmake: Add platform-specific flags (Hennadii Stepanov) e0621e9 cmake: Add `TryAppendLinkerFlag` module (Hennadii Stepanov) ae430cf cmake: Add `TryAppendCXXFlags` module (Hennadii Stepanov) 7903bd5 [FIXUP] Encapsulate common build flags into `core` interface library (Hennadii Stepanov) Pull request description: The parent PR: bitcoin#25797. The previous PRs in the staging branch: #5, #6, #7, #10, #13, #15, #17, #19. --- What is NEW: - functions for checking compiler and linker flags - managing flags for different build types (configurations) EXAMPLES of configuration output on Ubuntu 22.04: - for a single-config generator: ``` $ cmake .. -G "Unix Makefiles" ... Cross compiling ....................... FALSE Preprocessor defined macros ........... C compiler ............................ /usr/bin/cc CFLAGS ................................ C++ compiler .......................... /usr/bin/c++ CXXFLAGS .............................. Common compile options ................ Common link options ................... Linker flags for executables .......... Linker flags for shared libraries ..... Build type (configuration): - CMAKE_BUILD_TYPE ................... RelWithDebInfo - Preprocessor defined macros ........ - CFLAGS ............................. -O2 -g - CXXFLAGS ........................... -O2 -g - LDFLAGS for executables ............ - LDFLAGS for shared libraries ....... Use assembly routines ................. ON Use ccache for compiling .............. ON ... ``` - for a multi-config generator: ``` $ cmake .. -G "Ninja Multi-Config" ... Cross compiling ....................... FALSE Preprocessor defined macros ........... C compiler ............................ /usr/bin/cc CFLAGS ................................ C++ compiler .......................... /usr/bin/c++ CXXFLAGS .............................. Common compile options ................ Common link options ................... Linker flags for executables .......... Linker flags for shared libraries ..... Available build types (configurations) RelWithDebInfo Debug Release 'RelWithDebInfo' build type (configuration): - Preprocessor defined macros ........ - CFLAGS ............................. -O2 -g - CXXFLAGS ........................... -O2 -g - LDFLAGS for executables ............ - LDFLAGS for shared libraries ....... 'Debug' build type (configuration): - Preprocessor defined macros ........ DEBUG DEBUG_LOCKORDER DEBUG_LOCKCONTENTION RPC_DOC_CHECK ABORT_ON_FAILED_ASSUME - CFLAGS ............................. -O0 -g3 - CXXFLAGS ........................... -O0 -g3 -ftrapv - LDFLAGS for executables ............ - LDFLAGS for shared libraries ....... 'Release' build type (configuration): - Preprocessor defined macros ........ - CFLAGS ............................. -O2 - CXXFLAGS ........................... -O2 - LDFLAGS for executables ............ - LDFLAGS for shared libraries ....... Use assembly routines ................. ON Use ccache for compiling .............. ON ... ``` - cross-compiling for Windows: ``` $ make -C depends HOST=x86_64-w64-mingw32 DEBUG=1 NO_QT=1 $ cmake -B build --toolchain depends/x86_64-w64-mingw32/share/toolchain.cmake -DCMAKE_BUILD_TYPE=Debug ... Cross compiling ....................... TRUE, for Windows, x86_64 Preprocessor defined macros ........... _WIN32_WINNT=0x0601 _WIN32_IE=0x0501 WIN32_LEAN_AND_MEAN NOMINMAX WIN32 _WINDOWS _MT _GLIBCXX_DEBUG _GLIBCXX_DEBUG_PEDANTIC C compiler ............................ /usr/bin/x86_64-w64-mingw32-gcc CFLAGS ................................ -pipe -std=c11 -O1 C++ compiler .......................... /usr/bin/x86_64-w64-mingw32-g++-posix CXXFLAGS .............................. -pipe -std=c++17 -O1 Common compile options ................ Common link options ................... -Wl,--major-subsystem-version,6 -Wl,--minor-subsystem-version,1 Linker flags for executables .......... -static Linker flags for shared libraries ..... Build type (configuration): - CMAKE_BUILD_TYPE ................... Debug - Preprocessor defined macros ........ DEBUG DEBUG_LOCKORDER DEBUG_LOCKCONTENTION RPC_DOC_CHECK ABORT_ON_FAILED_ASSUME - CFLAGS ............................. -O0 -g3 - CXXFLAGS ........................... -O0 -g3 -ftrapv - LDFLAGS for executables ............ - LDFLAGS for shared libraries ....... Use assembly routines ................. ON Use ccache for compiling .............. ON ... ``` **A cross-project note.** The `ProcessConfigurations.cmake` is based on the same module that was suggested in bitcoin-core/secp256k1#1291. So, cross-reviewing is welcome :) ACKs for top commit: theuni: ACK a65da0d to keep this moving. This has been sitting for too long :( Tree-SHA512: 57c5e91ddf9675c6a2b56c0cb70fd3f045af8076bee74c49390de38b8d514e130d2086fde6d83d2d1278b437d0a10cc721f0aa44934698110aeadb3a1aef9e64
2 parents 46da0cf + a65da0d commit 92e4391

17 files changed

+470
-59
lines changed

CMakeLists.txt

+128-36
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ set(CMAKE_CXX_EXTENSIONS OFF)
8080

8181
set(configure_warnings)
8282

83+
# The core interface library aims to encapsulate all common build flags.
84+
# It is intended to be a usage requirement for all other targets.
85+
add_library(core INTERFACE)
86+
87+
include(TryAppendCXXFlags)
88+
include(TryAppendLinkerFlag)
89+
8390
if(WIN32)
8491
#[=[
8592
This build system supports two ways to build binaries for Windows.
@@ -97,29 +104,63 @@ if(WIN32)
97104
- A run-time library must be specified explicitly using _MT definition.
98105
]=]
99106

100-
add_compile_definitions(_WIN32_WINNT=0x0601 _WIN32_IE=0x0501 WIN32_LEAN_AND_MEAN NOMINMAX)
107+
target_compile_definitions(core INTERFACE
108+
_WIN32_WINNT=0x0601
109+
_WIN32_IE=0x0501
110+
WIN32_LEAN_AND_MEAN
111+
NOMINMAX
112+
)
101113

102114
if(MSVC)
103115
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
104-
add_compile_options(/utf-8 /Zc:__cplusplus)
116+
target_compile_options(core INTERFACE
117+
/utf-8
118+
/Zc:__cplusplus
119+
)
105120
# Improve parallelism in MSBuild.
106121
# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.
107122
list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true")
108123
endif()
109124

110125
if(MINGW)
111-
add_compile_definitions(WIN32 _WINDOWS _MT)
126+
target_compile_definitions(core INTERFACE
127+
WIN32
128+
_WINDOWS
129+
_MT
130+
)
112131
# We require Windows 7 (NT 6.1) or later.
113-
add_link_options(-Wl,--major-subsystem-version,6 -Wl,--minor-subsystem-version,1)
132+
try_append_linker_flag(core "-Wl,--major-subsystem-version,6")
133+
try_append_linker_flag(core "-Wl,--minor-subsystem-version,1")
114134
endif()
115135
endif()
116136

137+
# Use 64-bit off_t on 32-bit Linux.
138+
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
139+
# Ensure 64-bit offsets are used for filesystem accesses for 32-bit compilation.
140+
target_compile_definitions(core INTERFACE
141+
_FILE_OFFSET_BITS=64
142+
)
143+
endif()
144+
117145
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
118-
add_compile_definitions(MAC_OSX)
146+
target_compile_definitions(core INTERFACE
147+
MAC_OSX
148+
)
149+
# These flags are specific to ld64, and may cause issues with other linkers.
150+
# For example: GNU ld will interpret -dead_strip as -de and then try and use
151+
# "ad_strip" as the symbol for the entry point.
152+
try_append_linker_flag(core "-Wl,-dead_strip")
153+
try_append_linker_flag(core "-Wl,-dead_strip_dylibs")
154+
try_append_linker_flag(core "-Wl,-headerpad_max_install_names")
119155
endif()
120156

121-
if(CMAKE_CROSSCOMPILING AND DEPENDS_ALLOW_HOST_PACKAGES)
122-
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_SYSTEM_PREFIX_PATH}")
157+
if(CMAKE_CROSSCOMPILING)
158+
target_compile_definitions(core INTERFACE ${DEPENDS_COMPILE_DEFINITIONS})
159+
target_compile_options(core INTERFACE "$<$<COMPILE_LANGUAGE:C>:${DEPENDS_C_COMPILER_FLAGS}>")
160+
target_compile_options(core INTERFACE "$<$<COMPILE_LANGUAGE:CXX>:${DEPENDS_CXX_COMPILER_FLAGS}>")
161+
if(DEPENDS_ALLOW_HOST_PACKAGES)
162+
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_SYSTEM_PREFIX_PATH}")
163+
endif()
123164
endif()
124165

125166
include(AddThreadsIfNeeded)
@@ -140,6 +181,47 @@ include(cmake/leveldb.cmake)
140181
include(cmake/minisketch.cmake)
141182
include(cmake/secp256k1.cmake)
142183

184+
include(ProcessConfigurations)
185+
set_default_config(RelWithDebInfo)
186+
187+
# Redefine configuration flags.
188+
target_compile_definitions(core INTERFACE
189+
$<$<CONFIG:Debug>:DEBUG>
190+
$<$<CONFIG:Debug>:DEBUG_LOCKORDER>
191+
$<$<CONFIG:Debug>:DEBUG_LOCKCONTENTION>
192+
$<$<CONFIG:Debug>:RPC_DOC_CHECK>
193+
$<$<CONFIG:Debug>:ABORT_ON_FAILED_ASSUME>
194+
)
195+
# We leave assertions on.
196+
if(MSVC)
197+
remove_c_flag_from_all_configs(/DNDEBUG)
198+
remove_cxx_flag_from_all_configs(/DNDEBUG)
199+
else()
200+
remove_c_flag_from_all_configs(-DNDEBUG)
201+
remove_cxx_flag_from_all_configs(-DNDEBUG)
202+
203+
# Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)
204+
replace_c_flag_in_config(Release -O3 -O2)
205+
replace_cxx_flag_in_config(Release -O3 -O2)
206+
207+
set(debug_c_flags "")
208+
set(debug_cxx_flags "")
209+
try_append_cxx_flags(debug_cxx_flags "-O0" RESULT_VAR compiler_supports_O0)
210+
if(compiler_supports_O0)
211+
string(STRIP "${debug_c_flags} -O0" debug_c_flags)
212+
endif()
213+
try_append_cxx_flags(debug_cxx_flags "-g3" RESULT_VAR compiler_supports_g3)
214+
if(compiler_supports_g3)
215+
string(STRIP "${debug_c_flags} -g3" debug_c_flags)
216+
else()
217+
try_append_cxx_flags(debug_cxx_flags "-g")
218+
string(STRIP "${debug_c_flags} -g" debug_c_flags)
219+
endif()
220+
try_append_cxx_flags(debug_cxx_flags "-ftrapv")
221+
set(CMAKE_C_FLAGS_DEBUG "${debug_c_flags}")
222+
set(CMAKE_CXX_FLAGS_DEBUG "${debug_cxx_flags}")
223+
endif()
224+
143225
include(cmake/optional.cmake)
144226

145227
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
@@ -163,6 +245,9 @@ add_subdirectory(test)
163245

164246
include(cmake/tests.cmake)
165247

248+
get_target_property(definitions core INTERFACE_COMPILE_DEFINITIONS)
249+
separate_by_configs(definitions)
250+
166251
message("\n")
167252
message("Configure summary")
168253
message("=================")
@@ -190,40 +275,33 @@ else()
190275
set(cross_status "FALSE")
191276
endif()
192277
message("Cross compiling ....................... ${cross_status}")
193-
get_directory_property(definitions COMPILE_DEFINITIONS)
194-
string(REPLACE ";" " " definitions "${definitions}")
195-
message("Preprocessor defined macros ........... ${definitions}")
278+
message("Preprocessor defined macros ........... ${definitions_ALL}")
196279
message("C compiler ............................ ${CMAKE_C_COMPILER}")
197-
message("CFLAGS ................................ ${CMAKE_C_FLAGS}")
280+
list(JOIN DEPENDS_C_COMPILER_FLAGS " " depends_c_flags)
281+
string(STRIP "${CMAKE_C_FLAGS} ${depends_c_flags}" combined_c_flags)
282+
message("CFLAGS ................................ ${combined_c_flags}")
198283
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER}")
199-
message("CXXFLAGS .............................. ${CMAKE_CXX_FLAGS}")
200-
get_directory_property(common_compile_options COMPILE_OPTIONS)
201-
string(REPLACE ";" " " common_compile_options "${common_compile_options}")
284+
list(JOIN DEPENDS_CXX_COMPILER_FLAGS " " depends_cxx_flags)
285+
string(STRIP "${CMAKE_CXX_FLAGS} ${depends_cxx_flags}" combined_cxx_flags)
286+
message("CXXFLAGS .............................. ${combined_cxx_flags}")
287+
get_target_property(common_compile_options core INTERFACE_COMPILE_OPTIONS)
288+
if(common_compile_options)
289+
list(JOIN common_compile_options " " common_compile_options)
290+
else()
291+
set(common_compile_options)
292+
endif()
293+
string(GENEX_STRIP "${common_compile_options}" common_compile_options)
202294
message("Common compile options ................ ${common_compile_options}")
203-
get_directory_property(common_link_options LINK_OPTIONS)
204-
string(REPLACE ";" " " common_link_options "${common_link_options}")
205-
message("Common link options ................... ${common_link_options}")
206-
if(DEFINED CMAKE_BUILD_TYPE)
207-
message("Build type:")
208-
message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}")
209-
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
210-
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_${build_type}}")
211-
message(" - CXXFLAGS ........................... ${CMAKE_CXX_FLAGS_${build_type}}")
212-
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_${build_type}}")
213-
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_${build_type}}")
295+
get_target_property(common_link_options core INTERFACE_LINK_OPTIONS)
296+
if(common_link_options)
297+
list(JOIN common_link_options " " common_link_options)
214298
else()
215-
message("Available configurations .............. ${CMAKE_CONFIGURATION_TYPES}")
216-
message("Debug configuration:")
217-
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_DEBUG}")
218-
message(" - CXXFLAGS ........................... ${CMAKE_CXX_FLAGS_DEBUG}")
219-
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
220-
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
221-
message("Release configuration:")
222-
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_RELEASE}")
223-
message(" - CXXFLAGS ........................... ${CMAKE_CXX_FLAGS_RELEASE}")
224-
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
225-
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
299+
set(common_link_options)
226300
endif()
301+
message("Common link options ................... ${common_link_options}")
302+
message("Linker flags for executables .......... ${CMAKE_EXE_LINKER_FLAGS}")
303+
message("Linker flags for shared libraries ..... ${CMAKE_SHARED_LINKER_FLAGS}")
304+
print_config_flags()
227305
message("Use assembly routines ................. ${ASM}")
228306
message("Use ccache for compiling .............. ${CCACHE}")
229307
message("\n")
@@ -234,3 +312,17 @@ if(configure_warnings)
234312
endforeach()
235313
message(" ******\n")
236314
endif()
315+
316+
# We want all build properties to be encapsulated properly.
317+
get_directory_property(global_compile_definitions COMPILE_DEFINITIONS)
318+
if(global_compile_definitions)
319+
message(AUTHOR_WARNING "The directory's COMPILE_DEFINITIONS property is not empty: ${global_compile_definitions}")
320+
endif()
321+
get_directory_property(global_compile_options COMPILE_OPTIONS)
322+
if(global_compile_options)
323+
message(AUTHOR_WARNING "The directory's COMPILE_OPTIONS property is not empty: ${global_compile_options}")
324+
endif()
325+
get_directory_property(global_link_options LINK_OPTIONS)
326+
if(global_link_options)
327+
message(AUTHOR_WARNING "The directory's LINK_OPTIONS property is not empty: ${global_link_options}")
328+
endif()

cmake/crc32c.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,5 @@ if(HAVE_ARM64_CRC32C)
111111
APPEND PROPERTY COMPILE_OPTIONS ${ARM_CRC_CXXFLAGS}
112112
)
113113
endif()
114+
115+
target_link_libraries(crc32c PRIVATE core)

cmake/leveldb.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ target_include_directories(leveldb
9191
#TODO: figure out how to filter out:
9292
# -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override
9393

94-
target_link_libraries(leveldb PRIVATE crc32c)
94+
target_link_libraries(leveldb PRIVATE core crc32c)

cmake/minisketch.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ target_link_libraries(minisketch
6969
minisketch_defs
7070
$<TARGET_NAME_IF_EXISTS:minisketch_clmul>
7171
)
72+
73+
target_link_libraries(minisketch_clmul PRIVATE core)
74+
target_link_libraries(minisketch PRIVATE core)
+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Copyright (c) 2023-present The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or https://opensource.org/license/mit/.
4+
5+
function(get_all_configs output)
6+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
7+
if(is_multi_config)
8+
set(all_configs ${CMAKE_CONFIGURATION_TYPES})
9+
else()
10+
get_property(all_configs CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS)
11+
if(NOT all_configs)
12+
# See https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#default-and-custom-configurations
13+
set(all_configs Debug Release RelWithDebInfo MinSizeRel)
14+
endif()
15+
endif()
16+
set(${output} "${all_configs}" PARENT_SCOPE)
17+
endfunction()
18+
19+
20+
#[=[
21+
Set the default build configuration.
22+
23+
See: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#build-configurations.
24+
25+
On single-configuration generators, this function sets the CMAKE_BUILD_TYPE variable to
26+
the default build configuration, which can be overridden by the user at configure time if needed.
27+
28+
On multi-configuration generators, this function rearranges the CMAKE_CONFIGURATION_TYPES list,
29+
ensuring that the default build configuration appears first while maintaining the order of the
30+
remaining configurations. The user can choose a build configuration at build time.
31+
]=]
32+
function(set_default_config config)
33+
get_all_configs(all_configs)
34+
if(NOT ${config} IN_LIST all_configs)
35+
message(FATAL_ERROR "The default config is \"${config}\", but must be one of ${all_configs}.")
36+
endif()
37+
38+
list(REMOVE_ITEM all_configs ${config})
39+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
40+
list(PREPEND all_configs ${config})
41+
else()
42+
set(all_configs ${config} ${all_configs})
43+
endif()
44+
45+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
46+
if(is_multi_config)
47+
get_property(help_string CACHE CMAKE_CONFIGURATION_TYPES PROPERTY HELPSTRING)
48+
set(CMAKE_CONFIGURATION_TYPES "${all_configs}" CACHE STRING "${help_string}" FORCE)
49+
else()
50+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
51+
STRINGS "${all_configs}"
52+
)
53+
if(NOT CMAKE_BUILD_TYPE)
54+
message(STATUS "Setting build type to \"${config}\" as none was specified")
55+
get_property(help_string CACHE CMAKE_BUILD_TYPE PROPERTY HELPSTRING)
56+
set(CMAKE_BUILD_TYPE "${config}" CACHE STRING "${help_string}" FORCE)
57+
endif()
58+
endif()
59+
endfunction()
60+
61+
function(remove_c_flag_from_all_configs flag)
62+
get_all_configs(all_configs)
63+
foreach(config IN LISTS all_configs)
64+
string(TOUPPER "${config}" config_uppercase)
65+
set(flags "${CMAKE_C_FLAGS_${config_uppercase}}")
66+
separate_arguments(flags)
67+
list(FILTER flags EXCLUDE REGEX "${flag}")
68+
list(JOIN flags " " new_flags)
69+
set(CMAKE_C_FLAGS_${config_uppercase} "${new_flags}" PARENT_SCOPE)
70+
endforeach()
71+
endfunction()
72+
73+
function(remove_cxx_flag_from_all_configs flag)
74+
get_all_configs(all_configs)
75+
foreach(config IN LISTS all_configs)
76+
string(TOUPPER "${config}" config_uppercase)
77+
set(flags "${CMAKE_CXX_FLAGS_${config_uppercase}}")
78+
separate_arguments(flags)
79+
list(FILTER flags EXCLUDE REGEX "${flag}")
80+
list(JOIN flags " " new_flags)
81+
set(CMAKE_CXX_FLAGS_${config_uppercase} "${new_flags}" PARENT_SCOPE)
82+
endforeach()
83+
endfunction()
84+
85+
function(replace_c_flag_in_config config old_flag new_flag)
86+
string(TOUPPER "${config}" config_uppercase)
87+
string(REGEX REPLACE "(^| )${old_flag}( |$)" "\\1${new_flag}\\2" new_flags "${CMAKE_C_FLAGS_${config_uppercase}}")
88+
set(CMAKE_C_FLAGS_${config_uppercase} "${new_flags}" PARENT_SCOPE)
89+
endfunction()
90+
91+
function(replace_cxx_flag_in_config config old_flag new_flag)
92+
string(TOUPPER "${config}" config_uppercase)
93+
string(REGEX REPLACE "(^| )${old_flag}( |$)" "\\1${new_flag}\\2" new_flags "${CMAKE_CXX_FLAGS_${config_uppercase}}")
94+
set(CMAKE_CXX_FLAGS_${config_uppercase} "${new_flags}" PARENT_SCOPE)
95+
endfunction()
96+
97+
function(separate_by_configs options)
98+
list(JOIN ${options} " " ${options}_ALL)
99+
string(GENEX_STRIP "${${options}_ALL}" ${options}_ALL)
100+
set(${options}_ALL "${${options}_ALL}" PARENT_SCOPE)
101+
102+
get_all_configs(all_configs)
103+
foreach(config IN LISTS all_configs)
104+
string(REGEX MATCHALL "\\$<\\$<CONFIG:${config}>[^\n]*>" match "${${options}}")
105+
list(JOIN match " " match)
106+
string(REPLACE "\$<\$<CONFIG:${config}>:" "" match "${match}")
107+
string(REPLACE ">" "" match "${match}")
108+
string(TOUPPER "${config}" conf_upper)
109+
set(${options}_${conf_upper} "${match}" PARENT_SCOPE)
110+
endforeach()
111+
endfunction()
112+
113+
function(print_config_flags)
114+
macro(print_flags config)
115+
string(TOUPPER "${config}" config_uppercase)
116+
message(" - Preprocessor defined macros ........ ${definitions_${config_uppercase}}")
117+
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_${config_uppercase}}")
118+
message(" - CXXFLAGS ........................... ${CMAKE_CXX_FLAGS_${config_uppercase}}")
119+
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_${config_uppercase}}")
120+
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_${config_uppercase}}")
121+
endmacro()
122+
123+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
124+
if(is_multi_config)
125+
list(JOIN CMAKE_CONFIGURATION_TYPES " " configs)
126+
message("Available build types (configurations) ${configs}")
127+
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
128+
message("'${config}' build type (configuration):")
129+
print_flags(${config})
130+
endforeach()
131+
else()
132+
message("Build type (configuration):")
133+
message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}")
134+
print_flags(${CMAKE_BUILD_TYPE})
135+
endif()
136+
endfunction()

0 commit comments

Comments
 (0)