Skip to content

Commit e592ad1

Browse files
committed
Merge #17: build: Add CMake-based build system (7 of N)
a933ddf [FIXUP] Better document a workaround (Hennadii Stepanov) 769633e [FIXUP] for "cmake: Add wallet functionality" (Hennadii Stepanov) 31e4e62 [FIXUP] for "cmake: Build `test_bitcoin` executable" (Hennadii Stepanov) f2dbb17 [FIXUP] for "cmake: Build `test_bitcoin` executable" (Hennadii Stepanov) 91d7327 [FIXUP] Boost (Hennadii Stepanov) Pull request description: The parent PR: bitcoin#25797. The previous PRs in the staging branch: #5, #6, #7, #10, #13, #15. This PR consists of fixups only to make reviewing easier :) ACKs for top commit: theuni: ACK a933ddf Tree-SHA512: 270869a3bf9b9f2d56b75d169f25032385fa2d1297951a23c0d1900d9668a40b153c7a5d9b51fa87596eec681107c40da8e55f405d28a7ecd2ec0f72f3550bbf
2 parents 3f513eb + a933ddf commit e592ad1

File tree

5 files changed

+65
-6
lines changed

5 files changed

+65
-6
lines changed

cmake/module/AddBoostIfNeeded.cmake

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,35 @@ function(add_boost_if_needed)
2121
find_package(Boost 1.64.0 REQUIRED)
2222
set_target_properties(Boost::boost PROPERTIES IMPORTED_GLOBAL TRUE)
2323
target_compile_definitions(Boost::boost INTERFACE
24-
$<$<CONFIG:Debug>:BOOST_MULTI_INDEX_ENABLE_SAFE_MODE>
24+
# We don't use multi_index serialization.
25+
BOOST_MULTI_INDEX_DISABLE_SERIALIZATION
2526
)
2627
if(CMAKE_VERSION VERSION_LESS 3.15)
2728
add_library(Boost::headers ALIAS Boost::boost)
2829
endif()
2930

31+
if(BUILD_TESTS)
32+
include(CheckCXXSourceCompiles)
33+
set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR})
34+
check_cxx_source_compiles("
35+
#define BOOST_TEST_MAIN
36+
#include <boost/test/included/unit_test.hpp>
37+
" HAVE_BOOST_INCLUDED_UNIT_TEST_H
38+
)
39+
if(NOT HAVE_BOOST_INCLUDED_UNIT_TEST_H)
40+
message(FATAL_ERROR "Building test_bitcoin executable requested but boost/test/included/unit_test.hpp header not available.")
41+
endif()
42+
43+
check_cxx_source_compiles("
44+
#define BOOST_TEST_MAIN
45+
#include <boost/test/included/unit_test.hpp>
46+
#include <boost/test/unit_test.hpp>
47+
" HAVE_BOOST_UNIT_TEST_H
48+
)
49+
if(NOT HAVE_BOOST_UNIT_TEST_H)
50+
message(FATAL_ERROR "Building test_bitcoin executable requested but boost/test/unit_test.hpp header not available.")
51+
endif()
52+
endif()
53+
3054
mark_as_advanced(Boost_INCLUDE_DIR)
3155
endfunction()

cmake/module/CrossPkgConfig.cmake

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
find_package(PkgConfig REQUIRED)
66

77
function(remove_isystem_from_include_directories_internal target)
8+
#[=[
9+
A workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/20652.
10+
11+
When the pkg-config provides CFLAGS with -isystem options, for instance:
12+
13+
$ pkg-config --cflags-only-I libzmq
14+
-isystem /usr/include/mit-krb5 -I/usr/include/pgm-5.3 -I/usr/include/libxml2
15+
16+
an old CMake fails to parse them properly and the INTERFACE_INCLUDE_DIRECTORIES
17+
property contains "-isystem" as a separated element:
18+
19+
-isystem;/usr/include/mit-krb5;/usr/include/pgm-5.3;/usr/include/libxml2
20+
21+
which ends with an error "Imported target includes non-existent path".
22+
23+
Fixing by removing the "-isystem" element from the INTERFACE_INCLUDE_DIRECTORIES.
24+
]=]
25+
826
get_target_property(include_directories ${target} INTERFACE_INCLUDE_DIRECTORIES)
927
if(include_directories)
1028
list(REMOVE_ITEM include_directories -isystem)
@@ -25,7 +43,6 @@ macro(cross_pkg_check_modules prefix)
2543
pkg_check_modules(${prefix} ${ARGN})
2644
endif()
2745

28-
# A workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/20652.
2946
if(CMAKE_VERSION VERSION_LESS 3.17.3 AND TARGET PkgConfig::${prefix})
3047
remove_isystem_from_include_directories_internal(PkgConfig::${prefix})
3148
endif()

cmake/optional.cmake

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,16 @@ endif()
111111

112112
if(ENABLE_WALLET)
113113
if(WITH_SQLITE)
114-
include(CrossPkgConfig)
115-
cross_pkg_check_modules(sqlite sqlite3>=3.7.17 IMPORTED_TARGET)
116-
if(sqlite_FOUND)
114+
# TODO: Consider using the FindSQLite3 module after bumping
115+
# the minimum required CMake version up to 3.14+.
116+
if(MSVC)
117+
# Use of the `unofficial::` namespace is a vcpkg package manager convention.
118+
find_package(unofficial-sqlite3 CONFIG)
119+
else()
120+
include(CrossPkgConfig)
121+
cross_pkg_check_modules(sqlite3 sqlite3>=3.7.17 IMPORTED_TARGET)
122+
endif()
123+
if(TARGET unofficial::sqlite3::sqlite3 OR TARGET PkgConfig::sqlite3)
117124
set(WITH_SQLITE ON)
118125
set(USE_SQLITE ON)
119126
elseif(WITH_SQLITE STREQUAL "AUTO")

src/test/compilerbug_tests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
BOOST_AUTO_TEST_SUITE(compilerbug_tests)
88

9+
// At least one test case is required to avoid the "Test setup error: no test
10+
// cases matching filter or all test cases were disabled" errror.
11+
BOOST_AUTO_TEST_CASE(dummy)
12+
{
13+
BOOST_CHECK(true);
14+
}
15+
916
#if defined(__GNUC__)
1017
// This block will also be built under clang, which is fine (as it supports noinline)
1118
void __attribute__ ((noinline)) set_one(unsigned char* ptr)

src/wallet/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ if(NOT USE_SQLITE AND NOT USE_BDB)
4444
endif()
4545
if(USE_SQLITE)
4646
target_sources(bitcoin_wallet PRIVATE sqlite.cpp)
47-
target_link_libraries(bitcoin_wallet PRIVATE PkgConfig::sqlite)
47+
target_link_libraries(bitcoin_wallet
48+
PRIVATE
49+
$<TARGET_NAME_IF_EXISTS:unofficial::sqlite3::sqlite3>
50+
$<TARGET_NAME_IF_EXISTS:PkgConfig::sqlite3>
51+
)
4852
endif()
4953
if(USE_BDB)
5054
target_sources(bitcoin_wallet PRIVATE bdb.cpp salvage.cpp)

0 commit comments

Comments
 (0)