cmake: do not echo most inherited LDFLAGS to config files
Sync with autotools and filter out most linker flags inherited via `CMAKE_SHARED_LINKER_FLAGS` (that includes `LDFLAGS` env) before echoing them in `libcurl.pc` `Libs.private` and `curl-config` `--static-libs`. Keep inheriting `-l`, `-L`, `-F`, `--library-path=`, `-framework` options. Follow-up toe244d50064#15550 Follow-up to9f56bb608e#14681 Follow-up to8ed66f98a9Closes #15617
This commit is contained in:
parent
cb2ae6e8a8
commit
e233073f01
@ -2071,6 +2071,27 @@ if(NOT CURL_DISABLE_INSTALL)
|
|||||||
set(_ldflags "")
|
set(_ldflags "")
|
||||||
set(LIBCURL_PC_LIBS_PRIVATE "")
|
set(LIBCURL_PC_LIBS_PRIVATE "")
|
||||||
|
|
||||||
|
# Filter CMAKE_SHARED_LINKER_FLAGS for libs and libpaths
|
||||||
|
string(STRIP "${CMAKE_SHARED_LINKER_FLAGS}" _custom_ldflags)
|
||||||
|
string(REGEX REPLACE " +-([^ \\t;]*)" ";-\\1" _custom_ldflags "${_custom_ldflags}")
|
||||||
|
|
||||||
|
set(_custom_libs "")
|
||||||
|
set(_custom_libdirs "")
|
||||||
|
foreach(_flag IN LISTS _custom_ldflags)
|
||||||
|
if(_flag MATCHES "^-l")
|
||||||
|
string(REGEX REPLACE "^-l" "" _flag "${_flag}")
|
||||||
|
list(APPEND _custom_libs "${_flag}")
|
||||||
|
elseif(_flag MATCHES "^-framework|^-F")
|
||||||
|
list(APPEND _custom_libs "${_flag}")
|
||||||
|
elseif(_flag MATCHES "^-L")
|
||||||
|
string(REGEX REPLACE "^-L" "" _flag "${_flag}")
|
||||||
|
list(APPEND _custom_libdirs "${_flag}")
|
||||||
|
elseif(_flag MATCHES "^--library-path=")
|
||||||
|
string(REGEX REPLACE "^--library-path=" "" _flag "${_flag}")
|
||||||
|
list(APPEND _custom_libdirs "${_flag}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
# Avoid getting unnecessary -L options for known system directories.
|
# Avoid getting unnecessary -L options for known system directories.
|
||||||
unset(_sys_libdirs)
|
unset(_sys_libdirs)
|
||||||
foreach(_libdir IN LISTS CMAKE_SYSTEM_PREFIX_PATH)
|
foreach(_libdir IN LISTS CMAKE_SYSTEM_PREFIX_PATH)
|
||||||
@ -2090,7 +2111,7 @@ if(NOT CURL_DISABLE_INSTALL)
|
|||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
foreach(_libdir IN LISTS CURL_LIBDIRS)
|
foreach(_libdir IN LISTS _custom_libdirs CURL_LIBDIRS)
|
||||||
list(FIND _sys_libdirs "${_libdir}" _libdir_index)
|
list(FIND _sys_libdirs "${_libdir}" _libdir_index)
|
||||||
if(_libdir_index LESS 0)
|
if(_libdir_index LESS 0)
|
||||||
list(APPEND _ldflags "-L${_libdir}")
|
list(APPEND _ldflags "-L${_libdir}")
|
||||||
@ -2102,7 +2123,7 @@ if(NOT CURL_DISABLE_INSTALL)
|
|||||||
set(_implicit_libs ${CMAKE_C_IMPLICIT_LINK_LIBRARIES})
|
set(_implicit_libs ${CMAKE_C_IMPLICIT_LINK_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
foreach(_lib IN LISTS _implicit_libs CURL_LIBS)
|
foreach(_lib IN LISTS _implicit_libs _custom_libs CURL_LIBS)
|
||||||
if(TARGET "${_lib}")
|
if(TARGET "${_lib}")
|
||||||
set(_libname "${_lib}")
|
set(_libname "${_lib}")
|
||||||
get_target_property(_imported "${_libname}" IMPORTED)
|
get_target_property(_imported "${_libname}" IMPORTED)
|
||||||
@ -2145,12 +2166,13 @@ if(NOT CURL_DISABLE_INSTALL)
|
|||||||
if(LIBCURL_PC_LIBS_PRIVATE)
|
if(LIBCURL_PC_LIBS_PRIVATE)
|
||||||
string(REPLACE ";" " " LIBCURL_PC_LIBS_PRIVATE "${LIBCURL_PC_LIBS_PRIVATE}")
|
string(REPLACE ";" " " LIBCURL_PC_LIBS_PRIVATE "${LIBCURL_PC_LIBS_PRIVATE}")
|
||||||
endif()
|
endif()
|
||||||
set(LIBCURL_PC_LDFLAGS_PRIVATE "${CMAKE_SHARED_LINKER_FLAGS}")
|
|
||||||
if(_ldflags)
|
if(_ldflags)
|
||||||
list(REMOVE_DUPLICATES _ldflags)
|
list(REMOVE_DUPLICATES _ldflags)
|
||||||
string(REPLACE ";" " " _ldflags "${_ldflags}")
|
string(REPLACE ";" " " _ldflags "${_ldflags}")
|
||||||
set(LIBCURL_PC_LDFLAGS_PRIVATE "${LIBCURL_PC_LDFLAGS_PRIVATE} ${_ldflags}")
|
set(LIBCURL_PC_LDFLAGS_PRIVATE "${_ldflags}")
|
||||||
string(STRIP "${LIBCURL_PC_LDFLAGS_PRIVATE}" LIBCURL_PC_LDFLAGS_PRIVATE)
|
string(STRIP "${LIBCURL_PC_LDFLAGS_PRIVATE}" LIBCURL_PC_LDFLAGS_PRIVATE)
|
||||||
|
else()
|
||||||
|
set(LIBCURL_PC_LDFLAGS_PRIVATE "")
|
||||||
endif()
|
endif()
|
||||||
set(LIBCURL_PC_CFLAGS_PRIVATE "-DCURL_STATICLIB")
|
set(LIBCURL_PC_CFLAGS_PRIVATE "-DCURL_STATICLIB")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user