Make multiple find_package calls possible

In cases in which find_package(SOCI) was performed multiple times in a
single configure run (e.g. because two independent dependencies both
depend on SOCI), CMake would error due to the attempted re-definition of
the soci_interface (and SOCI::soci) targets created in SOCI's config
file.

This commit adds a check for the existence of these targets and only
creates them if they don't exist yet. Hence, multiple find_package calls
no longer lead to errors.

Closes #1293.
This commit is contained in:
Robert Adam
2025-08-06 18:06:10 +02:00
committed by Vadim Zeitlin
parent 64b1dbdb24
commit a4c57625f3

View File

@@ -157,14 +157,15 @@ unset(__dep_dep_targets)
check_required_components(SOCI)
if (NOT DEFINED SOCI_FOUND OR SOCI_FOUND)
add_library(soci_interface INTERFACE)
if (NOT TARGET soci_interface)
add_library(soci_interface INTERFACE)
add_library(SOCI::soci ALIAS soci_interface)
endif()
foreach (__comp IN LISTS SOCI_FIND_COMPONENTS)
target_link_libraries(soci_interface INTERFACE SOCI::${__comp})
endforeach()
add_library(SOCI::soci ALIAS soci_interface)
if (NOT SOCI_FIND_QUIETLY)
list(JOIN SOCI_FIND_COMPONENTS ", " __components)
message(STATUS "Found SOCI: ${CMAKE_CURRENT_LIST_FILE} (found version \"@PROJECT_VERSION@\") found components: ${__components}")