Skip to content

Commit

Permalink
cmake: Add add_executable_append_flags function
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Apr 26, 2024
1 parent 9016c6d commit 555798a
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 100 deletions.
7 changes: 7 additions & 0 deletions cmake/module/AddTargetMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ function(add_library_append_flags name)
endif()
target_append_flags_interface("${name}")
endfunction()

function(add_executable_append_flags name)
cmake_parse_arguments(PARSE_ARGV 1 FWD "" "" "")
add_executable("${name}" ${FWD_UNPARSED_ARGUMENTS})
target_link_libraries("${name}" PRIVATE core_interface)
target_append_flags_interface("${name}")
endfunction()
70 changes: 32 additions & 38 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,18 @@ if(ENABLE_WALLET)
add_subdirectory(wallet)

if(BUILD_WALLET_TOOL)
add_executable(bitcoin-wallet
add_executable_append_flags(bitcoin-wallet
bitcoin-wallet.cpp
init/bitcoin-wallet.cpp
wallet/wallettool.cpp
)
add_windows_resources(bitcoin-wallet bitcoin-wallet-res.rc)
target_link_libraries(bitcoin-wallet
core_interface
bitcoin_wallet
bitcoin_common
bitcoin_util
Boost::headers
PRIVATE
bitcoin_wallet
bitcoin_common
bitcoin_util
Boost::headers
)
list(APPEND installable_targets bitcoin-wallet)
endif()
Expand Down Expand Up @@ -256,28 +256,28 @@ target_link_libraries(bitcoin_node

# Bitcoin Core bitcoind.
if(BUILD_DAEMON)
add_executable(bitcoind
add_executable_append_flags(bitcoind
bitcoind.cpp
init/bitcoind.cpp
)
add_windows_resources(bitcoind bitcoind-res.rc)
target_link_libraries(bitcoind
core_interface
bitcoin_node
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
PRIVATE
bitcoin_node
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
)
list(APPEND installable_targets bitcoind)
endif()
if(MULTIPROCESS)
add_executable(bitcoin-node
add_executable_append_flags(bitcoin-node
bitcoind.cpp
init/bitcoin-node.cpp
)
target_link_libraries(bitcoin-node
core_interface
bitcoin_node
bitcoin_ipc
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
PRIVATE
bitcoin_node
bitcoin_ipc
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
)
list(APPEND installable_targets bitcoin-node)
endif()
Expand All @@ -295,39 +295,39 @@ target_link_libraries(bitcoin_cli

# Bitcoin Core RPC client
if(BUILD_CLI)
add_executable(bitcoin-cli bitcoin-cli.cpp)
add_executable_append_flags(bitcoin-cli bitcoin-cli.cpp)
add_windows_resources(bitcoin-cli bitcoin-cli-res.rc)
target_link_libraries(bitcoin-cli
core_interface
bitcoin_cli
bitcoin_common
bitcoin_util
libevent::libevent
PRIVATE
bitcoin_cli
bitcoin_common
bitcoin_util
libevent::libevent
)
list(APPEND installable_targets bitcoin-cli)
endif()


if(BUILD_TX)
add_executable(bitcoin-tx bitcoin-tx.cpp)
add_executable_append_flags(bitcoin-tx bitcoin-tx.cpp)
add_windows_resources(bitcoin-tx bitcoin-tx-res.rc)
target_link_libraries(bitcoin-tx
core_interface
bitcoin_common
bitcoin_util
univalue
PRIVATE
bitcoin_common
bitcoin_util
univalue
)
list(APPEND installable_targets bitcoin-tx)
endif()


if(BUILD_UTIL)
add_executable(bitcoin-util bitcoin-util.cpp)
add_executable_append_flags(bitcoin-util bitcoin-util.cpp)
add_windows_resources(bitcoin-util bitcoin-util-res.rc)
target_link_libraries(bitcoin-util
core_interface
bitcoin_common
bitcoin_util
PRIVATE
bitcoin_common
bitcoin_util
)
list(APPEND installable_targets bitcoin-util)
endif()
Expand All @@ -343,14 +343,8 @@ if(BUILD_KERNEL_LIB)
endif()

if(BUILD_UTIL_CHAINSTATE)
add_executable(bitcoin-chainstate
bitcoin-chainstate.cpp
)
target_link_libraries(bitcoin-chainstate
PRIVATE
core_interface
bitcoinkernel
)
add_executable_append_flags(bitcoin-chainstate bitcoin-chainstate.cpp)
target_link_libraries(bitcoin-chainstate PRIVATE bitcoinkernel)
endif()


Expand Down
12 changes: 6 additions & 6 deletions src/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
include(GenerateHeaders)
generate_header_from_raw(data/block413567.raw)

add_executable(bench_bitcoin
add_executable_append_flags(bench_bitcoin
bench_bitcoin.cpp
bench.cpp
data.cpp
Expand Down Expand Up @@ -53,10 +53,10 @@ add_executable(bench_bitcoin
)

target_link_libraries(bench_bitcoin
core_interface
test_util
bitcoin_node
Boost::headers
PRIVATE
test_util
bitcoin_node
Boost::headers
)

if(ENABLE_WALLET)
Expand All @@ -69,7 +69,7 @@ if(ENABLE_WALLET)
wallet_loading.cpp
wallet_ismine.cpp
)
target_link_libraries(bench_bitcoin bitcoin_wallet)
target_link_libraries(bench_bitcoin PRIVATE bitcoin_wallet)
endif()

install(TARGETS bench_bitcoin
Expand Down
24 changes: 9 additions & 15 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,41 +187,35 @@ if(QT_IS_STATIC)
)
endif()

add_executable(bitcoin-qt
add_executable_append_flags(bitcoin-qt WIN32
main.cpp
../init/bitcoin-qt.cpp
)

add_windows_resources(bitcoin-qt res/bitcoin-qt-res.rc)

target_link_libraries(bitcoin-qt
core_interface
bitcoinqt
bitcoin_node
PRIVATE
bitcoinqt
bitcoin_node
)

import_plugins(bitcoin-qt)
set(installable_targets bitcoin-qt)
if(WIN32)
set_target_properties(bitcoin-qt PROPERTIES WIN32_EXECUTABLE TRUE)
endif()

if(MULTIPROCESS)
add_executable(bitcoin-gui
add_executable_append_flags(bitcoin-gui WIN32
main.cpp
../init/bitcoin-gui.cpp
)
target_link_libraries(bitcoin-gui
core_interface
bitcoinqt
bitcoin_node
bitcoin_ipc
PRIVATE
bitcoinqt
bitcoin_node
bitcoin_ipc
)
import_plugins(bitcoin-gui)
list(APPEND installable_targets bitcoin-gui)
if(WIN32)
set_target_properties(bitcoin-gui PROPERTIES WIN32_EXECUTABLE TRUE)
endif()
endif()

install(TARGETS ${installable_targets}
Expand Down
14 changes: 7 additions & 7 deletions src/qt/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

add_executable(test_bitcoin-qt
add_executable_append_flags(test_bitcoin-qt
apptests.cpp
optiontests.cpp
rpcnestedtests.cpp
Expand All @@ -13,12 +13,12 @@ add_executable(test_bitcoin-qt
)

target_link_libraries(test_bitcoin-qt
core_interface
bitcoinqt
test_util
bitcoin_node
Boost::headers
Qt5::Test
PRIVATE
bitcoinqt
test_util
bitcoin_node
Boost::headers
Qt5::Test
)

import_plugins(test_bitcoin-qt)
Expand Down
20 changes: 10 additions & 10 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ generate_header_from_json(data/tx_invalid.json)
generate_header_from_json(data/tx_valid.json)
generate_header_from_raw(data/asmap.raw)

add_executable(test_bitcoin
add_executable_append_flags(test_bitcoin
main.cpp
$<TARGET_OBJECTS:bitcoin_consensus>
${CMAKE_CURRENT_BINARY_DIR}/data/asmap.raw.h
Expand Down Expand Up @@ -140,13 +140,13 @@ add_executable(test_bitcoin
)

target_link_libraries(test_bitcoin
core_interface
test_util
bitcoin_cli
bitcoin_node
minisketch
Boost::headers
libevent::libevent
PRIVATE
test_util
bitcoin_cli
bitcoin_node
minisketch
Boost::headers
libevent::libevent
)

if(ENABLE_WALLET)
Expand All @@ -170,10 +170,10 @@ if(ENABLE_WALLET)
../wallet/test/walletdb_tests.cpp
../wallet/test/walletload_tests.cpp
)
target_link_libraries(test_bitcoin bitcoin_wallet)
if(USE_BDB)
target_sources(test_bitcoin PRIVATE ../wallet/test/db_tests.cpp)
endif()
target_link_libraries(test_bitcoin PRIVATE bitcoin_wallet)
endif()

if(MULTIPROCESS)
Expand All @@ -191,7 +191,7 @@ if(MULTIPROCESS)
PRIVATE
ipc_tests.cpp
)
target_link_libraries(test_bitcoin bitcoin_ipc_test)
target_link_libraries(test_bitcoin PRIVATE bitcoin_ipc_test)
endif()

install(TARGETS test_bitcoin
Expand Down
24 changes: 12 additions & 12 deletions src/test/fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

add_subdirectory(util)

add_executable(fuzz
add_executable_append_flags(fuzz
addition_overflow.cpp
addrman.cpp
asmap.cpp
Expand Down Expand Up @@ -121,16 +121,16 @@ add_executable(fuzz
versionbits.cpp
)
target_link_libraries(fuzz
core_interface
test_fuzz
bitcoin_cli
bitcoin_common
minisketch
leveldb
univalue
secp256k1
Boost::headers
libevent::libevent
PRIVATE
test_fuzz
bitcoin_cli
bitcoin_common
minisketch
leveldb
univalue
secp256k1
Boost::headers
libevent::libevent
)

if(ENABLE_WALLET)
Expand All @@ -143,5 +143,5 @@ if(ENABLE_WALLET)
$<$<BOOL:${USE_SQLITE}>:${PROJECT_SOURCE_DIR}/src/wallet/test/fuzz/notifications.cpp>
$<$<BOOL:${USE_SQLITE}>:${PROJECT_SOURCE_DIR}/src/wallet/test/fuzz/scriptpubkeyman.cpp>
)
target_link_libraries(fuzz bitcoin_wallet)
target_link_libraries(fuzz PRIVATE bitcoin_wallet)
endif()
16 changes: 4 additions & 12 deletions src/univalue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@ target_include_directories(univalue
)

if(BUILD_TESTS)
add_executable(unitester test/unitester.cpp)
add_executable_append_flags(unitester test/unitester.cpp)
target_compile_definitions(unitester
PRIVATE
JSON_TEST_SRC=\"${CMAKE_CURRENT_SOURCE_DIR}/test\"
)
target_link_libraries(unitester
PRIVATE
core_interface
univalue
)
target_link_libraries(unitester PRIVATE univalue)

add_executable(object test/object.cpp)
target_link_libraries(object
PRIVATE
core_interface
univalue
)
add_executable_append_flags(object test/object.cpp)
target_link_libraries(object PRIVATE univalue)
endif()

0 comments on commit 555798a

Please sign in to comment.