From 622171f17922e0d99906b766a3655e4a9d85129f Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sat, 2 Sep 2023 18:41:26 +0100 Subject: [PATCH] [FIXUP] Encapsulate common build flags into `core` interface library --- CMakeLists.txt | 47 +++++++++++++++++++++++++++++------- cmake/crc32c.cmake | 2 ++ cmake/leveldb.cmake | 2 +- cmake/minisketch.cmake | 3 +++ cmake/secp256k1.cmake | 2 ++ src/CMakeLists.txt | 14 ++++++++++- src/bench/CMakeLists.txt | 1 + src/crypto/CMakeLists.txt | 2 ++ src/test/CMakeLists.txt | 1 + src/test/util/CMakeLists.txt | 3 +++ src/util/CMakeLists.txt | 1 + src/wallet/CMakeLists.txt | 1 + src/zmq/CMakeLists.txt | 1 + 13 files changed, 69 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 827ea7c24543c..53d959c074bff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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. @@ -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$<$:Debug>") - add_compile_options(/utf-8 /Zc:__cplusplus) + set_target_properties(core + PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$: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) @@ -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:") diff --git a/cmake/crc32c.cmake b/cmake/crc32c.cmake index fa3e629dc1d0b..a1a64d12059a9 100644 --- a/cmake/crc32c.cmake +++ b/cmake/crc32c.cmake @@ -111,3 +111,5 @@ if(HAVE_ARM64_CRC32C) APPEND PROPERTY COMPILE_OPTIONS ${ARM_CRC_CXXFLAGS} ) endif() + +target_link_libraries(crc32c PRIVATE core) diff --git a/cmake/leveldb.cmake b/cmake/leveldb.cmake index e137ef461db02..d1c34024151fb 100644 --- a/cmake/leveldb.cmake +++ b/cmake/leveldb.cmake @@ -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) diff --git a/cmake/minisketch.cmake b/cmake/minisketch.cmake index 4d8e4b8af74df..aaa3e9bcd9910 100644 --- a/cmake/minisketch.cmake +++ b/cmake/minisketch.cmake @@ -69,3 +69,6 @@ target_link_libraries(minisketch minisketch_defs $ ) + +target_link_libraries(minisketch_clmul PRIVATE core) +target_link_libraries(minisketch PRIVATE core) diff --git a/cmake/secp256k1.cmake b/cmake/secp256k1.cmake index 38014b1cde4f5..562d4cbf3914a 100644 --- a/cmake/secp256k1.cmake +++ b/cmake/secp256k1.cmake @@ -50,3 +50,5 @@ target_compile_options(secp256k1 PRIVATE $<$:/wd4146 /wd4334> ) + +target_link_libraries(secp256k1 PRIVATE core) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4f95797409580..ff499979078b3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) @@ -86,6 +90,7 @@ target_compile_definitions(bitcoin_common ) target_link_libraries(bitcoin_common PRIVATE + core bitcoin_consensus bitcoin_util univalue @@ -105,6 +110,7 @@ if(ENABLE_WALLET) wallet/wallettool.cpp ) target_link_libraries(bitcoin-wallet + core bitcoin_wallet bitcoin_common bitcoin_util @@ -211,6 +217,7 @@ else() endif() target_link_libraries(bitcoin_node PRIVATE + core bitcoin_common bitcoin_util leveldb @@ -233,6 +240,7 @@ if(BUILD_DAEMON) ) target_link_libraries(bitcoind PRIVATE + core bitcoin_node ) target_link_options(bitcoind @@ -248,6 +256,7 @@ add_library(bitcoin_cli STATIC EXCLUDE_FROM_ALL ) target_link_libraries(bitcoin_cli PUBLIC + core univalue ) @@ -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 @@ -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 @@ -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 ) diff --git a/src/bench/CMakeLists.txt b/src/bench/CMakeLists.txt index dce546744b1b9..362d3922636a7 100644 --- a/src/bench/CMakeLists.txt +++ b/src/bench/CMakeLists.txt @@ -49,6 +49,7 @@ add_executable(bench_bitcoin ) target_link_libraries(bench_bitcoin + core test_util leveldb univalue diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt index 3f191159a1506..b1005c8da3498 100644 --- a/src/crypto/CMakeLists.txt +++ b/src/crypto/CMakeLists.txt @@ -120,3 +120,5 @@ if(HAVE_ARM_SHANI) APPEND PROPERTY COMPILE_OPTIONS ${ARM_SHANI_CXXFLAGS} ) endif() + +target_link_libraries(bitcoin_crypto PRIVATE core) diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index f1e3e2938d226..8b1b6c020701b 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -134,6 +134,7 @@ add_executable(test_bitcoin ) target_link_libraries(test_bitcoin + core test_util bitcoin_cli bitcoin_node diff --git a/src/test/util/CMakeLists.txt b/src/test/util/CMakeLists.txt index 69d7ad02de2d2..d1de910212064 100644 --- a/src/test/util/CMakeLists.txt +++ b/src/test/util/CMakeLists.txt @@ -19,6 +19,7 @@ add_library(test_util STATIC EXCLUDE_FROM_ALL ) target_link_libraries(test_util PRIVATE + core bitcoin_common bitcoin_node leveldb @@ -32,3 +33,5 @@ if(ENABLE_WALLET) ../../wallet/test/util.cpp ) endif() + +target_link_libraries(test_util PRIVATE core) diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index c567293088c4c..70de3c3d8e77c 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -50,6 +50,7 @@ target_compile_definitions(bitcoin_util target_link_libraries(bitcoin_util PRIVATE + core bitcoin_crypto univalue Threads::Threads diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt index 9ff55d505815c..64bd9b943bf09 100644 --- a/src/wallet/CMakeLists.txt +++ b/src/wallet/CMakeLists.txt @@ -34,6 +34,7 @@ add_library(bitcoin_wallet STATIC EXCLUDE_FROM_ALL ) target_link_libraries(bitcoin_wallet PRIVATE + core bitcoin_common univalue Boost::headers diff --git a/src/zmq/CMakeLists.txt b/src/zmq/CMakeLists.txt index 39cef32fceb42..228a802965e8e 100644 --- a/src/zmq/CMakeLists.txt +++ b/src/zmq/CMakeLists.txt @@ -15,6 +15,7 @@ target_compile_definitions(bitcoin_zmq ) target_link_libraries(bitcoin_zmq PRIVATE + core leveldb univalue $