Merge topic 'cpack-innosetup-linux'
[kiteware-cmake.git] / Modules / FindJPEG.cmake
blob08a0bd3146152c740e91cd0f7b80de9a08f2477c
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:
5 FindJPEG
6 --------
8 Find the Joint Photographic Experts Group (JPEG) library (``libjpeg``)
10 Imported targets
11 ^^^^^^^^^^^^^^^^
13 .. versionadded:: 3.12
15 This module defines the following :prop_tgt:`IMPORTED` targets:
17 ``JPEG::JPEG``
18   The JPEG library, if found.
20 Result variables
21 ^^^^^^^^^^^^^^^^
23 This module will set the following variables in your project:
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
35 Cache variables
36 ^^^^^^^^^^^^^^^
38 The following cache variables may also be set:
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).
47 .. versionadded:: 3.12
48   Debug and Release variand are found separately.
50 Obsolete variables
51 ^^^^^^^^^^^^^^^^^^
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 #]=======================================================================]
59 cmake_policy(PUSH)
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")
67 endforeach()
69 if(NOT JPEG_LIBRARY)
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)
75 endif()
76 unset(jpeg_names)
77 unset(jpeg_names_debug)
79 if(JPEG_INCLUDE_DIR)
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}")
88       continue ()
89     endif ()
90     file(STRINGS "${_JPEG_CONFIG_HEADER}"
91       jpeg_lib_version REGEX "^#define[\t ]+JPEG_LIB_VERSION[\t ]+.*")
93     if (NOT jpeg_lib_version)
94       continue ()
95     endif ()
97     string(REGEX REPLACE "^#define[\t ]+JPEG_LIB_VERSION[\t ]+([0-9]+).*"
98       "\\1" JPEG_VERSION "${jpeg_lib_version}")
99     break ()
100   endforeach ()
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)
106 endif()
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)
113 if(JPEG_FOUND)
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}")
122     endif()
123     if(EXISTS "${JPEG_LIBRARY}")
124       set_target_properties(JPEG::JPEG PROPERTIES
125         IMPORTED_LINK_INTERFACE_LANGUAGES "C"
126         IMPORTED_LOCATION "${JPEG_LIBRARY}")
127     endif()
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}")
134     endif()
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}")
141     endif()
142   endif()
143 endif()
145 mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR)
147 cmake_policy(POP)