Skip to content

Commit 3bc91d2

Browse files
committed
Merge #5: build: Add CMake-based build system (1 of N)
e7fb823 cmake: Add `config/bitcoin-config.h` support (Hennadii Stepanov) bc25dda cmake: Add root `CMakeLists.txt` file (Hennadii Stepanov) Pull request description: This is a first PR into a staging branch as suggested in bitcoin#27060 (comment). This PR: 1. Establishes the minimum required CMake [version](https://gitlab.kitware.com/cmake/community/-/wikis/CMake-Versions-on-Linux-Distros). As it looks non-productive to support Ubuntu Bionic as a build platform, version [3.13](https://cmake.org/cmake/help/latest/release/3.13.html) has been chosen. 2. Creates a `bitcoin-config.h` header in the build tree. ## Notes for reviewers To configure a build system, one can run in their local repo root: - on Linux / *BSD / macOS: ```sh cmake -S . -B build ``` - on Windows: ```cmd cmake -G "Visual Studio 17 2022" -A x64 -S . -B build ``` To re-configure, it is recommended to use the clean build tree, for example: ```sh rm -rf build ``` For now, the only artifact we explicitly create in the build tree is a `bitcoin-config.h` header: ```sh cat build/src/config/bitcoin-config.h ``` ACKs for top commit: vasild: ACK e7fb823 TheCharlatan: ACK [e7fb823](e7fb823) theuni: So, sure, ACK e7fb823 to keep things moving. But I'm hoping 2/N is less boilerplate and more skeletal :) Tree-SHA512: cfbc775832b4758dc42a55c7f04ac50bd7136136007d68e8969d16f78bd557ad1eaeac6bed8622e4aa94d9249afbdd5be3d690ef01e7b97cca05f04b6fa115de
2 parents 5ecd14a + e7fb823 commit 3bc91d2

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed

CMakeLists.txt

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Copyright (c) 2023 The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
# IMPORTANT: Changes which affect binary results may not be quietly gated
6+
# by CMake version.
7+
#
8+
# Debian 10 Buster, https://wiki.debian.org/LTS, EOL 2024:
9+
# - CMake 3.13.4, https://packages.debian.org/buster/cmake
10+
#
11+
# Ubuntu 22.04 Jammy, https://wiki.ubuntu.com/Releases, EOL 2032:
12+
# - CMake 3.22.1, https://packages.ubuntu.com/jammy/cmake
13+
#
14+
# Visual Studio 17 2022, https://visualstudio.microsoft.com:
15+
# - CMake 3.24
16+
#
17+
# All policies known to the running version of CMake and introduced
18+
# in the 3.24 version or earlier will be set to use NEW behavior.
19+
# All policies introduced in later versions will be unset.
20+
# See: https://cmake.org/cmake/help/latest/manual/cmake-policies.7.html
21+
cmake_minimum_required(VERSION 3.13...3.24)
22+
23+
project("Bitcoin Core"
24+
VERSION 24.99.0
25+
DESCRIPTION "Bitcoin client software"
26+
HOMEPAGE_URL "https://bitcoincore.org/"
27+
LANGUAGES CXX C ASM
28+
)
29+
30+
set(CLIENT_VERSION_IS_RELEASE "false")
31+
set(COPYRIGHT_YEAR "2023")
32+
set(COPYRIGHT_HOLDERS "The %s developers")
33+
set(COPYRIGHT_HOLDERS_FINAL "The ${PROJECT_NAME} developers")
34+
set(PACKAGE_BUGREPORT "https://github.com/bitcoin/bitcoin/issues")
35+
36+
# Configurable options.
37+
# When adding a new option, end the <help_text> with a full stop for consistency.
38+
include(CMakeDependentOption)
39+
cmake_dependent_option(CXX20 "Enable compilation in C++20 mode." OFF "NOT MSVC" ON)
40+
41+
if(CXX20)
42+
set(CMAKE_CXX_STANDARD 20)
43+
else()
44+
set(CMAKE_CXX_STANDARD 17)
45+
endif()
46+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
47+
set(CMAKE_CXX_EXTENSIONS OFF)
48+
49+
set(configure_warnings)
50+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
51+
include(CheckPIESupported)
52+
check_pie_supported(OUTPUT_VARIABLE check_pie_output LANGUAGES CXX)
53+
if(NOT CMAKE_CXX_LINK_PIE_SUPPORTED)
54+
list(APPEND configure_warnings "PIE link options are not supported for executable targets: ${check_pie_output}.")
55+
endif()
56+
else()
57+
list(APPEND configure_warnings "No PIE options will be passed to a linker for executable targets.")
58+
endif()
59+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
60+
61+
add_subdirectory(src)
62+
63+
message("\n")
64+
message("Configure summary")
65+
message("=================")
66+
get_directory_property(definitions COMPILE_DEFINITIONS)
67+
string(REPLACE ";" " " definitions "${definitions}")
68+
message("Preprocessor defined macros ........... ${definitions}")
69+
message("C compiler ............................ ${CMAKE_C_COMPILER}")
70+
message("CFLAGS ................................ ${CMAKE_C_FLAGS}")
71+
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER}")
72+
message("CXXFLAGS .............................. ${CMAKE_CXX_FLAGS}")
73+
get_directory_property(common_compile_options COMPILE_OPTIONS)
74+
string(REPLACE ";" " " common_compile_options "${common_compile_options}")
75+
message("Common compile options ................ ${common_compile_options}")
76+
get_directory_property(common_link_options LINK_OPTIONS)
77+
string(REPLACE ";" " " common_link_options "${common_link_options}")
78+
message("Common link options ................... ${common_link_options}")
79+
if(DEFINED CMAKE_BUILD_TYPE)
80+
message("Build type:")
81+
message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}")
82+
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
83+
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_${build_type}}")
84+
message(" - CXXFLAGS ........................... ${CMAKE_CXX_FLAGS_${build_type}}")
85+
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_${build_type}}")
86+
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_${build_type}}")
87+
else()
88+
message("Available configurations .............. ${CMAKE_CONFIGURATION_TYPES}")
89+
message("Debug configuration:")
90+
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_DEBUG}")
91+
message(" - CXXFLAGS ........................... ${CMAKE_CXX_FLAGS_DEBUG}")
92+
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
93+
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
94+
message("Release configuration:")
95+
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_RELEASE}")
96+
message(" - CXXFLAGS ........................... ${CMAKE_CXX_FLAGS_RELEASE}")
97+
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
98+
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
99+
endif()
100+
message("\n")
101+
if(configure_warnings)
102+
message(" ******\n")
103+
foreach(warning IN LISTS configure_warnings)
104+
message(WARNING "${warning}")
105+
endforeach()
106+
message(" ******\n")
107+
endif()

