Skip to content

Commit 7903bd5

Browse files
committed
[FIXUP] Encapsulate common build flags into core interface library
1 parent 46da0cf commit 7903bd5

File tree

13 files changed

+66
-10
lines changed

13 files changed

+66
-10
lines changed

CMakeLists.txt

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ 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+
8387
if(WIN32)
8488
#[=[
8589
This build system supports two ways to build binaries for Windows.
@@ -97,25 +101,39 @@ if(WIN32)
97101
- A run-time library must be specified explicitly using _MT definition.
98102
]=]
99103

100-
add_compile_definitions(_WIN32_WINNT=0x0601 _WIN32_IE=0x0501 WIN32_LEAN_AND_MEAN NOMINMAX)
104+
target_compile_definitions(core INTERFACE
105+
_WIN32_WINNT=0x0601
106+
_WIN32_IE=0x0501
107+
WIN32_LEAN_AND_MEAN
108+
NOMINMAX
109+
)
101110

102111
if(MSVC)
103112
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
104-
add_compile_options(/utf-8 /Zc:__cplusplus)
113+
target_compile_options(core INTERFACE
114+
/utf-8
115+
/Zc:__cplusplus
116+
)
105117
# Improve parallelism in MSBuild.
106118
# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.
107119
list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true")
108120
endif()
109121

110122
if(MINGW)
111-
add_compile_definitions(WIN32 _WINDOWS _MT)
123+
target_compile_definitions(core INTERFACE
124+
WIN32
125+
_WINDOWS
126+
_MT
127+
)
112128
# We require Windows 7 (NT 6.1) or later.
113129
add_link_options(-Wl,--major-subsystem-version,6 -Wl,--minor-subsystem-version,1)
114130
endif()
115131
endif()
116132

117133
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
118-
add_compile_definitions(MAC_OSX)
134+
target_compile_definitions(core INTERFACE
135+
MAC_OSX
136+
)
119137
endif()
120138

121139
if(CMAKE_CROSSCOMPILING AND DEPENDS_ALLOW_HOST_PACKAGES)
@@ -197,11 +215,20 @@ message("C compiler ............................ ${CMAKE_C_COMPILER}")
197215
message("CFLAGS ................................ ${CMAKE_C_FLAGS}")
198216
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER}")
199217
message("CXXFLAGS .............................. ${CMAKE_CXX_FLAGS}")
200-
get_directory_property(common_compile_options COMPILE_OPTIONS)
201-
string(REPLACE ";" " " common_compile_options "${common_compile_options}")
218+
get_target_property(common_compile_options core INTERFACE_COMPILE_OPTIONS)
219+
if(common_compile_options)
220+
list(JOIN common_compile_options " " common_compile_options)
221+
else()
222+
set(common_compile_options)
223+
endif()
224+
string(GENEX_STRIP "${common_compile_options}" common_compile_options)
202225
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}")
226+
get_target_property(common_link_options core INTERFACE_LINK_OPTIONS)
227+
if(common_link_options)
228+
list(JOIN common_link_options " " common_link_options)
229+
else()
230+
set(common_link_options)
231+
endif()
205232
message("Common link options ................... ${common_link_options}")
206233
if(DEFINED CMAKE_BUILD_TYPE)
207234
message("Build type:")

cmake/crc32c.cmake

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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)

cmake/secp256k1.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ target_compile_options(secp256k1
5050
PRIVATE
5151
$<$<CXX_COMPILER_ID:MSVC>:/wd4146 /wd4334>
5252
)
53+
54+
target_link_libraries(secp256k1 PRIVATE core)

src/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ add_library(bitcoin_consensus OBJECT EXCLUDE_FROM_ALL
2727
uint256.cpp
2828
util/strencodings.cpp
2929
)
30-
target_link_libraries(bitcoin_consensus PRIVATE secp256k1)
30+
target_link_libraries(bitcoin_consensus
31+
PRIVATE
32+
core
33+
secp256k1
34+
)
3135

3236
if(WITH_ZMQ)
3337
add_subdirectory(zmq EXCLUDE_FROM_ALL)
@@ -86,6 +90,7 @@ target_compile_definitions(bitcoin_common
8690
)
8791
target_link_libraries(bitcoin_common
8892
PRIVATE
93+
core
8994
bitcoin_consensus
9095
bitcoin_util
9196
univalue
@@ -105,6 +110,7 @@ if(ENABLE_WALLET)
105110
wallet/wallettool.cpp
106111
)
107112
target_link_libraries(bitcoin-wallet
113+
core
108114
bitcoin_wallet
109115
bitcoin_common
110116
bitcoin_util
@@ -211,6 +217,7 @@ else()
211217
endif()
212218
target_link_libraries(bitcoin_node
213219
PRIVATE
220+
core
214221
bitcoin_common
215222
bitcoin_util
216223
leveldb
@@ -233,6 +240,7 @@ if(BUILD_DAEMON)
233240
)
234241
target_link_libraries(bitcoind
235242
PRIVATE
243+
core
236244
bitcoin_node
237245
)
238246
target_link_options(bitcoind
@@ -248,6 +256,7 @@ add_library(bitcoin_cli STATIC EXCLUDE_FROM_ALL
248256
)
249257
target_link_libraries(bitcoin_cli
250258
PUBLIC
259+
core
251260
univalue
252261
)
253262

@@ -256,6 +265,7 @@ target_link_libraries(bitcoin_cli
256265
if(BUILD_CLI)
257266
add_executable(bitcoin-cli bitcoin-cli.cpp)
258267
target_link_libraries(bitcoin-cli
268+
core
259269
bitcoin_cli
260270
bitcoin_common
261271
bitcoin_util
@@ -267,6 +277,7 @@ endif()
267277
if(BUILD_TX)
268278
add_executable(bitcoin-tx bitcoin-tx.cpp)
269279
target_link_libraries(bitcoin-tx
280+
core
270281
bitcoin_common
271282
bitcoin_util
272283
univalue
@@ -277,6 +288,7 @@ endif()
277288
if(BUILD_UTIL)
278289
add_executable(bitcoin-util bitcoin-util.cpp)
279290
target_link_libraries(bitcoin-util
291+
core
280292
bitcoin_common
281293
bitcoin_util
282294
)

src/bench/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ add_executable(bench_bitcoin
4949
)
5050

5151
target_link_libraries(bench_bitcoin
52+
core
5253
test_util
5354
leveldb
5455
univalue

src/crypto/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,5 @@ if(HAVE_ARM_SHANI)
120120
APPEND PROPERTY COMPILE_OPTIONS ${ARM_SHANI_CXXFLAGS}
121121
)
122122
endif()
123+
124+
target_link_libraries(bitcoin_crypto PRIVATE core)

src/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ add_executable(test_bitcoin
134134
)
135135

136136
target_link_libraries(test_bitcoin
137+
core
137138
test_util
138139
bitcoin_cli
139140
bitcoin_node

src/test/util/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ add_library(test_util STATIC EXCLUDE_FROM_ALL
1919
)
2020
target_link_libraries(test_util
2121
PRIVATE
22+
core
2223
bitcoin_common
2324
bitcoin_node
2425
leveldb
@@ -32,3 +33,5 @@ if(ENABLE_WALLET)
3233
../../wallet/test/util.cpp
3334
)
3435
endif()
36+
37+
target_link_libraries(test_util PRIVATE core)

0 commit comments

Comments
 (0)