Skip to content

FindZLIB: Search names per directory

Stefan Hacker requested to merge hacst/cmake:findzlib-folder-priority into master

FindZLIB accepts various names for zlib (e.g. "z", "zlib", ...) in various search locations. Before this patch zlib ignored the priority implied by the search locations and instead prioritized based on the library name. Consequently ensuring the pick of a zlib from e.g. a CMAKE_PREFIX_PATH was not possible if it didn't have the highest priority name ("z").

This unexpected behavior led to bugs in third party projects (e.g. https://github.com/Microsoft/vcpkg/issues/1939). A common way to encounter the issue in the wild is on Windows with the popular Anaconda python distribution which puts a "z.lib" in a lib/ subdirectory reachable from a bin/ path in PATH. From then on cmake will always pick up this library instead of the one intended by the user.

This patch adds the NAMES_PER_DIR option to the find_library calls made by FindZLIB making it search each directory for all names before considering lower priority directory names resolving these issues.

Merge request reports