Warning, /graphics/krita/cmake/modules/CheckLibTIFFPSDSupport.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
0002 # SPDX-License-Identifier: BSD-3-Clause
0003 
0004 # Test libtiff support for Photoshop TIFFs
0005 #
0006 # This module defines
0007 #   TIFF_HAS_PSD_TAGS -- if TIFFTAG_IMAGESOURCEDATA and TIFFTAG_PHOTOSHOP are defined in tiff.h
0008 #   TIFF_CAN_WRITE_PSD_TAGS -- if TIFFTAG_IMAGESOURCEDATA and TIFFTAG_PHOTOSHOP can be written by a call to TiffSetField
0009 
0010 function(check_libtiff_psd_support varname_read_tags varname_write_tags)
0011     include(CheckCXXSourceCompiles)
0012     include(CheckCXXSourceRuns)
0013 
0014     set(CMAKE_REQUIRED_LIBRARIES TIFF::TIFF)
0015     if (APPLE)
0016         set(CMAKE_REQUIRED_FLAGS "-rpath ${CMAKE_INSTALL_PREFIX}/lib")
0017     endif()
0018     check_cxx_source_compiles("
0019         #include <cstdint>
0020         #include <tiffio.h>
0021         int main()
0022         {
0023             TIFF *img;
0024             uint32_t length; uint8_t *data;
0025             TIFFGetField(img, TIFFTAG_IMAGESOURCEDATA, &length, &data);
0026             TIFFGetField(img, TIFFTAG_PHOTOSHOP, &length, &data);
0027         }
0028     " ${varname_read_tags})
0029     check_cxx_source_runs("
0030         #include <array>
0031         #include <cstdint>
0032         #include <tiff.h>
0033         #include <tiffio.h>
0034         int main() {
0035             TIFF *img = TIFFOpen(\"test.tif\", \"w\");
0036             TIFFCreateDirectory(img);
0037             const std::array<uint8_t, 4> data = {0, 0, 0, 0};
0038             if (!TIFFSetField(img, TIFFTAG_PHOTOSHOP,
0039                             static_cast<uint32_t>(data.size()), data.data())) {
0040                 TIFFClose(img);
0041                 return -1;
0042             }
0043             if (!TIFFSetField(img, TIFFTAG_IMAGESOURCEDATA,
0044                             static_cast<uint32_t>(data.size()), data.data())) {
0045                 TIFFClose(img);
0046                 return -1;
0047             }
0048             TIFFClose(img);
0049             return 0;
0050         }
0051     " ${varname_write_tags})
0052 endfunction(check_libtiff_psd_support)
0053 
0054 find_package(TIFF REQUIRED QUIET)
0055 if (TIFF_FOUND)
0056     if (NOT DEFINED TIFF_HAS_PSD_TAGS OR NOT DEFINED TIFF_CAN_WRITE_PSD_TAGS)
0057         check_libtiff_psd_support(TIFF_HAS_PSD_TAGS TIFF_CAN_WRITE_PSD_TAGS)
0058     endif()
0059     if (NOT TIFF_HAS_PSD_TAGS OR NOT TIFF_CAN_WRITE_PSD_TAGS)
0060         message(WARNING "Your version of libtiff cannot read or write Photoshop TIFFs!")
0061     endif (NOT TIFF_HAS_PSD_TAGS OR NOT TIFF_CAN_WRITE_PSD_TAGS)
0062 endif(TIFF_FOUND)