CMakeLists.txt raw

   1  # Copyright (c) 2023-present The Limenka developers
   2  # Distributed under the MIT software license, see the accompanying
   3  # file COPYING or https://opensource.org/license/mit/.
   4  
   5  include(AddWindowsResources)
   6  
   7  configure_file(${PROJECT_SOURCE_DIR}/cmake/limenka-build-config.h.in limenka-build-config.h USE_SOURCE_PERMISSIONS @ONLY)
   8  include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
   9  
  10  #=============================
  11  # Subprojects
  12  #=============================
  13  # Subprojects include subdirectories that do or could have tests
  14  # and/or benchmark binaries, such as all subtrees and univalue.
  15  # These need to be included before CMAKE_*_OUTPUT_DIRECTORY variables
  16  # are set, so output locations of subproject tests and libraries are
  17  # not overridden.
  18  if(NOT WITH_SYSTEM_LEVELDB)
  19  include(../cmake/crc32c.cmake)
  20  include(../cmake/leveldb.cmake)
  21  endif()  # WITH_SYSTEM_LEVELDB
  22  
  23  add_subdirectory(univalue)
  24  
  25  if(NOT WITH_SYSTEM_LIBSECP256K1)
  26  #=============================
  27  # secp256k1 subtree
  28  #=============================
  29  message("")
  30  message("Configuring secp256k1 subtree...")
  31  set(SECP256K1_DISABLE_SHARED ON CACHE BOOL "" FORCE)
  32  set(SECP256K1_ENABLE_MODULE_ECDH OFF CACHE BOOL "" FORCE)
  33  set(SECP256K1_ENABLE_MODULE_RECOVERY ON CACHE BOOL "" FORCE)
  34  set(SECP256K1_ENABLE_MODULE_MUSIG OFF CACHE BOOL "" FORCE)
  35  set(SECP256K1_BUILD_BENCHMARK OFF CACHE BOOL "" FORCE)
  36  set(SECP256K1_BUILD_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
  37  set(SECP256K1_BUILD_EXHAUSTIVE_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
  38  if(NOT BUILD_TESTS)
  39    # Always skip the ctime tests, if we are building no other tests.
  40    # Otherwise, they are built if Valgrind is available. See SECP256K1_VALGRIND.
  41    set(SECP256K1_BUILD_CTIME_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
  42  endif()
  43  set(SECP256K1_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
  44  include(GetTargetInterface)
  45  # -fsanitize and related flags apply to both C++ and C,
  46  # so we can pass them down to libsecp256k1 as CFLAGS and LDFLAGS.
  47  get_target_interface(SECP256K1_APPEND_CFLAGS "" sanitize_interface COMPILE_OPTIONS)
  48  string(STRIP "${SECP256K1_APPEND_CFLAGS} ${APPEND_CPPFLAGS}" SECP256K1_APPEND_CFLAGS)
  49  string(STRIP "${SECP256K1_APPEND_CFLAGS} ${APPEND_CFLAGS}" SECP256K1_APPEND_CFLAGS)
  50  set(SECP256K1_APPEND_CFLAGS ${SECP256K1_APPEND_CFLAGS} CACHE STRING "" FORCE)
  51  get_target_interface(SECP256K1_APPEND_LDFLAGS "" sanitize_interface LINK_OPTIONS)
  52  string(STRIP "${SECP256K1_APPEND_LDFLAGS} ${APPEND_LDFLAGS}" SECP256K1_APPEND_LDFLAGS)
  53  set(SECP256K1_APPEND_LDFLAGS ${SECP256K1_APPEND_LDFLAGS} CACHE STRING "" FORCE)
  54  # We want to build libsecp256k1 with the most tested RelWithDebInfo configuration.
  55  enable_language(C)
  56  foreach(config IN LISTS CMAKE_BUILD_TYPE CMAKE_CONFIGURATION_TYPES)
  57    if(config STREQUAL "")
  58      continue()
  59    endif()
  60    string(TOUPPER "${config}" config)
  61    set(CMAKE_C_FLAGS_${config} "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
  62  endforeach()
  63  # If the CFLAGS environment variable is defined during building depends
  64  # and configuring this build system, its content might be duplicated.
  65  if(DEFINED ENV{CFLAGS})
  66    deduplicate_flags(CMAKE_C_FLAGS)
  67  endif()
  68  set(CMAKE_EXPORT_COMPILE_COMMANDS OFF)
  69  add_subdirectory(secp256k1)
  70  set_target_properties(secp256k1 PROPERTIES
  71    EXCLUDE_FROM_ALL TRUE
  72  )
  73  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  74  endif()  # WITH_SYSTEM_LIBSECP256K1
  75  
  76  # Set top-level target output locations.
  77  if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  78    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
  79  endif()
  80  if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  81    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
  82  endif()
  83  if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  84    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
  85  endif()
  86  
  87  add_custom_target(generate_build_info
  88    BYPRODUCTS ${PROJECT_BINARY_DIR}/src/limenka-build-info.h
  89    COMMAND ${CMAKE_COMMAND} -DBUILD_INFO_HEADER_PATH=${PROJECT_BINARY_DIR}/src/limenka-build-info.h -DSOURCE_DIR=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateBuildInfo.cmake
  90    COMMENT "Generating limenka-build-info.h"
  91    VERBATIM
  92  )
  93  add_library(limenka_clientversion STATIC EXCLUDE_FROM_ALL
  94    clientversion.cpp
  95  )
  96  target_link_libraries(limenka_clientversion
  97    PRIVATE
  98      core_interface
  99  )
 100  add_dependencies(limenka_clientversion generate_build_info)
 101  
 102  add_subdirectory(crypto)
 103  add_subdirectory(util)
 104  if(WITH_MULTIPROCESS)
 105    add_subdirectory(ipc)
 106  endif()
 107  
 108  add_library(limenka_consensus STATIC EXCLUDE_FROM_ALL
 109    arith_uint256.cpp
 110    consensus/delay.cpp
 111    consensus/merkle.cpp
 112    consensus/tx_check.cpp
 113    hash.cpp
 114    primitives/block.cpp
 115    primitives/transaction.cpp
 116    pubkey.cpp
 117    script/interpreter.cpp
 118    script/script.cpp
 119    script/script_error.cpp
 120    uint256.cpp
 121  )
 122  target_link_libraries(limenka_consensus
 123    PRIVATE
 124      core_interface
 125      limenka_crypto
 126      secp256k1
 127  )
 128  
 129  if(WITH_ZMQ)
 130    add_subdirectory(zmq)
 131  endif()
 132  
 133  # Home for common functionality shared by different executables and libraries.
 134  # Similar to `limenka_util` library, but higher-level.
 135  add_library(limenka_common STATIC EXCLUDE_FROM_ALL
 136    addresstype.cpp
 137    base58.cpp
 138    bech32.cpp
 139    chain.cpp
 140    chainparams.cpp
 141    chainparamsbase.cpp
 142    codex32.cpp
 143    coins.cpp
 144    common/args.cpp
 145    common/bloom.cpp
 146    common/config.cpp
 147    common/init.cpp
 148    common/interfaces.cpp
 149    common/messages.cpp
 150    common/netif.cpp
 151    common/pcp.cpp
 152    common/run_command.cpp
 153    common/settings.cpp
 154    common/signmessage.cpp
 155    common/system.cpp
 156    common/system_ram.cpp
 157    common/url.cpp
 158    compressor.cpp
 159    core_read.cpp
 160    core_write.cpp
 161    deploymentinfo.cpp
 162    external_signer.cpp
 163    init/common.cpp
 164    kernel/chainparams.cpp
 165    key.cpp
 166    key_io.cpp
 167    merkleblock.cpp
 168    net_permissions.cpp
 169    net_types.cpp
 170    netaddress.cpp
 171    netbase.cpp
 172    outputtype.cpp
 173    policy/coin_age_priority.cpp
 174    policy/feerate.cpp
 175    policy/policy.cpp
 176    pow.cpp
 177    pow_fork.cpp
 178    protocol.cpp
 179    psbt.cpp
 180    rpc/rawtransaction_util.cpp
 181    rpc/request.cpp
 182    rpc/util.cpp
 183    scheduler.cpp
 184    script/descriptor.cpp
 185    script/miniscript.cpp
 186    script/parsing.cpp
 187    script/sign.cpp
 188    script/signingprovider.cpp
 189    script/solver.cpp
 190  )
 191  target_link_libraries(limenka_common
 192    PRIVATE
 193      core_interface
 194      limenka_consensus
 195      limenka_util
 196      univalue
 197      secp256k1
 198      Boost::headers
 199      $<TARGET_NAME_IF_EXISTS:USDT::headers>
 200      $<$<PLATFORM_ID:Windows>:ws2_32>
 201  )
 202  
 203  include(InstallBinaryComponent)
 204  
 205  if(ENABLE_WALLET)
 206    add_subdirectory(wallet)
 207  
 208    if(BUILD_WALLET_TOOL)
 209      add_executable(limenka-wallet
 210        limenka-wallet.cpp
 211        init/limenka-wallet.cpp
 212        wallet/wallettool.cpp
 213      )
 214      add_windows_resources(limenka-wallet limenka-wallet-res.rc)
 215      target_link_libraries(limenka-wallet
 216        core_interface
 217        limenka_wallet
 218        limenka_common
 219        limenka_util
 220        univalue
 221        Boost::headers
 222      )
 223      install_binary_component(limenka-wallet HAS_MANPAGE)
 224    endif()
 225  endif()
 226  
 227  
 228  # P2P and RPC server functionality used by `limenkad` and `limenka-qt` executables.
 229  add_library(limenka_node STATIC EXCLUDE_FROM_ALL
 230    addrdb.cpp
 231    addrman.cpp
 232    banman.cpp
 233    bip324.cpp
 234    blockencodings.cpp
 235    blockfilter.cpp
 236    consensus/tx_verify.cpp
 237    dbwrapper.cpp
 238    deploymentstatus.cpp
 239    flatfile.cpp
 240    headerssync.cpp
 241    httprpc.cpp
 242    httpserver.cpp
 243    i2p.cpp
 244    index/base.cpp
 245    index/blockfilterindex.cpp
 246    index/coinstatsindex.cpp
 247    index/txindex.cpp
 248    init.cpp
 249    kernel/chain.cpp
 250    kernel/checks.cpp
 251    kernel/coinstats.cpp
 252    kernel/context.cpp
 253    kernel/cs_main.cpp
 254    kernel/disconnected_transactions.cpp
 255    kernel/mempool_removal_reason.cpp
 256    mapport.cpp
 257    net.cpp
 258    net_processing.cpp
 259    netgroup.cpp
 260    node/abort.cpp
 261    node/blockmanager_args.cpp
 262    node/blockstorage.cpp
 263    node/caches.cpp
 264    node/dbcache.cpp
 265    node/chainstate.cpp
 266    node/chainstatemanager_args.cpp
 267    node/coin.cpp
 268    node/coins_view_args.cpp
 269    node/connection_types.cpp
 270    node/context.cpp
 271    node/database_args.cpp
 272    node/eviction.cpp
 273    node/interface_ui.cpp
 274    node/interfaces.cpp
 275    node/kernel_notifications.cpp
 276    node/mempool_args.cpp
 277    node/mempoolbridge.cpp
 278    node/mempool_persist.cpp
 279    node/mempool_persist_args.cpp
 280    node/miner.cpp
 281    node/mini_miner.cpp
 282    node/peerman_args.cpp
 283    node/psbt.cpp
 284    node/timeoffsets.cpp
 285    node/transaction.cpp
 286    node/txdownloadman_impl.cpp
 287    node/txreconciliation.cpp
 288    node/utxo_snapshot.cpp
 289    node/warnings.cpp
 290    noui.cpp
 291    policy/ephemeral_policy.cpp
 292    policy/fees.cpp
 293    policy/fees_args.cpp
 294    policy/packages.cpp
 295    policy/rbf.cpp
 296    policy/settings.cpp
 297    policy/truc_policy.cpp
 298    rest.cpp
 299    rpc/blockchain.cpp
 300    rpc/external_signer.cpp
 301    rpc/fees.cpp
 302    rpc/mempool.cpp
 303    rpc/mining.cpp
 304    rpc/net.cpp
 305    rpc/node.cpp
 306    rpc/output_script.cpp
 307    rpc/rawtransaction.cpp
 308    rpc/server.cpp
 309    rpc/server_util.cpp
 310    rpc/signmessage.cpp
 311    rpc/txoutproof.cpp
 312    script/sigcache.cpp
 313    signet.cpp
 314    stats/init.cpp
 315    stats/rpc_stats.cpp
 316    stats/stats.cpp
 317    torcontrol.cpp
 318    txdb.cpp
 319    txmempool.cpp
 320    txorphanage.cpp
 321    txrequest.cpp
 322    validation.cpp
 323    validationinterface.cpp
 324    versionbits.cpp
 325    $<$<TARGET_EXISTS:limenka_wallet>:wallet/init.cpp>
 326    $<$<NOT:$<TARGET_EXISTS:limenka_wallet>>:dummywallet.cpp>
 327  )
 328  target_link_libraries(limenka_node
 329    PRIVATE
 330      core_interface
 331      limenka_common
 332      limenka_util
 333      $<TARGET_NAME_IF_EXISTS:limenka_zmq>
 334      leveldb
 335      univalue
 336      Boost::headers
 337      $<TARGET_NAME_IF_EXISTS:libevent::core>
 338      $<TARGET_NAME_IF_EXISTS:libevent::extra>
 339      $<TARGET_NAME_IF_EXISTS:libevent::pthreads>
 340      $<TARGET_NAME_IF_EXISTS:MiniUPnPc::MiniUPnPc>
 341      $<TARGET_NAME_IF_EXISTS:USDT::headers>
 342  )
 343  
 344  
 345  # Limenka limenkad.
 346  if(BUILD_DAEMON)
 347    add_executable(limenkad
 348      limenkad.cpp
 349      init/limenkad.cpp
 350    )
 351    add_windows_resources(limenkad limenkad-res.rc)
 352    target_link_libraries(limenkad
 353      core_interface
 354      limenka_node
 355      $<TARGET_NAME_IF_EXISTS:limenka_wallet>
 356    )
 357    install_binary_component(limenkad HAS_MANPAGE)
 358  endif()
 359  if(WITH_MULTIPROCESS AND BUILD_DAEMON)
 360    add_executable(limenka-node
 361      limenkad.cpp
 362      init/limenka-node.cpp
 363    )
 364    target_link_libraries(limenka-node
 365      core_interface
 366      limenka_node
 367      limenka_ipc
 368      $<TARGET_NAME_IF_EXISTS:limenka_wallet>
 369    )
 370    install_binary_component(limenka-node)
 371  endif()
 372  
 373  if(WITH_MULTIPROCESS AND BUILD_TESTS)
 374      # limenka_ipc_test library target is defined here in src/CMakeLists.txt
 375      # instead of src/test/CMakeLists.txt so capnp files in src/test/ are able to
 376      # reference capnp files in src/ipc/capnp/ by relative path. The Cap'n Proto
 377      # compiler only allows importing by relative path when the importing and
 378      # imported files are underneath the same compilation source prefix, so the
 379      # source prefix must be src/, not src/test/
 380      add_library(limenka_ipc_test STATIC EXCLUDE_FROM_ALL
 381        test/ipc_test.cpp
 382      )
 383      target_capnp_sources(limenka_ipc_test ${PROJECT_SOURCE_DIR}
 384        test/ipc_test.capnp
 385      )
 386      add_dependencies(limenka_ipc_test limenka_ipc_headers)
 387  endif()
 388  
 389  
 390  add_library(limenka_cli STATIC EXCLUDE_FROM_ALL
 391    compat/stdin.cpp
 392    rpc/client.cpp
 393  )
 394  target_link_libraries(limenka_cli
 395    PUBLIC
 396      core_interface
 397      univalue
 398  )
 399  
 400  
 401  # Limenka RPC client
 402  if(BUILD_CLI)
 403    add_executable(limenka-cli limenka-cli.cpp)
 404    add_windows_resources(limenka-cli limenka-cli-res.rc)
 405    target_link_libraries(limenka-cli
 406      core_interface
 407      limenka_cli
 408      limenka_common
 409      limenka_util
 410      libevent::core
 411      libevent::extra
 412    )
 413    install_binary_component(limenka-cli HAS_MANPAGE)
 414  endif()
 415  
 416  
 417  if(BUILD_TX)
 418    add_executable(limenka-tx limenka-tx.cpp)
 419    add_windows_resources(limenka-tx limenka-tx-res.rc)
 420    target_link_libraries(limenka-tx
 421      core_interface
 422      limenka_common
 423      limenka_util
 424      univalue
 425    )
 426    install_binary_component(limenka-tx HAS_MANPAGE)
 427  endif()
 428  
 429  
 430  if(BUILD_UTIL)
 431    add_executable(limenka-util limenka-util.cpp)
 432    add_windows_resources(limenka-util limenka-util-res.rc)
 433    target_link_libraries(limenka-util
 434      core_interface
 435      limenka_common
 436      limenka_util
 437    )
 438    install_binary_component(limenka-util HAS_MANPAGE)
 439  endif()
 440  
 441  
 442  if(BUILD_GUI)
 443    add_subdirectory(qt)
 444  endif()
 445  
 446  
 447  if(BUILD_LIMENKACONSENSUS_LIB)
 448    add_subdirectory(consensus)
 449  endif()
 450  
 451  if(BUILD_KERNEL_LIB)
 452    add_subdirectory(kernel)
 453  endif()
 454  
 455  if(BUILD_UTIL_CHAINSTATE)
 456    add_executable(limenka-chainstate
 457      limenka-chainstate.cpp
 458    )
 459    # TODO: The `SKIP_BUILD_RPATH` property setting can be deleted
 460    #       in the future after reordering Guix script commands to
 461    #       perform binary checks after the installation step.
 462    # Relevant discussions:
 463    # - https://github.com/hebasto/limenka/pull/236#issuecomment-2183120953
 464    # - https://github.com/limenka/limenka/pull/30312#issuecomment-2191235833
 465    set_target_properties(limenka-chainstate PROPERTIES
 466      SKIP_BUILD_RPATH OFF
 467    )
 468    target_link_libraries(limenka-chainstate
 469      PRIVATE
 470        core_interface
 471        limenkakernel
 472    )
 473  endif()
 474  
 475  
 476  add_subdirectory(test/util)
 477  if(BUILD_BENCH)
 478    add_subdirectory(bench)
 479  endif()
 480  
 481  if(BUILD_TESTS)
 482    add_subdirectory(test)
 483  endif()
 484  
 485  if(BUILD_FUZZ_BINARY)
 486    add_subdirectory(test/fuzz)
 487  endif()
 488