Target "png_shared" links to:
ZLIB::ZLIB
but the target was not found. Possible reasons include:
* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.
After the instructions about zlib, I added the command : message("ZLib found ? ${ZLIB_FOUND}")
which confirmed me that ZLib was not found, because ${ZLIB_FOUND} doesn’t exist.
Note that if I use FIND_PACKAGE_ARGS, ${ZLIB_FOUND} doest exist, but its value is false.
I don’t understand why there are two different behaviors…
Zlib seems to have many troubles with CMake :
For now, I suppose FindZLIB() is called at one moment, and I see in its documentation that we can set ZLIB_ROOT to help it.
Zlib has been downloaded, and put in the build directory, in a subdirectory called _deps.
Then, there are three directories, alongside with three other ones related to libpng. The three directories are :
zlib-build
zlib-src
zlib-subbuild
So :
Am I right to think setting ZLIB_ROOT could help me ?
If so, where to put the instruction, and what value should I give to it ?
Thanks.
EDIT : I commented all the code above, but I kept the ZLIB build. Then I added the follwing instructions :
set(ZLIB_ROOT ${CMAKE_BINARY_DIR}/_deps/zlib-build)
message("${CMAKE_BINARY_DIR}/_deps/zlib-build")
find_package("zlib")
message("ZLib found ? ${ZLIB_FOUND}")
But zlib is not found yet, whereas the path seems to be good…
PS: Any other hint to help me to resolve my zlib troubles is welcome…
If you want this to try using the CMake-provided FindZLIB module first, that should be just FIND_PACKAGE_ARGS NAMES ZLIB. The capitalisation of ZLIB in this line also matters because it needs to match up with the capitalisation of FindZLIB.
I will say that trying to get any sort of CMake-related changes into the official zlib repository has been a fruitless task. Many have tried, but the maintainer has shown essentially zero interest. Others have tried setting up a better maintained fork, but I haven’t seen any that have gained widespread adoption. This is a really unfortunate situation, given that zlib is such a widely used, foundational dependency of so many other things. This means trying to bring it in using FetchContent is usually a frustrating experience. You will likely end up having to set up your own fork with the patches you need to get things to work. Normally I’d say just use a package manager and be done with it, but you’ve stated up front that isn’t an option for you.
I am trying to install/build the ZLib library on Windows through CMake, in order to install/use libpng afterwards […] and I can’t use a package manager as Conan or vcpkg
Ha, I was recently helping someone on a different forum with a similar problem/requirements, and I remembered about this thread. They also needed to resolve png library in their project (and through that also zlib, as it’s a dependency of png), and they also did not want to use a package manager.
So I made this example project, which can be built in two ways (the README contains build instructions for both):
With vcpkg, just in case they will reconsider in future;
With FetchContent, so the same way you tried to.
The FetchContent way was indeed problematic, but that is mainly “thanks to” zlib project “specifics”, as it was already mentioned in the thread. I could only make it work after quite some patching of the original zlib project.