When building libpng with CMake, the generated export script ${INSTALL}/lib/libpng/libpng16.cmake contains an absolute path to the Zlib library, which makes it impossible to relocate the installed package. This becomes an issue if the package has been built on another machine (in our case, on a build server).
Here's part of the faulty script (generated automatically by CMake):
...
set_target_properties(png_static PROPERTIES
INTERFACE_LINK_LIBRARIES "C:/Users/Utilisateur/dev/LindaleDeps3/libpng/../_install/zlib/lib/zlibstaticd.lib"
)
...
It should look like this:
...
set_target_properties(png_static PROPERTIES
INTERFACE_LINK_LIBRARIES "ZLIB::ZLIB"
)
...
The issue is caused by the main CMakeLists file linking Zlib with the old ${ZLIB_LIBRARIES} variable instead of using the newer ZLIB::ZLIB imported target. This target is provided since CMake 3.1, which is also the minimum version supported by libpng so that change should not break anything.
We have this working on a fork and can submit that change.
Fork: https://github.com/lindale-dev/libpng/commit/df5c35c18ed546bcdc232ddc01ac709c39d5697d