Skip to content

Commit

Permalink
Add CMake-based build system
Browse files Browse the repository at this point in the history
List of the squashed commits:
=============================

cmake: Add root `CMakeLists.txt` file

cmake: Introduce core interface libraries to encapsulate common flags

cmake: Add `config/bitcoin-config.h` support

cmake: Check system headers

cmake: Check system symbols

cmake: Check compiler features

cmake: Add position independent code support

cmake: Add platform-specific definitions and properties

cmake: Build `crc32c` static library

cmake: Build `leveldb` static library

cmake: Build `minisketch` static library

cmake: Build `secp256k1` static library

cmake: Build `univalue` static library

cmake: Build `bitcoin_crypto` library

cmake: Build `bitcoin_util` static library

cmake: Build `bitcoin_consensus` library

cmake: Build `bitcoind` executable

depends: Amend handling flags environment variables

build: Generate `share/toolchain.cmake` in depends

cmake: Add cross-compiling support

cmake: Add `TristateOption` module

cmake: Add `ccache` support

cmake: Add `libnatpmp` optional package support

cmake: Add `libminiupnpc` optional package support

cmake: Add `libzmq` optional package support

cmake: Add `systemtap-sdt` optional package support

cmake: Build `bitcoin-cli` executable

cmake: Build `bitcoin-tx` executable

cmake: Build `bitcoin-util` executable

cmake: Add wallet functionality

cmake: Add test config and runners

cmake: Build `bench_bitcoin` executable

cmake: Build `test_bitcoin` executable

cmake: Include CTest

cmake: Add `TryAppendCXXFlags` module

cmake: Add `TryAppendLinkerFlag` module

cmake: Add platform-specific compiler flags

cmake: Add platform-specific linker flags

cmake: Redefine/adjust per-configuration flags

cmake: Add general compile options

cmake: Add `HARDENING` option

cmake: Add `REDUCE_EXPORTS` option

cmake: Add `WERROR` option

cmake: Implement `make install`

cmake: Generate `obj/build.h` header

Revert "build, qt: Do not install *.prl files"

qt, build: Drop `QT_STATICPLUGIN` macro

cmake: Build `bitcoin-qt` executable

cmake: Build `test_bitcoin-qt` executable

qt: Drop `Q_IMPORT_PLUGIN` macros

cmake: Add `libqrencode` optional package support

cmake: Add `SANITIZERS` option

cmake: Add external signer support

cmake: Add fuzzing options

cmake: Add `AddWindowsResources` module

cmake: Add `Maintenance` module

cmake: Migrate Guix build scripts to CMake

cmake: Add vcpkg manifest file

cmake: Add preset for MSVC build

Fix MSVC warning C4273 "inconsistent dll linkage"

cmake, doc: Update `release-process.md`

cmake: Add compiler diagnostic flags

test: Fix MSVC warning C4101 "unreferenced local variable"

cmake: Build `bitcoinkernel` library

cmake: Build `bitcoin-chainstate` executable

ci: Test CMake edge cases

cmake, ci: Disable qt5 feature temporarily
  • Loading branch information
hebasto committed Apr 4, 2024
1 parent 71c51c1 commit 2dce3ac
Show file tree
Hide file tree
Showing 67 changed files with 5,613 additions and 90 deletions.
602 changes: 602 additions & 0 deletions .github/workflows/cmake.yml

Large diffs are not rendered by default.

