Skip to content

Commit

Permalink
Merge #17: build: Add CMake-based build system (7 of N)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hebasto committed Jul 20, 2023
2 parents 3f513eb + a933ddf commit e592ad1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
26 changes: 25 additions & 1 deletion cmake/module/AddBoostIfNeeded.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,35 @@ function(add_boost_if_needed)
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>
# We don't use multi_index serialization.
BOOST_MULTI_INDEX_DISABLE_SERIALIZATION
)
if(CMAKE_VERSION VERSION_LESS 3.15)
add_library(Boost::headers ALIAS Boost::boost)
endif()

if(BUILD_TESTS)
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR})
check_cxx_source_compiles("
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
" HAVE_BOOST_INCLUDED_UNIT_TEST_H
)
if(NOT HAVE_BOOST_INCLUDED_UNIT_TEST_H)
message(FATAL_ERROR "Building test_bitcoin executable requested but boost/test/included/unit_test.hpp header not available.")
endif()

check_cxx_source_compiles("
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
" HAVE_BOOST_UNIT_TEST_H
)
if(NOT HAVE_BOOST_UNIT_TEST_H)
message(FATAL_ERROR "Building test_bitcoin executable requested but boost/test/unit_test.hpp header not available.")
endif()
endif()

mark_as_advanced(Boost_INCLUDE_DIR)
endfunction()
19 changes: 18 additions & 1 deletion cmake/module/CrossPkgConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
find_package(PkgConfig REQUIRED)

function(remove_isystem_from_include_directories_internal target)
#[=[
A workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/20652.

When the pkg-config provides CFLAGS with -isystem options, for instance:

$ pkg-config --cflags-only-I libzmq
-isystem /usr/include/mit-krb5 -I/usr/include/pgm-5.3 -I/usr/include/libxml2

an old CMake fails to parse them properly and the INTERFACE_INCLUDE_DIRECTORIES
property contains "-isystem" as a separated element:

-isystem;/usr/include/mit-krb5;/usr/include/pgm-5.3;/usr/include/libxml2

which ends with an error "Imported target includes non-existent path".

Fixing by removing the "-isystem" element from the INTERFACE_INCLUDE_DIRECTORIES.
]=]

get_target_property(include_directories ${target} INTERFACE_INCLUDE_DIRECTORIES)
if(include_directories)
list(REMOVE_ITEM include_directories -isystem)
Expand All @@ -25,7 +43,6 @@ macro(cross_pkg_check_modules prefix)
pkg_check_modules(${prefix} ${ARGN})
endif()

# A workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/20652.
if(CMAKE_VERSION VERSION_LESS 3.17.3 AND TARGET PkgConfig::${prefix})
remove_isystem_from_include_directories_internal(PkgConfig::${prefix})
endif()
Expand Down
13 changes: 10 additions & 3 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,16 @@ endif()

if(ENABLE_WALLET)
if(WITH_SQLITE)
include(CrossPkgConfig)
cross_pkg_check_modules(sqlite sqlite3>=3.7.17 IMPORTED_TARGET)
if(sqlite_FOUND)
# TODO: Consider using the FindSQLite3 module after bumping
# the minimum required CMake version up to 3.14+.
if(MSVC)
# Use of the `unofficial::` namespace is a vcpkg package manager convention.
find_package(unofficial-sqlite3 CONFIG)
else()
include(CrossPkgConfig)
cross_pkg_check_modules(sqlite3 sqlite3>=3.7.17 IMPORTED_TARGET)
endif()
if(TARGET unofficial::sqlite3::sqlite3 OR TARGET PkgConfig::sqlite3)
set(WITH_SQLITE ON)
set(USE_SQLITE ON)
elseif(WITH_SQLITE STREQUAL "AUTO")
Expand Down
7 changes: 7 additions & 0 deletions src/test/compilerbug_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

BOOST_AUTO_TEST_SUITE(compilerbug_tests)

// At least one test case is required to avoid the "Test setup error: no test
// cases matching filter or all test cases were disabled" errror.
BOOST_AUTO_TEST_CASE(dummy)
{
BOOST_CHECK(true);
}

#if defined(__GNUC__)
// This block will also be built under clang, which is fine (as it supports noinline)
void __attribute__ ((noinline)) set_one(unsigned char* ptr)
Expand Down
6 changes: 5 additions & 1 deletion src/wallet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ if(NOT USE_SQLITE AND NOT USE_BDB)
endif()
if(USE_SQLITE)
target_sources(bitcoin_wallet PRIVATE sqlite.cpp)
target_link_libraries(bitcoin_wallet PRIVATE PkgConfig::sqlite)
target_link_libraries(bitcoin_wallet
PRIVATE
$<TARGET_NAME_IF_EXISTS:unofficial::sqlite3::sqlite3>
$<TARGET_NAME_IF_EXISTS:PkgConfig::sqlite3>
)
endif()
if(USE_BDB)
target_sources(bitcoin_wallet PRIVATE bdb.cpp salvage.cpp)
Expand Down

0 comments on commit e592ad1

Please sign in to comment.