vcpkg/ports/curl/vcpkg-cmake-wrapper.cmake
Kai Pastor b9152d18a0
[curl] Avoid targets in CURL_LIBRARIES (#29061)
* [curl] Avoid targets in CURL_LIBRARIES

* [libarchive] Don't mix targets and paths in LibArchive_LIBRARIES
2023-01-20 22:12:40 -08:00

69 lines
3.2 KiB
CMake

cmake_policy(PUSH)
cmake_policy(SET CMP0012 NEW)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0057 NEW)
if(NOT CMAKE_VERSION VERSION_LESS 3.14 AND COMPONENTS IN_LIST ARGS)
include("${CMAKE_CURRENT_LIST_DIR}/CURLConfigComponents.cmake")
endif()
list(REMOVE_ITEM ARGS "NO_MODULE" "CONFIG" "MODULE")
_find_package(${ARGS} CONFIG)
if(CURL_FOUND)
include("${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake")
get_target_property(_curl_include_dirs CURL::libcurl INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(_curl_link_libraries CURL::libcurl INTERFACE_LINK_LIBRARIES)
if(NOT _curl_link_libraries)
set(_curl_link_libraries "")
endif()
if(_curl_link_libraries MATCHES "ZLIB::ZLIB")
string(REGEX REPLACE "([\$]<[^;]*)?ZLIB::ZLIB([^;]*>)?" "${ZLIB_LIBRARIES}" _curl_link_libraries "${_curl_link_libraries}")
endif()
if(_curl_link_libraries MATCHES "OpenSSL::")
string(REGEX REPLACE "([\$]<[^;]*)?OpenSSL::(SSL|Crypto)([^;]*>)?" "${OPENSSL_LIBRARIES}" _curl_link_libraries "${_curl_link_libraries}")
endif()
if(_curl_link_libraries MATCHES "Libssh2::libssh2")
# TODO: move find_dependency(Libssh2 CONFIG) into CURL config
find_package(Libssh2 CONFIG QUIET)
get_target_property(_libssh2_LIBRARY_DEBUG Libssh2::libssh2 IMPORTED_IMPLIB_DEBUG)
get_target_property(_libssh2_LIBRARY_RELEASE Libssh2::libssh2 IMPORTED_IMPLIB_RELEASE)
if(NOT IMPORTED_IMPLIB_DEBUG AND NOT IMPORTED_IMPLIB_RELEASE)
get_target_property(_libssh2_LIBRARY_DEBUG Libssh2::libssh2 IMPORTED_LOCATION_DEBUG)
get_target_property(_libssh2_LIBRARY_RELEASE Libssh2::libssh2 IMPORTED_LOCATION_RELEASE)
endif()
select_library_configurations(_libssh2)
string(REGEX REPLACE "([\$]<[^;]*)?Libssh2::libssh2([^;]*>)?" "${_libssh2_LIBRARIES}" _curl_link_libraries "${_curl_link_libraries}")
unset(_libssh2_LIBRARIES)
unset(_libssh2_LIBRARY_DEBUG)
unset(_libssh2_LIBRARY_RELEASE)
endif()
if(_curl_link_libraries MATCHES "::")
message(WARNING "CURL_LIBRARIES list at least one target. This will not work for use cases where targets are not resolved.")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
get_target_property(_curl_location_debug CURL::libcurl IMPORTED_IMPLIB_DEBUG)
get_target_property(_curl_location_release CURL::libcurl IMPORTED_IMPLIB_RELEASE)
endif()
if(NOT _curl_location_debug AND NOT _curl_location_release)
get_target_property(_curl_location_debug CURL::libcurl IMPORTED_LOCATION_DEBUG)
get_target_property(_curl_location_release CURL::libcurl IMPORTED_LOCATION_RELEASE)
endif()
set(CURL_INCLUDE_DIRS "${_curl_include_dirs}")
set(CURL_LIBRARY_DEBUG "${_curl_location_debug}" CACHE INTERNAL "vcpkg")
set(CURL_LIBRARY_RELEASE "${_curl_location_release}" CACHE INTERNAL "vcpkg")
select_library_configurations(CURL)
set(CURL_LIBRARIES ${CURL_LIBRARY} ${_curl_link_libraries})
set(CURL_VERSION_STRING "${CURL_VERSION}")
unset(_curl_include_dirs)
unset(_curl_link_libraries)
unset(_curl_location_debug)
unset(_curl_location_release)
endif()
cmake_policy(POP)