Skip to content

Commit b648953

Browse files
committed
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.
1 parent a3b72ff commit b648953

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

CMakeLists.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ option(FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE "Path to libdispatch source" "")
2727
option(FOUNDATION_PATH_TO_LIBDISPATCH_BUILD "Path to libdispatch build" "")
2828
option(FOUNDATION_PATH_TO_XCTEST_BUILD "Path to XCTest build" "")
2929

30-
find_package(CURL REQUIRED)
30+
find_package(CURL CONFIG)
31+
if(CURL_FOUND)
32+
include(CMakeExpandImportedTargets)
33+
cmake_expand_imported_targets(CURL_LIBRARIES LIBRARIES CURL::libcurl)
34+
else()
35+
find_package(CURL REQUIRED)
36+
endif()
3137
find_package(ICU COMPONENTS uc i18n REQUIRED)
3238
find_package(LibXml2 REQUIRED)
3339

CoreFoundation/CMakeLists.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,15 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
454454
target_include_directories(CFXMLInterface
455455
PRIVATE
456456
${LIBXML2_INCLUDE_DIR})
457-
find_package(CURL REQUIRED)
457+
find_package(CURL CONFIG)
458+
if(NOT CURL_FOUND)
459+
find_package(CURL REQUIRED)
460+
if(NOT TARGET CURL::libcurl)
461+
add_library(CURL::libcurl UNKNOWN IMPORTED)
462+
set_target_properties(CURL::libcurl PROPERTIES
463+
IMPORTED_LOCATION ${CURL_LIBRARIES})
464+
endif()
465+
endif()
458466
target_include_directories(CFURLSessionInterface
459467
PRIVATE
460468
${CURL_INCLUDE_DIRS})
@@ -606,7 +614,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
606614
${LIBXML2_LIBRARIES})
607615
target_link_libraries(CFURLSessionInterface
608616
PRIVATE
609-
${CURL_LIBRARIES})
617+
CURL::libcurl)
610618
endif()
611619
if(CMAKE_SYSTEM_NAME STREQUAL Android)
612620
target_link_libraries(CoreFoundation

0 commit comments

Comments
 (0)