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 .. versionadded:: 3.12
15 This module defines the following :prop_tgt:`IMPORTED` targets:
18 The JPEG library, if found.
23 This module will set the following variables in your project:
26 If false, do not try to use JPEG.
28 where to find jpeglib.h, etc.
30 the libraries needed to use JPEG.
32 .. versionadded:: 3.12
33 the version of the JPEG library found
38 The following cache variables may also be set:
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).
47 .. versionadded:: 3.12
48 Debug and Release variand are found separately.
54 where to find jpeglib.h, etc. (same as JPEG_INCLUDE_DIRS)
56 where to find the JPEG library.
57 #]=======================================================================]
60 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
62 find_path(JPEG_INCLUDE_DIR jpeglib.h)
64 set(jpeg_names ${JPEG_NAMES} jpeg jpeg-static libjpeg libjpeg-static)
65 foreach(name ${jpeg_names})
66 list(APPEND jpeg_names_debug "${name}d")
70 find_library(JPEG_LIBRARY_RELEASE NAMES ${jpeg_names} NAMES_PER_DIR)
71 find_library(JPEG_LIBRARY_DEBUG NAMES ${jpeg_names_debug} NAMES_PER_DIR)
72 include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
73 select_library_configurations(JPEG)
74 mark_as_advanced(JPEG_LIBRARY_RELEASE JPEG_LIBRARY_DEBUG)
77 unset(jpeg_names_debug)
80 file(GLOB _JPEG_CONFIG_HEADERS_FEDORA "${JPEG_INCLUDE_DIR}/jconfig*.h")
81 file(GLOB _JPEG_CONFIG_HEADERS_DEBIAN "${JPEG_INCLUDE_DIR}/*/jconfig.h")
82 set(_JPEG_CONFIG_HEADERS
83 "${JPEG_INCLUDE_DIR}/jpeglib.h"
84 ${_JPEG_CONFIG_HEADERS_FEDORA}
85 ${_JPEG_CONFIG_HEADERS_DEBIAN})
86 foreach (_JPEG_CONFIG_HEADER IN LISTS _JPEG_CONFIG_HEADERS)
87 if (NOT EXISTS "${_JPEG_CONFIG_HEADER}")
90 file(STRINGS "${_JPEG_CONFIG_HEADER}"
91 jpeg_lib_version REGEX "^#define[\t ]+JPEG_LIB_VERSION[\t ]+.*")
93 if (NOT jpeg_lib_version)
97 string(REGEX REPLACE "^#define[\t ]+JPEG_LIB_VERSION[\t ]+([0-9]+).*"
98 "\\1" JPEG_VERSION "${jpeg_lib_version}")
101 unset(jpeg_lib_version)
102 unset(_JPEG_CONFIG_HEADER)
103 unset(_JPEG_CONFIG_HEADERS)
104 unset(_JPEG_CONFIG_HEADERS_FEDORA)
105 unset(_JPEG_CONFIG_HEADERS_DEBIAN)
108 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
109 find_package_handle_standard_args(JPEG
110 REQUIRED_VARS JPEG_LIBRARY JPEG_INCLUDE_DIR
111 VERSION_VAR JPEG_VERSION)
114 set(JPEG_LIBRARIES ${JPEG_LIBRARY})
115 set(JPEG_INCLUDE_DIRS "${JPEG_INCLUDE_DIR}")
117 if(NOT TARGET JPEG::JPEG)
118 add_library(JPEG::JPEG UNKNOWN IMPORTED)
119 if(JPEG_INCLUDE_DIRS)
120 set_target_properties(JPEG::JPEG PROPERTIES
121 INTERFACE_INCLUDE_DIRECTORIES "${JPEG_INCLUDE_DIRS}")
123 if(EXISTS "${JPEG_LIBRARY}")
124 set_target_properties(JPEG::JPEG PROPERTIES
125 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
126 IMPORTED_LOCATION "${JPEG_LIBRARY}")
128 if(EXISTS "${JPEG_LIBRARY_RELEASE}")
129 set_property(TARGET JPEG::JPEG APPEND PROPERTY
130 IMPORTED_CONFIGURATIONS RELEASE)
131 set_target_properties(JPEG::JPEG PROPERTIES
132 IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
133 IMPORTED_LOCATION_RELEASE "${JPEG_LIBRARY_RELEASE}")
135 if(EXISTS "${JPEG_LIBRARY_DEBUG}")
136 set_property(TARGET JPEG::JPEG APPEND PROPERTY
137 IMPORTED_CONFIGURATIONS DEBUG)
138 set_target_properties(JPEG::JPEG PROPERTIES
139 IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
140 IMPORTED_LOCATION_DEBUG "${JPEG_LIBRARY_DEBUG}")
145 mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR)