summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-03-16 15:23:15 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-03-16 15:23:24 (GMT)
commit0766687b2abab8042250af25eba8c0c7850e15d8 (patch)
treec88f76b16b444c0478810e4f12c4e67991920fa3
parent4e54f56ebde400278d0ec96f72698789c2595eee (diff)
parent185723461f02872987de862ecfcb5ec32e6ecde6 (diff)
downloadCMake-0766687b2abab8042250af25eba8c0c7850e15d8.zip
CMake-0766687b2abab8042250af25eba8c0c7850e15d8.tar.gz
CMake-0766687b2abab8042250af25eba8c0c7850e15d8.tar.bz2
Merge topic 'findzlib-static'
185723461f FindZLIB: more library names + option to prefer static library Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !7067
-rw-r--r--Help/release/dev/findzlib-static.rst5
-rw-r--r--Modules/FindZLIB.cmake24
2 files changed, 27 insertions, 2 deletions
diff --git a/Help/release/dev/findzlib-static.rst b/Help/release/dev/findzlib-static.rst
new file mode 100644
index 0000000..35855f6
--- /dev/null
+++ b/Help/release/dev/findzlib-static.rst
@@ -0,0 +1,5 @@
+findzlib-static
+---------------
+
+* The :module:`FindZLIB` learned a new ``ZLIB_USE_STATIC_LIBS`` variable to
+ search only for static libraries.
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()