diff --git a/src/sail-codecs/tiff/tiff.cmake b/src/sail-codecs/tiff/tiff.cmake index 0b158ea0..0da1b2bf 100644 --- a/src/sail-codecs/tiff/tiff.cmake +++ b/src/sail-codecs/tiff/tiff.cmake @@ -41,70 +41,83 @@ macro(sail_codec_post_add) # Check if we can actually write defined compressions # - cmake_push_check_state(RESET) - set(CMAKE_REQUIRED_INCLUDES ${sail_tiff_include_dirs}) - set(CMAKE_REQUIRED_LIBRARIES ${sail_tiff_libs}) - - check_c_source_runs( - " - #include - #include - #include - - int main(int argc, char *argv[]) { - - TIFF *tiff = TIFFOpen(\"file.tiff\", \"w\"); - - if (tiff == NULL) { - return 1; - } - - TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, 1); - TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, 1); - TIFFSetField(tiff, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); - TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 4); - TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8); - TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); - TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); - TIFFSetField(tiff, TIFFTAG_COMPRESSION, COMPRESSION_${tiff_codec}); - TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tiff, (uint32)-1)); - - unsigned char *scan = malloc(4); - memset(scan, 255, 4); - - if (TIFFWriteScanline(tiff, scan, 0, 0) < 0) { - return 2; - } - - TIFFClose(tiff); - - free(scan); - - return 0; - } - " - SAIL_HAVE_TIFF_WRITE_${tiff_codec} - ) - cmake_pop_check_state() - - if (SAIL_HAVE_TIFF_WRITE_${tiff_codec}) - # Match the SAIL namings + if (SAIL_VCPKG) + # Hardcode compressions as check_c_source_runs() fails in VCPKG mode. + # It fails because it cannot find tiff.dll. # - string(REPLACE "_" "-" tiff_codec_fixed ${tiff_codec}) - string(REPLACE "CCITTRLE" "CCITT-RLE" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "CCITTRLEW" "CCITT-RLEW" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "IT8BL" "IT8-BL" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "IT8CTPAD" "IT8-CTPAD" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "IT8LW" "IT8-LW" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "IT8MP" "IT8-MP" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "JP2000" "JPEG2000" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "PIXARLOG" "PIXAR-LOG" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "PIXARFILM" "PIXAR-FILM" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "SGILOG24" "SGI-LOG24" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "SGILOG" "SGI-LOG" tiff_codec_fixed ${tiff_codec_fixed}) - list(APPEND CODEC_INFO_COMPRESSIONS ${tiff_codec_fixed}) - - target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_${tiff_codec}) + set(CODEC_INFO_COMPRESSIONS ADOBE-DEFLATE DEFLATE JPEG LZW NONE PACKBITS) + target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_ADOBE_DEFLATE) + target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_DEFLATE) + target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_JPEG) + target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_LZW) + target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_NONE) + target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_PACKBITS) + else() + cmake_push_check_state(RESET) + set(CMAKE_REQUIRED_INCLUDES ${sail_tiff_include_dirs}) + set(CMAKE_REQUIRED_LIBRARIES ${sail_tiff_libs}) + + check_c_source_runs( + " + #include + #include + #include + + int main(int argc, char *argv[]) { + + TIFF *tiff = TIFFOpen(\"file.tiff\", \"w\"); + + if (tiff == NULL) { + return 1; + } + + TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, 1); + TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, 1); + TIFFSetField(tiff, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); + TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 4); + TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8); + TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); + TIFFSetField(tiff, TIFFTAG_COMPRESSION, COMPRESSION_${tiff_codec}); + TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tiff, (uint32)-1)); + + unsigned char *scan = malloc(4); + memset(scan, 255, 4); + + if (TIFFWriteScanline(tiff, scan, 0, 0) < 0) { + return 2; + } + + TIFFClose(tiff); + + free(scan); + + return 0; + } + " + SAIL_HAVE_TIFF_WRITE_${tiff_codec} + ) + cmake_pop_check_state() + + if (SAIL_HAVE_TIFF_WRITE_${tiff_codec}) + # Match the SAIL namings + # + string(REPLACE "_" "-" tiff_codec_fixed ${tiff_codec}) + string(REPLACE "CCITTRLE" "CCITT-RLE" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "CCITTRLEW" "CCITT-RLEW" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "IT8BL" "IT8-BL" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "IT8CTPAD" "IT8-CTPAD" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "IT8LW" "IT8-LW" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "IT8MP" "IT8-MP" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "JP2000" "JPEG2000" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "PIXARLOG" "PIXAR-LOG" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "PIXARFILM" "PIXAR-FILM" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "SGILOG24" "SGI-LOG24" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "SGILOG" "SGI-LOG" tiff_codec_fixed ${tiff_codec_fixed}) + list(APPEND CODEC_INFO_COMPRESSIONS ${tiff_codec_fixed}) + + target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_${tiff_codec}) + endif() endif() endforeach()