584 changes: 584 additions & 0 deletions CMakeLists.txt

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"version": 3,
"cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0},
"configurePresets": [
{
"name": "vs2022",
"displayName": "Build using 'Visual Studio 17 2022' generator",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"toolchainFile": "$env{VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-windows",
"WITH_NATPMP": "OFF"
}
},
{
"name": "vs2022-static",
"displayName": "Build using 'Visual Studio 17 2022' generator",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"toolchainFile": "$env{VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-windows-static",
"WITH_NATPMP": "OFF"
}
}
]
}
1 change: 0 additions & 1 deletion build-aux/m4/bitcoin_qt.m4
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ AC_DEFUN([BITCOIN_QT_CONFIGURE],[
fi
fi
AC_DEFINE([QT_STATICPLUGIN], [1], [Define this symbol if qt plugins are static])
if test "$TARGET_OS" != "android"; then
_BITCOIN_QT_CHECK_STATIC_PLUGIN([QMinimalIntegrationPlugin], [-lqminimal])
AC_DEFINE([QT_QPA_PLATFORM_MINIMAL], [1], [Define this symbol if the minimal qt platform exists])
Expand Down
3 changes: 0 additions & 3 deletions build_msvc/bitcoin_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@
/* Define this symbol if the qt platform is windows */
#define QT_QPA_PLATFORM_WINDOWS 1

/* Define this symbol if qt plugins are static */
#define QT_STATICPLUGIN 1

/* Windows Universal Platform constraints */
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
/* Either a desktop application without API restrictions, or and older system
Expand Down
148 changes: 148 additions & 0 deletions cmake/bitcoin-config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// 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.

#ifndef BITCOIN_CONFIG_H

#define BITCOIN_CONFIG_H

/* Version Build */
#define CLIENT_VERSION_BUILD @CLIENT_VERSION_BUILD@

/* Version is release */
#define CLIENT_VERSION_IS_RELEASE @CLIENT_VERSION_IS_RELEASE@

/* Major version */
#define CLIENT_VERSION_MAJOR @CLIENT_VERSION_MAJOR@

/* Minor version */
#define CLIENT_VERSION_MINOR @CLIENT_VERSION_MINOR@

/* Copyright holder(s) before %s replacement */
#define COPYRIGHT_HOLDERS "@COPYRIGHT_HOLDERS@"

/* Copyright holder(s) */
#define COPYRIGHT_HOLDERS_FINAL "@COPYRIGHT_HOLDERS_FINAL@"

/* Replacement for %s in copyright holders string */
#define COPYRIGHT_HOLDERS_SUBSTITUTION "@PACKAGE_NAME@"

/* Copyright year */
#define COPYRIGHT_YEAR @COPYRIGHT_YEAR@

/* Define to 1 to enable tracepoints for Userspace, Statically Defined Tracing
*/
#cmakedefine ENABLE_TRACING 1

/* Define this symbol if you have __builtin_clzl */
#cmakedefine HAVE_BUILTIN_CLZL 1

/* Define this symbol if you have __builtin_clzll */
#cmakedefine HAVE_BUILTIN_CLZLL 1

/* Define to 1 if you have the declaration of `fork', and to 0 if you don't.
*/
#cmakedefine01 HAVE_DECL_FORK

/* Define to 1 if you have the declaration of `freeifaddrs', and to 0 if you
don't. */
#cmakedefine01 HAVE_DECL_FREEIFADDRS

/* Define to 1 if you have the declaration of `getifaddrs', and to 0 if you
don't. */
#cmakedefine01 HAVE_DECL_GETIFADDRS

/* Define to 1 if you have the declaration of `pipe2', and to 0 if you don't.
*/
#cmakedefine01 HAVE_DECL_PIPE2

/* Define to 1 if you have the declaration of `setsid', and to 0 if you don't.
*/
#cmakedefine01 HAVE_DECL_SETSID

/* Define if the visibility attribute is supported. */
#cmakedefine HAVE_DEFAULT_VISIBILITY_ATTRIBUTE 1

/* Define if the dllexport attribute is supported. */
#cmakedefine HAVE_DLLEXPORT_ATTRIBUTE 1

/* Define to 1 if fdatasync is available. */
#cmakedefine HAVE_FDATASYNC 1

/* Define this symbol if the BSD getentropy system call is available with
sys/random.h */
#cmakedefine HAVE_GETENTROPY_RAND 1

/* Define this symbol if the Linux getrandom function call is available */
#cmakedefine HAVE_GETRANDOM 1

/* Define this symbol if gmtime_r is available */
#cmakedefine HAVE_GMTIME_R 1

/* Define this symbol if you have malloc_info */
#cmakedefine HAVE_MALLOC_INFO 1

/* Define this symbol if you have mallopt with M_ARENA_MAX */
#cmakedefine HAVE_MALLOPT_ARENA_MAX 1

/* Define to 1 if O_CLOEXEC flag is available. */
#cmakedefine01 HAVE_O_CLOEXEC

/* Define this symbol if you have posix_fallocate */
#cmakedefine HAVE_POSIX_FALLOCATE 1

/* Define this symbol if platform supports unix domain sockets */
#cmakedefine HAVE_SOCKADDR_UN 1

/* Define this symbol to build code that uses getauxval */
#cmakedefine HAVE_STRONG_GETAUXVAL 1

/* Define this symbol if the BSD sysctl() is available */
#cmakedefine HAVE_SYSCTL 1

/* Define this symbol if the BSD sysctl(KERN_ARND) is available */
#cmakedefine HAVE_SYSCTL_ARND 1

/* Define to 1 if std::system or ::wsystem is available. */
#cmakedefine HAVE_SYSTEM 1

/* Define to 1 if you have the <sys/prctl.h> header file. */
#cmakedefine HAVE_SYS_PRCTL_H 1

/* Define to 1 if you have the <sys/resources.h> header file. */
#cmakedefine HAVE_SYS_RESOURCES_H 1

/* Define to 1 if you have the <sys/vmmeter.h> header file. */
#cmakedefine HAVE_SYS_VMMETER_H 1

/* Define to 1 if you have the <vm/vm_param.h> header file. */
#cmakedefine HAVE_VM_VM_PARAM_H 1

/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"

/* Define to the full name of this package. */
#define PACKAGE_NAME "@PACKAGE_NAME@"

/* Define to the home page for this package. */
#define PACKAGE_URL "@PROJECT_HOMEPAGE_URL@"

/* Define to the version of this package. */
#define PACKAGE_VERSION "@PACKAGE_VERSION@"

/* Define to 1 if strerror_r returns char *. */
#cmakedefine STRERROR_R_CHAR_P 1

/* Define to 1 to enable wallet functions. */
#cmakedefine ENABLE_WALLET 1

/* Define if SQLite support should be compiled in. */
#cmakedefine USE_SQLITE

/* Define if Berkeley DB (BDB) support should be compiled in. */
#cmakedefine USE_BDB

/* Define if external signer support is enabled. */
#cmakedefine ENABLE_EXTERNAL_SIGNER

#endif //BITCOIN_CONFIG_H
115 changes: 115 additions & 0 deletions cmake/crc32c.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# 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.

include(CheckCXXSourceCompiles)

# Check for __builtin_prefetch support in the compiler.
check_cxx_source_compiles("
int main() {
char data = 0;
const char* address = &data;
__builtin_prefetch(address, 0, 0);
return 0;
}
" HAVE_BUILTIN_PREFETCH
)

# Check for _mm_prefetch support in the compiler.
check_cxx_source_compiles("
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <xmmintrin.h>
#endif
int main() {
char data = 0;
const char* address = &data;
_mm_prefetch(address, _MM_HINT_NTA);
return 0;
}
" HAVE_MM_PREFETCH
)

# Check for SSE4.2 support in the compiler.
if(MSVC)
set(SSE42_CXXFLAGS /arch:AVX)
else()
set(SSE42_CXXFLAGS -msse4.2)
endif()
check_cxx_source_compiles_with_flags("${SSE42_CXXFLAGS}" "
#include <cstdint>
#if defined(_MSC_VER)
#include <intrin.h>
#elif defined(__GNUC__) && defined(__SSE4_2__)
#include <nmmintrin.h>
#endif
int main() {
uint64_t l = 0;
l = _mm_crc32_u8(l, 0);
l = _mm_crc32_u32(l, 0);
l = _mm_crc32_u64(l, 0);
return l;
}
" HAVE_SSE42
)

# Check for ARMv8 w/ CRC and CRYPTO extensions support in the compiler.
set(ARM_CRC_CXXFLAGS -march=armv8-a+crc+crypto)
check_cxx_source_compiles_with_flags("${ARM_CRC_CXXFLAGS}" "
#include <arm_acle.h>
#include <arm_neon.h>
int main() {
#ifdef __aarch64__
__crc32cb(0, 0); __crc32ch(0, 0); __crc32cw(0, 0); __crc32cd(0, 0);
vmull_p64(0, 0);
#else
#error crc32c library does not support hardware acceleration on 32-bit ARM
#endif
return 0;
}
" HAVE_ARM64_CRC32C
)

add_library(crc32c STATIC EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c.cc
${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_portable.cc
)

target_compile_definitions(crc32c
PRIVATE
HAVE_BUILTIN_PREFETCH=$<BOOL:${HAVE_BUILTIN_PREFETCH}>
HAVE_MM_PREFETCH=$<BOOL:${HAVE_MM_PREFETCH}>
HAVE_STRONG_GETAUXVAL=$<BOOL:${HAVE_STRONG_GETAUXVAL}>
HAVE_SSE42=$<BOOL:${HAVE_SSE42}>
HAVE_ARM64_CRC32C=$<BOOL:${HAVE_ARM64_CRC32C}>
BYTE_ORDER_BIG_ENDIAN=$<STREQUAL:${CMAKE_CXX_BYTE_ORDER},BIG_ENDIAN>
)

target_include_directories(crc32c
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/crc32c/include>
)

if(HAVE_SSE42)
target_sources(crc32c PRIVATE ${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_sse42.cc)
set_property(SOURCE ${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_sse42.cc
APPEND PROPERTY COMPILE_OPTIONS ${SSE42_CXXFLAGS}
)
endif()

if(HAVE_ARM64_CRC32C)
target_sources(crc32c PRIVATE ${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_arm64.cc)
set_property(SOURCE ${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_arm64.cc
APPEND PROPERTY COMPILE_OPTIONS ${ARM_CRC_CXXFLAGS}
)
endif()

target_link_libraries(crc32c PRIVATE core_base_interface)
Loading

0 comments on commit 2dce3ac

Please sign in to comment.