Skip to content

FindZLIB: fix CMAKE_FIND_LIBRARY_PREFIXES being unset when it was empty

CMAKE_FIND_LIBRARY_PREFIXES and CMAKE_FIND_LIBRARY_SUFFIXES have different behavior when undefined and when defined but empty: Empty means to use an empty prefix/suffix while undefined means to use a hardcoded default for the platform we are running on.

Unfortunately, set(a ${b}) will undefine a when b is empty, meaning that when targeting a platform where either of these variables is empty (e.g. Windows where CMAKE_FIND_LIBRARY_PREFIXES is empty) the unpatched FindZLIB code ends up unsetting that variable, causing all subsequent find_library calls to use the hardcoded default for the runtime platform (e.g. "lib" for CMAKE_FIND_LIBRARY_PREFIXES on Linux).

On the other hand, set(a "${b}") will always define a to be empty but defined so we have to do this dance to fully preserve the state of these variables.

--

Other find modules that mess with CMAKE_FIND_LIBRARY_{PREFIXES,SUFFIXES} probably need a similar fix.

Note that while this is especially noticeable while cross-compiling, the existing FindZLIB code changes the effective value of CMAKE_FIND_LIBRARY_PREFIXES even on native Windows builds from "" set in Modules/Platform/Windows.cmake to the hardcoded ";lib" in Source/cmFindLibraryCommand.cxx.

Backport: release

Edited by Brad King

Merge request reports