FindZLIB: fix ZLIB_USE_STATIC_LIBS on Windows

- on Windows, the ZLIB_USE_STATIC_LIBS options requires a reordering of
  the search names in order to prefer the static library, since in most
  cases both static and shared libraries are built
- add zlibwapi[d] library name for the contrib/vstudio builds
- add lib prefix and .dll.a suffix for the win32/Makefile.gcc build

Fixes #23140
This commit is contained in:
Peter Würth
2022-05-13 18:26:27 +02:00
parent e00e67cb92
commit 3f0b9663a4

View File

@@ -77,8 +77,13 @@ set(_ZLIB_SEARCH_NORMAL
unset(_ZLIB_x86)
list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
set(ZLIB_NAMES z zlib zdll zlib1 zlibstatic zlibstat zlibvc)
set(ZLIB_NAMES_DEBUG zd zlibd zdlld zlibd1 zlib1d zlibstaticd zlibstatd zlibvcd)
if(ZLIB_USE_STATIC_LIBS)
set(ZLIB_NAMES zlibstatic zlibstat zlib z)
set(ZLIB_NAMES_DEBUG zlibstaticd zlibstatd zlibd zd)
else()
set(ZLIB_NAMES z zlib zdll zlib1 zlibstatic zlibwapi zlibvc zlibstat)
set(ZLIB_NAMES_DEBUG zd zlibd zdlld zlibd1 zlib1d zlibstaticd zlibwapid zlibvcd zlibstatd)
endif()
# Try each search configuration.
foreach(search ${_ZLIB_SEARCHES})
@@ -87,9 +92,15 @@ endforeach()
# Allow ZLIB_LIBRARY to be set manually, as the location of the zlib library
if(NOT ZLIB_LIBRARY)
set(_zlib_ORIG_CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES})
set(_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
# Prefix/suffix of the win32/Makefile.gcc build
if(WIN32)
list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "" "lib")
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a")
endif()
# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
if(ZLIB_USE_STATIC_LIBS)
set(_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
@@ -103,9 +114,8 @@ if(NOT ZLIB_LIBRARY)
endforeach()
# Restore the original find library ordering
if(ZLIB_USE_STATIC_LIBS)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_PREFIXES ${_zlib_ORIG_CMAKE_FIND_LIBRARY_PREFIXES})
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
select_library_configurations(ZLIB)