Debian Codegraph @

cmake/modules/MacroJPEG.cmake

raw
1 # A macro wrapper to find JPEG library version
2 #
3 # Syntax: DETECT_JPEG()
4 # JPEG_LIB_VERSION is set to version ID depending of libjpeg version detected.
5 #
6 # SPDX-FileCopyrightText: 2010-2014 Gilles Caulier <caulier dot gilles at gmail dot com>
7 #
8 # SPDX-License-Identifier: BSD-3-Clause
9 #
10 # check version of libjpeg so that we can use the appropriate dir
11 # See bug #227313 for details
12
13 function(CompileToCheckVersion LibId Ret)
14
15 set(_jpeglib_version_source "
16 #include <stddef.h>
17 #include <stdio.h>
18 #include <jpeglib.h>
19 int main()
20 {
21 #if (JPEG_LIB_VERSION >= ${LibId})
22 #error JPEG_LIB_VERSION >= ${LibId}
23 #endif
24 }
25 ")
26
27 set(_jpeglib_version_source_file ${CMAKE_BINARY_DIR}/CMakeTmp/cmake_jpeglib_version_check.cpp)
28 file(WRITE "${_jpeglib_version_source_file}" "${_jpeglib_version_source}")
29 set(_jpeglib_version_include_dirs "-DINCLUDE_DIRECTORIES:STRING=${JPEG_INCLUDE_DIR}")
30
31 try_compile(_jpeglib_version_compile_result ${CMAKE_BINARY_DIR} ${_jpeglib_version_source_file}
32 CMAKE_FLAGS "${_jpeglib_version_include_dirs}"
33 COMPILE_OUTPUT_VARIABLE _jpeglib_version_compile_output_var)
34
35 set(${Ret} ${_jpeglib_version_compile_result} PARENT_SCOPE)
36
37 endfunction()
38
39 macro(DETECT_JPEG)
40
41 find_package(JPEG REQUIRED)
42
43 if(JPEG_FOUND)
44
45 CompileToCheckVersion(90 _CompileResult)
46
47 if(_CompileResult)
48
49 # Compile successfully. It's not libjpeg 90. We check previous version.
50
51 CompileToCheckVersion(80 _CompileResult)
52
53 if(_CompileResult)
54
55 # Compile successfully. It's not libjpeg 90. We check previous version.
56
57 CompileToCheckVersion(70 _CompileResult)
58
59 if(_CompileResult)
60
61 # Compile successfully. It's not libjpeg 70.
62 set(JPEG_LIB_VERSION 62)
63
64 else()
65
66 set(JPEG_LIB_VERSION 70)
67
68 endif()
69
70 else()
71
72 set(JPEG_LIB_VERSION 84)
73
74 endif()
75
76 else()
77
78 set(JPEG_LIB_VERSION 91)
79
80 endif()
81
82 message(STATUS "Libjpeg version: ${JPEG_LIB_VERSION}")
83
84 endif()
85
86 endmacro()