From e8f52f0b4eecd35384412a65bd869e0071980ced Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Mar 2025 01:57:20 +0100 Subject: [PATCH] cm: add target prop processor logic --- CMakeLists.txt | 52 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d6e7ca3e6..db99075b75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2252,7 +2252,41 @@ if(NOT CURL_DISABLE_INSTALL) endif() endforeach() - foreach(_libdir IN LISTS _custom_libdirs CURL_LIBDIRS) + set(_explicit_libs "") + set(_explicit_libdirs "") + set(LIBCURL_PC_REQUIRES_PRIVATE "") + foreach(_lib IN LISTS CURL_LIBS) + if(TARGET "${_lib}") + get_target_property(_imported "${_lib}" IMPORTED) + if(NOT _imported) + # Reading the LOCATION property on non-imported target will error out. + # Assume the user will not need this information in the .pc file. + continue() + endif() + get_target_property(_libname "${_lib}" LOCATION) + if(_libname) + list(APPEND _explicit_libs "${_libname}") + else() + get_target_property(_libs "${_lib}" INTERFACE_LINK_LIBRARIES) + if(_libs) + list(APPEND _explicit_libs "${_libs}") + endif() + get_target_property(_libdirs "${_lib}" INTERFACE_LINK_DIRECTORIES) + if(_libdirs) + list(APPEND _explicit_libdirs "${_libdirs}") + endif() + endif() + if(NOT _libname AND NOT _libs AND NOT _libdirs) + message(WARNING "Bad lib in library list: ${_lib}") + endif() + get_target_property(_modules "${_lib}" LIBCURL_PC_MODULES) + if(_modules) + list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "${_modules}") + endif() + endif() + endforeach() + + foreach(_libdir IN LISTS _custom_libdirs _explicit_libdirs) if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20) cmake_path(SET _libdir NORMALIZE "${_libdir}") endif() @@ -2267,21 +2301,7 @@ if(NOT CURL_DISABLE_INSTALL) set(_implicit_libs "${CMAKE_C_IMPLICIT_LINK_LIBRARIES}") endif() - foreach(_lib IN LISTS _implicit_libs _custom_libs CURL_LIBS) - if(TARGET "${_lib}") - set(_libname "${_lib}") - get_target_property(_imported "${_libname}" IMPORTED) - if(NOT _imported) - # Reading the LOCATION property on non-imported target will error out. - # Assume the user will not need this information in the .pc file. - continue() - endif() - get_target_property(_lib "${_libname}" LOCATION) - if(NOT _lib) - message(WARNING "Bad lib in library list: ${_libname}") - continue() - endif() - endif() + foreach(_lib IN LISTS _implicit_libs _custom_libs _explicit_libs) if(_lib MATCHES "^-") # '-framework ' list(APPEND _ldflags "${_lib}") elseif(_lib MATCHES "/")