diff --git a/cmake/module/AddBoostIfNeeded.cmake b/cmake/module/AddBoostIfNeeded.cmake index a31ed10a9f58b..32b4abdd18fcb 100644 --- a/cmake/module/AddBoostIfNeeded.cmake +++ b/cmake/module/AddBoostIfNeeded.cmake @@ -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 - $<$: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 + " 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 + #include + " 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() diff --git a/cmake/module/CrossPkgConfig.cmake b/cmake/module/CrossPkgConfig.cmake index 429fa5fdc2432..cbd6f3c27b288 100644 --- a/cmake/module/CrossPkgConfig.cmake +++ b/cmake/module/CrossPkgConfig.cmake @@ -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) @@ -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() diff --git a/cmake/optional.cmake b/cmake/optional.cmake index e018a47f73725..812f93c4bbc67 100644 --- a/cmake/optional.cmake +++ b/cmake/optional.cmake @@ -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") diff --git a/src/test/compilerbug_tests.cpp b/src/test/compilerbug_tests.cpp index ef558c1e32269..4492a9686c766 100644 --- a/src/test/compilerbug_tests.cpp +++ b/src/test/compilerbug_tests.cpp @@ -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) diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt index 9ff55d505815c..319b8960dfb62 100644 --- a/src/wallet/CMakeLists.txt +++ b/src/wallet/CMakeLists.txt @@ -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 + $ + $ + ) endif() if(USE_BDB) target_sources(bitcoin_wallet PRIVATE bdb.cpp salvage.cpp)