aboutsummaryrefslogtreecommitdiff
path: root/cmake/Modules
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-01-16 11:53:37 +0100
committerAndreas Schneider <asn@cryptomilk.org>2011-01-16 11:53:37 +0100
commit90fc5554e1438a506f7c05d2341a6c1a9c2e5004 (patch)
tree10d0b00fc99e261ee539cd39f8bd724b05b22d50 /cmake/Modules
parente579dfb342aac3597741912a3ae302da9738ff88 (diff)
downloadlibssh-90fc5554e1438a506f7c05d2341a6c1a9c2e5004.tar.gz
libssh-90fc5554e1438a506f7c05d2341a6c1a9c2e5004.tar.xz
libssh-90fc5554e1438a506f7c05d2341a6c1a9c2e5004.zip
cmake: Improved the ZLIB find module based on CMake one.
Diffstat (limited to 'cmake/Modules')
-rw-r--r--cmake/Modules/FindZLIB.cmake144
1 files changed, 95 insertions, 49 deletions
diff --git a/cmake/Modules/FindZLIB.cmake b/cmake/Modules/FindZLIB.cmake
index 9c941455..fcd63b1b 100644
--- a/cmake/Modules/FindZLIB.cmake
+++ b/cmake/Modules/FindZLIB.cmake
@@ -1,72 +1,118 @@
# - Try to find ZLIB
# Once done this will define
#
+# ZLIB_ROOT_DIR - Set this variable to the root installation of ZLIB
+#
+# Read-Only variables:
# ZLIB_FOUND - system has ZLIB
# ZLIB_INCLUDE_DIRS - the ZLIB include directory
# ZLIB_LIBRARIES - Link these to use ZLIB
-# ZLIB_DEFINITIONS - Compiler switches required for using ZLIB
#
-# Copyright (c) 2009-2010 Andreas Schneider <mail@cynapses.org>
+# ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
+# ZLIB_VERSION_MAJOR - The major version of zlib
+# ZLIB_VERSION_MINOR - The minor version of zlib
+# ZLIB_VERSION_PATCH - The patch version of zlib
+# ZLIB_VERSION_TWEAK - The tweak version of zlib
#
-# Redistribution and use is allowed according to the terms of the New
-# BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+# The following variable are provided for backward compatibility
+#
+# ZLIB_MAJOR_VERSION - The major version of zlib
+# ZLIB_MINOR_VERSION - The minor version of zlib
+# ZLIB_PATCH_VERSION - The patch version of zlib
+#
+#=============================================================================
+# Copyright (c) 2001-2009 Kitware, Inc.
+# Copyright (c) 2011 Andreas Schneider <asn@cryptomilk.org>
+#
+# 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.
+#=============================================================================
#
-
if (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
# in cache already
set(ZLIB_FOUND TRUE)
else (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
- find_path(ZLIB_INCLUDE_DIR
- NAMES
- zlib.h
- PATHS
- ${_ZLIB_DIR}/include
- /usr/include
- /usr/local/include
- /opt/local/include
- /sw/include
- /usr/lib/sfw/include
- $ENV{PROGRAMFILES}/GnuWin32/include
- $ENV{PROGRAMFILES}/zlib/include
- )
+ set(_ZLIB_ROOT_HINTS
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/include"
+ )
- find_library(Z_LIBRARY
- NAMES
- z
- zdll
- zlib
- zlib1
- PATHS
- ${_ZLIB_DIR}/lib
- /usr/lib
- /usr/local/lib
- /opt/local/lib
- /sw/lib
- /usr/sfw/lib/64
- /usr/sfw/lib
- $ENV{PROGRAMFILES}/GnuWin32/lib
- $ENV{PROGRAMFILES}/zlib/lib
- )
+ set(_ZLIB_ROOT_PATHS
+ "$ENV{PROGRAMFILES}/zlib"
+ )
- set(ZLIB_INCLUDE_DIRS
- ${ZLIB_INCLUDE_DIR}
- )
+ find_path(ZLIB_ROOT_DIR
+ NAMES
+ include/zlib.h
+ HINTS
+ ${_ZLIB_ROOT_HINTS}
+ PATHS
+ ${_ZLIB_ROOT_PATHS}
+ )
+ mark_as_advanced(ZLIB_ROOT_DIR)
- if (Z_LIBRARY)
- set(ZLIB_LIBRARIES
- ${ZLIB_LIBRARIES}
- ${Z_LIBRARY}
+ # check for header file
+ find_path(ZLIB_INCLUDE_DIR
+ NAMES
+ zlib.h
+ PATHS
+ /usr/local/include
+ /opt/local/include
+ /sw/include
+ /usr/lib/sfw/include
)
- endif (Z_LIBRARY)
+ mark_as_advanced(ZLIB_INCLUDE_DIR)
- include(FindPackageHandleStandardArgs)
- find_package_handle_standard_args(ZLIB DEFAULT_MSG ZLIB_LIBRARIES ZLIB_INCLUDE_DIRS)
+ # check version number
+ if (ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
+ file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
- # show the ZLIB_INCLUDE_DIRS and ZLIB_LIBRARIES variables only in the advanced view
- mark_as_advanced(ZLIB_INCLUDE_DIRS ZLIB_LIBRARIES)
+ string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
+ string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}")
+ string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
-endif (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
+ set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
+
+ # only append a TWEAK version if it exists:
+ set(ZLIB_VERSION_TWEAK "")
+ if ("${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
+ set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
+ set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}")
+ endif ("${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
+
+ set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
+ set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
+ set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
+ endif (ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
+ find_library(ZLIB_LIBRARY
+ NAMES
+ z
+ zdll
+ zlib
+ zlib1
+ PATHS
+ ${_ZLIB_DIR}/lib
+ /usr/lib
+ /usr/local/lib
+ /opt/local/lib
+ /sw/lib
+ /usr/sfw/lib/64
+ /usr/sfw/lib
+ )
+ mark_as_advanced(ZLIB_LIBRARY)
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(ZLIB REQUIRED_VARS ZLIB_INCLUDE_DIR ZLIB_LIBRARY
+ VERSION_VAR ZLIB_VERSION_STRING)
+
+ if (ZLIB_FOUND)
+ set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
+ set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
+ endif (ZLIB_FOUND)
+endif (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)