How to set ZLIB_ROOT

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):

  1. With vcpkg, just in case they will reconsider in future;
  2. With FetchContent, so the same way you tried to.

The FetchContent way was indeed problematic, but that is mainly “thanks tozlib 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.