Skip to content

Commit df487a0

Browse files
committed
CMake: rewrite lib generation for pkg-config files
The list of libs linked against a target is known, so no need to query them again.
1 parent 0fc76cf commit df487a0

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

CMakeLists.txt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -625,30 +625,26 @@ endif()
625625
#
626626
# this gets the libraries needed by TARGET in "-libx -liby ..." form
627627
#
628-
function(get_link_libraries OUT TARGET)
628+
function(get_link_libraries OUT EXTRA_LIBS)
629629
set(RESULT "")
630-
get_target_property(LIBRARIES ${TARGET} INTERFACE_LINK_LIBRARIES)
631-
foreach(LIB ${LIBRARIES})
632-
if(NOT LIB)
633-
continue()
630+
foreach(LIB ${ADDITIONAL_LIBS} ${EXTRA_LIBS})
631+
if(LIB MATCHES "^-")
632+
list(APPEND RESULT " ${LIB}")
633+
else()
634+
get_filename_component(FNAME "${LIB}" NAME)
635+
string(REGEX REPLACE "^${CMAKE_SHARED_LIBRARY_PREFIX}(.+)${CMAKE_SHARED_LIBRARY_SUFFIX}$" "\\1" LIB "${FNAME}")
636+
list(APPEND RESULT " -l${LIB}")
634637
endif()
635-
string(REGEX REPLACE "^.*/lib" "" LIB ${LIB}) # remove leading path and "lib" name prefix
636-
string(REGEX REPLACE "-l" "" LIB ${LIB}) # remove leading -l
637-
string(REGEX REPLACE "\\.so$" "" LIB ${LIB}) # remove trailing .so
638-
list(APPEND RESULT "-l${LIB}")
639638
endforeach()
640639
list(REMOVE_DUPLICATES RESULT)
641640
string(CONCAT RESULT ${RESULT}) # back to string
642-
if(RESULT)
643-
string(REPLACE "-l" " -l" RESULT ${RESULT}) # re-add separators
644-
endif()
645641
set(${OUT} ${RESULT} PARENT_SCOPE)
646642
endfunction()
647643

648644
if(NOT WIN32)
649-
get_link_libraries(PRIVATE_LIBS vncserver)
645+
get_link_libraries(PRIVATE_LIBS "${PNG_LIBRARIES}")
650646
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libvncserver.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libvncserver.pc @ONLY)
651-
get_link_libraries(PRIVATE_LIBS vncclient)
647+
get_link_libraries(PRIVATE_LIBS "")
652648
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libvncclient.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libvncclient.pc @ONLY)
653649
endif()
654650

0 commit comments

Comments
 (0)