From 897dac8f9cb327eb24827731e569fadd32ae53d4 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Thu, 19 Mar 2026 15:58:42 +0100 Subject: [PATCH] Allow multiple find_package(SOCI) calls in application using SOCI We now only define our targets if they don't exist yet to avoid errors due to redefining them if find_package(SOCI) is done more than once. Note that multiple calls to find_package(SOCI) that specify different components will cause all call-sides to use the superset of all requested components as targets are global (and hence also their link dependencies). Fixes #1344. See #1346. --- soci-config.cmake.in | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/soci-config.cmake.in b/soci-config.cmake.in index 3104e5b1..60b49e8d 100644 --- a/soci-config.cmake.in +++ b/soci-config.cmake.in @@ -157,17 +157,23 @@ unset(__dep_dep_targets) check_required_components(SOCI) if (NOT DEFINED SOCI_FOUND OR SOCI_FOUND) - add_library(SOCI::SOCI INTERFACE IMPORTED) + if (NOT TARGET SOCI::SOCI) + add_library(SOCI::SOCI INTERFACE IMPORTED) + endif() foreach (__comp IN LISTS SOCI_FIND_COMPONENTS) target_link_libraries(SOCI::SOCI INTERFACE SOCI::${__comp}) endforeach() # Shall be removed in SOCI v5 - add_library(soci_interface_deprecated INTERFACE) + if (NOT TARGET soci_interface_deprecated) + add_library(soci_interface_deprecated INTERFACE) + endif() target_link_libraries(soci_interface_deprecated INTERFACE SOCI::SOCI) set_target_properties(soci_interface_deprecated PROPERTIES DEPRECATION "Use SOCI::SOCI (all-uppercase) instead of SOCI::soci") - add_library(SOCI::soci ALIAS soci_interface_deprecated) + if (NOT TARGET SOCI::soci) + add_library(SOCI::soci ALIAS soci_interface_deprecated) + endif() if (NOT SOCI_FIND_QUIETLY) list(JOIN SOCI_FIND_COMPONENTS ", " __components)