Skip to content

Commit 9bb2b9a

Browse files
CMake: use Requires: for .pc generation (don't parse link flags)
Instead of trying to translate/parse the INTERFACE link flags from CMake to the .pc file, make use of the more native-to-pkg-config "Requires" and "Requires.private", so that we can refer to the whole dependent .pc pacakge name. This fixes static linking when the dependencies of static libraries are also static, and allows for using pkg-config all the way down. When sasl and zlib are found, Rfb public headers also include headers from these libraries so they are the only ones listed in "Requires". The others can be in "Requires.private". Signed-off-by: Johannes Kauffmann <johanneskauffmann@hotmail.com>
1 parent 1dbd8ac commit 9bb2b9a

File tree

3 files changed

+15
-32
lines changed

3 files changed

+15
-32
lines changed

CMakeLists.txt

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,15 @@ if(SYSTEMD_FOUND)
247247
add_definitions(-DLIBVNCSERVER_WITH_SYSTEMD)
248248
include_directories(${SYSTEMD_INCLUDE_DIRS})
249249
set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${SYSTEMD_LIBRARIES})
250+
list(APPEND LIBVNC_REQUIRES_PRIVATE libsystemd)
250251
endif(SYSTEMD_FOUND)
251252

252253
# common crypto used by both libvncserver and libvncclient
253254
if(WITH_GCRYPT AND LIBGCRYPT_LIBRARIES)
254255
message(STATUS "Building crypto with Libgcrypt")
255256
set(CRYPTO_LIBRARIES ${LIBGCRYPT_LIBRARIES})
256257
set(CRYPTO_SOURCES ${COMMON_DIR}/crypto_libgcrypt.c)
258+
list(APPEND LIBVNC_REQUIRES_PRIVATE libgcrypt)
257259
elseif(OPENSSL_FOUND)
258260
message(STATUS "Building crypto with OpenSSL")
259261
set(CRYPTO_LIBRARIES ${OPENSSL_LIBRARIES})
@@ -344,6 +346,7 @@ if(WITH_SASL AND LIBSASL2_LIBRARIES AND SASL2_INCLUDE_DIR)
344346
set(LIBVNCSERVER_HAVE_SASL 1)
345347
set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${LIBSASL2_LIBRARIES})
346348
include_directories(${SASL2_INCLUDE_DIR})
349+
list(APPEND LIBVNC_REQUIRES sasl)
347350
endif(WITH_SASL AND LIBSASL2_LIBRARIES AND SASL2_INCLUDE_DIR)
348351

