CMake: Guard target creation in exported config (#464)

User projects may call 'find_package(c-ares)' multiple times (e.g.
via dependencies), but targets must be created only once.
Shared and static target must be treated independently.

Fix By: Kai Pastor (@dg0yt)
pull/465/head
Kai Pastor 3 years ago committed by GitHub
parent 7eb399a83c
commit 0e678f2fb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      c-ares-config.cmake.in

@ -8,14 +8,17 @@ include("${CMAKE_CURRENT_LIST_DIR}/c-ares-targets.cmake")
set(c-ares_LIBRARY c-ares::cares)
if(@CARES_SHARED@)
add_library(c-ares::cares_shared INTERFACE IMPORTED)
set_target_properties(c-ares::cares_shared PROPERTIES INTERFACE_LINK_LIBRARIES "c-ares::cares")
if(NOT TARGET c-ares::cares_shared)
add_library(c-ares::cares_shared INTERFACE IMPORTED)
set_target_properties(c-ares::cares_shared PROPERTIES INTERFACE_LINK_LIBRARIES "c-ares::cares")
endif()
set(c-ares_SHARED_LIBRARY c-ares::cares_shared)
elseif(@CARES_STATIC@)
add_library(c-ares::cares_static INTERFACE IMPORTED)
set_target_properties(c-ares::cares_static PROPERTIES INTERFACE_LINK_LIBRARIES "c-ares::cares")
endif()
if(@CARES_STATIC@)
if(NOT TARGET c-ares::cares_static)
add_library(c-ares::cares_static INTERFACE IMPORTED)
set_target_properties(c-ares::cares_static PROPERTIES INTERFACE_LINK_LIBRARIES "c-ares::cares")
endif()
set(c-ares_STATIC_LIBRARY c-ares::cares_static)
endif()

Loading…
Cancel
Save