1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
8 Find the Joint Photographic Experts Group (JPEG) library (``libjpeg``)
13 This module defines the following :prop_tgt:`IMPORTED` targets:
16 The JPEG library, if found.
21 This module will set the following variables in your project:
24 If false, do not try to use JPEG.
26 where to find jpeglib.h, etc.
28 the libraries needed to use JPEG.
30 the version of the JPEG library found
35 The following cache variables may also be set:
38 where to find jpeglib.h, etc.
39 ``JPEG_LIBRARY_RELEASE``
40 where to find the JPEG library (optimized).
41 ``JPEG_LIBRARY_DEBUG``
42 where to find the JPEG library (debug).
48 where to find jpeglib.h, etc. (same as JPEG_INCLUDE_DIRS)
50 where to find the JPEG library.
51 #]=======================================================================]
53 find_path(JPEG_INCLUDE_DIR jpeglib.h)
55 set(jpeg_names ${JPEG_NAMES} jpeg jpeg-static libjpeg libjpeg-static)
56 foreach(name ${jpeg_names})
57 list(APPEND jpeg_names_debug "${name}d")
61 find_library(JPEG_LIBRARY_RELEASE NAMES ${jpeg_names})
62 find_library(JPEG_LIBRARY_DEBUG NAMES ${jpeg_names_debug})
63 include(SelectLibraryConfigurations)
64 select_library_configurations(JPEG)
65 mark_as_advanced(JPEG_LIBRARY_RELEASE JPEG_LIBRARY_DEBUG)
68 unset(jpeg_names_debug)
71 file(GLOB _JPEG_CONFIG_HEADERS_FEDORA "${JPEG_INCLUDE_DIR}/jconfig*.h")
72 file(GLOB _JPEG_CONFIG_HEADERS_DEBIAN "${JPEG_INCLUDE_DIR}/*/jconfig.h")
73 set(_JPEG_CONFIG_HEADERS
74 "${JPEG_INCLUDE_DIR}/jpeglib.h"
75 ${_JPEG_CONFIG_HEADERS_FEDORA}
76 ${_JPEG_CONFIG_HEADERS_DEBIAN})
77 foreach (_JPEG_CONFIG_HEADER IN LISTS _JPEG_CONFIG_HEADERS)
78 if (NOT EXISTS "${_JPEG_CONFIG_HEADER}")
81 file(STRINGS "${_JPEG_CONFIG_HEADER}"
82 jpeg_lib_version REGEX "^#define[\t ]+JPEG_LIB_VERSION[\t ]+.*")
84 if (NOT jpeg_lib_version)
88 string(REGEX REPLACE "^#define[\t ]+JPEG_LIB_VERSION[\t ]+([0-9]+).*"
89 "\\1" JPEG_VERSION "${jpeg_lib_version}")
92 unset(jpeg_lib_version)
93 unset(_JPEG_CONFIG_HEADER)
94 unset(_JPEG_CONFIG_HEADERS)
95 unset(_JPEG_CONFIG_HEADERS_FEDORA)
96 unset(_JPEG_CONFIG_HEADERS_DEBIAN)
99 include(FindPackageHandleStandardArgs)
100 find_package_handle_standard_args(JPEG
101 REQUIRED_VARS JPEG_LIBRARY JPEG_INCLUDE_DIR
102 VERSION_VAR JPEG_VERSION)
105 set(JPEG_LIBRARIES ${JPEG_LIBRARY})
106 set(JPEG_INCLUDE_DIRS "${JPEG_INCLUDE_DIR}")
108 if(NOT TARGET JPEG::JPEG)
109 add_library(JPEG::JPEG UNKNOWN IMPORTED)
110 if(JPEG_INCLUDE_DIRS)
111 set_target_properties(JPEG::JPEG PROPERTIES
112 INTERFACE_INCLUDE_DIRECTORIES "${JPEG_INCLUDE_DIRS}")
114 if(EXISTS "${JPEG_LIBRARY}")
115 set_target_properties(JPEG::JPEG PROPERTIES
116 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
117 IMPORTED_LOCATION "${JPEG_LIBRARY}")
119 if(EXISTS "${JPEG_LIBRARY_RELEASE}")
120 set_property(TARGET JPEG::JPEG APPEND PROPERTY
121 IMPORTED_CONFIGURATIONS RELEASE)
122 set_target_properties(JPEG::JPEG PROPERTIES
123 IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
124 IMPORTED_LOCATION_RELEASE "${JPEG_LIBRARY_RELEASE}")
126 if(EXISTS "${JPEG_LIBRARY_DEBUG}")
127 set_property(TARGET JPEG::JPEG APPEND PROPERTY
128 IMPORTED_CONFIGURATIONS DEBUG)
129 set_target_properties(JPEG::JPEG PROPERTIES
130 IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
131 IMPORTED_LOCATION_DEBUG "${JPEG_LIBRARY_DEBUG}")
136 mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR)