diff options
author | Peter Würth <wuerth.peter@freenet.de> | 2022-05-13 16:26:27 (GMT) |
---|---|---|
committer | Peter Würth <wuerth.peter@freenet.de> | 2022-05-13 16:26:27 (GMT) |
commit | 3f0b9663a449cd8c1fd96dc7dcdc475ff8fe9f2f (patch) | |
tree | e446e39384231a878af4c83d63684b4d1e9d7412 /Modules | |
parent | e00e67cb924495aab72bfc60dec0451a6566d8a2 (diff) | |
download | CMake-3f0b9663a449cd8c1fd96dc7dcdc475ff8fe9f2f.zip CMake-3f0b9663a449cd8c1fd96dc7dcdc475ff8fe9f2f.tar.gz CMake-3f0b9663a449cd8c1fd96dc7dcdc475ff8fe9f2f.tar.bz2 |
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
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindZLIB.cmake | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Modules/FindZLIB.cmake b/Modules/FindZLIB.cmake index 4af842a..f50116f 100644 --- a/Modules/FindZLIB.cmake +++ b/Modules/FindZLIB.cmake @@ -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) |