]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: reference OpenSSL and ZLIB imported targets only when enabled
authorJoshua Vandaƫle <joshua@vandaele.software>
Wed, 7 Jan 2026 23:55:45 +0000 (00:55 +0100)
committerViktor Szakats <commit@vsz.me>
Fri, 9 Jan 2026 21:03:28 +0000 (22:03 +0100)
This otherwise broke building on a parent with a static library which is
available but disabled (e.g. CURL_ZLIB is set to OFF but ZLIB::ZLIB
exists)

Closes #20217

CMakeLists.txt

index 8e5383ac98b8b0dcff41e3e23ebb7b8a64e0fe02..e42a3f7da0f8f261cc061576b278271c5b739cbf 100644 (file)
@@ -1799,7 +1799,14 @@ endif()
 # before dependencies detected via curl's custom Find modules, and breaks
 # linkers sensitive to lib order. There must be a better solution to this.
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
-  foreach(_lib IN ITEMS OpenSSL::Crypto ZLIB::ZLIB)
+  set(_libs "")
+  if(USE_OPENSSL)
+    list(APPEND _libs OpenSSL::Crypto)
+  endif()
+  if(HAVE_LIBZ)
+    list(APPEND _libs ZLIB::ZLIB)
+  endif()
+  foreach(_lib IN LISTS _libs)
     if(TARGET "${_lib}")
       add_library(CURL::${_lib} INTERFACE IMPORTED)
       get_target_property(_libname "${_lib}" LOCATION)