Skip to content

FindCImg.cmake: Propagate png and jpeg library paths properly#328

Merged
TheAssassin merged 1 commit into
linuxdeploy:masterfrom
arrowd:cimg-cmake
Apr 21, 2026
Merged

FindCImg.cmake: Propagate png and jpeg library paths properly#328
TheAssassin merged 1 commit into
linuxdeploy:masterfrom
arrowd:cimg-cmake

Conversation

@arrowd
Copy link
Copy Markdown
Contributor

@arrowd arrowd commented Apr 14, 2026

According to FindPkgConfig documentation, the ${prefix}_LINK_LIBRARIES expands to a full path to the library. This is what we want to pass to target_link_libraries() later, because this allows CMake to properly generate -L and -l flags. Using just ${prefix}_LIBRARIES works on Linux, where libraries are put in the default library search path, but fails on FreeBSD.

This change does not fix the case for STATIC_BUILD due to bug on the CMake side: Kitware/CMake@7e4adca

According to FindPkgConfig documentation, the ${prefix}_LINK_LIBRARIES expands
to a full path to the library. This is what we want to pass to
target_link_libraries() later, because this allows CMake to properly generate
-L and -l flags. Using just ${prefix}_LIBRARIES works on Linux, where libraries
are put in the default library search path, but fails on FreeBSD.

This change does not fix the case for STATIC_BUILD due to bug on the CMake side:
Kitware/CMake@7e4adca
Copy link
Copy Markdown
Member

@TheAssassin TheAssassin left a comment

Choose a reason for hiding this comment

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

Looks good to me. Let's see if CI agrees. Thanks!

@TheAssassin TheAssassin enabled auto-merge (rebase) April 21, 2026 23:12
@TheAssassin TheAssassin merged commit 33d18db into linuxdeploy:master Apr 21, 2026
5 of 6 checks passed
@TheAssassin
Copy link
Copy Markdown
Member

Unfortunately, this change breaks dynamic linking which the coverage build uses (and possibly other users, too). Looks like this requires some additional logic (and we should perhaps not allow that coverage build to fail).

Can you please explain why this is not working on FreeBSD? I think using _LIBRARIES and adding the _LIBRARY_DIRS in addition should work.

@arrowd
Copy link
Copy Markdown
Contributor Author

arrowd commented Apr 22, 2026

Can you please explain why this is not working on FreeBSD? I think using _LIBRARIES and adding the _LIBRARY_DIRS in addition should work.

To successfully link to a pkg-config-based library, one should pass both -L and -l flags in general case. The previous variant of the code was taking only -l ones into account. It works on Linux, because libraries are installed under /usr/lib64, which is a default search path for the linker. On FreeBSD 3rd-party libraries are installed under /usr/local/lib, which isn't in a default path, so omitting -L flags leads to error.

In CMake passing an absolute path to target_link_libraries automatically generates proper -L and -l flags, so my change does exactly that.

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