summaryrefslogtreecommitdiffstats
path: root/Modules/FindZLIB.cmake
diff options
context:
space:
mode:
authorPeter Würth <wuerth.peter@freenet.de>2022-03-12 16:06:53 (GMT)
committerPeter Würth <wuerth.peter@freenet.de>2022-03-12 16:55:57 (GMT)
commit185723461f02872987de862ecfcb5ec32e6ecde6 (patch)
treee50eabc3a67ad2007eba26752f4889230de8e41d /Modules/FindZLIB.cmake
parentde52151359f404ee8acb25f29de1f7fc3b1fa9ca (diff)
downloadCMake-185723461f02872987de862ecfcb5ec32e6ecde6.zip
CMake-185723461f02872987de862ecfcb5ec32e6ecde6.tar.gz
CMake-185723461f02872987de862ecfcb5ec32e6ecde6.tar.bz2
FindZLIB: more library names + option to prefer static library
Adds additional library names `zlibstat[d]` and `zlibvc[d]` for Windows, when zlib is built using one of the Visual Studio solutions under `zlib/contrib/vstudio`. Adds a `ZLIB_USE_STATIC_LIBS` option that is equivilent to similar settings in other modules such as FindProtobuf, FindOpenSSL, etc. Implements #18029 and #23140
Diffstat (limited to 'Modules/FindZLIB.cmake')
-rw-r--r--Modules/FindZLIB.cmake24
1 files changed, 22 insertions, 2 deletions
diff --git a/Modules/FindZLIB.cmake b/Modules/FindZLIB.cmake
index 5778b03..4af842a 100644
--- a/Modules/FindZLIB.cmake
+++ b/Modules/FindZLIB.cmake
@@ -53,6 +53,11 @@ Hints
A user may set ``ZLIB_ROOT`` to a zlib installation root to tell this
module where to look.
+
+.. versionadded:: 3.24
+ Set ``ZLIB_USE_STATIC_LIBS`` to ``ON`` to look for static libraries.
+ Default is ``OFF``.
+
#]=======================================================================]
set(_ZLIB_SEARCHES)
@@ -72,8 +77,8 @@ set(_ZLIB_SEARCH_NORMAL
unset(_ZLIB_x86)
list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
-set(ZLIB_NAMES z zlib zdll zlib1 zlibstatic)
-set(ZLIB_NAMES_DEBUG zd zlibd zdlld zlibd1 zlib1d zlibstaticd)
+set(ZLIB_NAMES z zlib zdll zlib1 zlibstatic zlibstat zlibvc)
+set(ZLIB_NAMES_DEBUG zd zlibd zdlld zlibd1 zlib1d zlibstaticd zlibstatd zlibvcd)
# Try each search configuration.
foreach(search ${_ZLIB_SEARCHES})
@@ -82,11 +87,26 @@ endforeach()
# Allow ZLIB_LIBRARY to be set manually, as the location of the zlib library
if(NOT ZLIB_LIBRARY)
+ # 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()
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
+ endif()
+ endif()
+
foreach(search ${_ZLIB_SEARCHES})
find_library(ZLIB_LIBRARY_RELEASE NAMES ${ZLIB_NAMES} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
find_library(ZLIB_LIBRARY_DEBUG NAMES ${ZLIB_NAMES_DEBUG} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
endforeach()
+ # Restore the original find library ordering
+ if(ZLIB_USE_STATIC_LIBS)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
+ endif()
+
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
select_library_configurations(ZLIB)
endif()