MSWSP: * add parse_lcid()
[wireshark-wip.git] / cmake / modules / FindZLIB.cmake
blob0e6c4a384e294eb352f3c502fb2fa17a29b9acf5
1 # - Find zlib
3 # $Id$
5 # Find the native ZLIB includes and library.
6 # Once done this will define
8 #  ZLIB_INCLUDE_DIRS   - where to find zlib.h, etc.
9 #  ZLIB_LIBRARIES      - List of libraries when using zlib.
10 #  ZLIB_FOUND          - True if zlib found.
12 #  ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
13 #  ZLIB_VERSION_MAJOR  - The major version of zlib
14 #  ZLIB_VERSION_MINOR  - The minor version of zlib
15 #  ZLIB_VERSION_PATCH  - The patch version of zlib
16 #  ZLIB_VERSION_TWEAK  - The tweak version of zlib
18 # The following variable are provided for backward compatibility
20 #  ZLIB_MAJOR_VERSION  - The major version of zlib
21 #  ZLIB_MINOR_VERSION  - The minor version of zlib
22 #  ZLIB_PATCH_VERSION  - The patch version of zlib
24 #=============================================================================
25 # Copyright 2001-2009 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.)
37 INCLUDE(FindWSWinLibs)
38 FindWSWinLibs("zlib" "ZLIB_HINTS")
40 FIND_PATH(ZLIB_INCLUDE_DIR
41     NAMES
42         zlib.h
43     HINTS
44         ${ZLIB_HINTS}/include
45         ${ZLIB_HINTS}
46     PATHS
47         "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/include"
50 SET(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1)
51 FIND_LIBRARY(ZLIB_LIBRARY
52     NAMES
53         ${ZLIB_NAMES}
54     HINTS
55         ${ZLIB_HINTS}/lib
56         ${ZLIB_HINTS}
57     PATHS
58         "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/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}")
75     ENDIF( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
77     SET(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
78     SET(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
79     SET(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
80 ENDIF()
82 INCLUDE(CheckFunctionExists)
83 SET(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})
84 CHECK_FUNCTION_EXISTS("inflatePrime" HAVE_INFLATEPRIME)
85 # reset
86 SET(CMAKE_REQUIRED_LIBRARIES "")
88 # handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if 
89 # all listed variables are TRUE
90 INCLUDE(FindPackageHandleStandardArgs)
91 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR
92                                        VERSION_VAR ZLIB_VERSION_STRING)
94 IF(ZLIB_FOUND)
95     SET(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
96     SET(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
97 ENDIF()