diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d9f7ed669..45c163cc7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,276 +1,276 @@ # Copyright (c) 2017 The Bitcoin developers set(CMAKE_CXX_STANDARD 11) option(BUILD_BITCOIN_WALLET "Activate the wallet functionality" ON) option(BUILD_BITCOIN_ZMQ "Activate the ZeroMQ functionalities" ON) option(BUILD_BITCOIN_SEEDER "Build bitcoin-seeder" ON) option(BUILD_BITCOIN_CLI "Build bitcoin-cli" ON) option(BUILD_BITCOIN_TX "Build bitcoin-tx" ON) option(BUILD_BITCOIN_QT "Build bitcoin-qt" ON) # Ensure that WINDRES_PREPROC is enabled when using windres. if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") list(APPEND CMAKE_RC_FLAGS "-DWINDRES_PREPROC") endif() # Enable warning include(AddCompilerFlags) add_c_compiler_flag(-Wnested-externs -Wstrict-prototypes) add_compiler_flag( -Wall -Wextra -Wformat -Wvla -Wformat-security -Wcast-align ) option(EXTRA_WARNINGS "Enable extra warnings" OFF) if(EXTRA_WARNINGS) add_compiler_flag(-Wshadow) add_cxx_compiler_flag(-Wsuggest-override) else() add_compiler_flag(-Wno-unused-parameter) endif() # libtool style configure add_subdirectory(config) # libraries add_subdirectory(crypto) add_subdirectory(leveldb) add_subdirectory(secp256k1) add_subdirectory(univalue) # Because the Bitcoin ABc source code is disorganised, we # end up with a bunch of libraries without any aparent # cohesive structure. This is inherited from Bitcoin Core # and reflecting this. # TODO: Improve the structure once cmake is rocking. # Various completely unrelated features shared by all executables. add_library(util chainparamsbase.cpp clientversion.cpp compat/glibc_sanity.cpp compat/glibcxx_sanity.cpp compat/strnlen.cpp fs.cpp random.cpp rpc/protocol.cpp support/cleanse.cpp support/lockedpool.cpp sync.cpp threadinterrupt.cpp uint256.cpp util.cpp utilmoneystr.cpp utilstrencodings.cpp utiltime.cpp ) target_compile_definitions(util PUBLIC HAVE_CONFIG_H) target_include_directories(util PUBLIC . # To access the config. ${CMAKE_CURRENT_BINARY_DIR} ) # Dependencies set(BOOST_PACKAGES_REQUIRED chrono filesystem program_options) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(Boost_USE_STATIC_LIBS ON) list(APPEND BOOST_PACKAGES_REQUIRED thread_win32) find_package(SHLWAPI REQUIRED) target_link_libraries(util ${SHLWAPI_LIBRARY}) target_include_directories(util PUBLIC ${SHLWAPI_INCLUDE_DIR}) find_library(WS2_32_LIBRARY NAMES ws2_32) target_link_libraries(util ${WS2_32_LIBRARY}) else() list(APPEND BOOST_PACKAGES_REQUIRED date_time thread) endif() function(prepend var prefix) - set(listVar "") - foreach(f ${ARGN}) - list(APPEND listVar "${prefix}${f}") - endforeach(f) - set(${var} "${listVar}" PARENT_SCOPE) + set(listVar "") + foreach(f ${ARGN}) + list(APPEND listVar "${prefix}${f}") + endforeach(f) + set(${var} "${listVar}" PARENT_SCOPE) endfunction(prepend) prepend(BOOST_LIBRARIES "Boost::" ${BOOST_PACKAGES_REQUIRED}) find_package(Boost 1.58 REQUIRED ${BOOST_PACKAGES_REQUIRED}) target_link_libraries(util univalue crypto ${BOOST_LIBRARIES}) # More completely unrelated features shared by all executables. # Because nothing says this is different from util than "common" add_library(common amount.cpp base58.cpp cashaddr.cpp cashaddrenc.cpp chainparams.cpp config.cpp consensus/merkle.cpp coins.cpp compressor.cpp dstencode.cpp globals.cpp core_read.cpp core_write.cpp key.cpp keystore.cpp netaddress.cpp netbase.cpp primitives/block.cpp protocol.cpp scheduler.cpp script/sign.cpp script/standard.cpp warnings.cpp ) target_link_libraries(common util secp256k1) # libbitcoinconsensus add_library(bitcoinconsensus arith_uint256.cpp hash.cpp primitives/transaction.cpp pubkey.cpp script/bitcoinconsensus.cpp script/interpreter.cpp script/script.cpp script/script_error.cpp uint256.cpp utilstrencodings.cpp ) target_link_libraries(bitcoinconsensus common) # Bitcoin server facilities add_library(server addrman.cpp addrdb.cpp bloom.cpp blockencodings.cpp chain.cpp checkpoints.cpp config.cpp globals.cpp httprpc.cpp httpserver.cpp init.cpp dbwrapper.cpp merkleblock.cpp miner.cpp net.cpp net_processing.cpp noui.cpp policy/fees.cpp policy/policy.cpp pow.cpp rest.cpp rpc/abc.cpp rpc/blockchain.cpp rpc/mining.cpp rpc/misc.cpp rpc/net.cpp rpc/rawtransaction.cpp rpc/server.cpp script/scriptcache.cpp script/sigcache.cpp script/ismine.cpp timedata.cpp torcontrol.cpp txdb.cpp txmempool.cpp ui_interface.cpp validation.cpp validationinterface.cpp versionbits.cpp ) # This require libevent find_package(Event REQUIRED) target_include_directories(server PRIVATE leveldb/helpers/memenv ${EVENT_INCLUDE_DIR} ) target_link_libraries(server ${EVENT_LIBRARY} bitcoinconsensus leveldb memenv ) if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") target_link_libraries(server ${EVENT_PTHREAD_LIBRARY}) endif() # Test suite. add_subdirectory(test) # Wallet if(BUILD_BITCOIN_WALLET) add_subdirectory(wallet) target_link_libraries(server wallet) endif() # ZeroMQ if(BUILD_BITCOIN_ZMQ) add_subdirectory(zmq) target_link_libraries(server zmq) endif() # RPC client support add_library(rpcclient rpc/client.cpp) target_link_libraries(rpcclient univalue util) # bitcoin-seeder if(BUILD_BITCOIN_SEEDER) add_subdirectory(seeder) endif() # bitcoin-cli if(BUILD_BITCOIN_CLI) add_executable(bitcoin-cli bitcoin-cli.cpp) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") target_sources(bitcoin-cli PRIVATE bitcoin-cli-res.rc) endif() target_include_directories(bitcoin-cli PRIVATE ${EVENT_INCLUDE_DIR}) target_link_libraries(bitcoin-cli common rpcclient ${EVENT_LIBRARY}) endif() # bitcoin-tx if(BUILD_BITCOIN_TX) add_executable(bitcoin-tx bitcoin-tx.cpp) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") target_sources(bitcoin-tx PRIVATE bitcoin-tx-res.rc) endif() target_link_libraries(bitcoin-tx bitcoinconsensus) endif() # bitcoind add_executable(bitcoind bitcoind.cpp) target_link_libraries(bitcoind server) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") target_sources(bitcoind PRIVATE bitcoind-res.rc) endif() # Bitcoin-qt if(BUILD_BITCOIN_QT) add_subdirectory(qt) endif() diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index d5e64fddb..03fb24a5f 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,94 +1,148 @@ # Copyright (c) 2018 The Bitcoin developers project(bitcoin-test) +# Process json files. +find_program(HEXDUMP "hexdump") +find_program(SED "sed") +function(gen_json_header NAME) + set(HEADERS "") + foreach(f ${ARGN}) + set(hex "${CMAKE_CURRENT_BINARY_DIR}/${f}.hex") + set(h "${CMAKE_CURRENT_BINARY_DIR}/${f}.h") + add_custom_command(OUTPUT ${hex} + COMMAND ${HEXDUMP} + ARGS + -v + -e "8/1 \"0x%02x, \"" + -e "\"\\n\"" + "${CMAKE_CURRENT_SOURCE_DIR}/${f}" > ${hex} + MAIN_DEPENDENCY ${f} + VERBATIM + ) + # Get the proper name for the test variable. + get_filename_component(TEST_NAME ${f} NAME_WE) + add_custom_command(OUTPUT ${h} + COMMAND ${SED} + ARGS + -e "s/0x ,//g" + -e "1 s/^/namespace json_tests{\\nstatic unsigned const char ${TEST_NAME}[] = {\\n/" + -e "\${s:\$:\\n\\};\\n\\}; // namespace json_tests:}" + < ${hex} > ${h} + MAIN_DEPENDENCY ${hex} + VERBATIM + ) + list(APPEND HEADERS ${h}) + endforeach(f) + set(${NAME} "${HEADERS}" PARENT_SCOPE) +endfunction() + +gen_json_header(JSON_HEADERS + data/script_tests.json + data/base58_keys_valid.json + data/base58_encode_decode.json + data/base58_keys_invalid.json + data/tx_invalid.json + data/tx_valid.json + data/sighash.json +) + add_executable(test_bitcoin arith_uint256_tests.cpp addrman_tests.cpp amount_tests.cpp allocator_tests.cpp base32_tests.cpp - # base58_tests.cpp + base58_tests.cpp base64_tests.cpp bip32_tests.cpp blockcheck_tests.cpp blockencodings_tests.cpp bloom_tests.cpp bswap_tests.cpp cashaddr_tests.cpp cashaddrenc_tests.cpp coins_tests.cpp compress_tests.cpp config_tests.cpp crypto_tests.cpp cuckoocache_tests.cpp DoS_tests.cpp dstencode_tests.cpp excessiveblock_tests.cpp getarg_tests.cpp hash_tests.cpp inv_tests.cpp key_tests.cpp limitedmap_tests.cpp dbwrapper_tests.cpp main_tests.cpp mempool_tests.cpp merkle_tests.cpp miner_tests.cpp monolith_opcodes.cpp multisig_tests.cpp net_tests.cpp netbase_tests.cpp pmt_tests.cpp policyestimator_tests.cpp pow_tests.cpp prevector_tests.cpp raii_event_tests.cpp random_tests.cpp reverselock_tests.cpp rpc_tests.cpp sanity_tests.cpp scheduler_tests.cpp script_antireplay_tests.cpp script_P2SH_tests.cpp - # script_tests.cpp + script_tests.cpp script_sighashtype_tests.cpp scriptflags.cpp scriptnum_tests.cpp serialize_tests.cpp - # sighash_tests.cpp + sighash_tests.cpp sigopcount_tests.cpp sigutil.cpp skiplist_tests.cpp streams_tests.cpp test_bitcoin.cpp test_bitcoin_main.cpp testutil.cpp timedata_tests.cpp - # transaction_tests.cpp + transaction_tests.cpp txvalidationcache_tests.cpp versionbits_tests.cpp uint256_tests.cpp undo_tests.cpp univalue_tests.cpp util_tests.cpp validation_tests.cpp + + # Tests generated from JSON + ${JSON_HEADERS} +) + +target_include_directories(test_bitcoin + PUBLIC + # To access the generated json headers. + ${CMAKE_CURRENT_BINARY_DIR} ) find_package(Boost 1.58 REQUIRED unit_test_framework) target_link_libraries(test_bitcoin Boost::unit_test_framework rpcclient server) # FIXME: We need to detect if that flag is required. For now assume it is. target_compile_definitions(test_bitcoin PRIVATE BOOST_TEST_DYN_LINK) if(BUILD_BITCOIN_WALLET) target_sources(test_bitcoin PRIVATE ../wallet/test/wallet_test_fixture.cpp ../wallet/test/accounting_tests.cpp ../wallet/test/wallet_tests.cpp ../wallet/test/walletdb_tests.cpp ../wallet/test/crypto_tests.cpp ) endif()