cmake: fix confusing error when a dependency is undetected in curl-config.cmake

Fixing:
```
CMake Error at /path/to/CURL/CURLConfig.cmake:190 (get_target_property):
  get_target_property() called with non-existent target "CURL::libssh2".
```
and replacing it with the clearer message:
```
CMake Error at /path/to/CURL/CURLTargets.cmake:61 (set_target_properties):
  The link interface of target "CURL::libcurl_static" contains:

    CURL::libssh2

  but the target was not found.  Possible reasons include:
[...]
```

Reported-by: Val S.
Ref: #20729
Follow-up to 16f073ef49 #16973

Closes #20737
This commit is contained in:
Viktor Szakats 2026-02-26 12:35:51 +01:00
parent c111275366
commit fb58b23256
No known key found for this signature in database

View file

@ -176,9 +176,11 @@ if(TARGET @PROJECT_NAME@::@LIB_STATIC@)
if(NOT _has_CMP0099 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND _curl_libs)
set(_curl_libdirs "")
foreach(_curl_lib IN LISTS _curl_libs)
get_target_property(_curl_libdir "${_curl_lib}" INTERFACE_LINK_DIRECTORIES)
if(_curl_libdir)
list(APPEND _curl_libdirs "${_curl_libdir}")
if(TARGET "${_curl_lib}")
get_target_property(_curl_libdir "${_curl_lib}" INTERFACE_LINK_DIRECTORIES)
if(_curl_libdir)
list(APPEND _curl_libdirs "${_curl_libdir}")
endif()
endif()
endforeach()
if(_curl_libdirs)