FindZLIB.cmake
Go to the documentation of this file.
1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3 
4 #[=======================================================================[.rst:
5 FindZLIB
6 --------
7 
8 Find the native ZLIB includes and library.
9 
10 IMPORTED Targets
11 ^^^^^^^^^^^^^^^^
12 
13 This module defines :prop_tgt:`IMPORTED` target ``ZLIB::ZLIB``, if
14 ZLIB has been found.
15 
16 Result Variables
17 ^^^^^^^^^^^^^^^^
18 
19 This module defines the following variables:
20 
21 ::
22 
23  ZLIB_INCLUDE_DIRS - where to find zlib.h, etc.
24  ZLIB_LIBRARIES - List of libraries when using zlib.
25  ZLIB_FOUND - True if zlib found.
26 
27 :: ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
28  ZLIB_VERSION_MAJOR - The major version of zlib
29  ZLIB_VERSION_MINOR - The minor version of zlib
30  ZLIB_VERSION_PATCH - The patch version of zlib
31  ZLIB_VERSION_TWEAK - The tweak version of zlib
32 
33 Backward Compatibility
34 ^^^^^^^^^^^^^^^^^^^^^^
35 
36 The following variable are provided for backward compatibility
37 
38 ::
39 
40  ZLIB_MAJOR_VERSION - The major version of zlib
41  ZLIB_MINOR_VERSION - The minor version of zlib
42  ZLIB_PATCH_VERSION - The patch version of zlib
43 
44 Hints
45 ^^^^^
46 
47 A user may set ``ZLIB_ROOT`` to a zlib installation root to tell this
48 module where to look.
49 #]=======================================================================]
50 
51 set(_ZLIB_SEARCHES)
52 
53 # Search ZLIB_ROOT first if it is set.
54 if(ZLIB_ROOT)
55  set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH)
56  list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT)
57 endif()
58 
59 # Normal search.
60 set(_ZLIB_x86 "(x86)")
61 set(_ZLIB_SEARCH_NORMAL
62  PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]"
63  "$ENV{ProgramFiles}/zlib"
64  "$ENV{ProgramFiles${_ZLIB_x86}}/zlib")
65 unset(_ZLIB_x86)
66 list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
67 
68 set(ZLIB_NAMES z zlib zdll zlib1)
69 set(ZLIB_NAMES_DEBUG zlibd zlibd1)
70 
71 # Try each search configuration.
72 foreach(search ${_ZLIB_SEARCHES})
73  find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include)
74 endforeach()
75 
76 # Allow ZLIB_LIBRARY to be set manually, as the location of the zlib library
77 if(NOT ZLIB_LIBRARY)
78  foreach(search ${_ZLIB_SEARCHES})
79  find_library(ZLIB_LIBRARY_RELEASE NAMES ${ZLIB_NAMES} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
80  find_library(ZLIB_LIBRARY_DEBUG NAMES ${ZLIB_NAMES_DEBUG} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
81  endforeach()
82 
83  include(SelectLibraryConfigurations)
84  select_library_configurations(ZLIB)
85 endif()
86 
87 unset(ZLIB_NAMES)
88 unset(ZLIB_NAMES_DEBUG)
89 
90 mark_as_advanced(ZLIB_INCLUDE_DIR)
91 
92 if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
93  file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
94 
95  string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
96  string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}")
97  string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
98  set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
99 
100  # only append a TWEAK version if it exists:
101  set(ZLIB_VERSION_TWEAK "")
102  if( "${ZLIB_H}" MATCHES "ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+)")
103  set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
104  string(APPEND ZLIB_VERSION_STRING ".${ZLIB_VERSION_TWEAK}")
105  endif()
106 
107  set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
108  set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
109  set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
110 endif()
111 
112 include(FindPackageHandleStandardArgs)
113 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR
114  VERSION_VAR ZLIB_VERSION_STRING)
115 
116 if(ZLIB_FOUND)
117  set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
118 
119  if(NOT ZLIB_LIBRARIES)
120  set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
121  endif()
122 
123  if(NOT TARGET ZLIB::ZLIB)
124  add_library(ZLIB::ZLIB UNKNOWN IMPORTED)
125  set_target_properties(ZLIB::ZLIB PROPERTIES
126  INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}")
127 
128  if(ZLIB_LIBRARY_RELEASE)
129  set_property(TARGET ZLIB::ZLIB APPEND PROPERTY
130  IMPORTED_CONFIGURATIONS RELEASE)
131  set_target_properties(ZLIB::ZLIB PROPERTIES
132  IMPORTED_LOCATION_RELEASE "${ZLIB_LIBRARY_RELEASE}")
133  endif()
134 
135  if(ZLIB_LIBRARY_DEBUG)
136  set_property(TARGET ZLIB::ZLIB APPEND PROPERTY
137  IMPORTED_CONFIGURATIONS DEBUG)
138  set_target_properties(ZLIB::ZLIB PROPERTIES
139  IMPORTED_LOCATION_DEBUG "${ZLIB_LIBRARY_DEBUG}")
140  endif()
141 
142  if(NOT ZLIB_LIBRARY_RELEASE AND NOT ZLIB_LIBRARY_DEBUG)
143  set_property(TARGET ZLIB::ZLIB APPEND PROPERTY
144  IMPORTED_LOCATION "${ZLIB_LIBRARY}")
145  endif()
146  endif()
147 endif()
148 
boost::graph_traits< vtkGraph *>::vertex_descriptor target(boost::graph_traits< vtkGraph *>::edge_descriptor e, vtkGraph *)
version
string