diff options
author | Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com> | 2010-07-31 07:24:47 +0200 |
---|---|---|
committer | Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com> | 2010-07-31 07:24:47 +0200 |
commit | 6b9b9f44c80af7ba080be4054e462175737f98dc (patch) | |
tree | c1e55140e9eb141eaac1ff20fd8bc71d1dc5b63b /Modules/FindZLIB.cmake | |
parent | 41dbdb71cda5b3428c36b2ea283db71d1ab26578 (diff) | |
download | cmake-6b9b9f44c80af7ba080be4054e462175737f98dc.tar.gz |
FindZLIB: optimize zlib.h version parsing
Read zlib.h by using file(STRINGS.....REGEX) to limit the amount of text we apply the version regex on. This patch also addresses the fact that the version string may contain a tweak component.
Patch by Simone Rossetto
Diffstat (limited to 'Modules/FindZLIB.cmake')
-rw-r--r-- | Modules/FindZLIB.cmake | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/Modules/FindZLIB.cmake b/Modules/FindZLIB.cmake index 7432257cea..fa991f1099 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() |