FindJPEG.cmake
Go to the documentation of this file.
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 JPEG library (libjpeg)
9 
10 Imported targets
11 ^^^^^^^^^^^^^^^^
12 
13 This module defines the following :prop_tgt:`IMPORTED` targets:
14 
15 ``JPEG::JPEG``
16  The JPEG library, if found.
17 
18 Result variables
19 ^^^^^^^^^^^^^^^^
20 
21 This module will set the following variables in your project:
22 
23 ``JPEG_FOUND``
24  If false, do not try to use JPEG.
25 ``JPEG_INCLUDE_DIRS``
26  where to find jpeglib.h, etc.
27 ``JPEG_LIBRARIES``
28  the libraries needed to use JPEG.
29 ``JPEG_VERSION``
30  the version of the JPEG library found
31 
32 Cache variables
33 ^^^^^^^^^^^^^^^
34 
35 The following cache variables may also be set:
36 
37 ``JPEG_INCLUDE_DIRS``
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).
43 
44 Obsolete variables
45 ^^^^^^^^^^^^^^^^^^
46 
47 ``JPEG_INCLUDE_DIR``
48  where to find jpeglib.h, etc. (same as JPEG_INCLUDE_DIRS)
49 ``JPEG_LIBRARY``
50  where to find the JPEG library.
51 #]=======================================================================]
52 
53 find_path(JPEG_INCLUDE_DIR jpeglib.h)
54 
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")
58 endforeach()
59 
60 if(NOT JPEG_LIBRARY)
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)
66 endif()
67 unset(jpeg_names)
68 unset(jpeg_names_debug)
69 
70 if(JPEG_INCLUDE_DIR AND EXISTS "${JPEG_INCLUDE_DIR}/jpeglib.h")
71  file(GLOB _JPEG_CONFIG_HEADERS "${JPEG_INCLUDE_DIR}/jconfig*.h")
72  list(INSERT _JPEG_CONFIG_HEADERS 0
73  "${JPEG_INCLUDE_DIR}/jpeglib.h")
74  foreach (_JPEG_CONFIG_HEADER IN LISTS _JPEG_CONFIG_HEADERS)
75  file(STRINGS "${_JPEG_CONFIG_HEADER}"
76  jpeg_lib_version REGEX "^#define[\t ]+JPEG_LIB_VERSION[\t ]+.*")
77 
78  if (NOT jpeg_lib_version)
79  continue ()
80  endif ()
81 
82  string(REGEX REPLACE "^#define[\t ]+JPEG_LIB_VERSION[\t ]+([0-9]+).*"
83  "\\1" JPEG_VERSION "${jpeg_lib_version}")
84  break ()
85  endforeach ()
86  unset(jpeg_lib_version)
87  unset(_JPEG_CONFIG_HEADER)
88  unset(_JPEG_CONFIG_HEADERS)
89 endif()
90 
91 include(FindPackageHandleStandardArgs)
92 find_package_handle_standard_args(JPEG
93  REQUIRED_VARS JPEG_LIBRARY JPEG_INCLUDE_DIR
94  VERSION_VAR JPEG_VERSION)
95 
96 if(JPEG_FOUND)
97  set(JPEG_LIBRARIES ${JPEG_LIBRARY})
98  set(JPEG_INCLUDE_DIRS "${JPEG_INCLUDE_DIR}")
99 
100  if(NOT TARGET JPEG::JPEG)
101  add_library(JPEG::JPEG UNKNOWN IMPORTED)
102  if(JPEG_INCLUDE_DIRS)
103  set_target_properties(JPEG::JPEG PROPERTIES
104  INTERFACE_INCLUDE_DIRECTORIES "${JPEG_INCLUDE_DIRS}")
105  endif()
106  if(EXISTS "${JPEG_LIBRARY}")
107  set_target_properties(JPEG::JPEG PROPERTIES
108  IMPORTED_LINK_INTERFACE_LANGUAGES "C"
109  IMPORTED_LOCATION "${JPEG_LIBRARY}")
110  endif()
111  if(EXISTS "${JPEG_LIBRARY_RELEASE}")
112  set_property(TARGET JPEG::JPEG APPEND PROPERTY
113  IMPORTED_CONFIGURATIONS RELEASE)
114  set_target_properties(JPEG::JPEG PROPERTIES
115  IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
116  IMPORTED_LOCATION_RELEASE "${JPEG_LIBRARY_RELEASE}")
117  endif()
118  if(EXISTS "${JPEG_LIBRARY_DEBUG}")
119  set_property(TARGET JPEG::JPEG APPEND PROPERTY
120  IMPORTED_CONFIGURATIONS DEBUG)
121  set_target_properties(JPEG::JPEG PROPERTIES
122  IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
123  IMPORTED_LOCATION_DEBUG "${JPEG_LIBRARY_DEBUG}")
124  endif()
125  endif()
126 endif()
127 
128 mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR)
version
#define JPEG_LIB_VERSION
Definition: jconfig.h:4