FindZLIB.cmake 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. # Copyright 2001-2011 Kitware, Inc.
  25. #
  26. # Distributed under the OSI-approved BSD License (the "License");
  27. # see accompanying file Copyright.txt for details.
  28. #
  29. # This software is distributed WITHOUT ANY WARRANTY; without even the
  30. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  31. # See the License for more information.
  32. #=============================================================================
  33. # (To distribute this file outside of CMake, substitute the full
  34. # License text for the above reference.)
  35. set(_ZLIB_SEARCHES)
  36. # Search ZLIB_ROOT first if it is set.
  37. if(ZLIB_ROOT)
  38. set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH)
  39. list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT)
  40. endif()
  41. # Normal search.
  42. set(_ZLIB_SEARCH_NORMAL
  43. PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]"
  44. "$ENV{PROGRAMFILES}/zlib"
  45. )
  46. list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
  47. set(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1)
  48. # Try each search configuration.
  49. foreach(search ${_ZLIB_SEARCHES})
  50. find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include)
  51. find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES lib)
  52. endforeach()
  53. mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
  54. if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
  55. file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
  56. string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
  57. string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}")
  58. string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
  59. set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
  60. # only append a TWEAK version if it exists:
  61. set(ZLIB_VERSION_TWEAK "")
  62. if( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$")
  63. set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
  64. set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}")
  65. endif()
  66. set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
  67. set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
  68. set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
  69. endif()
  70. # handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if
  71. # all listed variables are TRUE
  72. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  73. FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR
  74. VERSION_VAR ZLIB_VERSION_STRING)
  75. if(ZLIB_FOUND)
  76. set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
  77. set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
  78. endif()