From b6489533013d93eb420e05468cbdb3d85d0e34a8 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 31 Jul 2019 22:48:49 -0700 Subject: [PATCH] build: prefer CONFIG over MODULE for CURL This improves the CURL linkage to use the CONFIG from CMake enabling linking against the dependencies implicitly which ensures that we get all the dependencies properly tracked by CMake. --- CMakeLists.txt | 8 +++++++- CoreFoundation/CMakeLists.txt | 12 ++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d359a506a..fedcc9da7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,13 @@ option(FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE "Path to libdispatch source" "") option(FOUNDATION_PATH_TO_LIBDISPATCH_BUILD "Path to libdispatch build" "") option(FOUNDATION_PATH_TO_XCTEST_BUILD "Path to XCTest build" "") -find_package(CURL REQUIRED) +find_package(CURL CONFIG) +if(CURL_FOUND) + include(CMakeExpandImportedTargets) + cmake_expand_imported_targets(CURL_LIBRARIES LIBRARIES CURL::libcurl) +else() + find_package(CURL REQUIRED) +endif() find_package(ICU COMPONENTS uc i18n REQUIRED) find_package(LibXml2 REQUIRED) diff --git a/CoreFoundation/CMakeLists.txt b/CoreFoundation/CMakeLists.txt index fc1b5f9f71..bab458df69 100644 --- a/CoreFoundation/CMakeLists.txt +++ b/CoreFoundation/CMakeLists.txt @@ -454,7 +454,15 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) target_include_directories(CFXMLInterface PRIVATE ${LIBXML2_INCLUDE_DIR}) - find_package(CURL REQUIRED) + find_package(CURL CONFIG) + if(NOT CURL_FOUND) + find_package(CURL REQUIRED) + if(NOT TARGET CURL::libcurl) + add_library(CURL::libcurl UNKNOWN IMPORTED) + set_target_properties(CURL::libcurl PROPERTIES + IMPORTED_LOCATION ${CURL_LIBRARIES}) + endif() + endif() target_include_directories(CFURLSessionInterface PRIVATE ${CURL_INCLUDE_DIRS}) @@ -606,7 +614,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) ${LIBXML2_LIBRARIES}) target_link_libraries(CFURLSessionInterface PRIVATE - ${CURL_LIBRARIES}) + CURL::libcurl) endif() if(CMAKE_SYSTEM_NAME STREQUAL Android) target_link_libraries(CoreFoundation