1
0

FindZLIB.cmake 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. # Copyright 2001-2009 Kitware, Inc.
  22. #
  23. # Distributed under the OSI-approved BSD License (the "License");
  24. # see accompanying file Copyright.txt for details.
  25. #
  26. # This software is distributed WITHOUT ANY WARRANTY; without even the
  27. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  28. # See the License for more information.
  29. #=============================================================================
  30. # (To distribute this file outside of CMake, substitute the full
  31. # License text for the above reference.)
  32. FIND_PATH(ZLIB_INCLUDE_DIR zlib.h
  33. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/include"
  34. )
  35. SET(ZLIB_NAMES z zlib zdll)
  36. FIND_LIBRARY(ZLIB_LIBRARY
  37. NAMES
  38. ${ZLIB_NAMES}
  39. PATHS
  40. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]/lib"
  41. )
  42. MARK_AS_ADVANCED(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
  43. IF(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
  44. FILE(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
  45. STRING(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
  46. STRING(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}")
  47. STRING(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
  48. STRING(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_TWEAK "${ZLIB_H}")
  49. SET(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}.${ZLIB_VERSION_TWEAK}")
  50. SET(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
  51. SET(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
  52. SET(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
  53. ENDIF()
  54. # handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if
  55. # all listed variables are TRUE
  56. INCLUDE(FindPackageHandleStandardArgs)
  57. FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB DEFAULT_MSG ZLIB_INCLUDE_DIR ZLIB_LIBRARY)
  58. # handle the VERSION provided in find_package() command
  59. if(ZLIB_FIND_VERSION)
  60. if(ZLIB_FIND_VERSION_EXACT AND NOT ${ZLIB_VERSION_STRING} VERSION_EQUAL ${ZLIB_FIND_VERSION})
  61. message(FATAL_ERROR "ZLIB version found (${ZLIB_VERSION_STRING}) does not match the required one (${ZLIB_FIND_VERSION}), aborting.")
  62. elseif(${ZLIB_VERSION_STRING} VERSION_LESS ${ZLIB_FIND_VERSION})
  63. if(ZLIB_FIND_REQUIRED)
  64. message(FATAL_ERROR "ZLIB version found (${ZLIB_VERSION_STRING}) is less then the minimum required (${ZLIB_FIND_VERSION}), aborting.")
  65. else(ZLIB_FIND_REQUIRED)
  66. message("ZLIB version found (${ZLIB_VERSION_STRING}) is less then the minimum required (${ZLIB_FIND_VERSION}), continue without ZLIB support.")
  67. set(ZLIB_FOUND FALSE)
  68. endif(ZLIB_FIND_REQUIRED)
  69. endif()
  70. endif(ZLIB_FIND_VERSION)
  71. IF(ZLIB_FOUND)
  72. SET(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
  73. SET(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
  74. ENDIF()