forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #7: build: Add CMake-based build system (3 of N)
a80fb45 cmake: Build `bitcoind` executable (Hennadii Stepanov) ffd10d1 cmake: Build `bitcoin_consensus` library (Hennadii Stepanov) d028a49 cmake: Build `bitcoin_util` static library (Hennadii Stepanov) 318dd82 cmake: Build `bitcoin_crypto` library (Hennadii Stepanov) e990724 cmake: Build `univalue` static library (Hennadii Stepanov) eb3546f cmake: Build `secp256k1` static library (Hennadii Stepanov) 0e2287c cmake: Build `minisketch` static library (Hennadii Stepanov) a06290e cmake: Add `CheckStdFilesystem` module (Hennadii Stepanov) 6317164 cmake: Add essential platform-specific definitions and options (Hennadii Stepanov) Pull request description: The parent PR: bitcoin#25797. The previous PRs in the staging branch: #5, #6. This PR adds the `bitcoind` build target with its dependencies. To get comparable binaries, one can use the following commands: - with CMake: ``` cmake -S . -B build -DCMAKE_CXX_FLAGS="-g -O2" cmake --build build ``` - with Autotools: ``` ./autogen.sh ./configure --disable-hardening --disable-wallet --disable-zmq --without-miniupnpc --without-natpmp --disable-usdt make clean make -C src bitcoind ``` --- **Windows-specific notes for reviewers** Windows MSVC builds use dependencies provided by the [vcpkg](https://vcpkg.io) package manager. To install them, run: ```cmd vcpkg --triplet=x64-windows-static install boost-multi-index boost-signals2 libevent ``` To configure, a toolchain file and a triplet must be specified: ```cmd cmake -G "Visual Studio 17 2022" -A x64 --toolchain C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -S . -B build ``` Then, build the `all` target as usual: ```cmd cmake --build build --config Debug ``` ACKs for top commit: TheCharlatan: ACK a80fb45 theuni: ACK a80fb45 Tree-SHA512: c37af3bf3975128acba0ef2ff0b13aab1fc44a5ec96b15bcbed1b42f1cc91c533c515762417becc31384839c3408ddafb567b7f9dd53c525e71070e78150d812
- Loading branch information
Showing
12 changed files
with
729 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
# Check for clmul instructions support. | ||
if(MSVC) | ||
set(CLMUL_CXXFLAGS) | ||
else() | ||
set(CLMUL_CXXFLAGS -mpclmul) | ||
endif() | ||
check_cxx_source_compiles_with_flags("${CLMUL_CXXFLAGS}" " | ||
#include <immintrin.h> | ||
#include <cstdint> | ||
int main() | ||
{ | ||
__m128i a = _mm_cvtsi64_si128((uint64_t)7); | ||
__m128i b = _mm_clmulepi64_si128(a, a, 37); | ||
__m128i c = _mm_srli_epi64(b, 41); | ||
__m128i d = _mm_xor_si128(b, c); | ||
uint64_t e = _mm_cvtsi128_si64(d); | ||
return e == 0; | ||
} | ||
" HAVE_CLMUL | ||
) | ||
|
||
add_library(minisketch_defs INTERFACE) | ||
target_compile_definitions(minisketch_defs INTERFACE | ||
DISABLE_DEFAULT_FIELDS | ||
ENABLE_FIELD_32 | ||
$<$<AND:$<BOOL:${HAVE_BUILTIN_CLZL}>,$<BOOL:${HAVE_BUILTIN_CLZLL}>>:HAVE_CLZ> | ||
) | ||
|
||
if(HAVE_CLMUL) | ||
add_library(minisketch_clmul OBJECT EXCLUDE_FROM_ALL | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_1byte.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_2bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_3bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_4bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_5bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_6bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_7bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/clmul_8bytes.cpp | ||
) | ||
target_compile_definitions(minisketch_clmul PUBLIC HAVE_CLMUL) | ||
target_compile_options(minisketch_clmul PRIVATE ${CLMUL_CXXFLAGS}) | ||
target_link_libraries(minisketch_clmul PRIVATE minisketch_defs) | ||
endif() | ||
|
||
add_library(minisketch STATIC EXCLUDE_FROM_ALL | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/minisketch.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_1byte.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_2bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_3bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_4bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_5bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_6bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_7bytes.cpp | ||
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_8bytes.cpp | ||
) | ||
|
||
target_include_directories(minisketch | ||
PUBLIC | ||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/minisketch/include> | ||
) | ||
|
||
target_link_libraries(minisketch | ||
PRIVATE | ||
minisketch_defs | ||
$<TARGET_NAME_IF_EXISTS:minisketch_clmul> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
function(add_boost_if_needed) | ||
#[=[ | ||
TODO: Not all targets, which will be added in the future, require | ||
Boost. Therefore, a proper check will be appropriate here. | ||
|
||
Implementation notes: | ||
Although only Boost headers are used to build Bitcoin Core, | ||
we still leverage a standard CMake's approach to handle | ||
dependencies, i.e., the Boost::headers "library". | ||
A command target_link_libraries(target PRIVATE Boost::headers) | ||
will propagate Boost::headers usage requirements to the target. | ||
For Boost::headers such usage requirements is an include | ||
directory and other added INTERFACE properties. | ||
]=] | ||
|
||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND BREW_COMMAND) | ||
execute_process( | ||
COMMAND ${BREW_COMMAND} --prefix boost | ||
OUTPUT_VARIABLE BOOST_ROOT | ||
ERROR_QUIET | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
endif() | ||
|
||
set(Boost_NO_BOOST_CMAKE ON) | ||
find_package(Boost 1.64.0 REQUIRED) | ||
set_target_properties(Boost::boost PROPERTIES IMPORTED_GLOBAL TRUE) | ||
target_compile_definitions(Boost::boost INTERFACE | ||
$<$<CONFIG:Debug>:BOOST_MULTI_INDEX_ENABLE_SAFE_MODE> | ||
) | ||
if(CMAKE_VERSION VERSION_LESS 3.15) | ||
add_library(Boost::headers ALIAS Boost::boost) | ||
endif() | ||
|
||
mark_as_advanced(Boost_INCLUDE_DIR) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
macro(check_evhttp_connection_get_peer target) | ||
# Check whether evhttp_connection_get_peer expects const char**. | ||
# Fail if neither are available. | ||
check_cxx_source_compiles(" | ||
#include <cstdint> | ||
#include <event2/http.h> | ||
int main() | ||
{ | ||
evhttp_connection* conn = (evhttp_connection*)1; | ||
const char* host; | ||
uint16_t port; | ||
evhttp_connection_get_peer(conn, &host, &port); | ||
} | ||
" HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR | ||
) | ||
target_compile_definitions(${target} INTERFACE | ||
$<$<BOOL:${HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR}>:HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR=1> | ||
) | ||
endmacro() | ||
|
||
function(add_libevent_if_needed) | ||
# TODO: Not all targets, which will be added in the future, | ||
# require libevent. Therefore, a proper check will be | ||
# appropriate here. | ||
|
||
set(libevent_minimum_version 2.1.8) | ||
|
||
if(MSVC) | ||
find_package(Libevent ${libevent_minimum_version} REQUIRED COMPONENTS extra CONFIG) | ||
check_evhttp_connection_get_peer(libevent::extra) | ||
add_library(libevent::libevent ALIAS libevent::extra) | ||
return() | ||
endif() | ||
|
||
find_package(PkgConfig) | ||
pkg_check_modules(libevent REQUIRED libevent>=${libevent_minimum_version} IMPORTED_TARGET GLOBAL) | ||
check_evhttp_connection_get_peer(PkgConfig::libevent) | ||
target_link_libraries(PkgConfig::libevent INTERFACE | ||
$<$<BOOL:${MINGW}>:iphlpapi;ws2_32> | ||
) | ||
add_library(libevent::libevent ALIAS PkgConfig::libevent) | ||
|
||
if(NOT WIN32) | ||
pkg_check_modules(libevent_pthreads REQUIRED libevent_pthreads>=${libevent_minimum_version} IMPORTED_TARGET) | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
function(add_threads_if_needed) | ||
# TODO: Not all targets, which will be added in the future, | ||
# require Threads. Therefore, a proper check will be | ||
# appropriate here. | ||
|
||
set(THREADS_PREFER_PTHREAD_FLAG ON) | ||
find_package(Threads REQUIRED) | ||
|
||
set(thread_local) | ||
if(MINGW) | ||
#[=[ | ||
mingw32's implementation of thread_local has been shown to behave | ||
erroneously under concurrent usage. | ||
See: | ||
- https://github.com/bitcoin/bitcoin/pull/15849 | ||
- https://gist.github.com/jamesob/fe9a872051a88b2025b1aa37bfa98605 | ||
]=] | ||
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") | ||
#[=[ | ||
FreeBSD's implementation of thread_local is buggy. | ||
See: | ||
- https://github.com/bitcoin/bitcoin/pull/16059 | ||
- https://groups.google.com/d/msg/bsdmailinglist/22ncTZAbDp4/Dii_pII5AwAJ | ||
]=] | ||
elseif(THREADLOCAL) | ||
set(thread_local "$<$<COMPILE_FEATURES:cxx_thread_local>:HAVE_THREAD_LOCAL>") | ||
endif() | ||
set(THREAD_LOCAL_IF_AVAILABLE "${thread_local}" PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
# GCC 8.x (libstdc++) requires -lstdc++fs | ||
# Clang 8.x (libc++) requires -lc++fs | ||
|
||
function(check_std_filesystem) | ||
set(source " | ||
#include <filesystem> | ||
int main() | ||
{ | ||
(void)std::filesystem::current_path().root_name(); | ||
} | ||
") | ||
|
||
include(CheckCXXSourceCompiles) | ||
check_cxx_source_links("${source}" STD_FILESYSTEM_NO_EXTRA_LIBS_NEEDED) | ||
if(STD_FILESYSTEM_NO_EXTRA_LIBS_NEEDED) | ||
return() | ||
endif() | ||
|
||
add_library(std_filesystem INTERFACE) | ||
check_cxx_source_links_with_libs(stdc++fs "${source}" STD_FILESYSTEM_NEEDS_LINK_TO_LIBSTDCXXFS) | ||
if(STD_FILESYSTEM_NEEDS_LINK_TO_LIBSTDCXXFS) | ||
target_link_libraries(std_filesystem INTERFACE stdc++fs) | ||
return() | ||
endif() | ||
check_cxx_source_links_with_libs(c++fs "${source}" STD_FILESYSTEM_NEEDS_LINK_TO_LIBCXXFS) | ||
if(STD_FILESYSTEM_NEEDS_LINK_TO_LIBCXXFS) | ||
target_link_libraries(std_filesystem INTERFACE c++fs) | ||
return() | ||
endif() | ||
message(FATAL_ERROR "Cannot figure out how to use std::filesystem.") | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
# This file is part of the transition from Autotools to CMake. Once CMake | ||
# support has been merged we should switch to using the upstream CMake | ||
# buildsystem. | ||
|
||
set(CMAKE_C_STANDARD 90) | ||
set(CMAKE_C_EXTENSIONS OFF) | ||
|
||
include(CheckCSourceCompiles) | ||
check_c_source_compiles(" | ||
#include <stdint.h> | ||
int main() | ||
{ | ||
uint64_t a = 11, tmp; | ||
__asm__ __volatile__(\"movq $0x100000000,%1; mulq %%rsi\" : \"+a\"(a) : \"S\"(tmp) : \"cc\", \"%rdx\"); | ||
} | ||
" HAVE_64BIT_ASM | ||
) | ||
|
||
add_library(secp256k1 STATIC EXCLUDE_FROM_ALL | ||
${PROJECT_SOURCE_DIR}/src/secp256k1/src/secp256k1.c | ||
${PROJECT_SOURCE_DIR}/src/secp256k1/src/precomputed_ecmult.c | ||
${PROJECT_SOURCE_DIR}/src/secp256k1/src/precomputed_ecmult_gen.c | ||
) | ||
|
||
target_compile_definitions(secp256k1 | ||
PRIVATE | ||
ECMULT_GEN_PREC_BITS=4 | ||
ECMULT_WINDOW_SIZE=15 | ||
ENABLE_MODULE_RECOVERY | ||
ENABLE_MODULE_SCHNORRSIG | ||
ENABLE_MODULE_EXTRAKEYS | ||
$<$<BOOL:${HAVE_64BIT_ASM}>:USE_ASM_X86_64=1> | ||
) | ||
|
||
target_include_directories(secp256k1 | ||
PUBLIC | ||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/secp256k1/include> | ||
) | ||
|
||
target_compile_options(secp256k1 | ||
PRIVATE | ||
$<$<CXX_COMPILER_ID:MSVC>:/wd4146 /wd4334> | ||
) |
Oops, something went wrong.