FindZLIB fails starting with CMake 3.17

Hi!

I have a project where FindZLIB used to return correct ZLIB_LIBRARY_RELEASE on 3.16.x (zlib1.dll), however starting with 3.17.x and further I’m getting:


CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.7")
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.17/Modules/FindZLIB.cmake:115 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  rts/lib/minizip/CMakeLists.txt:22 (find_package)

I’m building on Windows and use mingw environment to get executables.

How do I fix it?

P.S. The project is here: GitHub - beyond-all-reason/spring: A powerful free cross-platform RTS game engine And the libs are here: GitHub - beyond-all-reason/mingwlibs64 (to be cloned under the root dir of the project)

Does passing --debug-find to CMake shine any light on this?

Yes it does reveal some, thanks for the hint.

My zlib dll is at:
C:\spring\mingwlibs64\dll\zlib1.dll

log2.txt has the --debug-find output:

$ cat log2.txt | grep "zlib1(" | grep "mingwlibs64/dll"
    C:/spring/mingwlibs64/dll/lib/(lib|)zlib1(\.dll\.a|\.a|\.lib)
    C:/spring/mingwlibs64/dll/(lib|)zlib1(\.dll\.a|\.a|\.lib)

As far as I can tell the second line here should match my path.
Yet it says: The item was not found. in the end

Similar issue is observed with a few other libs (dlls) too.

Hmm… I was able to rectify the issue by setting:
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" ${CMAKE_FIND_LIBRARY_SUFFIXES}) in my CMakeLists.txt overriding the standard set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" ".a" ".lib") set in Windows-GNU.cmake.

I must say .dll.a is a very strange extension for mingw built libs. At the very least “.dll” should be added to the list too.

Does it qualify for a bug? Should I reopen this one: https://gitlab.kitware.com/cmake/cmake/-/issues/23714 ?

On Windows .dll is a runtime dependency. For linking you need .lib (MinGW uses .dll.a (dynamic lib) or .a (static lib) for that). Those are correct extensions to look for for linking.