Debian Codegraph @

cmake/modules/CheckLibTIFFPSDSupport.cmake

raw
1 # SPDX-FileCopyrightText: 2021 L. E. Segovia <[email protected]>
2 # SPDX-License-Identifier: BSD-3-Clause
3
4 # Test libtiff support for Photoshop TIFFs
5 #
6 # This module defines
7 # TIFF_HAS_PSD_TAGS -- if TIFFTAG_IMAGESOURCEDATA and TIFFTAG_PHOTOSHOP are defined in tiff.h
8 # TIFF_CAN_WRITE_PSD_TAGS -- if TIFFTAG_IMAGESOURCEDATA and TIFFTAG_PHOTOSHOP can be written by a call to TiffSetField
9
10 function(check_libtiff_psd_support varname_read_tags varname_write_tags)
11 include(CheckCXXSourceCompiles)
12 include(CheckCXXSourceRuns)
13
14 set(CMAKE_REQUIRED_LIBRARIES TIFF::TIFF)
15 if (APPLE)
16 set(CMAKE_REQUIRED_FLAGS "-rpath ${CMAKE_INSTALL_PREFIX}/lib")
17 endif()
18 check_cxx_source_compiles("
19 #include <cstdint>
20 #include <tiffio.h>
21 int main()
22 {
23 TIFF *img;
24 uint32_t length; uint8_t *data;
25 TIFFGetField(img, TIFFTAG_IMAGESOURCEDATA, &length, &data);
26 TIFFGetField(img, TIFFTAG_PHOTOSHOP, &length, &data);
27 }
28 " ${varname_read_tags})
29 check_cxx_source_runs("
30 #include <array>
31 #include <cstdint>
32 #include <tiff.h>
33 #include <tiffio.h>
34 int main() {
35 TIFF *img = TIFFOpen(\"test.tif\", \"w\");
36 TIFFCreateDirectory(img);
37 const std::array<uint8_t, 4> data = {0, 0, 0, 0};
38 if (!TIFFSetField(img, TIFFTAG_PHOTOSHOP,
39 static_cast<uint32_t>(data.size()), data.data())) {
40 TIFFClose(img);
41 return -1;
42 }
43 if (!TIFFSetField(img, TIFFTAG_IMAGESOURCEDATA,
44 static_cast<uint32_t>(data.size()), data.data())) {
45 TIFFClose(img);
46 return -1;
47 }
48 TIFFClose(img);
49 return 0;
50 }
51 " ${varname_write_tags})
52 endfunction(check_libtiff_psd_support)
53
54 find_package(TIFF REQUIRED QUIET)
55 if (TIFF_FOUND)
56 if (NOT DEFINED TIFF_HAS_PSD_TAGS OR NOT DEFINED TIFF_CAN_WRITE_PSD_TAGS)
57 check_libtiff_psd_support(TIFF_HAS_PSD_TAGS TIFF_CAN_WRITE_PSD_TAGS)
58 endif()
59 if (NOT TIFF_HAS_PSD_TAGS OR NOT TIFF_CAN_WRITE_PSD_TAGS)
60 message(WARNING "Your version of libtiff cannot read or write Photoshop TIFFs!")
61 endif (NOT TIFF_HAS_PSD_TAGS OR NOT TIFF_CAN_WRITE_PSD_TAGS)
62 endif(TIFF_FOUND)