cmake/bitcoin-config.h.in

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2023 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_CONFIG_H
6+
7+
#define BITCOIN_CONFIG_H
8+
9+
/* Version Build */
10+
#define CLIENT_VERSION_BUILD @PROJECT_VERSION_PATCH@
11+
12+
/* Version is release */
13+
#define CLIENT_VERSION_IS_RELEASE @CLIENT_VERSION_IS_RELEASE@
14+
15+
/* Major version */
16+
#define CLIENT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
17+
18+
/* Minor version */
19+
#define CLIENT_VERSION_MINOR @PROJECT_VERSION_MINOR@
20+
21+
/* Copyright holder(s) before %s replacement */
22+
#define COPYRIGHT_HOLDERS "@COPYRIGHT_HOLDERS@"
23+
24+
/* Copyright holder(s) */
25+
#define COPYRIGHT_HOLDERS_FINAL "@COPYRIGHT_HOLDERS_FINAL@"
26+
27+
/* Replacement for %s in copyright holders string */
28+
#define COPYRIGHT_HOLDERS_SUBSTITUTION "@PROJECT_NAME@"
29+
30+
/* Copyright year */
31+
#define COPYRIGHT_YEAR @COPYRIGHT_YEAR@
32+
33+
/* Define to the address where bug reports for this package should be sent. */
34+
#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
35+
36+
/* Define to the full name of this package. */
37+
#define PACKAGE_NAME "@PROJECT_NAME@"
38+
39+
/* Define to the home page for this package. */
40+
#define PACKAGE_URL "@PROJECT_HOMEPAGE_URL@"
41+
42+
/* Define to the version of this package. */
43+
#define PACKAGE_VERSION "@PROJECT_VERSION@"
44+
45+
#endif //BITCOIN_CONFIG_H

src/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2023 The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
configure_file(${CMAKE_SOURCE_DIR}/cmake/bitcoin-config.h.in config/bitcoin-config.h @ONLY)
6+
add_compile_definitions(HAVE_CONFIG_H)
7+
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})

0 commit comments

Comments
 (0)