diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a83d9162..d89de683b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,23 +1,23 @@ # Copyright (c) 2017 The Bitcoin developers -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(BitcoinABC) # Add path for custom modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ) # If ccache is available, then use it. find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) endif(CCACHE_FOUND) # Add the magic taret check and check-all add_custom_target(check-all) add_custom_target(check) add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 45c163cc7..81c7c6210 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,276 +1,283 @@ # Copyright (c) 2017 The Bitcoin developers +cmake_minimum_required(VERSION 3.5) +project(BitcoinABC) + set(CMAKE_CXX_STANDARD 11) +# Default visibility is hidden on all targets. +set(CMAKE_C_VISIBILITY_PRESET hidden) +set(CMAKE_CXX_VISIBILITY_PRESET hidden) + 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) 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/leveldb/CMakeLists.txt b/src/leveldb/CMakeLists.txt index a2c5d187f..929ca4865 100644 --- a/src/leveldb/CMakeLists.txt +++ b/src/leveldb/CMakeLists.txt @@ -1,223 +1,223 @@ # Copyright 2017 The LEVELDB Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. See the AUTHORS file for names of contributors. -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(Leveldb VERSION 0.1.0 LANGUAGES C CXX) # This project can take advantage of C++11. set(CMAKE_CXX_STANDARD 11) # Remove some warnings for leveldb as they can get noisy. add_compiler_flag(-Wno-sign-compare -Wno-implicit-fallthrough) add_c_compiler_flag(-Wno-strict-prototypes) remove_compiler_flags(-Wstrict-prototypes) include(TestBigEndian) test_big_endian(LEVELDB_IS_BIG_ENDIAN) include(CheckIncludeFile) check_include_file("unistd.h" HAVE_UNISTD_H) include(CheckIncludeFileCXX) check_include_file_cxx("atomic" LEVELDB_ATOMIC_PRESENT) include(CheckLibraryExists) check_library_exists(crc32c crc32c_value "" HAVE_CRC32C) check_library_exists(snappy snappy_compress "" HAVE_SNAPPY) include(CheckSymbolExists) check_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC) configure_file( port/port_config.h.cmake.in include/port/port_config.h ) include_directories(.) add_library(leveldb db/builder.cc db/c.cc db/dbformat.cc db/db_impl.cc db/db_iter.cc db/dumpfile.cc db/filename.cc db/log_reader.cc db/log_writer.cc db/memtable.cc db/repair.cc db/table_cache.cc db/version_edit.cc db/version_set.cc db/write_batch.cc table/block_builder.cc table/block.cc table/filter_block.cc table/format.cc table/iterator.cc table/merger.cc table/table_builder.cc table/table.cc table/two_level_iterator.cc util/arena.cc util/bloom.cc util/cache.cc util/coding.cc util/comparator.cc util/crc32c.cc util/env.cc util/env_posix.cc util/filter_policy.cc util/hash.cc util/histogram.cc util/logging.cc util/options.cc util/status.cc # Always include that guy even when not using SSE or posix. # TODO: proper support of SSE. port/port_posix_sse.cc ) target_include_directories(leveldb PUBLIC include "${PROJECT_BINARY_DIR}/include" ) # Select the proper port: posix or Windows. if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(LEVELDB_PLATFORM WINDOWS) set(LEVELDB_OS WINDOWS) target_sources(leveldb PRIVATE util/env_win.cc port/port_win.cc ) target_compile_definitions(leveldb PRIVATE WINVER=0x0500 __USE_MINGW_ANSI_STDIO=1 ) find_package(SHLWAPI REQUIRED) target_link_libraries(leveldb ${SHLWAPI_LIBRARY}) target_include_directories(leveldb PUBLIC ${SHLWAPI_INCLUDE_DIR}) else() set(LEVELDB_PLATFORM POSIX) target_sources(leveldb PRIVATE port/port_posix.cc ) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) target_link_libraries(leveldb Threads::Threads) # TODO: If the plateform supports SSE4.2 activate # LEVELDB_PLATFORM_POSIX_SSE and the proper compiler flags. if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(LEVELDB_OS LINUX) elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(LEVELDB_OS MACOSX) elseif(${CMAKE_SYSTEM_NAME} MATCHES "(Solaris|SunOS)") set(LEVELDB_OS SOLARIS) elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") set(LEVELDB_OS FREEBSD) elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") set(LEVELDB_OS NETBSD) elseif(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") set(LEVELDB_OS OPENBSD) elseif(${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") set(LEVELDB_OS DRAGONFLYBSD) elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") set(LEVELDB_OS ANDROID) elseif(${CMAKE_SYSTEM_NAME} MATCHES "HPUX") # No idea what's the proper system name is here. set(LEVELDB_OS HPUX) elseif(${CMAKE_SYSTEM_NAME} MATCHES "iOS") # No idea what's the proper system name is here. set(LEVELDB_OS IOS) else() set(LEVELDB_OS LINUX) endif() endif() target_compile_definitions(leveldb PUBLIC OS_${LEVELDB_OS} LEVELDB_PLATFORM_${LEVELDB_PLATFORM} ) # Right now this is not used but the latest version of leveldb uses this # so we might as well be ready for it. if (HAVE_CRC32C) target_link_libraries(leveldb crc32c) endif (HAVE_CRC32C) if (HAVE_SNAPPY) target_link_libraries(leveldb snappy) endif (HAVE_SNAPPY) # The libmemenv library. add_library(memenv helpers/memenv/memenv.cc) target_include_directories(memenv PUBLIC include) target_compile_definitions(memenv PUBLIC OS_${LEVELDB_OS} LEVELDB_PLATFORM_${LEVELDB_PLATFORM} ) option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON) if(LEVELDB_BUILD_TESTS) include(TestSuite) create_test_suite(leveldb) add_library(leveldb_test_base EXCLUDE_FROM_ALL util/testharness.cc util/testutil.cc ) target_link_libraries(leveldb_test_base leveldb) function(create_leveldb_test NAME FILES) add_test_to_suite(leveldb ${NAME} EXCLUDE_FROM_ALL ${FILES}) target_link_libraries(${NAME} leveldb_test_base) endfunction() create_leveldb_test(autocompact_test db/autocompact_test.cc) create_leveldb_test(corruption_test db/corruption_test.cc) create_leveldb_test(db_test db/db_test.cc) create_leveldb_test(dbformat_test db/dbformat_test.cc) create_leveldb_test(fault_injection_test db/fault_injection_test.cc) create_leveldb_test(filename_test db/filename_test.cc) create_leveldb_test(log_test db/log_test.cc) create_leveldb_test(recovery_test db/recovery_test.cc) create_leveldb_test(skiplist_test db/skiplist_test.cc) create_leveldb_test(version_edit_test db/version_edit_test.cc) create_leveldb_test(version_set_test db/version_set_test.cc) create_leveldb_test(write_batch_test db/write_batch_test.cc) create_leveldb_test(issue178_test issues/issue178_test.cc) create_leveldb_test(issue200_test issues/issue200_test.cc) create_leveldb_test(filter_block_test table/filter_block_test.cc) create_leveldb_test(table_test table/table_test.cc) create_leveldb_test(arena_test util/arena_test.cc) create_leveldb_test(bloom_test util/bloom_test.cc) create_leveldb_test(cache_test util/cache_test.cc) create_leveldb_test(coding_test util/coding_test.cc) create_leveldb_test(crc32c_test util/crc32c_test.cc) create_leveldb_test(env_test util/env_test.cc) create_leveldb_test(hash_test util/hash_test.cc) create_leveldb_test(memenv_test helpers/memenv/memenv_test.cc) target_link_libraries(memenv_test memenv) # These tests only work on posix if(${LEVELDB_PLATFORM} MATCHES "POSIX") create_leveldb_test(c_test db/c_test.c) create_leveldb_test(env_posix_test util/env_posix_test.cc) endif() endif(LEVELDB_BUILD_TESTS) diff --git a/src/secp256k1/CMakeLists.txt b/src/secp256k1/CMakeLists.txt index ae135fa63..8a8f544a6 100644 --- a/src/secp256k1/CMakeLists.txt +++ b/src/secp256k1/CMakeLists.txt @@ -1,152 +1,155 @@ # Copyright (c) 2017 The Bitcoin developers -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(secp256k1) # libsecp256k1 use a different set of flags. add_compiler_flag( -pedantic -Wshadow -Wno-unused-function -Wno-nonnull -Wno-nonnull-compare ) add_c_compiler_flag( -std=c89 -Wno-long-long ) +# Default visibility is hidden on all targets. +set(CMAKE_C_VISIBILITY_PRESET hidden) + # TODO: change this to include when possible include_directories( . src # For the config ${CMAKE_CURRENT_BINARY_DIR}/src ) # The library add_library(secp256k1 src/secp256k1.c) target_include_directories(secp256k1 PUBLIC include) # We need to link in GMP find_package(GMP) if(GMP_FOUND) target_include_directories(secp256k1 PUBLIC ${GMP_INCLUDE_DIR}) target_link_libraries(secp256k1 ${GMP_LIBRARIES}) set(USE_NUM_GMP 1) set(USE_FIELD_INV_NUM 1) set(USE_SCALAR_INV_NUM 1) else() set(USE_NUM_NONE 1) set(USE_FIELD_INV_BUILTIN 1) set(USE_SCALAR_INV_BUILTIN 1) endif() # We make sure __int128 is defined include(CheckTypeSize) check_type_size(__int128 SIZEOF___INT128) if(SIZEOF___INT128 EQUAL 16) set(HAVE___INT128 1) else() # If we do not support __int128, we should be falling back # on 32bits implementations for field and scalar. endif() # Detect if we are on a 32 or 64 bits plateform and chose # scalar and filed implementation accordingly if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64 bits implementationr require either __int128 or asm support. # TODO: support asm. if(NOT SIZEOF___INT128 EQUAL 16) message(SEND_ERROR "Compiler does not support __int128") endif() set(USE_SCALAR_4X64 1) set(USE_FIELD_5X52 1) else() set(USE_SCALAR_8X32 1) set(USE_FIELD_10X26 1) endif() # Executable internal to secp256k1 need to have the HAVE_CONFIG_H define set. # For convenience, we wrap this into a function. function(link_secp256k1_internal NAME) target_link_libraries(${NAME} secp256k1) target_compile_definitions(${NAME} PRIVATE HAVE_CONFIG_H) endfunction(link_secp256k1_internal) # Phony target to build benchmarks add_custom_target(bench-secp256k1) function(add_secp256k1_bench NAME) add_executable(${NAME} EXCLUDE_FROM_ALL ${ARGN}) link_secp256k1_internal(${NAME}) add_dependencies(bench-secp256k1 ${NAME}) endfunction(add_secp256k1_bench) # Recovery module option(SECP256K1_ENABLE_MODULE_RECOVERY "Build libsecp256k1's recovery module" ON) if(SECP256K1_ENABLE_MODULE_RECOVERY) set(ENABLE_MODULE_RECOVERY 1) add_secp256k1_bench(bench_recover src/bench_recover.c) endif() # ECDH module option(SECP256K1_ENABLE_MODULE_ECDH "Build libsecp256k1's ECDH module" OFF) if(SECP256K1_ENABLE_MODULE_ECDH) set(ENABLE_MODULE_ECDH 1) add_secp256k1_bench(bench_ecdh src/bench_ecdh.c) endif() # MultiSet module option(SECP256K1_ENABLE_MODULE_MULTISET "Build libsecp256k1's MULTISET module" ON) if(SECP256K1_ENABLE_MODULE_MULTISET) set(ENABLE_MODULE_MULTISET 1) add_secp256k1_bench(bench_multiset src/bench_multiset.c) endif() # Static precomputation for eliptic curve mutliplication option(SECP256K1_ECMULT_STATIC_PRECOMPUTATION "Precompute libsecp256k1's eliptic curve mutliplication tables" ON) if(SECP256K1_ECMULT_STATIC_PRECOMPUTATION) set(USE_ECMULT_STATIC_PRECOMPUTATION 1) include(NativeExecutable) add_native_executable(gen_context src/gen_context.c) add_custom_command( OUTPUT ecmult_static_context.h COMMAND gen_context ) target_sources(secp256k1 PRIVATE ecmult_static_context.h) endif() # Generate the config configure_file(src/libsecp256k1-config.h.cmake.in src/libsecp256k1-config.h ESCAPE_QUOTES) target_compile_definitions(secp256k1 PRIVATE HAVE_CONFIG_H) # Tests option(SECP256K1_BUILD_TEST "Build secp256k1's unit tests" ON) if(SECP256K1_BUILD_TEST) include(TestSuite) create_test_suite(secp256k1) function(create_secp256k1_test NAME FILES) add_test_to_suite(secp256k1 ${NAME} EXCLUDE_FROM_ALL ${FILES}) link_secp256k1_internal(${NAME}) endfunction() create_secp256k1_test(secp256k1_tests src/tests.c) target_compile_definitions(secp256k1_tests PRIVATE VERIFY) create_secp256k1_test(exhaustive_tests src/tests_exhaustive.c) # This should not be enabled at the same time as coverage is. # TODO: support coverage. target_compile_definitions(exhaustive_tests PRIVATE VERIFY) endif(SECP256K1_BUILD_TEST) # Benchmarks add_secp256k1_bench(bench_verify src/bench_verify.c) add_secp256k1_bench(bench_sign src/bench_sign.c) add_secp256k1_bench(bench_internal src/bench_internal.c) diff --git a/src/univalue/CMakeLists.txt b/src/univalue/CMakeLists.txt index 0888cafc3..bf1a4b97c 100644 --- a/src/univalue/CMakeLists.txt +++ b/src/univalue/CMakeLists.txt @@ -1,54 +1,54 @@ # Copyright (c) 2017 The Bitcoin developers -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(univalue) option(UNIVALUE_BUILD_TESTS "Build univalue's unit tests" ON) # TODO: Version info add_library(univalue lib/univalue.cpp lib/univalue_get.cpp lib/univalue_read.cpp lib/univalue_write.cpp ) target_include_directories(univalue PUBLIC include PRIVATE lib ) if(UNIVALUE_BUILD_TESTS) include(TestSuite) create_test_suite(univalue) function(create_univalue_test NAME FILES) add_test_to_suite(univalue ${NAME} ${FILES}) target_link_libraries(${NAME} univalue) endfunction() create_univalue_test(unitester_test test/unitester.cpp) target_compile_definitions(unitester_test PUBLIC JSON_TEST_SRC="${PROJECT_SOURCE_DIR}/test" ) create_univalue_test(no_nul_test test/no_nul.cpp) create_univalue_test(object_test test/object.cpp) # test_json is not meant to run in an automated test suite. add_executable(json_test EXCLUDE_FROM_ALL test/test_json.cpp) target_link_libraries(json_test univalue) add_dependencies(check-univalue json_test) endif(UNIVALUE_BUILD_TESTS) # Generate lib/univalue_escapes.h include(NativeExecutable) add_native_executable(univalue_gen gen/gen.cpp) native_target_include_directories(univalue_gen PUBLIC include) # Custom target to regenerate univalue_escapes.h add_custom_target(generate_univalue_escapes_h COMMAND univalue_gen > ${CMAKE_CURRENT_SOURCE_DIR}/lib/univalue_escapes.h )