3 # Find the native ZLIBNG includes and library.
4 # Once done this will define
6 # ZLIBNG_INCLUDE_DIRS - where to find zlib-ng.h, etc.
7 # ZLIBNG_LIBRARIES - List of libraries when using zlib-ng.
8 # ZLIBNG_FOUND - True if zlib-ng found.
9 # ZLIBNG_DLL_DIR - (Windows) Path to the zlib-ng DLL.
10 # ZLIBNG_DLL - (Windows) Name of the zlib-ng DLL.
11 # ZLIBNG_PDB - (Windows) Name of the zlib-ng PDB.
13 # ZLIBNG_VERSION_STRING - The version of zlib-ng found (x.y.z)
14 # ZLIBNG_VERSION_MAJOR - The major version of zlib-ng
15 # ZLIBNG_VERSION_MINOR - The minor version of zlib-ng
16 # ZLIBNG_VERSION_PATCH - The patch version of zlib-ng
17 # ZLIBNG_VERSION_TWEAK - The tweak version of zlib-ng
19 # The following variable are provided for backward compatibility
21 # ZLIBNG_MAJOR_VERSION - The major version of zlib-ng
22 # ZLIBNG_MINOR_VERSION - The minor version of zlib-ng
23 # ZLIBNG_PATCH_VERSION - The patch version of zlib-ng
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( "zlib-ng-" "ZLIBNG_HINTS" )
42 if (NOT USE_REPOSITORY) # else we'll find Strawberry Perl's pkgconfig
43 find_package(PkgConfig)
44 pkg_search_module(ZLIBNG zlib-ng)
47 FIND_PATH(ZLIBNG_INCLUDE_DIR
52 ${ZLIBNG_HINTS}/include
57 SET(ZLIBNG_NAMES z-ng zlib-ng libz-ng.a)
58 FIND_LIBRARY(ZLIBNG_LIBRARY
69 MARK_AS_ADVANCED(ZLIBNG_LIBRARY ZLIBNG_INCLUDE_DIR)
71 # handle the QUIETLY and REQUIRED arguments and set ZLIBNG_FOUND to TRUE if
72 # all listed variables are TRUE
73 INCLUDE(FindPackageHandleStandardArgs)
74 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIBNG REQUIRED_VARS ZLIBNG_LIBRARY ZLIBNG_INCLUDE_DIR
75 VERSION_VAR ZLIBNG_VERSION_STRING)
78 IF(ZLIBNG_INCLUDE_DIR AND EXISTS "${ZLIBNG_INCLUDE_DIR}/zlib-ng.h")
79 FILE(STRINGS "${ZLIBNG_INCLUDE_DIR}/zlib-ng.h" ZLIBNG_H REGEX "^#define ZLIBNG_VERSION \"[^\"]*\"$")
81 STRING(REGEX REPLACE "^.*ZLIBNG_VERSION \"([0-9]+).*$" "\\1" ZLIBNG_VERSION_MAJOR "${ZLIBNG_H}")
82 STRING(REGEX REPLACE "^.*ZLIBNG_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIBNG_VERSION_MINOR "${ZLIBNG_H}")
83 STRING(REGEX REPLACE "^.*ZLIBNG_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIBNG_VERSION_PATCH "${ZLIBNG_H}")
84 SET(ZLIBNG_VERSION_STRING "${ZLIBNG_VERSION_MAJOR}.${ZLIBNG_VERSION_MINOR}.${ZLIBNG_VERSION_PATCH}")
86 # only append a TWEAK version if it exists:
87 SET(ZLIBNG_VERSION_TWEAK "")
88 IF( "${ZLIBNG_H}" MATCHES "^.*ZLIBNG_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
89 SET(ZLIBNG_VERSION_TWEAK "${CMAKE_MATCH_1}")
90 SET(ZLIBNG_VERSION_STRING "${ZLIBNG_VERSION_STRING}.${ZLIBNG_VERSION_TWEAK}")
91 ENDIF( "${ZLIBNG_H}" MATCHES "^.*ZLIBNG_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
93 SET(ZLIBNG_MAJOR_VERSION "${ZLIBNG_VERSION_MAJOR}")
94 SET(ZLIBNG_MINOR_VERSION "${ZLIBNG_VERSION_MINOR}")
95 SET(ZLIBNG_PATCH_VERSION "${ZLIBNG_VERSION_PATCH}")
97 INCLUDE(CMakePushCheckState)
98 INCLUDE(CheckFunctionExists)
99 CMAKE_PUSH_CHECK_STATE()
100 set(CMAKE_REQUIRED_INCLUDES ${ZLIBNG_INCLUDE_DIR})
101 set(CMAKE_REQUIRED_LIBRARIES ${ZLIBNG_LIBRARY})
103 # Check for inflate() in zlib, to make sure the zlib library is
106 # For example, on at least some versions of Fedora, if you have a
107 # 64-bit machine, have both the 32-bit and 64-bit versions of the
108 # run-time zlib package installed, and have only the *32-bit*
109 # version of the zlib development package installed, it'll find the
110 # header, and think it can use zlib, and will use it in subsequent
111 # tests, but it'll try and link 64-bit test programs with the 32-bit
112 # library, causing those tests to falsely fail. Hilarity ensues.
114 CHECK_FUNCTION_EXISTS("zng_gzopen" WITH_GZFILEOP)
115 IF(NOT WITH_GZFILEOP)
116 MESSAGE(FATAL_ERROR "zlib-ng.h found but linking with -lz failed to find zng_gzopen();")
119 CMAKE_POP_CHECK_STATE()
121 AddWSWinDLL(ZLIBNG ZLIBNG_HINTS "zlib-ng*")
122 SET(ZLIBNG_INCLUDE_DIRS ${ZLIBNG_INCLUDE_DIR})
123 SET(ZLIBNG_LIBRARIES ${ZLIBNG_LIBRARY})
125 SET(ZLIBNG_INCLUDE_DIRS )
126 SET(ZLIBNG_LIBRARIES )