summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2010-08-03 20:18:42 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2010-08-03 20:18:42 (GMT)
commit976aaf45ded17774fb1523a983be9cbaf31c72dc (patch)
treeeeab26ce79cbceb522c88008a55c220b299577f7
parentcbfc37dc182e8f11231f1ab1ad72ad0060be0f39 (diff)
parent6b9b9f44c80af7ba080be4054e462175737f98dc (diff)
downloadCMake-976aaf45ded17774fb1523a983be9cbaf31c72dc.zip
CMake-976aaf45ded17774fb1523a983be9cbaf31c72dc.tar.gz
CMake-976aaf45ded17774fb1523a983be9cbaf31c72dc.tar.bz2
Merge topic 'findzlib_fix_version'
6b9b9f4 FindZLIB: optimize zlib.h version parsing
-rw-r--r--Modules/FindZLIB.cmake46
1 files changed, 39 insertions, 7 deletions
diff --git a/Modules/FindZLIB.cmake b/Modules/FindZLIB.cmake
index 7432257..fa991f1 100644
--- a/Modules/FindZLIB.cmake
+++ b/Modules/FindZLIB.cmake
@@ -1,12 +1,20 @@
# - Find zlib
-# Find the native ZLIB includes and library
+# Find the native ZLIB includes and library.
+# Once done this will define
#
# ZLIB_INCLUDE_DIRS - where to find zlib.h, etc.
# ZLIB_LIBRARIES - List of libraries when using zlib.
# ZLIB_FOUND - True if zlib found.
#
# ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
-# ZLIB_MAJOR_VERSION - the major version of zlib
+# 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
+#
+# 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
@@ -36,9 +44,19 @@ FIND_LIBRARY(ZLIB_LIBRARY
)
MARK_AS_ADVANCED(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-IF (ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
- FILE(READ "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H)
- STRING(REGEX REPLACE ".*#define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\1.\\2.\\3" ZLIB_VERSION_STRING "${ZLIB_H}")
+IF(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
+ FILE(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
+
+ 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}")
+ STRING(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_TWEAK "${ZLIB_H}")
+
+ SET(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}.${ZLIB_VERSION_TWEAK}")
+
+ SET(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
+ SET(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
+ SET(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
ENDIF()
# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if
@@ -46,8 +64,22 @@ ENDIF()
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB DEFAULT_MSG ZLIB_INCLUDE_DIR ZLIB_LIBRARY)
-IF (ZLIB_FOUND)
+# handle the VERSION provided in find_package() command
+if(ZLIB_FIND_VERSION)
+ if(ZLIB_FIND_VERSION_EXACT AND NOT ${ZLIB_VERSION_STRING} VERSION_EQUAL ${ZLIB_FIND_VERSION})
+ message(FATAL_ERROR "ZLIB version found (${ZLIB_VERSION_STRING}) does not match the required one (${ZLIB_FIND_VERSION}), aborting.")
+ elseif(${ZLIB_VERSION_STRING} VERSION_LESS ${ZLIB_FIND_VERSION})
+ if(ZLIB_FIND_REQUIRED)
+ message(FATAL_ERROR "ZLIB version found (${ZLIB_VERSION_STRING}) is less then the minimum required (${ZLIB_FIND_VERSION}), aborting.")
+ else(ZLIB_FIND_REQUIRED)
+ message("ZLIB version found (${ZLIB_VERSION_STRING}) is less then the minimum required (${ZLIB_FIND_VERSION}), continue without ZLIB support.")
+ set(ZLIB_FOUND FALSE)
+ endif(ZLIB_FIND_REQUIRED)
+ endif()
+endif(ZLIB_FIND_VERSION)
+
+IF(ZLIB_FOUND)
SET(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
- SET(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
+ SET(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
ENDIF()