~ubuntu-branches/ubuntu/precise/libssh/precise

« back to all changes in this revision

Viewing changes to cmake/Modules/FindZLIB.cmake

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-06-15 15:48:07 UTC
  • mfrom: (1.1.10 upstream) (4.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20110615154807-3muklcqfftr1vtch
Tags: 0.5.0-2
* debian/patches/0002-Check-for-NULL-pointers-in-string-c.patch:
  Consolidate patch (Should fix previous REJECT)
* Support multiarch spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# - Try to find ZLIB
2
2
# Once done this will define
3
3
#
 
4
#  ZLIB_ROOT_DIR - Set this variable to the root installation of ZLIB
 
5
#
 
6
# Read-Only variables:
4
7
#  ZLIB_FOUND - system has ZLIB
5
8
#  ZLIB_INCLUDE_DIRS - the ZLIB include directory
6
9
#  ZLIB_LIBRARIES - Link these to use ZLIB
7
 
#  ZLIB_DEFINITIONS - Compiler switches required for using ZLIB
8
 
#
9
 
#  Copyright (c) 2009 Andreas Schneider <mail@cynapses.org>
10
 
#
11
 
#  Redistribution and use is allowed according to the terms of the New
12
 
#  BSD license.
13
 
#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
14
 
#
15
 
 
 
10
#
 
11
#  ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
 
12
#  ZLIB_VERSION_MAJOR  - The major version of zlib
 
13
#  ZLIB_VERSION_MINOR  - The minor version of zlib
 
14
#  ZLIB_VERSION_PATCH  - The patch version of zlib
 
15
#  ZLIB_VERSION_TWEAK  - The tweak version of zlib
 
16
#
 
17
# The following variable are provided for backward compatibility
 
18
#
 
19
#  ZLIB_MAJOR_VERSION  - The major version of zlib
 
20
#  ZLIB_MINOR_VERSION  - The minor version of zlib
 
21
#  ZLIB_PATCH_VERSION  - The patch version of zlib
 
22
#
 
23
#=============================================================================
 
24
#  Copyright (c) 2001-2009 Kitware, Inc.
 
25
#  Copyright (c) 2011      Andreas Schneider <asn@cryptomilk.org>
 
26
#
 
27
#  Distributed under the OSI-approved BSD License (the "License");
 
28
#  see accompanying file Copyright.txt for details.
 
29
#
 
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
#
16
35
 
17
36
if (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
18
37
  # in cache already
19
38
  set(ZLIB_FOUND TRUE)
20
39
else (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
21
 
  if (WIN32)
22
 
    set(_ZLIB_DIR $ENV{PROGRAMFILES}/GnuWin32)
23
 
  endif (WIN32)
24
 
 
25
 
  find_path(ZLIB_INCLUDE_DIR
26
 
    NAMES
27
 
      zlib.h
28
 
    PATHS
29
 
      ${_ZLIB_DIR}/include
30
 
      /usr/include
31
 
      /usr/local/include
32
 
      /opt/local/include
33
 
      /sw/include
34
 
  )
35
 
  mark_as_advanced(ZLIB_INCLUDE_DIR)
36
 
 
37
 
  find_library(Z_LIBRARY
38
 
    NAMES
39
 
      z
40
 
      zlib
41
 
      zlib1
42
 
    PATHS
43
 
      ${_ZLIB_DIR}/lib
44
 
      /usr/lib
45
 
      /usr/local/lib
46
 
      /opt/local/lib
47
 
      /sw/lib
48
 
  )
49
 
  mark_as_advanced(Z_LIBRARY)
50
 
 
51
 
  if (Z_LIBRARY)
52
 
    set(Z_FOUND TRUE)
53
 
  endif (Z_LIBRARY)
54
 
 
55
 
  set(ZLIB_INCLUDE_DIRS
56
 
    ${ZLIB_INCLUDE_DIR}
57
 
  )
58
 
 
59
 
  if (Z_FOUND)
60
 
    set(ZLIB_LIBRARIES
61
 
      ${ZLIB_LIBRARIES}
62
 
      ${Z_LIBRARY}
63
 
    )
64
 
  endif (Z_FOUND)
65
 
 
66
 
  if (ZLIB_INCLUDE_DIRS AND ZLIB_LIBRARIES)
67
 
     set(ZLIB_FOUND TRUE)
68
 
  endif (ZLIB_INCLUDE_DIRS AND ZLIB_LIBRARIES)
69
 
 
70
 
  if (ZLIB_FOUND)
71
 
    if (NOT ZLIB_FIND_QUIETLY)
72
 
      message(STATUS "Found ZLIB: ${ZLIB_LIBRARIES}")
73
 
    endif (NOT ZLIB_FIND_QUIETLY)
74
 
  else (ZLIB_FOUND)
75
 
    if (ZLIB_FIND_REQUIRED)
76
 
      message(FATAL_ERROR "Could not find ZLIB")
77
 
    endif (ZLIB_FIND_REQUIRED)
78
 
  endif (ZLIB_FOUND)
79
 
 
80
 
  # show the ZLIB_INCLUDE_DIRS and ZLIB_LIBRARIES variables only in the advanced view
81
 
  mark_as_advanced(ZLIB_INCLUDE_DIRS ZLIB_LIBRARIES)
82
 
 
 
40
 
 
41
    set(_ZLIB_ROOT_HINTS
 
42
        "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/include"
 
43
    )
 
44
 
 
45
    set(_ZLIB_ROOT_PATHS
 
46
        "$ENV{PROGRAMFILES}/zlib"
 
47
    )
 
48
 
 
49
    find_path(ZLIB_ROOT_DIR
 
50
        NAMES
 
51
            include/zlib.h
 
52
        HINTS
 
53
            ${_ZLIB_ROOT_HINTS}
 
54
        PATHS
 
55
            ${_ZLIB_ROOT_PATHS}
 
56
    )
 
57
    mark_as_advanced(ZLIB_ROOT_DIR)
 
58
 
 
59
    # check for header file
 
60
    find_path(ZLIB_INCLUDE_DIR
 
61
        NAMES
 
62
            zlib.h
 
63
        PATHS
 
64
            /usr/local/include
 
65
            /opt/local/include
 
66
            /sw/include
 
67
            /usr/lib/sfw/include
 
68
            ${ZLIB_ROOT_DIR}/include
 
69
    )
 
70
    mark_as_advanced(ZLIB_INCLUDE_DIR)
 
71
 
 
72
    # check version number
 
73
    if (ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
 
74
        file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
 
75
 
 
76
        string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
 
77
        string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR  "${ZLIB_H}")
 
78
        string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
 
79
 
 
80
        set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
 
81
 
 
82
        # only append a TWEAK version if it exists:
 
83
        set(ZLIB_VERSION_TWEAK "")
 
84
        if ("${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
 
85
            set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
 
86
            set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}")
 
87
        endif ("${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
 
88
 
 
89
        set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
 
90
        set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
 
91
        set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
 
92
    endif (ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
 
93
 
 
94
    find_library(ZLIB_LIBRARY
 
95
        NAMES
 
96
            z
 
97
            zdll
 
98
            zlib
 
99
            zlib1
 
100
        PATHS
 
101
            /usr/local/lib
 
102
            /opt/local/lib
 
103
            /sw/lib
 
104
            /usr/sfw/lib/64
 
105
            /usr/sfw/lib
 
106
            ${ZLIB_ROOT_DIR}/lib
 
107
    )
 
108
    mark_as_advanced(ZLIB_LIBRARY)
 
109
 
 
110
    include(FindPackageHandleStandardArgs)
 
111
    find_package_handle_standard_args(ZLIB DEFAULT_MSG ZLIB_INCLUDE_DIR ZLIB_LIBRARY)
 
112
    #find_package_handle_standard_args(ZLIB REQUIRED_VARS ZLIB_INCLUDE_DIR ZLIB_LIBRARY
 
113
    #                                       VERSION_VAR ZLIB_VERSION_STRING)
 
114
 
 
115
    if (ZLIB_FOUND)
 
116
        set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
 
117
        set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
 
118
    endif (ZLIB_FOUND)
83
119
endif (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
84