Skip to content

Commit fb2901a

Browse files
JohannesKauffmannbk138
authored andcommitted
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". libsystemd and libpng are exclusively libvncserver dependencies, while sasl is exclusively a libvncclient dependency. The rest of the libraries are common dependencies to both. Signed-off-by: Johannes Kauffmann <johanneskauffmann@hotmail.com>
1 parent 89df6f1 commit fb2901a

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

CMakeLists.txt

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,16 @@ if(SYSTEMD_FOUND)
245245
add_definitions(-DLIBVNCSERVER_WITH_SYSTEMD)
246246
include_directories(${SYSTEMD_INCLUDE_DIRS})
247247
set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${SYSTEMD_LIBRARIES})
248+
list(APPEND LIBVNCSERVER_REQUIRES_PRIVATE libsystemd)
248249
endif(SYSTEMD_FOUND)
249250

250251
# common crypto used by both libvncserver and libvncclient
251252
if(WITH_GCRYPT AND LIBGCRYPT_LIBRARIES)
252253
message(STATUS "Building crypto with Libgcrypt")
253254
set(CRYPTO_LIBRARIES ${LIBGCRYPT_LIBRARIES})
254255
set(CRYPTO_SOURCES ${COMMON_DIR}/crypto_libgcrypt.c)
256+
list(APPEND LIBVNCCLIENT_REQUIRES_PRIVATE libgcrypt)
257+
list(APPEND LIBVNCSERVER_REQUIRES_PRIVATE libgcrypt)
255258
elseif(OPENSSL_FOUND)
256259
message(STATUS "Building crypto with OpenSSL")
257260
set(CRYPTO_LIBRARIES ${OPENSSL_LIBRARIES})
@@ -342,6 +345,7 @@ if(WITH_SASL AND LIBSASL2_LIBRARIES AND SASL2_INCLUDE_DIR)
342345
set(LIBVNCSERVER_HAVE_SASL 1)
343346
set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${LIBSASL2_LIBRARIES})
344347
include_directories(${SASL2_INCLUDE_DIR})
348+
list(APPEND LIBVNCCLIENT_REQUIRES sasl)
345349
endif(WITH_SASL AND LIBSASL2_LIBRARIES AND SASL2_INCLUDE_DIR)
346350

