# How to set ZLIB\_ROOT

**URL:** <https://discourse.cmake.org/t/how-to-set-zlib-root/9765>\
**Category:** Code\
**Created:** [January 3, 2024, 4:03pm UTC](https://discourse.cmake.org/t/how-to-set-zlib-root/9765 "2024-01-03T16:03:33Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [September 30, 2025, 4:33pm UTC](https://discourse.cmake.org/t/how-to-set-zlib-root/9765/6 "2025-09-30T16:33:12Z")

</div>

> 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](https://github.com/retifrav/MREs/tree/93ac2c86efa7c8815ccde3e312922c506b8a0c0a/cyberforum-ru/3213759), 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 to_” `zlib` project “_specifics_”, as it was already mentioned in the thread. I could only make it work after quite some [patching](https://github.com/retifrav/MREs/blob/93ac2c86efa7c8815ccde3e312922c506b8a0c0a/cyberforum-ru/3213759/3rd-party/zlib/001-single-target-and-installation.patch) of the original `zlib` project.

---

_[View the full topic](https://discourse.cmake.org/t/how-to-set-zlib-root/9765)._
