Skip to content

CMake: use "Requires:" for .pc generation (fixes static linking)#691

Open
JohannesKauffmann wants to merge 1 commit intoLibVNC:masterfrom
JohannesKauffmann:fix-static-pcfile-generation
Open

CMake: use "Requires:" for .pc generation (fixes static linking)#691
JohannesKauffmann wants to merge 1 commit intoLibVNC:masterfrom
JohannesKauffmann:fix-static-pcfile-generation

Conversation

@JohannesKauffmann
Copy link

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".

Additionally, re-order the CMake option()'s such that all the different types are grouped by type (general, dependencies, examples) and rewrite WITH_XCB description to clarify that this concerns an example.

Signed-off-by: Johannes Kauffmann johanneskauffmann@hotmail.com

@JohannesKauffmann
Copy link
Author

JohannesKauffmann commented Feb 21, 2026

This fixes static linking when the dependencies of static libraries are also static, and allows for using pkg-config all the way down.

One (rather, my) use case for this is the VNC client plugin in VLC Media Player, which on Windows/Apple (generally non-Unix) is statically linked to: -lgcrypt -lgpg-error -lgnutls -latomic -lhogweed -lgmp -lnettle -ljpeg -lpng16 -lm -lz, but these link flags are only correctly picked up when referring the .pc package as a whole.

See also:

@JohannesKauffmann JohannesKauffmann force-pushed the fix-static-pcfile-generation branch from 9bb2b9a to 55d9ff6 Compare February 21, 2026 14:40
@JohannesKauffmann
Copy link
Author

(now fixed my committer identity, sorry for the noise)

CMakeLists.txt Outdated
option(WITH_LIBVNCSERVER "Build libvncserver" ON)
option(WITH_LIBVNCCLIENT "Build libvncclient" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" ${UNIX})
option(WITH_TESTS "Build tests" ON)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't re-order the options, it's not pertainining to the proposed change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, dropped for now.

Version: @LibVNCServer_VERSION@
Requires:
Requires.private:
Requires: @LIBVNC_REQUIRES@
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack these, but you should differentiate between libvncclient and -server here :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the review. Indeed I did assume that the dependencies were common between server and client. Now it's split; as far as I could tell:

  • sasl is client-only
  • libsystemd and libpng are server-only
  • the rest is common

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>
@JohannesKauffmann JohannesKauffmann force-pushed the fix-static-pcfile-generation branch from 55d9ff6 to 8b89f5e Compare March 4, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants