Skip to content

Commit

Permalink
[FIXUP] Encapsulate common build flags into core interface library
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Sep 2, 2023
1 parent 3f513eb commit 622171f
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 11 deletions.
47 changes: 38 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ set(CMAKE_CXX_EXTENSIONS OFF)

set(configure_warnings)

# The core interface library aims to encapsulate all common build flags.
# It is intended to be a usage requirement for all other targets.
add_library(core INTERFACE)

if(WIN32)
#[=[
This build system supports two ways to build binaries for Windows.
Expand All @@ -97,22 +101,38 @@ if(WIN32)
- A run-time library must be specified explicitly using _MT definition.
]=]

add_compile_definitions(_WIN32_WINNT=0x0601 _WIN32_IE=0x0501 WIN32_LEAN_AND_MEAN NOMINMAX)
target_compile_definitions(core INTERFACE
_WIN32_WINNT=0x0601
_WIN32_IE=0x0501
WIN32_LEAN_AND_MEAN
NOMINMAX
)

if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
add_compile_options(/utf-8 /Zc:__cplusplus)
set_target_properties(core
PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
target_compile_options(core INTERFACE
/utf-8
/Zc:__cplusplus
)
endif()

if(MINGW)
add_compile_definitions(WIN32 _WINDOWS _MT)
target_compile_definitions(core INTERFACE
WIN32
_WINDOWS
_MT
)
# We require Windows 7 (NT 6.1) or later.
add_link_options(-Wl,--major-subsystem-version,6 -Wl,--minor-subsystem-version,1)
endif()
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_definitions(MAC_OSX)
target_compile_definitions(core INTERFACE
MAC_OSX
)
endif()

if(CMAKE_CROSSCOMPILING AND DEPENDS_ALLOW_HOST_PACKAGES)
Expand Down Expand Up @@ -194,11 +214,20 @@ message("C compiler ............................ ${CMAKE_C_COMPILER}")
message("CFLAGS ................................ ${CMAKE_C_FLAGS}")
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER}")
message("CXXFLAGS .............................. ${CMAKE_CXX_FLAGS}")
get_directory_property(common_compile_options COMPILE_OPTIONS)
string(REPLACE ";" " " common_compile_options "${common_compile_options}")
get_target_property(common_compile_options core INTERFACE_COMPILE_OPTIONS)
if(common_compile_options)
list(JOIN common_compile_options " " common_compile_options)
else()
set(common_compile_options)
endif()
string(GENEX_STRIP "${common_compile_options}" common_compile_options)
message("Common compile options ................ ${common_compile_options}")
get_directory_property(common_link_options LINK_OPTIONS)
string(REPLACE ";" " " common_link_options "${common_link_options}")
get_target_property(common_link_options core INTERFACE_LINK_OPTIONS)
if(common_link_options)
list(JOIN common_link_options " " common_link_options)
else()
set(common_link_options)
endif()
message("Common link options ................... ${common_link_options}")
if(DEFINED CMAKE_BUILD_TYPE)
message("Build type:")
Expand Down
2 changes: 2 additions & 0 deletions cmake/crc32c.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ if(HAVE_ARM64_CRC32C)
APPEND PROPERTY COMPILE_OPTIONS ${ARM_CRC_CXXFLAGS}
)
endif()

