1# CMake build for libtiff 2# 3# Copyright © 2015 Open Microscopy Environment / University of Dundee 4# Written by Roger Leigh <rleigh@codelibre.net> 5# 6# Permission to use, copy, modify, distribute, and sell this software and 7# its documentation for any purpose is hereby granted without fee, provided 8# that (i) the above copyright notices and this permission notice appear in 9# all copies of the software and related documentation, and (ii) the names of 10# Sam Leffler and Silicon Graphics may not be used in any advertising or 11# publicity relating to the software without the specific, prior written 12# permission of Sam Leffler and Silicon Graphics. 13# 14# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 15# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 16# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 17# 18# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR 19# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 20# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 21# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 22# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 23# OF THIS SOFTWARE. 24 25include_directories(${PROJECT_SOURCE_DIR}/libtiff 26 ${PROJECT_BINARY_DIR}/libtiff 27 ${CMAKE_CURRENT_BINARY_DIR} 28 ${TIFF_INCLUDES}) 29 30# Test scripts (not used by CMake) 31set(TESTSCRIPTS 32 bmp2tiff_palette.sh 33 bmp2tiff_rgb.sh 34 gif2tiff.sh 35 ppm2tiff_pbm.sh 36 ppm2tiff_pgm.sh 37 ppm2tiff_ppm.sh 38 tiffcp-g3.sh 39 tiffcp-g3-1d.sh 40 tiffcp-g3-1d-fill.sh 41 tiffcp-g3-2d.sh 42 tiffcp-g3-2d-fill.sh 43 tiffcp-g4.sh 44 tiffcp-logluv.sh 45 tiffcp-thumbnail.sh 46 tiffcp-lzw-compat.sh 47 tiffdump.sh 48 tiffinfo.sh 49 tiffcp-split.sh 50 tiffcp-split-join.sh 51 tiff2ps-PS1.sh 52 tiff2ps-PS2.sh 53 tiff2ps-PS3.sh 54 tiff2ps-EPS1.sh 55 tiff2pdf.sh 56 tiffcrop-doubleflip-logluv-3c-16b.sh 57 tiffcrop-doubleflip-minisblack-1c-16b.sh 58 tiffcrop-doubleflip-minisblack-1c-8b.sh 59 tiffcrop-doubleflip-minisblack-2c-8b-alpha.sh 60 tiffcrop-doubleflip-miniswhite-1c-1b.sh 61 tiffcrop-doubleflip-palette-1c-1b.sh 62 tiffcrop-doubleflip-palette-1c-4b.sh 63 tiffcrop-doubleflip-palette-1c-8b.sh 64 tiffcrop-doubleflip-rgb-3c-16b.sh 65 tiffcrop-doubleflip-rgb-3c-8b.sh 66 tiffcrop-extract-logluv-3c-16b.sh 67 tiffcrop-extract-minisblack-1c-16b.sh 68 tiffcrop-extract-minisblack-1c-8b.sh 69 tiffcrop-extract-minisblack-2c-8b-alpha.sh 70 tiffcrop-extract-miniswhite-1c-1b.sh 71 tiffcrop-extract-palette-1c-1b.sh 72 tiffcrop-extract-palette-1c-4b.sh 73 tiffcrop-extract-palette-1c-8b.sh 74 tiffcrop-extract-rgb-3c-16b.sh 75 tiffcrop-extract-rgb-3c-8b.sh 76 tiffcrop-extractz14-logluv-3c-16b.sh 77 tiffcrop-extractz14-minisblack-1c-16b.sh 78 tiffcrop-extractz14-minisblack-1c-8b.sh 79 tiffcrop-extractz14-minisblack-2c-8b-alpha.sh 80 tiffcrop-extractz14-miniswhite-1c-1b.sh 81 tiffcrop-extractz14-palette-1c-1b.sh 82 tiffcrop-extractz14-palette-1c-4b.sh 83 tiffcrop-extractz14-palette-1c-8b.sh 84 tiffcrop-extractz14-rgb-3c-16b.sh 85 tiffcrop-extractz14-rgb-3c-8b.sh 86 tiffcrop-R90-logluv-3c-16b.sh 87 tiffcrop-R90-minisblack-1c-16b.sh 88 tiffcrop-R90-minisblack-1c-8b.sh 89 tiffcrop-R90-minisblack-2c-8b-alpha.sh 90 tiffcrop-R90-miniswhite-1c-1b.sh 91 tiffcrop-R90-palette-1c-1b.sh 92 tiffcrop-R90-palette-1c-4b.sh 93 tiffcrop-R90-palette-1c-8b.sh 94 tiffcrop-R90-rgb-3c-16b.sh 95 tiffcrop-R90-rgb-3c-8b.sh 96 tiff2rgba-logluv-3c-16b.sh 97 tiff2rgba-minisblack-1c-16b.sh 98 tiff2rgba-minisblack-1c-8b.sh 99 tiff2rgba-minisblack-2c-8b-alpha.sh 100 tiff2rgba-miniswhite-1c-1b.sh 101 tiff2rgba-palette-1c-1b.sh 102 tiff2rgba-palette-1c-4b.sh 103 tiff2rgba-palette-1c-8b.sh 104 tiff2rgba-rgb-3c-16b.sh 105 tiff2rgba-rgb-3c-8b.sh 106 tiff2rgba-quad-tile.jpg.sh) 107 108# This list should contain all of the TIFF files in the 'images' 109# subdirectory which are intended to be used as input images for 110# tests. All of these files should use the extension ".tiff". 111set(TIFFIMAGES 112 images/logluv-3c-16b.tiff 113 images/minisblack-1c-16b.tiff 114 images/minisblack-1c-8b.tiff 115 images/minisblack-2c-8b-alpha.tiff 116 images/miniswhite-1c-1b.tiff 117 images/palette-1c-1b.tiff 118 images/palette-1c-4b.tiff 119 images/palette-1c-8b.tiff 120 images/rgb-3c-16b.tiff 121 images/rgb-3c-8b.tiff 122 images/quad-tile.jpg.tiff 123 images/quad-lzw-compat.tiff) 124 125set(BMPIMAGES 126 images/palette-1c-8b.bmp 127 images/rgb-3c-8b.bmp) 128 129set(GIFIMAGES 130 images/palette-1c-8b.gif) 131 132set(PNMIMAGES 133 images/minisblack-1c-8b.pgm 134 images/miniswhite-1c-1b.pbm 135 images/rgb-3c-8b.ppm) 136 137# All uncompressed image files 138set(UNCOMPRESSEDIMAGES 139 images/minisblack-1c-16b.tiff 140 images/minisblack-1c-8b.tiff 141 images/miniswhite-1c-1b.tiff 142 images/palette-1c-1b.tiff 143 images/palette-1c-4b.tiff 144 images/palette-1c-8b.tiff 145 images/rgb-3c-8b.tiff) 146 147# This list should include all of the files in the 'images' 148# subdirectory which are intended to be distributed. This may include 149# files which are not currently used by the tests. 150set(IMAGES_EXTRA_DIST 151 images/README.txt 152 ${BMPIMAGES} 153 ${GIFIMAGES} 154 ${PNMIMAGES} 155 ${TIFFIMAGES}) 156 157extra_dist( 158 ${TESTSCRIPTS} 159 ${IMAGES_EXTRA_DIST} 160 common.sh) 161 162set(noinst_HEADERS tifftest.h) 163 164add_executable(ascii_tag ascii_tag.c) 165target_link_libraries(ascii_tag tiff port) 166 167add_executable(long_tag long_tag.c check_tag.c) 168target_link_libraries(long_tag tiff port) 169 170add_executable(short_tag short_tag.c check_tag.c) 171target_link_libraries(short_tag tiff port) 172 173add_executable(strip_rw strip_rw.c strip.c test_arrays.c test_arrays.h) 174target_link_libraries(strip_rw tiff port) 175 176add_executable(rewrite rewrite_tag.c) 177target_link_libraries(rewrite tiff port) 178 179if(JPEG_SUPPORT) 180 add_executable(raw_decode raw_decode.c) 181 target_link_libraries(raw_decode tiff port) 182endif() 183 184add_executable(custom_dir custom_dir.c) 185target_link_libraries(custom_dir tiff port) 186 187set(TEST_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output") 188file(MAKE_DIRECTORY "${TEST_OUTPUT}") 189 190set(tiff_test_extra_args 191 "-DTIFFCP=$<TARGET_FILE:tiffcp>" 192 "-DTIFFINFO=$<TARGET_FILE:tiffinfo>" 193 "-DTIFFSPLIT=$<TARGET_FILE:tiffsplit>" 194 "-DLIBTIFF=$<TARGET_FILE:tiff>") 195if(WIN32) 196 list(APPEND tiff_test_extra_args "-DWIN32=${WIN32}") 197endif() 198if(CYGWIN) 199 list(APPEND tiff_test_extra_args "-DCYGWIN=${CYGWIN}") 200endif() 201 202macro(tiff_test_convert name command1 command2 command3 infile outfile validate) 203 add_test(NAME "${name}" 204 COMMAND "${CMAKE_COMMAND}" 205 "-DCONVERT_COMMAND1=${command1}" 206 "-DCONVERT_COMMAND2=${command2}" 207 "-DCONVERT_COMMAND3=${command3}" 208 "-DINFILE=${infile}" 209 "-DOUTFILE=${outfile}" 210 "-DVALIDATE=${validate}" 211 ${tiff_test_extra_args} 212 -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake") 213endmacro() 214 215macro(tiff_test_stdout name command infile outfile) 216 add_test(NAME "${name}" 217 COMMAND "${CMAKE_COMMAND}" 218 "-DSTDOUT_COMMAND=${command}" 219 "-DINFILE=${infile}" 220 "-DOUTFILE=${outfile}" 221 ${tiff_test_extra_args} 222 -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake") 223endmacro() 224 225macro(tiff_test_reader name command infile) 226 add_test(NAME "${name}" 227 COMMAND "${CMAKE_COMMAND}" 228 "-DREADER_COMMAND=${command}" 229 "-DINFILE=${infile}" 230 ${tiff_test_extra_args} 231 -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake") 232endmacro() 233 234macro(add_convert_test_multi commandname1 commandname2 commandname3 235 categoryname commandargs1 commandargs2 commandargs3 236 image validate) 237 string(REPLACE " " "^" escaped_commandargs1 "${commandargs1}") 238 string(REPLACE " " "^" escaped_commandargs2 "${commandargs2}") 239 string(REPLACE " " "^" escaped_commandargs3 "${commandargs3}") 240 get_filename_component(name "${image}" NAME) 241 get_filename_component(base "${image}" NAME_WE) 242 set(testname "${commandname1}-${categoryname}-${base}") 243 if(commandname1) 244 set(command1 245 "$<TARGET_FILE:${commandname1}>^${escaped_commandargs1}") 246 else() 247 set(command1) 248 endif() 249 if(commandname2) 250 set(command2 251 "$<TARGET_FILE:${commandname2}>^${escaped_commandargs2}") 252 else() 253 set(command2) 254 endif() 255 if(commandname3) 256 set(command3 257 "$<TARGET_FILE:${commandname3}>^${escaped_commandargs3}") 258 else() 259 set(command3) 260 endif() 261 set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${image}") 262 set(outfile "${TEST_OUTPUT}/${commandname1}-${categoryname}-${name}") 263 string(REGEX REPLACE "\\.tiff\$" "" name "${name}") 264 tiff_test_convert("${testname}" "${command1}" "${command2}" "${command3}" 265 "${infile}" "${outfile}" "${validate}") 266endmacro() 267 268macro(add_convert_test commandname 269 categoryname commandargs 270 image validate) 271 add_convert_test_multi("${commandname}" "" "" 272 "${categoryname}" "${commandargs}" "" "" 273 "${image}" "${validate}") 274endmacro() 275 276macro(add_convert_tests_multi commandname commandname2 commandname3 277 categoryname 278 commandargs1 commandargs2 commandargs3 279 images validate) 280 foreach(file ${${images}}) 281 add_convert_test_multi("${commandname1}" "${commandname2}" 282 "${commandname3}" "${categoryname}" 283 "${commandargs1}" "${commandargs2}" 284 "${commandargs3}" "${file}" "${validate}") 285 endforeach() 286endmacro() 287 288macro(add_convert_tests commandname categoryname commandargs images validate) 289 foreach(file ${${images}}) 290 add_convert_test("${commandname}" "${categoryname}" 291 "${commandargs}" "${file}" "${validate}") 292 endforeach() 293endmacro() 294 295macro(add_stdout_test commandname commandargs image) 296 string(REPLACE " " "^" escaped_commandargs "${commandargs}") 297 get_filename_component(name "${image}" NAME) 298 get_filename_component(base "${image}" NAME_WE) 299 set(testname "${commandname}-${base}") 300 set(command "$<TARGET_FILE:${commandname}>^${escaped_commandargs}") 301 set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${image}") 302 set(outfile "${TEST_OUTPUT}/${commandname}-${name}") 303 string(REGEX REPLACE "\\.tiff\$" "" name "${name}") 304 tiff_test_stdout("${testname}" "${command}" "${infile}" "${outfile}") 305endmacro() 306 307macro(add_reader_test commandname commandargs image) 308 string(REPLACE " " "^" escaped_commandargs "${commandargs}") 309 get_filename_component(name "${image}" NAME) 310 get_filename_component(base "${image}" NAME_WE) 311 set(testname "${commandname}-${base}") 312 set(command "$<TARGET_FILE:${commandname}>^${escaped_commandargs}") 313 set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${image}") 314 string(REGEX REPLACE "\\.tiff\$" "" name "${name}") 315 tiff_test_reader("${testname}" "${command}" "${infile}") 316endmacro() 317 318# BMP 319add_convert_test(bmp2tiff palette "" "images/palette-1c-8b.bmp" TRUE) 320add_convert_test(bmp2tiff rgb "" "images/rgb-3c-8b.bmp" TRUE) 321 322# GIF 323add_convert_test(gif2tiff palette "" "images/palette-1c-8b.gif" TRUE) 324 325# PPM 326add_convert_test(ppm2tiff miniswhite "" "images/miniswhite-1c-1b.pbm" TRUE) 327add_convert_test(ppm2tiff minisblack "" "images/minisblack-1c-8b.pgm" TRUE) 328add_convert_test(ppm2tiff rgb "" "images/rgb-3c-8b.ppm" TRUE) 329 330# tiffcp 331add_convert_test(tiffcp g3 "-c g3" "images/miniswhite-1c-1b.tiff" FALSE) 332add_convert_test(tiffcp g31d "-c g3:1d" "images/miniswhite-1c-1b.tiff" FALSE) 333add_convert_test(tiffcp g31dfill "-c g3:1d:fill" "images/miniswhite-1c-1b.tiff" FALSE) 334add_convert_test(tiffcp g32d "-c g3:2d" "images/miniswhite-1c-1b.tiff" FALSE) 335add_convert_test(tiffcp g32dfill "-c g3:2d:fill" "images/miniswhite-1c-1b.tiff" FALSE) 336add_convert_test(tiffcp g4 "-c g4" "images/miniswhite-1c-1b.tiff" FALSE) 337add_convert_test(tiffcp none "-c none" "images/quad-lzw-compat.tiff" FALSE) 338add_convert_test_multi(tiffcp tiffcp "" logluv "-c none" "-c sgilog" "" 339 "images/logluv-3c-16b.tiff" FALSE) 340add_convert_test_multi(tiffcp thumbnail "" thumbnail "g3:1d" "" "" 341 "images/miniswhite-1c-1b.tiff" FALSE) 342 343# tiffdump 344add_reader_test(tiffdump "" "images/miniswhite-1c-1b.tiff") 345 346# tiffinfo 347add_reader_test(tiffinfo "-c -D -d -j -s" "images/minisblack-1c-16b.tiff") 348 349# tiffcp split/join 350foreach(image ${UNCOMPRESSEDIMAGES}) 351 list(APPEND ESCAPED_UNCOMPRESSED "${CMAKE_CURRENT_SOURCE_DIR}/${image}") 352endforeach() 353string(REPLACE ";" "^" ESCAPED_UNCOMPRESSED "${ESCAPED_UNCOMPRESSED}") 354add_test(NAME "tiffcp-split" 355 COMMAND "${CMAKE_COMMAND}" 356 "-DTESTFILES=${ESCAPED_UNCOMPRESSED}" 357 "-DCONJOINED=${TEST_OUTPUT}/tiffcp-split-conjoined.tif" 358 "-DSPLITFILE=${TEST_OUTPUT}/tiffcp-split-split-" 359 ${tiff_test_extra_args} 360 -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffSplitTest.cmake") 361add_test(NAME "tiffcp-split-join" 362 COMMAND "${CMAKE_COMMAND}" 363 "-DTESTFILES=${ESCAPED_UNCOMPRESSED}" 364 "-DCONJOINED=${TEST_OUTPUT}/tiffcp-split-join-conjoined.tif" 365 "-DSPLITFILE=${TEST_OUTPUT}/tiffcp-split-join-split-" 366 "-DRECONJOINED=${TEST_OUTPUT}/tiffcp-split-join-reconjoined.tif" 367 ${tiff_test_extra_args} 368 -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffSplitTest.cmake") 369 370# PDF 371add_stdout_test(tiff2pdf "" "images/miniswhite-1c-1b.tiff" TRUE) 372 373# RGBA 374add_convert_tests(tiff2rgba default "" TIFFIMAGES TRUE) 375# Test rotations 376add_convert_tests(tiffcrop R90 "-R90" TIFFIMAGES TRUE) 377# Test flip (mirror) 378add_convert_tests(tiffcrop doubleflip "-F both" TIFFIMAGES TRUE) 379# Test extracting a section 60 pixels wide and 60 pixels high 380add_convert_tests(tiffcrop extract "-U px -E top -X 60 -Y 60" TIFFIMAGES TRUE) 381# Test extracting the first and fourth quarters from the left side. 382add_convert_tests(tiffcrop extractz14 "-E left -Z1:4,2:4" TIFFIMAGES TRUE) 383