347351
# TODO:
@@ -403,6 +407,8 @@ if(GNUTLS_FOUND)
403407
${LIBVNCSERVER_DIR}/rfbssl_gnutls.c
404408
)
405409
include_directories(${GNUTLS_INCLUDE_DIR})
410+
list(APPEND LIBVNCCLIENT_REQUIRES_PRIVATE gnutls)
411+
list(APPEND LIBVNCSERVER_REQUIRES_PRIVATE gnutls)
406412
elseif(OPENSSL_FOUND)
407413
message(STATUS "Building TLS with OpenSSL")
408414
set(LIBVNCCLIENT_SOURCES
@@ -414,6 +420,8 @@ elseif(OPENSSL_FOUND)
414420
${LIBVNCSERVER_DIR}/rfbssl_openssl.c
415421
)
416422
include_directories(${OPENSSL_INCLUDE_DIR})
423+
list(APPEND LIBVNCCLIENT_REQUIRES_PRIVATE openssl)
424+
list(APPEND LIBVNCSERVER_REQUIRES_PRIVATE openssl)
417425
else()
418426
message(STATUS "Building without TLS")
419427
set(LIBVNCCLIENT_SOURCES
@@ -436,6 +444,8 @@ endif()
436444
if(ZLIB_FOUND)
437445
add_definitions(-DLIBVNCSERVER_HAVE_LIBZ)
438446
include_directories(${ZLIB_INCLUDE_DIR})
447+
list(APPEND LIBVNCCLIENT_REQUIRES zlib)
448+
list(APPEND LIBVNCSERVER_REQUIRES zlib)
439449
set(LIBVNCSERVER_SOURCES
440450
${LIBVNCSERVER_SOURCES}
441451
${LIBVNCSERVER_DIR}/zlib.c
@@ -448,6 +458,8 @@ endif(ZLIB_FOUND)
448458
if(LZO_FOUND)
449459
add_definitions(-DLIBVNCSERVER_HAVE_LZO)
450460
include_directories(${LZO_INCLUDE_DIR})
461+
list(APPEND LIBVNCCLIENT_REQUIRES_PRIVATE lzo2)
462+
list(APPEND LIBVNCSERVER_REQUIRES_PRIVATE lzo2)
451463
else()
452464
set(LIBVNCSERVER_SOURCES
453465
${LIBVNCSERVER_SOURCES}
@@ -462,6 +474,8 @@ endif()
462474
if(JPEG_FOUND)
463475
add_definitions(-DLIBVNCSERVER_HAVE_LIBJPEG)
464476
include_directories(${JPEG_INCLUDE_DIR})
477+
list(APPEND LIBVNCCLIENT_REQUIRES_PRIVATE libjpeg)
478+
list(APPEND LIBVNCSERVER_REQUIRES_PRIVATE libjpeg)
465479
if(PNG_FOUND OR ZLIB_FOUND)
466480
set(TIGHT_C ${LIBVNCSERVER_DIR}/tight.c ${COMMON_DIR}/turbojpeg.c)
467481
endif(PNG_FOUND OR ZLIB_FOUND)
@@ -470,6 +484,7 @@ endif(JPEG_FOUND)
470484
if(PNG_FOUND)
471485
add_definitions(-DLIBVNCSERVER_HAVE_LIBPNG)
472486
include_directories(${PNG_INCLUDE_DIR})
487+
list(APPEND LIBVNCSERVER_REQUIRES_PRIVATE libpng)
473488
endif(PNG_FOUND)
474489

475490
set(LIBVNCSERVER_SOURCES
@@ -761,37 +776,16 @@ endif(LIBVNCSERVER_WITH_WEBSOCKETS AND WITH_LIBVNCSERVER)
761776

762777
endif(WITH_TESTS)
763778

764-
#
765-
# this gets the libraries needed by TARGET in "-libx -liby ..." form
766-
#
767-
function(get_link_libraries OUT TARGET)
768-
set(RESULT "")
769-
get_target_property(LIBRARIES ${TARGET} INTERFACE_LINK_LIBRARIES)
770-
foreach(LIB ${LIBRARIES})
771-
if("${LIB}" MATCHES ".*NOTFOUND.*")
772-
continue()
773-
endif()
774-
string(REGEX REPLACE "^.*/lib" "" LIB ${LIB}) # remove leading path and "lib" name prefix
775-
string(REGEX REPLACE "-l" "" LIB ${LIB}) # remove leading -l
776-
string(REGEX REPLACE "\\.so$" "" LIB ${LIB}) # remove trailing .so
777-
list(APPEND RESULT "-l${LIB}")
778-
endforeach()
779-
list(REMOVE_DUPLICATES RESULT)
780-
string(CONCAT RESULT ${RESULT}) # back to string
781-
if(RESULT)
782-
string(REPLACE "-l" " -l" RESULT ${RESULT}) # re-add separators
783-
endif(RESULT)
784-
set(${OUT} ${RESULT} PARENT_SCOPE)
785-
endfunction()
786-
779+
string(REPLACE ";" " " LIBVNCCLIENT_REQUIRES "${LIBVNCCLIENT_REQUIRES}")
780+
string(REPLACE ";" " " LIBVNCCLIENT_REQUIRES_PRIVATE "${LIBVNCCLIENT_REQUIRES_PRIVATE}")
781+
string(REPLACE ";" " " LIBVNCSERVER_REQUIRES "${LIBVNCSERVER_REQUIRES}")
782+
string(REPLACE ";" " " LIBVNCSERVER_REQUIRES_PRIVATE "${LIBVNCSERVER_REQUIRES_PRIVATE}")
787783
set(LIBVNCSERVER_PC_FILES )
788784
if(WITH_LIBVNCSERVER)
789-
get_link_libraries(PRIVATE_LIBS vncserver)
790785
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/libvncserver/libvncserver.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libvncserver.pc @ONLY)
791786
list(APPEND LIBVNCSERVER_PC_FILES ${CMAKE_CURRENT_BINARY_DIR}/libvncserver.pc)
792787
endif(WITH_LIBVNCSERVER)
793788
if(WITH_LIBVNCCLIENT)
794-
get_link_libraries(PRIVATE_LIBS vncclient)
795789
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/libvncclient/libvncclient.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libvncclient.pc @ONLY)
796790
list(APPEND LIBVNCSERVER_PC_FILES ${CMAKE_CURRENT_BINARY_DIR}/libvncclient.pc)
797791
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: @LIBVNCCLIENT_REQUIRES@
10+
Requires.private: @LIBVNCCLIENT_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: @LIBVNCSERVER_REQUIRES@
10+
Requires.private: @LIBVNCSERVER_REQUIRES_PRIVATE@
1111
Libs: -L${libdir} -lvncserver
12-
Libs.private: @PRIVATE_LIBS@
1312
Cflags: -I${includedir}

0 commit comments

Comments
 (0)