summaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindZLIBNG.cmake
blob: ae779e4b154dd4d221d1b1ad293a0b6f705d8bb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# - Find zlib-ng
#
# Find the native ZLIBNG includes and library.
# Once done this will define
#
#  ZLIBNG_INCLUDE_DIRS   - where to find zlib-ng.h, etc.
#  ZLIBNG_LIBRARIES      - List of libraries when using zlib-ng.
#  ZLIBNG_FOUND          - True if zlib-ng found.
#  ZLIBNG_DLL_DIR        - (Windows) Path to the zlib-ng DLL.
#  ZLIBNG_DLL            - (Windows) Name of the zlib-ng DLL.
#  ZLIBNG_PDB            - (Windows) Name of the zlib-ng PDB.
#
#  ZLIBNG_VERSION_STRING - The version of zlib-ng found (x.y.z)
#  ZLIBNG_VERSION_MAJOR  - The major version of zlib-ng
#  ZLIBNG_VERSION_MINOR  - The minor version of zlib-ng
#  ZLIBNG_VERSION_PATCH  - The patch version of zlib-ng
#  ZLIBNG_VERSION_TWEAK  - The tweak version of zlib-ng
#
# The following variable are provided for backward compatibility
#
#  ZLIBNG_MAJOR_VERSION  - The major version of zlib-ng
#  ZLIBNG_MINOR_VERSION  - The minor version of zlib-ng
#  ZLIBNG_PATCH_VERSION  - The patch version of zlib-ng

#=============================================================================
# Copyright 2001-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
#  License text for the above reference.)

include( FindWSWinLibs )
# Zlib is included with GLib2
FindWSWinLibs( "zlib-ng-" "ZLIBNG_HINTS" )

if (NOT USE_REPOSITORY) # else we'll find Strawberry Perl's pkgconfig
    find_package(PkgConfig)
    pkg_search_module(ZLIBNG zlib-ng)
endif()

FIND_PATH(ZLIBNG_INCLUDE_DIR
    NAMES
        zlib-ng.h
    HINTS
        ${ZLIBNG_INCLUDEDIR}
        ${ZLIBNG_HINTS}/include
    /usr/include
    /usr/local/include
)

SET(ZLIBNG_NAMES z-ng zlib-ng libz-ng.a)
FIND_LIBRARY(ZLIBNG_LIBRARY
    NAMES
        ${ZLIBNG_NAMES}
    HINTS
        ${ZLIBNG_LIBDIR}
        ${ZLIBNG_HINTS}/lib
      PATHS
      /usr/lib
      /usr/local/lib
)

MARK_AS_ADVANCED(ZLIBNG_LIBRARY ZLIBNG_INCLUDE_DIR)

# handle the QUIETLY and REQUIRED arguments and set ZLIBNG_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIBNG REQUIRED_VARS ZLIBNG_LIBRARY ZLIBNG_INCLUDE_DIR
                                       VERSION_VAR ZLIBNG_VERSION_STRING)

if(ZLIBNG_FOUND)
    IF(ZLIBNG_INCLUDE_DIR AND EXISTS "${ZLIBNG_INCLUDE_DIR}/zlib-ng.h")
        FILE(STRINGS "${ZLIBNG_INCLUDE_DIR}/zlib-ng.h" ZLIBNG_H REGEX "^#define ZLIBNG_VERSION \"[^\"]*\"$")

        STRING(REGEX REPLACE "^.*ZLIBNG_VERSION \"([0-9]+).*$" "\\1" ZLIBNG_VERSION_MAJOR "${ZLIBNG_H}")
        STRING(REGEX REPLACE "^.*ZLIBNG_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIBNG_VERSION_MINOR  "${ZLIBNG_H}")
        STRING(REGEX REPLACE "^.*ZLIBNG_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIBNG_VERSION_PATCH "${ZLIBNG_H}")
        SET(ZLIBNG_VERSION_STRING "${ZLIBNG_VERSION_MAJOR}.${ZLIBNG_VERSION_MINOR}.${ZLIBNG_VERSION_PATCH}")

        # only append a TWEAK version if it exists:
        SET(ZLIBNG_VERSION_TWEAK "")
        IF( "${ZLIBNG_H}" MATCHES "^.*ZLIBNG_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
            SET(ZLIBNG_VERSION_TWEAK "${CMAKE_MATCH_1}")
            SET(ZLIBNG_VERSION_STRING "${ZLIBNG_VERSION_STRING}.${ZLIBNG_VERSION_TWEAK}")
        ENDIF( "${ZLIBNG_H}" MATCHES "^.*ZLIBNG_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")

        SET(ZLIBNG_MAJOR_VERSION "${ZLIBNG_VERSION_MAJOR}")
        SET(ZLIBNG_MINOR_VERSION "${ZLIBNG_VERSION_MINOR}")
        SET(ZLIBNG_PATCH_VERSION "${ZLIBNG_VERSION_PATCH}")
    ENDIF()
        INCLUDE(CMakePushCheckState)
        INCLUDE(CheckFunctionExists)
        CMAKE_PUSH_CHECK_STATE()
        set(CMAKE_REQUIRED_INCLUDES ${ZLIBNG_INCLUDE_DIR})
        set(CMAKE_REQUIRED_LIBRARIES ${ZLIBNG_LIBRARY})
        #
        # Check for inflate() in zlib, to make sure the zlib library is
        # usable.
        #
        # For example, on at least some versions of Fedora, if you have a
        # 64-bit machine, have both the 32-bit and 64-bit versions of the
        # run-time zlib package installed, and have only the *32-bit*
        # version of the zlib development package installed, it'll find the
        # header, and think it can use zlib, and will use it in subsequent
        # tests, but it'll try and link 64-bit test programs with the 32-bit
        # library, causing those tests to falsely fail.  Hilarity ensues.
        #
        CHECK_FUNCTION_EXISTS("zng_gzopen" WITH_GZFILEOP)
        IF(NOT WITH_GZFILEOP)
            MESSAGE(FATAL_ERROR "zlib-ng.h found but linking with -lz failed to find zng_gzopen();")
        ENDIF()
        # reset
        CMAKE_POP_CHECK_STATE()

    AddWSWinDLL(ZLIBNG ZLIBNG_HINTS "zlib-ng*")
    SET(ZLIBNG_INCLUDE_DIRS ${ZLIBNG_INCLUDE_DIR})
    SET(ZLIBNG_LIBRARIES ${ZLIBNG_LIBRARY})
ELSE()
    SET(ZLIBNG_INCLUDE_DIRS )
    SET(ZLIBNG_LIBRARIES )
    SET(ZLIBNG_DLL_DIR )
    SET(ZLIBNG_DLL )
    SET(ZLIBNG_PDB )
ENDIF()