2016-09-27 19:01:08 +00:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
|
|
|
|
2013-10-15 15:17:36 +00:00
|
|
|
#.rst:
|
|
|
|
# FindZLIB
|
|
|
|
# --------
|
|
|
|
#
|
2014-06-10 08:54:24 +00:00
|
|
|
# Find the native ZLIB includes and library.
|
2013-10-15 15:17:36 +00:00
|
|
|
#
|
2014-06-10 08:54:24 +00:00
|
|
|
# IMPORTED Targets
|
|
|
|
# ^^^^^^^^^^^^^^^^
|
|
|
|
#
|
|
|
|
# This module defines :prop_tgt:`IMPORTED` target ``ZLIB::ZLIB``, if
|
|
|
|
# ZLIB has been found.
|
|
|
|
#
|
|
|
|
# Result Variables
|
|
|
|
# ^^^^^^^^^^^^^^^^
|
|
|
|
#
|
|
|
|
# This module defines the following variables:
|
2013-10-15 15:17:36 +00:00
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# 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_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
|
2002-09-02 20:24:25 +00:00
|
|
|
#
|
2014-06-10 08:54:24 +00:00
|
|
|
# Backward Compatibility
|
|
|
|
# ^^^^^^^^^^^^^^^^^^^^^^
|
2010-07-31 05:24:47 +00:00
|
|
|
#
|
|
|
|
# The following variable are provided for backward compatibility
|
|
|
|
#
|
2013-10-15 15:17:36 +00:00
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# ZLIB_MAJOR_VERSION - The major version of zlib
|
|
|
|
# ZLIB_MINOR_VERSION - The minor version of zlib
|
|
|
|
# ZLIB_PATCH_VERSION - The patch version of zlib
|
|
|
|
#
|
2014-06-10 08:54:24 +00:00
|
|
|
# Hints
|
|
|
|
# ^^^^^
|
2013-10-15 15:17:36 +00:00
|
|
|
#
|
2014-06-10 08:54:24 +00:00
|
|
|
# A user may set ``ZLIB_ROOT`` to a zlib installation root to tell this
|
2013-10-15 15:17:36 +00:00
|
|
|
# module where to look.
|
2002-09-02 20:24:25 +00:00
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
set(_ZLIB_SEARCHES)
|
2011-11-30 13:40:58 +00:00
|
|
|
|
|
|
|
# Search ZLIB_ROOT first if it is set.
|
2012-08-13 17:47:32 +00:00
|
|
|
if(ZLIB_ROOT)
|
|
|
|
set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH)
|
|
|
|
list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT)
|
|
|
|
endif()
|
2011-11-30 13:40:58 +00:00
|
|
|
|
|
|
|
# Normal search.
|
2012-08-13 17:47:32 +00:00
|
|
|
set(_ZLIB_SEARCH_NORMAL
|
2011-11-30 13:40:58 +00:00
|
|
|
PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]"
|
|
|
|
"$ENV{PROGRAMFILES}/zlib"
|
|
|
|
)
|
2012-08-13 17:47:32 +00:00
|
|
|
list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
|
2002-09-02 20:24:25 +00:00
|
|
|
|
2015-09-01 19:41:27 +00:00
|
|
|
set(ZLIB_NAMES z zlib zdll zlib1)
|
|
|
|
set(ZLIB_NAMES_DEBUG zlibd zlibd1)
|
2011-11-30 13:40:58 +00:00
|
|
|
|
|
|
|
# Try each search configuration.
|
2012-08-13 17:47:32 +00:00
|
|
|
foreach(search ${_ZLIB_SEARCHES})
|
2015-09-01 19:41:27 +00:00
|
|
|
find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include)
|
2012-08-13 17:47:32 +00:00
|
|
|
endforeach()
|
2011-11-30 13:40:58 +00:00
|
|
|
|
2015-09-01 19:41:27 +00:00
|
|
|
# Allow ZLIB_LIBRARY to be set manually, as the location of the zlib library
|
|
|
|
if(NOT ZLIB_LIBRARY)
|
|
|
|
foreach(search ${_ZLIB_SEARCHES})
|
|
|
|
find_library(ZLIB_LIBRARY_RELEASE NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES lib)
|
|
|
|
find_library(ZLIB_LIBRARY_DEBUG NAMES ${ZLIB_NAMES_DEBUG} ${${search}} PATH_SUFFIXES lib)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
|
|
|
|
select_library_configurations(ZLIB)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
unset(ZLIB_NAMES)
|
|
|
|
unset(ZLIB_NAMES_DEBUG)
|
|
|
|
|
2016-06-21 12:56:56 +00:00
|
|
|
mark_as_advanced(ZLIB_INCLUDE_DIR)
|
2009-10-30 16:17:25 +00:00
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
|
|
|
|
file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
|
2010-07-31 05:24:47 +00:00
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
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}")
|
|
|
|
set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
|
2010-07-31 05:24:47 +00:00
|
|
|
|
2010-08-14 20:16:06 +00:00
|
|
|
# only append a TWEAK version if it exists:
|
2012-08-13 17:47:32 +00:00
|
|
|
set(ZLIB_VERSION_TWEAK "")
|
2014-04-11 16:17:46 +00:00
|
|
|
if( "${ZLIB_H}" MATCHES "ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+)")
|
2012-08-13 17:47:32 +00:00
|
|
|
set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
|
2016-07-27 22:41:13 +00:00
|
|
|
string(APPEND ZLIB_VERSION_STRING ".${ZLIB_VERSION_TWEAK}")
|
2012-08-13 17:50:14 +00:00
|
|
|
endif()
|
2010-07-31 05:24:47 +00:00
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
|
|
|
|
set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
|
|
|
|
set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
|
|
|
|
endif()
|
2010-04-11 08:29:20 +00:00
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
2011-04-07 16:22:24 +00:00
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR
|
2010-08-04 06:18:05 +00:00
|
|
|
VERSION_VAR ZLIB_VERSION_STRING)
|
2010-07-31 05:24:47 +00:00
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
if(ZLIB_FOUND)
|
|
|
|
set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
|
2015-09-01 19:41:27 +00:00
|
|
|
|
|
|
|
if(NOT ZLIB_LIBRARIES)
|
|
|
|
set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
|
|
|
|
endif()
|
2006-06-09 19:49:27 +00:00
|
|
|
|
2014-06-10 08:54:24 +00:00
|
|
|
if(NOT TARGET ZLIB::ZLIB)
|
|
|
|
add_library(ZLIB::ZLIB UNKNOWN IMPORTED)
|
|
|
|
set_target_properties(ZLIB::ZLIB PROPERTIES
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}")
|
2015-09-01 19:41:27 +00:00
|
|
|
|
|
|
|
if(ZLIB_LIBRARY_RELEASE)
|
|
|
|
set_property(TARGET ZLIB::ZLIB APPEND PROPERTY
|
|
|
|
IMPORTED_CONFIGURATIONS RELEASE)
|
|
|
|
set_target_properties(ZLIB::ZLIB PROPERTIES
|
|
|
|
IMPORTED_LOCATION_RELEASE "${ZLIB_LIBRARY_RELEASE}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(ZLIB_LIBRARY_DEBUG)
|
|
|
|
set_property(TARGET ZLIB::ZLIB APPEND PROPERTY
|
|
|
|
IMPORTED_CONFIGURATIONS DEBUG)
|
|
|
|
set_target_properties(ZLIB::ZLIB PROPERTIES
|
|
|
|
IMPORTED_LOCATION_DEBUG "${ZLIB_LIBRARY_DEBUG}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT ZLIB_LIBRARY_RELEASE AND NOT ZLIB_LIBRARY_DEBUG)
|
|
|
|
set_property(TARGET ZLIB::ZLIB APPEND PROPERTY
|
|
|
|
IMPORTED_LOCATION "${ZLIB_LIBRARY}")
|
|
|
|
endif()
|
2014-06-10 08:54:24 +00:00
|
|
|
endif()
|
|
|
|
endif()
|