From 479b7de2c57f142c09321d1a9ea34079259bc666 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 17 Apr 2025 01:05:21 +0200 Subject: [PATCH] Re-add manual check for Boost to SOCI config file Do it manually, i.e. separately from the code checking for the dependencies created by soci_public_dependency(), as Boost is a special case because it is optional and has an optional component. --- soci-config.cmake.in | 24 ++++++++++++++++++++++++ src/core/CMakeLists.txt | 2 ++ 2 files changed, 26 insertions(+) diff --git a/soci-config.cmake.in b/soci-config.cmake.in index 1caa1d2a..005c30b0 100644 --- a/soci-config.cmake.in +++ b/soci-config.cmake.in @@ -6,6 +6,8 @@ set(__dep_soci_comps "@SOCI_DEPENDENCY_SOCI_COMPONENTS@") set(__dep_names "@SOCI_DEPENDENCY_NAMES@") set(__dep_dep_targets "@SOCI_DEPENDENCY_TARGETS@") +set(__dep_soci_boost "@SOCI_DEPENDENCY_BOOST@") +set(__dep_soci_boost_components "@SOCI_DEPENDENCY_BOOST_COMPONENTS@") set(__prev_module_path "${CMAKE_MODULE_PATH}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/find_package_files/") @@ -28,6 +30,28 @@ endif() list(REMOVE_ITEM SOCI_FIND_COMPONENTS Core) list(INSERT SOCI_FIND_COMPONENTS 0 Core) +# Check (optional) Core dependency on Boost. +if (${__dep_soci_boost}) + if (NOT "${__dep_soci_boost_components}" STREQUAL "") + set(SOCI_BOOST_COMPONENTS COMPONENTS ${__dep_soci_boost_components}) + endif() + + # Don't use REQUIRED to be able to give a better error message below. + find_package(Boost ${SOCI_BOOST_COMPONENTS} ${__quiet}) + + if (NOT Boost_FOUND) + set(SOCI_FOUND FALSE) + set(SOCI_NOT_FOUND_MESSAGE "Unmet dependency 'Boost' for SOCI component 'Core'") + else() + # Check for all the components too + foreach (__soci_boost_component IN LISTS __dep_soci_boost_components) + if (NOT TARGET Boost::${__soci_boost_component}) + set(SOCI_FOUND FALSE) + set(SOCI_NOT_FOUND_MESSAGE "Unmet dependency 'Boost::${__soci_boost_component}' for SOCI component 'Core'") + endif() + endforeach() + endif() +endif() list(LENGTH __dep_soci_comps __list_size) foreach (__item IN ITEMS __dep_names __dep_dep_targets) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 175ec6fb..0bf8a823 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -79,6 +79,7 @@ if (WITH_BOOST) # we found only Boost headers, but not the date_time library. if (TARGET Boost::date_time) set(SOCI_BOOST_DATE_TIME_MESSAGE " (with date_time component)") + set(SOCI_DEPENDENCY_BOOST_COMPONENTS "date_time" CACHE INTERNAL "Boost components used by SOCI") target_link_libraries(soci_core PUBLIC Boost::date_time) target_compile_definitions(soci_core PUBLIC SOCI_HAVE_BOOST_DATE_TIME) @@ -96,6 +97,7 @@ if (WITH_BOOST) # find_package() call or just Boost headers in the second one. if (Boost_FOUND) message(STATUS "Found Boost: v${Boost_VERSION_STRING} in ${Boost_INCLUDE_DIRS}${SOCI_BOOST_DATE_TIME_MESSAGE}") + set(SOCI_DEPENDENCY_BOOST TRUE CACHE INTERNAL "Whether SOCI depends on Boost") target_link_libraries(soci_core PUBLIC Boost::boost Boost::disable_autolinking) target_compile_definitions(soci_core PUBLIC SOCI_HAVE_BOOST)