Debian Codegraph @

texk/xdvipsk/thirdparty/libtiff/cmake/FindJPEG.cmake

raw
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 FindJPEG
6 --------
7
8 Find the Joint Photographic Experts Group (JPEG) library (``libjpeg``)
9
10 Imported targets
11 ^^^^^^^^^^^^^^^^
12
13 .. versionadded:: 3.12
14
15 This module defines the following :prop_tgt:`IMPORTED` targets:
16
17 ``JPEG::JPEG``
18 The JPEG library, if found.
19
20 Result variables
21 ^^^^^^^^^^^^^^^^
22
23 This module will set the following variables in your project:
24
25 ``JPEG_FOUND``
26 If false, do not try to use JPEG.
27 ``JPEG_INCLUDE_DIRS``
28 where to find jpeglib.h, etc.
29 ``JPEG_LIBRARIES``
30 the libraries needed to use JPEG.
31 ``JPEG_VERSION``
32 .. versionadded:: 3.12
33 the version of the JPEG library found
34
35 Cache variables
36 ^^^^^^^^^^^^^^^
37
38 The following cache variables may also be set:
39
40 ``JPEG_INCLUDE_DIRS``
41 where to find jpeglib.h, etc.
42 ``JPEG_LIBRARY_RELEASE``
43 where to find the JPEG library (optimized).
44 ``JPEG_LIBRARY_DEBUG``
45 where to find the JPEG library (debug).
46
47 .. versionadded:: 3.12
48 Debug and Release variand are found separately.
49
50 Obsolete variables
51 ^^^^^^^^^^^^^^^^^^
52
53 ``JPEG_INCLUDE_DIR``
54 where to find jpeglib.h, etc. (same as JPEG_INCLUDE_DIRS)
55 ``JPEG_LIBRARY``
56 where to find the JPEG library.
57 #]=======================================================================]
58
59 find_path(JPEG_INCLUDE_DIR jpeglib.h)
60
61 set(jpeg_names ${JPEG_NAMES} jpeg jpeg-static libjpeg libjpeg-static turbojpeg turbojpeg-static)
62 foreach(name ${jpeg_names})
63 list(APPEND jpeg_names_debug "${name}d")
64 endforeach()
65
66 if(NOT JPEG_LIBRARY)
67 find_library(JPEG_LIBRARY_RELEASE NAMES ${jpeg_names} NAMES_PER_DIR)
68 find_library(JPEG_LIBRARY_DEBUG NAMES ${jpeg_names_debug} NAMES_PER_DIR)
69 include(SelectLibraryConfigurations)
70 select_library_configurations(JPEG)
71 mark_as_advanced(JPEG_LIBRARY_RELEASE JPEG_LIBRARY_DEBUG)
72 endif()
73 unset(jpeg_names)
74 unset(jpeg_names_debug)
75
76 if(JPEG_INCLUDE_DIR)
77 file(GLOB _JPEG_CONFIG_HEADERS_FEDORA "${JPEG_INCLUDE_DIR}/jconfig*.h")
78 file(GLOB _JPEG_CONFIG_HEADERS_DEBIAN "${JPEG_INCLUDE_DIR}/*/jconfig.h")
79 set(_JPEG_CONFIG_HEADERS
80 "${JPEG_INCLUDE_DIR}/jpeglib.h"
81 ${_JPEG_CONFIG_HEADERS_FEDORA}
82 ${_JPEG_CONFIG_HEADERS_DEBIAN})
83 foreach (_JPEG_CONFIG_HEADER IN LISTS _JPEG_CONFIG_HEADERS)
84 if (NOT EXISTS "${_JPEG_CONFIG_HEADER}")
85 continue ()
86 endif ()
87 file(STRINGS "${_JPEG_CONFIG_HEADER}"
88 jpeg_lib_version REGEX "^#define[\t ]+JPEG_LIB_VERSION[\t ]+.*")
89
90 if (NOT jpeg_lib_version)
91 continue ()
92 endif ()
93
94 string(REGEX REPLACE "^#define[\t ]+JPEG_LIB_VERSION[\t ]+([0-9]+).*"
95 "\\1" JPEG_VERSION "${jpeg_lib_version}")
96 break ()
97 endforeach ()
98 unset(jpeg_lib_version)
99 unset(_JPEG_CONFIG_HEADER)
100 unset(_JPEG_CONFIG_HEADERS)
101 unset(_JPEG_CONFIG_HEADERS_FEDORA)
102 unset(_JPEG_CONFIG_HEADERS_DEBIAN)
103 endif()
104
105 include(FindPackageHandleStandardArgs)
106 find_package_handle_standard_args(JPEG
107 REQUIRED_VARS JPEG_LIBRARY JPEG_INCLUDE_DIR
108 VERSION_VAR JPEG_VERSION)
109
110 if(JPEG_FOUND)
111 set(JPEG_LIBRARIES ${JPEG_LIBRARY})
112 set(JPEG_INCLUDE_DIRS "${JPEG_INCLUDE_DIR}")
113
114 if(NOT TARGET JPEG::JPEG)
115 add_library(JPEG::JPEG UNKNOWN IMPORTED)
116 if(JPEG_INCLUDE_DIRS)
117 set_target_properties(JPEG::JPEG PROPERTIES
118 INTERFACE_INCLUDE_DIRECTORIES "${JPEG_INCLUDE_DIRS}")
119 endif()
120 if(EXISTS "${JPEG_LIBRARY}")
121 set_target_properties(JPEG::JPEG PROPERTIES
122 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
123 IMPORTED_LOCATION "${JPEG_LIBRARY}")
124 endif()
125 if(EXISTS "${JPEG_LIBRARY_RELEASE}")
126 set_property(TARGET JPEG::JPEG APPEND PROPERTY
127 IMPORTED_CONFIGURATIONS RELEASE)
128 set_target_properties(JPEG::JPEG PROPERTIES
129 IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
130 IMPORTED_LOCATION_RELEASE "${JPEG_LIBRARY_RELEASE}")
131 endif()
132 if(EXISTS "${JPEG_LIBRARY_DEBUG}")
133 set_property(TARGET JPEG::JPEG APPEND PROPERTY
134 IMPORTED_CONFIGURATIONS DEBUG)
135 set_target_properties(JPEG::JPEG PROPERTIES
136 IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
137 IMPORTED_LOCATION_DEBUG "${JPEG_LIBRARY_DEBUG}")
138 endif()
139 endif()
140 endif()
141
142 mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR)