source: pacpussensors/trunk/Vislab/20150310_lib3dv-1.2.0/cmake/FindZLIB.cmake

Last change on this file was 136, checked in by ldecherf, 8 years ago

Doc

File size: 3.8 KB
Line 
1# - Find zlib
2# Find the native ZLIB includes and library.
3# Once done this will define
4#
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.
8#
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
14#
15# The following variable are provided for backward compatibility
16#
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
20#
21# An includer may set ZLIB_ROOT to a zlib installation root to tell
22# this module where to look.
23
24#=============================================================================
25# Copyright 2001-2011 Kitware, Inc.
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# (To distribute this file outside of CMake, substitute the full
35# License text for the above reference.)
36
37SET(_ZLIB_SEARCHES)
38
39# Search ZLIB_INCLUDEDIR and ZLIB_LIBRARYDIR if specified
40
41IF(ZLIB_INCLUDEDIR OR ZLIB_LIBRARYDIR)
42 SET(_ZLIB_SEARCHDIR PATHS ${ZLIB_INCLUDEDIR} ${ZLIB_LIBRARYDIR} NO_DEFAULT_PATH)
43 LIST(APPEND _ZLIB_SEARCHES _ZLIB_SEARCHDIR)
44ENDIF()
45
46# Search ZLIB_ROOT first if it is set.
47IF(ZLIB_ROOT)
48 SET(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH)
49 LIST(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT)
50ENDIF()
51
52# Normal search.
53SET(_ZLIB_SEARCH_NORMAL
54 PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]"
55 "$ENV{PROGRAMFILES}/zlib"
56 )
57LIST(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
58
59SET(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1)
60
61# Try each search configuration.
62FOREACH(search ${_ZLIB_SEARCHES})
63 FIND_PATH(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}})
64 FIND_LIBRARY(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${${search}})
65ENDFOREACH()
66
67MARK_AS_ADVANCED(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
68
69IF(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
70 FILE(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
71
72 STRING(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
73 STRING(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}")
74 STRING(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
75 SET(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
76
77 # only append a TWEAK version if it exists:
78 SET(ZLIB_VERSION_TWEAK "")
79 IF( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
80 SET(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
81 SET(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}")
82 ENDIF( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
83
84 SET(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
85 SET(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
86 SET(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
87ENDIF()
88
89# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if
90# all listed variables are TRUE
91INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
92FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR
93 VERSION_VAR ZLIB_VERSION_STRING)
94
95IF(ZLIB_FOUND)
96 SET(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
97 SET(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
98ENDIF()
99
Note: See TracBrowser for help on using the repository browser.