2 # Find the native ZLIB includes and library.
3 # Once done this will define
5 # ZLIB_INCLUDE_DIRS - where to find zlib.h, etc.
6 # ZLIB_LIBRARIES - List of libraries when using zlib.
7 # ZLIB_FOUND - True if zlib found.
9 # ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
10 # ZLIB_VERSION_MAJOR - The major version of zlib
11 # ZLIB_VERSION_MINOR - The minor version of zlib
12 # ZLIB_VERSION_PATCH - The patch version of zlib
13 # ZLIB_VERSION_TWEAK - The tweak version of zlib
15 # The following variable are provided for backward compatibility
17 # ZLIB_MAJOR_VERSION - The major version of zlib
18 # ZLIB_MINOR_VERSION - The minor version of zlib
19 # ZLIB_PATCH_VERSION - The patch version of zlib
21 # An includer may set ZLIB_ROOT to a zlib installation root to tell
22 # this module where to look.
24 #=============================================================================
25 # Copyright 2001-2011 Kitware, Inc.
27 # Distributed under the OSI-approved BSD License (the "License");
28 # see accompanying file Copyright.txt for details.
30 # This software is distributed WITHOUT ANY WARRANTY; without even the
31 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
32 # See the License for more information.
33 #=============================================================================
34 # (To distribute this file outside of CMake, substitute the full
35 # License text for the above reference.)
39 # Search ZLIB_ROOT first if it is set.
41 set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH)
42 list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT)
46 set(_ZLIB_SEARCH_NORMAL
47 PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]"
48 "$ENV{PROGRAMFILES}/zlib"
50 list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
52 set(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1)
54 # Try each search configuration.
55 foreach(search ${_ZLIB_SEARCHES})
56 find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include)
57 find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES lib)
60 mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
62 if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
63 file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
65 string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
66 string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}")
67 string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
68 set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
70 # only append a TWEAK version if it exists:
71 set(ZLIB_VERSION_TWEAK "")
72 if( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
73 set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
74 set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}")
77 set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
78 set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
79 set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
82 # handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if
83 # all listed variables are TRUE
84 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
85 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR
86 VERSION_VAR ZLIB_VERSION_STRING)
89 set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
90 set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})