3 # Find the native ZLIB includes and library.
4 # Once done this will define
6 # ZLIB_INCLUDE_DIRS - where to find zlib.h, etc.
7 # ZLIB_LIBRARIES - List of libraries when using zlib.
8 # ZLIB_FOUND - True if zlib found.
9 # ZLIB_DLL_DIR - (Windows) Path to the zlib DLL.
10 # ZLIB_DLL - (Windows) Name of the zlib DLL.
11 # ZLIB_PDB - (Windows) Name of the zlib PDB.
13 # ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
14 # ZLIB_VERSION_MAJOR - The major version of zlib
15 # ZLIB_VERSION_MINOR - The minor version of zlib
16 # ZLIB_VERSION_PATCH - The patch version of zlib
17 # ZLIB_VERSION_TWEAK - The tweak version of zlib
19 # The following variable are provided for backward compatibility
21 # ZLIB_MAJOR_VERSION - The major version of zlib
22 # ZLIB_MINOR_VERSION - The minor version of zlib
23 # ZLIB_PATCH_VERSION - The patch version of zlib
25 #=============================================================================
26 # Copyright 2001-2009 Kitware, Inc.
28 # Distributed under the OSI-approved BSD License (the "License");
29 # see accompanying file Copyright.txt for details.
31 # This software is distributed WITHOUT ANY WARRANTY; without even the
32 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
33 # See the License for more information.
34 #=============================================================================
35 # (To distribute this file outside of CMake, substitute the full
36 # License text for the above reference.)
38 include( FindWSWinLibs )
39 # Zlib is included with GLib2
40 FindWSWinLibs( "vcpkg-export-*" "ZLIB_HINTS" )
43 # else we'll find Strawberry Perl's version
44 set (_zlib_sys_env_option NO_SYSTEM_ENVIRONMENT_PATH)
47 if (NOT ZLIB_INCLUDE_DIR OR NOT ZLIB_LIBRARY)
48 if (NOT USE_REPOSITORY) # else we'll find Strawberry Perl's pkgconfig
49 find_package(PkgConfig)
50 pkg_search_module(ZLIB zlib)
53 FIND_PATH(ZLIB_INCLUDE_DIR
61 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/include"
62 ${_zlib_sys_env_option}
65 SET(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1)
66 FIND_LIBRARY(ZLIB_LIBRARY
74 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/lib"
75 ${_zlib_sys_env_option}
78 unset(_zlib_sys_env_option)
79 MARK_AS_ADVANCED(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
81 # handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if
82 # all listed variables are TRUE
83 INCLUDE(FindPackageHandleStandardArgs)
84 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR
85 VERSION_VAR ZLIB_VERSION_STRING)
88 IF(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
89 FILE(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
91 STRING(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
92 STRING(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}")
93 STRING(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
94 SET(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
96 # only append a TWEAK version if it exists:
97 SET(ZLIB_VERSION_TWEAK "")
98 IF( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
99 SET(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
100 SET(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}")
101 ENDIF( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
103 SET(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
104 SET(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
105 SET(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
109 # inflatePrime was added in zlib 1.2.2.4 in 2005. We're guaranteed
110 # to have it on Windows.
113 SET(HAVE_INFLATEPRIME ON)
115 INCLUDE(CMakePushCheckState)
116 INCLUDE(CheckFunctionExists)
117 CMAKE_PUSH_CHECK_STATE()
118 set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
119 set(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
121 # Check for inflate() in zlib, to make sure the zlib library is
124 # For example, on at least some versions of Fedora, if you have a
125 # 64-bit machine, have both the 32-bit and 64-bit versions of the
126 # run-time zlib package installed, and have only the *32-bit*
127 # version of the zlib development package installed, it'll find the
128 # header, and think it can use zlib, and will use it in subsequent
129 # tests, but it'll try and link 64-bit test programs with the 32-bit
130 # library, causing those tests to falsely fail. Hilarity ensues.
132 CHECK_FUNCTION_EXISTS("inflate" HAVE_INFLATE)
134 MESSAGE(FATAL_ERROR "zlib.h found but linking with -lz failed to find inflate(); do you have the right developer package installed (32-bit vs. 64-bit)?")
136 CHECK_FUNCTION_EXISTS("inflatePrime" HAVE_INFLATEPRIME)
138 CMAKE_POP_CHECK_STATE()
141 #AddWSWinDLL(ZLIB ZLIB_HINTS "zlib*")
142 # With zlib-ng the hints does not work
143 set ( ZLIB_DLL_DIR "${ZLIB_HINTS}/bin"
144 CACHE PATH "Path to ZLIB DLL"
146 file( GLOB _ZLIB_dll RELATIVE "${ZLIB_DLL_DIR}"
147 "${ZLIB_DLL_DIR}/zlib1.dll"
149 set ( ZLIB_DLL ${_ZLIB_dll}
150 CACHE FILEPATH "ZLIB DLL file name"
152 file( GLOB _ZLIB_pdb RELATIVE "${ZLIB_DLL_DIR}"
153 "${ZLIB_DLL_DIR}/zlib.pdb"
155 set ( ZLIB_PDB ${_ZLIB_pdb}
156 CACHE FILEPATH "ZLIB PDB file name"
158 SET(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
159 SET(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
161 SET(ZLIB_INCLUDE_DIRS )