File: FindZLIB.cmake

package info (click to toggle)
gr-framework 0.73.22%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,476 kB
  • sloc: ansic: 87,950; cpp: 58,388; objc: 3,057; javascript: 2,647; python: 1,000; yacc: 855; pascal: 554; sh: 281; fortran: 228; makefile: 174
file content (72 lines) | stat: -rw-r--r-- 1,760 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#.rst:
# FindZLIB
# --------
#
# Find the Z compression library.
#
# Imported targets
# ^^^^^^^^^^^^^^^^
#
# This module defines the following :prop_tgt:`IMPORTED` target:
#
# ``ZLIB::ZLIB``
#   The Zlib library, if found.
#
# Result variables
# ^^^^^^^^^^^^^^^^
#
# This module will set the following variables in your project:
#
# ``ZLIB_INCLUDE_DIRS``
#   where to find zlib.h, etc.
# ``ZLIB_LIBRARIES``
#   the libraries to link against to use Zlib.
# ``ZLIB_FOUND``
#   If false, do not try to use Zlib.

if(NOT ZLIB_INCLUDE_DIR)
  find_path(ZLIB_INCLUDE_DIR zlib.h)
endif()

if(NOT ZLIB_LIBRARY)
  find_library(ZLIB_LIBRARY NAMES z zlib)
endif()

if(ZLIB_INCLUDE_DIR)
  if(NOT ZLIB_VERSION_STRING)
    file(READ ${ZLIB_INCLUDE_DIR}/zlib.h ZLIB_H_TEXT)
    string(REGEX REPLACE ".*#define ZLIB_VERSION \"([0-9]+.[0-9]+(.[0-9]+)?)\".*" "\\1" ZLIB_VERSION_STRING
                         ${ZLIB_H_TEXT}
    )
  endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
  ZLIB
  VERSION_VAR
  ZLIB_VERSION_STRING
  REQUIRED_VARS
  ZLIB_LIBRARY
  ZLIB_INCLUDE_DIR
  ZLIB_VERSION_STRING
)

if(ZLIB_FOUND)
  set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
  set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})

  if(NOT TARGET ZLIB::ZLIB)
    add_library(ZLIB::ZLIB UNKNOWN IMPORTED)
    set_target_properties(
      ZLIB::ZLIB
      PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}"
                 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
                 IMPORTED_LOCATION "${ZLIB_LIBRARY}"
    )
  endif()
elseif(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
  message(FATAL_ERROR "${CMAKE_FIND_PACKAGE_NAME} was required but could not be found.")
endif()

mark_as_advanced(ZLIB_INCLUDE_DIR ZLIB_LIBRARY ZLIB_H_TEXT ZLIB_VERSION_STRING)