target_link_libraries(crc32c PRIVATE core)
2 changes: 1 addition & 1 deletion cmake/leveldb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ target_include_directories(leveldb
#TODO: figure out how to filter out:
# -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override

target_link_libraries(leveldb PRIVATE crc32c)
target_link_libraries(leveldb PRIVATE core crc32c)
3 changes: 3 additions & 0 deletions cmake/minisketch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ target_link_libraries(minisketch
minisketch_defs
$<TARGET_NAME_IF_EXISTS:minisketch_clmul>
)

target_link_libraries(minisketch_clmul PRIVATE core)
target_link_libraries(minisketch PRIVATE core)
2 changes: 2 additions & 0 deletions cmake/secp256k1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ target_compile_options(secp256k1
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/wd4146 /wd4334>
)

target_link_libraries(secp256k1 PRIVATE core)
14 changes: 13 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ add_library(bitcoin_consensus OBJECT EXCLUDE_FROM_ALL
uint256.cpp
util/strencodings.cpp
)
target_link_libraries(bitcoin_consensus PRIVATE secp256k1)
target_link_libraries(bitcoin_consensus
PRIVATE
core
secp256k1
)

if(WITH_ZMQ)
add_subdirectory(zmq EXCLUDE_FROM_ALL)
Expand Down Expand Up @@ -86,6 +90,7 @@ target_compile_definitions(bitcoin_common
)
target_link_libraries(bitcoin_common
PRIVATE
core
bitcoin_consensus
bitcoin_util
univalue
Expand All @@ -105,6 +110,7 @@ if(ENABLE_WALLET)
wallet/wallettool.cpp
)
target_link_libraries(bitcoin-wallet
core
bitcoin_wallet
bitcoin_common
bitcoin_util
Expand Down Expand Up @@ -211,6 +217,7 @@ else()
endif()
target_link_libraries(bitcoin_node
PRIVATE
core
bitcoin_common
bitcoin_util
leveldb
Expand All @@ -233,6 +240,7 @@ if(BUILD_DAEMON)
)
target_link_libraries(bitcoind
PRIVATE
core
bitcoin_node
)
target_link_options(bitcoind
Expand All @@ -248,6 +256,7 @@ add_library(bitcoin_cli STATIC EXCLUDE_FROM_ALL
)
target_link_libraries(bitcoin_cli
PUBLIC
core
univalue
)

Expand All @@ -256,6 +265,7 @@ target_link_libraries(bitcoin_cli
if(BUILD_CLI)
add_executable(bitcoin-cli bitcoin-cli.cpp)
target_link_libraries(bitcoin-cli
core
bitcoin_cli
bitcoin_common
bitcoin_util
Expand All @@ -267,6 +277,7 @@ endif()
if(BUILD_TX)
add_executable(bitcoin-tx bitcoin-tx.cpp)
target_link_libraries(bitcoin-tx
core
bitcoin_common
bitcoin_util
univalue
Expand All @@ -277,6 +288,7 @@ endif()
if(BUILD_UTIL)
add_executable(bitcoin-util bitcoin-util.cpp)
target_link_libraries(bitcoin-util
core
bitcoin_common
bitcoin_util
)
Expand Down
1 change: 1 addition & 0 deletions src/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ add_executable(bench_bitcoin
)

target_link_libraries(bench_bitcoin
core
test_util
leveldb
univalue
Expand Down
2 changes: 2 additions & 0 deletions src/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,5 @@ if(HAVE_ARM_SHANI)
APPEND PROPERTY COMPILE_OPTIONS ${ARM_SHANI_CXXFLAGS}
)
endif()

target_link_libraries(bitcoin_crypto PRIVATE core)
1 change: 1 addition & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ add_executable(test_bitcoin
)

target_link_libraries(test_bitcoin
core
test_util
bitcoin_cli
bitcoin_node
Expand Down
3 changes: 3 additions & 0 deletions src/test/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_library(test_util STATIC EXCLUDE_FROM_ALL
)
target_link_libraries(test_util
PRIVATE
core
bitcoin_common
bitcoin_node
leveldb
Expand All @@ -32,3 +33,5 @@ if(ENABLE_WALLET)
../../wallet/test/util.cpp
)
endif()

target_link_libraries(test_util PRIVATE core)
1 change: 1 addition & 0 deletions src/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ target_compile_definitions(bitcoin_util

target_link_libraries(bitcoin_util
PRIVATE
core
bitcoin_crypto
univalue
Threads::Threads
Expand Down
1 change: 1 addition & 0 deletions src/wallet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_library(bitcoin_wallet STATIC EXCLUDE_FROM_ALL
)
target_link_libraries(bitcoin_wallet
PRIVATE
core
bitcoin_common
univalue
Boost::headers
Expand Down
1 change: 1 addition & 0 deletions src/zmq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ target_compile_definitions(bitcoin_zmq
)
target_link_libraries(bitcoin_zmq
PRIVATE
core
leveldb
univalue
$<TARGET_NAME_IF_EXISTS:libzmq>
Expand Down

0 comments on commit 622171f

Please sign in to comment.