349352
# TODO:
@@ -405,6 +408,7 @@ if(GNUTLS_FOUND)
405408
${LIBVNCSERVER_DIR}/rfbssl_gnutls.c
406409
)
407410
include_directories(${GNUTLS_INCLUDE_DIR})
411+
list(APPEND LIBVNC_REQUIRES_PRIVATE gnutls)
408412
elseif(OPENSSL_FOUND)
409413
message(STATUS "Building TLS with OpenSSL")
410414
set(LIBVNCCLIENT_SOURCES
@@ -416,6 +420,7 @@ elseif(OPENSSL_FOUND)
416420
${LIBVNCSERVER_DIR}/rfbssl_openssl.c
417421
)
418422
include_directories(${OPENSSL_INCLUDE_DIR})
423+
list(APPEND LIBVNC_REQUIRES_PRIVATE openssl)
419424
else()
420425
message(STATUS "Building without TLS")
421426
set(LIBVNCCLIENT_SOURCES
@@ -438,6 +443,7 @@ endif()
438443
if(ZLIB_FOUND)
439444
add_definitions(-DLIBVNCSERVER_HAVE_LIBZ)
440445
include_directories(${ZLIB_INCLUDE_DIR})
446+
list(APPEND LIBVNC_REQUIRES zlib)
441447
set(LIBVNCSERVER_SOURCES
442448
${LIBVNCSERVER_SOURCES}
443449
${LIBVNCSERVER_DIR}/zlib.c
@@ -450,6 +456,7 @@ endif(ZLIB_FOUND)
450456
if(LZO_FOUND)
451457
add_definitions(-DLIBVNCSERVER_HAVE_LZO)
452458
include_directories(${LZO_INCLUDE_DIR})
459+
list(APPEND LIBVNC_REQUIRES_PRIVATE lzo2)
453460
else()
454461
set(LIBVNCSERVER_SOURCES
455462
${LIBVNCSERVER_SOURCES}
@@ -464,6 +471,7 @@ endif()
464471
if(JPEG_FOUND)
465472
add_definitions(-DLIBVNCSERVER_HAVE_LIBJPEG)
466473
include_directories(${JPEG_INCLUDE_DIR})
474+
list(APPEND LIBVNC_REQUIRES_PRIVATE libjpeg)
467475
if(PNG_FOUND OR ZLIB_FOUND)
468476
set(TIGHT_C ${LIBVNCSERVER_DIR}/tight.c ${COMMON_DIR}/turbojpeg.c)
469477
endif(PNG_FOUND OR ZLIB_FOUND)
@@ -472,6 +480,7 @@ endif(JPEG_FOUND)
472480
if(PNG_FOUND)
473481
add_definitions(-DLIBVNCSERVER_HAVE_LIBPNG)
474482
include_directories(${PNG_INCLUDE_DIR})
483+
list(APPEND LIBVNC_REQUIRES_PRIVATE libpng)
475484
endif(PNG_FOUND)
476485

477486
set(LIBVNCSERVER_SOURCES
@@ -763,37 +772,14 @@ endif(LIBVNCSERVER_WITH_WEBSOCKETS AND WITH_LIBVNCSERVER)
763772

764773
endif(WITH_TESTS)
765774

766-
#
767-
# this gets the libraries needed by TARGET in "-libx -liby ..." form
768-
#
769-
function(get_link_libraries OUT TARGET)
770-
set(RESULT "")
771-
get_target_property(LIBRARIES ${TARGET} INTERFACE_LINK_LIBRARIES)
772-
foreach(LIB ${LIBRARIES})
773-
if("${LIB}" MATCHES ".*NOTFOUND.*")
774-
continue()
775-
endif()
776-
string(REGEX REPLACE "^.*/lib" "" LIB ${LIB}) # remove leading path and "lib" name prefix
777-
string(REGEX REPLACE "-l" "" LIB ${LIB}) # remove leading -l
778-
string(REGEX REPLACE "\\.so$" "" LIB ${LIB}) # remove trailing .so
779-
list(APPEND RESULT "-l${LIB}")
780-
endforeach()
781-
list(REMOVE_DUPLICATES RESULT)
782-
string(CONCAT RESULT ${RESULT}) # back to string
783-
if(RESULT)
784-
string(REPLACE "-l" " -l" RESULT ${RESULT}) # re-add separators
785-
endif(RESULT)
786-
set(${OUT} ${RESULT} PARENT_SCOPE)
787-
endfunction()
788-
775+
string(REPLACE ";" " " LIBVNC_REQUIRES "${LIBVNC_REQUIRES}")
776+
string(REPLACE ";" " " LIBVNC_REQUIRES_PRIVATE "${LIBVNC_REQUIRES_PRIVATE}")
789777
set(LIBVNCSERVER_PC_FILES )
790778
if(WITH_LIBVNCSERVER)
791-
get_link_libraries(PRIVATE_LIBS vncserver)
792779
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/libvncserver/libvncserver.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libvncserver.pc @ONLY)
793780
list(APPEND LIBVNCSERVER_PC_FILES ${CMAKE_CURRENT_BINARY_DIR}/libvncserver.pc)
794781
endif(WITH_LIBVNCSERVER)
795782
if(WITH_LIBVNCCLIENT)
796-
get_link_libraries(PRIVATE_LIBS vncclient)
797783
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/libvncclient/libvncclient.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libvncclient.pc @ONLY)
798784
list(APPEND LIBVNCSERVER_PC_FILES ${CMAKE_CURRENT_BINARY_DIR}/libvncclient.pc)
799785
endif(WITH_LIBVNCCLIENT)

src/libvncclient/libvncclient.pc.cmakein

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ includedir=@CMAKE_INSTALL_PREFIX@/include
66
Name: LibVNCClient
77
Description: A library for easy implementation of a VNC client.
88
Version: @LibVNCServer_VERSION@
9-
Requires:
10-
Requires.private:
9+
Requires: @LIBVNC_REQUIRES@
10+
Requires.private: @LIBVNC_REQUIRES_PRIVATE@
1111
Libs: -L${libdir} -lvncclient
12-
Libs.private: @PRIVATE_LIBS@
1312
Cflags: -I${includedir}
14-

src/libvncserver/libvncserver.pc.cmakein

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ includedir=@CMAKE_INSTALL_PREFIX@/include
66
Name: LibVNCServer
77
Description: A library for easy implementation of a VNC server.
88
Version: @LibVNCServer_VERSION@
9-
Requires:
10-
Requires.private:
9+
Requires: @LIBVNC_REQUIRES@
10+
Requires.private: @LIBVNC_REQUIRES_PRIVATE@
1111
Libs: -L${libdir} -lvncserver
12-
Libs.private: @PRIVATE_LIBS@
1312
Cflags: -I${includedir}

0 commit comments

Comments
 (0)