Bump to 4.0.10
[platform/upstream/tiff.git] / CMakeLists.txt
1 # CMake build for libtiff
2 # Run "cmake" to generate the build files for your platform
3 #
4 # Copyright © 2015 Open Microscopy Environment / University of Dundee
5 # Written by Roger Leigh <rleigh@codelibre.net>
6 #
7 # Permission to use, copy, modify, distribute, and sell this software and
8 # its documentation for any purpose is hereby granted without fee, provided
9 # that (i) the above copyright notices and this permission notice appear in
10 # all copies of the software and related documentation, and (ii) the names of
11 # Sam Leffler and Silicon Graphics may not be used in any advertising or
12 # publicity relating to the software without the specific, prior written
13 # permission of Sam Leffler and Silicon Graphics.
14 #
15 # THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 # EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 # WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 #
19 # IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 # ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 # WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 # OF THIS SOFTWARE.
25
26 cmake_minimum_required(VERSION 2.8.11) # b/c of use of BUILD_INTERFACE generator expression
27
28 # Default policy is from 2.8.9
29 cmake_policy(VERSION 2.8.9)
30 # Set MacOSX @rpath usage globally.
31 if (POLICY CMP0020)
32   cmake_policy(SET CMP0020 NEW)
33 endif(POLICY CMP0020)
34 if (POLICY CMP0042)
35   cmake_policy(SET CMP0042 NEW)
36 endif(POLICY CMP0042)
37 # Use new variable expansion policy.
38 if (POLICY CMP0053)
39   cmake_policy(SET CMP0053 NEW)
40 endif(POLICY CMP0053)
41 if (POLICY CMP0054)
42   cmake_policy(SET CMP0054 NEW)
43 endif(POLICY CMP0054)
44
45 # Read version information from configure.ac.
46 FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" configure)
47 STRING(REGEX REPLACE ";" "\\\\;" configure "${configure}")
48 STRING(REGEX REPLACE "\n" ";" configure "${configure}")
49 foreach(line ${configure})
50   foreach(var LIBTIFF_MAJOR_VERSION LIBTIFF_MINOR_VERSION LIBTIFF_MICRO_VERSION LIBTIFF_ALPHA_VERSION
51           LIBTIFF_CURRENT LIBTIFF_REVISION LIBTIFF_AGE)
52     if(NOT ${var})
53       string(REGEX MATCH "^${var}=(.*)" ${var}_MATCH "${line}")
54       if(${var}_MATCH)
55         string(REGEX REPLACE "^${var}=(.*)" "\\1" ${var} "${line}")
56       endif()
57     endif()
58   endforeach()
59 endforeach()
60
61 math(EXPR SO_MAJOR "${LIBTIFF_CURRENT} - ${LIBTIFF_AGE}")
62 set(SO_MINOR "${LIBTIFF_AGE}")
63 set(SO_REVISION "${LIBTIFF_REVISION}")
64
65 message(STATUS "Building tiff version ${LIBTIFF_MAJOR_VERSION}.${LIBTIFF_MINOR_VERSION}.${LIBTIFF_MICRO_VERSION}${LIBTIFF_ALPHA_VERSION}")
66 message(STATUS "libtiff library version ${SO_MAJOR}.${SO_MINOR}.${SO_REVISION}")
67
68 set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
69
70 # Project version
71 project(tiff C)
72 set(VERSION "${LIBTIFF_MAJOR_VERSION}.${LIBTIFF_MINOR_VERSION}.${LIBTIFF_MICRO_VERSION}")
73 set(tiff_VERSION "${VERSION}")
74 set(tiff_VERSION_MAJOR "${LIBTIFF_MAJOR_VERSION}")
75 set(tiff_VERSION_MINOR "${LIBTIFF_MINOR_VERSION}")
76 set(tiff_VERSION_PATCH "${LIBTIFF_MICRO_VERSION}")
77
78 # the other tiff_VERSION_* variables are set automatically
79 set(tiff_VERSION_ALPHA "${LIBTIFF_ALPHA_VERSION}")
80 # Library version (unlike libtool's baroque scheme, WYSIWYG here)
81 set(SO_COMPATVERSION "${SO_MAJOR}")
82 set(SO_VERSION "${SO_MAJOR}.${SO_MINOR}.${SO_REVISION}")
83
84 # For autotools header compatibility
85 set(PACKAGE_NAME "LibTIFF Software")
86 set(PACKAGE_TARNAME "${PROJECT_NAME}")
87 set(PACKAGE_VERSION "${PROJECT_VERSION}${tiff_VERSION_ALPHA}")
88 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
89 set(PACKAGE_BUGREPORT "tiff@lists.maptools.org")
90
91 include(GNUInstallDirs)
92 include(CheckCCompilerFlag)
93 include(CheckCSourceCompiles)
94 include(CheckIncludeFile)
95 include(CheckLibraryExists)
96 include(CheckTypeSize)
97 include(CheckSymbolExists)
98 enable_testing()
99
100 macro(current_date var)
101   if(UNIX)
102     execute_process(COMMAND "date" +"%Y%m%d" OUTPUT_VARIABLE ${var})
103   endif()
104 endmacro()
105
106 current_date(RELEASE_DATE)
107
108 macro(extra_dist)
109   foreach(file ${ARGV})
110     file(RELATIVE_PATH relfile "${PROJECT_SOURCE_DIR}"
111          "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
112     list(APPEND EXTRA_DIST "${relfile}")
113   endforeach()
114   set(EXTRA_DIST "${EXTRA_DIST}" PARENT_SCOPE)
115 endmacro()
116
117 set(EXTRA_DIST
118   HOWTO-RELEASE
119   Makefile.vc
120   SConstruct
121   autogen.sh
122   configure.com
123   nmake.opt
124   libtiff-4.pc.in)
125
126 # These are annoyingly verbose, produce false positives or don't work
127 # nicely with all supported compiler versions, so are disabled unless
128 # explicitly enabled.
129 option(extra-warnings "Enable extra compiler warnings" OFF)
130
131 # This will cause the compiler to fail when an error occurs.
132 option(fatal-warnings "Compiler warnings are errors" OFF)
133
134 # Check if the compiler supports each of the following additional
135 # flags, and enable them if supported.  This greatly improves the
136 # quality of the build by checking for a number of common problems,
137 # some of which are quite serious.
138 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
139    CMAKE_C_COMPILER_ID MATCHES "Clang")
140   set(test_flags
141       -Wall
142       -Winline
143       -W
144       -Wformat-security
145       -Wpointer-arith
146       -Wdisabled-optimization
147       -Wno-unknown-pragmas
148       -Wdeclaration-after-statement
149       -fstrict-aliasing)
150   if(extra-warnings)
151     list(APPEND test_flags
152         -Wfloat-equal
153         -Wmissing-prototypes
154         -Wunreachable-code)
155   endif()
156   if(fatal-warnings)
157     list(APPEND test_flags
158          -Werror)
159   endif()
160 elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
161   set(test_flags)
162   if(extra-warnings)
163     list(APPEND test_flags
164          /W4)
165   else()
166     list(APPEND test_flags
167          /W3)
168   endif()
169   if (fatal-warnings)
170     list(APPEND test_flags
171          /WX)
172   endif()
173 endif()
174
175 foreach(flag ${test_flags})
176   string(REGEX REPLACE "[^A-Za-z0-9]" "_" flag_var "${flag}")
177   set(test_c_flag "C_FLAG${flag_var}")
178   CHECK_C_COMPILER_FLAG(${flag} "${test_c_flag}")
179   if (${test_c_flag})
180      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
181   endif (${test_c_flag})
182 endforeach(flag ${test_flags})
183
184 if(MSVC)
185     set(CMAKE_DEBUG_POSTFIX "d")
186 endif()
187
188 option(ld-version-script "Enable linker version script" ON)
189 # Check if LD supports linker scripts.
190 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map" "VERS_1 {
191         global: sym;
192 };
193
194 VERS_2 {
195         global: sym;
196 } VERS_1;
197 ")
198 set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
199 set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
200 check_c_source_compiles("int main(void){return 0;}" HAVE_LD_VERSION_SCRIPT)
201 set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
202 file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
203 if (ld-version-script AND HAVE_LD_VERSION_SCRIPT)
204   set(HAVE_LD_VERSION_SCRIPT TRUE)
205 else()
206   set(HAVE_LD_VERSION_SCRIPT FALSE)
207 endif()
208
209 # Find libm, if available
210 find_library(M_LIBRARY m)
211
212 check_include_file(assert.h    HAVE_ASSERT_H)
213 check_include_file(dlfcn.h     HAVE_DLFCN_H)
214 check_include_file(fcntl.h     HAVE_FCNTL_H)
215 check_include_file(inttypes.h  HAVE_INTTYPES_H)
216 check_include_file(io.h        HAVE_IO_H)
217 check_include_file(search.h    HAVE_SEARCH_H)
218 check_include_file(stdint.h    HAVE_STDINT_H)
219 check_include_file(string.h    HAVE_STRING_H)
220 check_include_file(strings.h   HAVE_STRINGS_H)
221 check_include_file(sys/time.h  HAVE_SYS_TIME_H)
222 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
223 check_include_file(unistd.h    HAVE_UNISTD_H)
224
225 # Inspired from /usr/share/autoconf/autoconf/c.m4
226 foreach(inline_keyword "inline" "__inline__" "__inline")
227   if(NOT DEFINED C_INLINE)
228     set(CMAKE_REQUIRED_DEFINITIONS_SAVE ${CMAKE_REQUIRED_DEFINITIONS})
229     set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
230         "-Dinline=${inline_keyword}")
231     check_c_source_compiles("
232         typedef int foo_t;
233         static inline foo_t static_foo() {return 0;}
234         foo_t foo(){return 0;}
235         int main(int argc, char *argv[]) {return 0;}"
236       C_HAS_${inline_keyword})
237     set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS_SAVE})
238     if(C_HAS_${inline_keyword})
239       set(C_INLINE TRUE)
240       set(INLINE_KEYWORD "${inline_keyword}")
241     endif()
242  endif()
243 endforeach()
244 if(NOT DEFINED C_INLINE)
245   set(INLINE_KEYWORD)
246 endif()
247
248 # off_t and size_t checks omitted; not clear they are used at all
249 # Are off_t and size_t checks strictly necessary?
250
251 # Check if sys/time.h and time.h allow use together
252 check_c_source_compiles("
253 #include <sys/time.h>
254 #include <time.h>
255 int main(void){return 0;}"
256   TIME_WITH_SYS_TIME)
257
258 # Check if struct tm is in sys/time.h
259 check_c_source_compiles("
260 #include <sys/types.h>
261 #include <time.h>
262
263 int main(void){
264   struct tm tm;
265   int *p = &tm.tm_sec;
266   return !p;
267 }"
268   TM_IN_SYS_TIME)
269
270 # Check type sizes
271 # NOTE: Could be replaced with C99 <stdint.h>
272 check_type_size("signed int" SIZEOF_SIGNED_INT)
273 check_type_size("unsigned int" SIZEOF_UNSIGNED_INT)
274 check_type_size("signed long" SIZEOF_SIGNED_LONG)
275 check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
276 check_type_size("signed long long" SIZEOF_SIGNED_LONG_LONG)
277 check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG)
278 check_type_size("unsigned char *" SIZEOF_UNSIGNED_CHAR_P)
279
280 set(CMAKE_EXTRA_INCLUDE_FILES_SAVE ${CMAKE_EXTRA_INCLUDE_FILES})
281 set(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES} "stddef.h")
282 check_type_size("size_t" SIZEOF_SIZE_T)
283 check_type_size("ptrdiff_t" SIZEOF_PTRDIFF_T)
284 set(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES_SAVE})
285
286 macro(report_values)
287   foreach(val ${ARGV})
288     message(STATUS "${val} set to ${${val}}")
289   endforeach()
290 endmacro()
291
292 set(TIFF_INT8_T "signed char")
293 set(TIFF_UINT8_T "unsigned char")
294
295 set(TIFF_INT16_T "signed short")
296 set(TIFF_UINT16_T "unsigned short")
297
298 if(SIZEOF_SIGNED_INT EQUAL 4)
299   set(TIFF_INT32_T "signed int")
300   set(TIFF_INT32_FORMAT "%d")
301 elseif(SIZEOF_SIGNED_LONG EQUAL 4)
302   set(TIFF_INT32_T "signed long")
303   set(TIFF_INT32_FORMAT "%ld")
304 endif()
305
306 if(SIZEOF_UNSIGNED_INT EQUAL 4)
307   set(TIFF_UINT32_T "unsigned int")
308   set(TIFF_UINT32_FORMAT "%u")
309 elseif(SIZEOF_UNSIGNED_LONG EQUAL 4)
310   set(TIFF_UINT32_T "unsigned long")
311   set(TIFF_UINT32_FORMAT "%lu")
312 endif()
313
314 if(SIZEOF_SIGNED_LONG EQUAL 8)
315   set(TIFF_INT64_T "signed long")
316   set(TIFF_INT64_FORMAT "%ld")
317 elseif(SIZEOF_SIGNED_LONG_LONG EQUAL 8)
318   set(TIFF_INT64_T "signed long long")
319   if (MINGW)
320     set(TIFF_INT64_FORMAT "%I64d")
321   else()
322     set(TIFF_INT64_FORMAT "%lld")
323   endif()
324 endif()
325
326 if(SIZEOF_UNSIGNED_LONG EQUAL 8)
327   set(TIFF_UINT64_T "unsigned long")
328   set(TIFF_UINT64_FORMAT "%lu")
329 elseif(SIZEOF_UNSIGNED_LONG_LONG EQUAL 8)
330   set(TIFF_UINT64_T "unsigned long long")
331   if (MINGW)
332     set(TIFF_UINT64_FORMAT "%I64u")
333   else()
334     set(TIFF_UINT64_FORMAT "%llu")
335   endif()
336 endif()
337
338 if(SIZEOF_UNSIGNED_INT EQUAL SIZEOF_SIZE_T)
339   set(TIFF_SIZE_T "unsigned int")
340   set(TIFF_SIZE_FORMAT "%u")
341 elseif(SIZEOF_UNSIGNED_LONG EQUAL SIZEOF_SIZE_T)
342   set(TIFF_SIZE_T "unsigned long")
343   set(TIFF_SIZE_FORMAT "%lu")
344 elseif(SIZEOF_UNSIGNED_LONG_LONG EQUAL SIZEOF_SIZE_T)
345   set(TIFF_SIZE_T "unsigned long")
346   if (MINGW)
347     set(TIFF_SIZE_FORMAT "%I64u")
348   else()
349     set(TIFF_SIZE_FORMAT "%llu")
350   endif()
351 endif()
352
353 if(SIZEOF_SIGNED_INT EQUAL SIZEOF_UNSIGNED_CHAR_P)
354   set(TIFF_SSIZE_T "signed int")
355   set(TIFF_SSIZE_FORMAT "%d")
356 elseif(SIZEOF_SIGNED_LONG EQUAL SIZEOF_UNSIGNED_CHAR_P)
357   set(TIFF_SSIZE_T "signed long")
358   set(TIFF_SSIZE_FORMAT "%ld")
359 elseif(SIZEOF_SIGNED_LONG_LONG EQUAL SIZEOF_UNSIGNED_CHAR_P)
360   set(TIFF_SSIZE_T "signed long long")
361   if (MINGW)
362     set(TIFF_SSIZE_FORMAT "%I64d")
363   else()
364     set(TIFF_SSIZE_FORMAT "%lld")
365   endif()
366 endif()
367
368 if(NOT SIZEOF_PTRDIFF_T)
369   set(TIFF_PTRDIFF_T "${TIFF_SSIZE_T}")
370   set(TIFF_PTRDIFF_FORMAT "${SSIZE_FORMAT}")
371 else()
372   set(TIFF_PTRDIFF_T "ptrdiff_t")
373   set(TIFF_PTRDIFF_FORMAT "%ld")
374 endif()
375
376 #report_values(TIFF_INT8_T TIFF_INT8_FORMAT
377 #              TIFF_UINT8_T TIFF_UINT8_FORMAT
378 #              TIFF_INT16_T TIFF_INT16_FORMAT
379 #              TIFF_UINT16_T TIFF_UINT16_FORMAT
380 #              TIFF_INT32_T TIFF_INT32_FORMAT
381 #              TIFF_UINT32_T TIFF_UINT32_FORMAT
382 #              TIFF_INT64_T TIFF_INT64_FORMAT
383 #              TIFF_UINT64_T TIFF_UINT64_FORMAT
384 #              TIFF_SSIZE_T TIFF_SSIZE_FORMAT
385 #              TIFF_PTRDIFF_T TIFF_PTRDIFF_FORMAT)
386
387 check_symbol_exists(mmap "sys/mman.h" HAVE_MMAP)
388 check_symbol_exists(setmode "unistd.h" HAVE_SETMODE)
389 check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
390 check_symbol_exists(strcasecmp "strings.h" HAVE_STRCASECMP)
391 check_symbol_exists(strtol "stdlib.h" HAVE_STRTOL)
392 check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL)
393 check_symbol_exists(strtoul "stdlib.h" HAVE_STRTOUL)
394 check_symbol_exists(strtoull "stdlib.h" HAVE_STRTOULL)
395 check_symbol_exists(getopt "unistd.h" HAVE_GETOPT)
396 check_symbol_exists(lfind "search.h" HAVE_LFIND)
397
398 if(NOT HAVE_SNPRINTF)
399   add_definitions(-DNEED_LIBPORT)
400 endif()
401
402 # CPU bit order
403 set(HOST_FILLORDER FILLORDER_MSB2LSB)
404 if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i.*86.*" OR
405    CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*" OR
406    CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64.*")
407   set(HOST_FILLORDER FILLORDER_LSB2MSB)
408 endif()
409
410 # CPU endianness
411 include(TestBigEndian)
412 test_big_endian(HOST_BIG_ENDIAN)
413
414 # IEEE floating point
415 set(HAVE_IEEEFP 1)
416
417 report_values(CMAKE_HOST_SYSTEM_PROCESSOR HOST_FILLORDER
418               HOST_BIG_ENDIAN HAVE_IEEEFP)
419
420 # Large file support
421 if (UNIX OR MINGW)
422   # This might not catch every possibility catered for by
423   # AC_SYS_LARGEFILE.
424   add_definitions(-D_FILE_OFFSET_BITS=64)
425   set(FILE_OFFSET_BITS 64)
426 endif()
427
428 # Documentation install directory (default to cmake project docdir)
429 set(LIBTIFF_DOCDIR "${CMAKE_INSTALL_FULL_DOCDIR}")
430
431 # Options to enable and disable internal codecs
432
433 option(ccitt "support for CCITT Group 3 & 4 algorithms" ON)
434 set(CCITT_SUPPORT ${ccitt})
435
436 option(packbits "support for Macintosh PackBits algorithm" ON)
437 set(PACKBITS_SUPPORT ${packbits})
438
439 option(lzw "support for LZW algorithm" ON)
440 set(LZW_SUPPORT ${lzw})
441
442 option(thunder "support for ThunderScan 4-bit RLE algorithm" ON)
443 set(THUNDER_SUPPORT ${thunder})
444
445 option(next "support for NeXT 2-bit RLE algorithm" ON)
446 set(NEXT_SUPPORT ${next})
447
448 option(logluv "support for LogLuv high dynamic range algorithm" ON)
449 set(LOGLUV_SUPPORT ${logluv})
450
451 # Option for Microsoft Document Imaging
452 option(mdi "support for Microsoft Document Imaging" ON)
453 set(MDI_SUPPORT ${mdi})
454
455 # ZLIB
456 option(zlib "use zlib (required for Deflate compression)" ON)
457 if (zlib)
458   find_package(ZLIB)
459 endif()
460 set(ZLIB_SUPPORT 0)
461 if(ZLIB_FOUND)
462   set(ZLIB_SUPPORT 1)
463 endif()
464 set(ZIP_SUPPORT ${ZLIB_SUPPORT})
465 # Option for Pixar log-format algorithm
466
467 # Pixar log format
468 option(pixarlog "support for Pixar log-format algorithm (requires Zlib)" ON)
469 set(PIXARLOG_SUPPORT FALSE)
470 if (ZLIB_SUPPORT)
471   if(pixarlog)
472     set(PIXARLOG_SUPPORT TRUE)
473   endif()
474 endif()
475
476 # JPEG
477 option(jpeg "use libjpeg (required for JPEG compression)" ON)
478 if (jpeg)
479   find_package(JPEG)
480 endif()
481 set(JPEG_SUPPORT FALSE)
482 if(JPEG_FOUND)
483   set(JPEG_SUPPORT TRUE)
484 endif()
485
486 option(old-jpeg "support for Old JPEG compression (read-only)" ON)
487 set(OJPEG_SUPPORT FALSE)
488 if (JPEG_SUPPORT)
489   if (old-jpeg)
490     set(OJPEG_SUPPORT TRUE)
491   endif()
492 endif()
493
494 # JBIG-KIT
495 option(jbig "use ISO JBIG compression (requires JBIT-KIT library)" ON)
496 if (jbig)
497   set(JBIG_FOUND 0)
498   find_path(JBIG_INCLUDE_DIR jbig.h)
499   set(JBIG_NAMES ${JBIG_NAMES} jbig libjbig)
500   find_library(JBIG_LIBRARY NAMES ${JBIG_NAMES})
501   if (JBIG_INCLUDE_DIR AND JBIG_LIBRARY)
502     set(JBIG_FOUND 1)
503     set(JBIG_LIBRARIES ${JBIG_LIBRARY})
504   endif()
505 endif()
506 set(JBIG_SUPPORT 0)
507 if(JBIG_FOUND)
508   set(JBIG_FOUND TRUE)
509   set(JBIG_SUPPORT 1)
510 else()
511   set(JBIG_FOUND FALSE)
512 endif()
513
514 set(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES})
515 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${JBIG_INCLUDE_DIR})
516 check_symbol_exists(jbg_newlen "jbig.h" HAVE_JBG_NEWLEN)
517 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE})
518
519 # liblzma2
520 option(lzma "use liblzma (required for LZMA2 compression)" ON)
521 if (lzma)
522   find_package(LibLZMA)
523 endif()
524 set(LZMA_SUPPORT 0)
525 if(LIBLZMA_FOUND)
526   set(LZMA_SUPPORT 1)
527 endif()
528
529 # libzstd
530 option(zstd "use libzstd (required for ZSTD compression)" ON)
531 if (zstd)
532     find_path(ZSTD_INCLUDE_DIR zstd.h)
533     find_library(ZSTD_LIBRARY NAMES zstd)
534     if (ZSTD_INCLUDE_DIR AND ZSTD_LIBRARY)
535         check_library_exists ("${ZSTD_LIBRARY}" ZSTD_decompressStream "" ZSTD_RECENT_ENOUGH)
536         if (ZSTD_RECENT_ENOUGH)
537             set(ZSTD_FOUND TRUE)
538             set(ZSTD_LIBRARIES ${ZSTD_LIBRARY})
539             message(STATUS "Found ZSTD library: ${ZSTD_LIBRARY}")
540         else ()
541             message(WARNING "Found ZSTD library, but not recent enough. Use zstd >= 1.0")
542         endif ()
543     endif ()
544 endif()
545 set(ZSTD_SUPPORT 0)
546 if(ZSTD_FOUND)
547   set(ZSTD_SUPPORT 1)
548 endif()
549
550 # libwebp
551 option(webp "use libwebp (required for WEBP compression)" ON)
552 if (webp)
553     find_path(WEBP_INCLUDE_DIR /webp/decode.h)
554     find_library(WEBP_LIBRARY NAMES webp)
555 endif()
556 set(WEBP_SUPPORT 0)
557 set(WEBP_FOUND FALSE)
558 if (WEBP_INCLUDE_DIR AND WEBP_LIBRARY)
559   set(WEBP_SUPPORT 1)
560   set(WEBP_FOUND TRUE)
561   set(WEBP_LIBRARIES ${WEBP_LIBRARY})
562   message(STATUS "Found WEBP library: ${WEBP_LIBRARY}")
563 endif()
564
565 # 8/12-bit jpeg mode
566 option(jpeg12 "enable libjpeg 8/12-bit dual mode (requires separate
567 12-bit libjpeg build)" ON)
568 set(JPEG12_INCLUDE_DIR JPEG12_INCLUDE_DIR-NOTFOUND CACHE PATH "Include directory for 12-bit libjpeg")
569 set(JPEG12_LIBRARY JPEG12_LIBRARY-NOTFOUND CACHE FILEPATH "12-bit libjpeg library")
570 set(JPEG12_FOUND FALSE)
571 if (JPEG12_INCLUDE_DIR AND JPEG12_LIBRARY)
572   set(JPEG12_LIBRARIES ${JPEG12_LIBRARY})
573   set(JPEG12_FOUND TRUE)
574 endif()
575 if (JPEG12_FOUND)
576   set(JPEG_DUAL_MODE_8_12 1)
577   set(LIBJPEG_12_PATH "${JPEG12_INCLUDE_DIR}/jpeglib.h")
578 endif()
579
580 # C++ support
581 option(cxx "Enable C++ stream API building (requires C++ compiler)" ON)
582 set(CXX_SUPPORT FALSE)
583 if (cxx)
584   enable_language(CXX)
585   set(CXX_SUPPORT TRUE)
586 endif()
587
588 # OpenGL and GLUT
589 find_package(OpenGL)
590 find_package(GLUT)
591 set(HAVE_OPENGL FALSE)
592 if(OPENGL_FOUND AND OPENGL_GLU_FOUND AND GLUT_FOUND)
593   set(HAVE_OPENGL TRUE)
594 endif()
595 # Purely to satisfy the generated headers:
596 check_include_file(GL/gl.h HAVE_GL_GL_H)
597 check_include_file(GL/glu.h HAVE_GL_GLU_H)
598 check_include_file(GL/glut.h HAVE_GL_GLUT_H)
599 check_include_file(GLUT/glut.h HAVE_GLUT_GLUT_H)
600 check_include_file(OpenGL/gl.h HAVE_OPENGL_GL_H)
601 check_include_file(OpenGL/glu.h HAVE_OPENGL_GLU_H)
602
603 # Win32 IO
604 set(win32_io FALSE)
605 if(WIN32)
606   set(win32_io TRUE)
607 endif()
608
609 set(USE_WIN32_FILEIO ${win32_io})
610
611 # Orthogonal features
612
613 # Strip chopping
614 option(strip-chopping "strip chopping (whether or not to convert single-strip uncompressed images to mutiple strips of specified size to reduce memory usage)" ON)
615 set(TIFF_DEFAULT_STRIP_SIZE 8192 CACHE STRING "default size of the strip in bytes (when strip chopping is enabled)")
616
617 set(STRIPCHOP_DEFAULT)
618 if(strip-chopping)
619   set(STRIPCHOP_DEFAULT TRUE)
620   if(TIFF_DEFAULT_STRIP_SIZE)
621     set(STRIP_SIZE_DEFAULT "${TIFF_DEFAULT_STRIP_SIZE}")
622   endif()
623 endif()
624
625 # Defer loading of strip/tile offsets
626 option(defer-strile-load "enable deferred strip/tile offset/size loading (experimental)" OFF)
627 set(DEFER_STRILE_LOAD ${defer-strile-load})
628
629 # CHUNKY_STRIP_READ_SUPPORT
630 option(chunky-strip-read "enable reading large strips in chunks for TIFFReadScanline() (experimental)" OFF)
631 set(CHUNKY_STRIP_READ_SUPPORT ${chunky-strip-read})
632
633 # SUBIFD support
634 set(SUBIFD_SUPPORT 1)
635
636 # Default handling of ASSOCALPHA support.
637 option(extrasample-as-alpha "the RGBA interface will treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many packages produce RGBA files but don't mark the alpha properly" ON)
638 if(extrasample-as-alpha)
639   set(DEFAULT_EXTRASAMPLE_AS_ALPHA 1)
640 endif()
641
642 # Default handling of YCbCr subsampling support.
643 # See Bug 168 in Bugzilla, and JPEGFixupTestSubsampling() for details.
644 option(check-ycbcr-subsampling "enable picking up YCbCr subsampling info from the JPEG data stream to support files lacking the tag" ON)
645 if (check-ycbcr-subsampling)
646   set(CHECK_JPEG_YCBCR_SUBSAMPLING 1)
647 endif()
648
649 # Generate pkg-config file
650 set(prefix "${CMAKE_INSTALL_PREFIX}")
651 set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
652 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
653 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
654 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libtiff-4.pc.in
655                ${CMAKE_CURRENT_BINARY_DIR}/libtiff-4.pc)
656 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtiff-4.pc
657         DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
658
659 # Includes used by libtiff (and tests)
660 if(ZLIB_INCLUDE_DIRS)
661   list(APPEND TIFF_INCLUDES ${ZLIB_INCLUDE_DIRS})
662 endif()
663 if(JPEG_INCLUDE_DIR)
664   list(APPEND TIFF_INCLUDES ${JPEG_INCLUDE_DIR})
665 endif()
666 if(JPEG12_INCLUDE_DIR)
667   list(APPEND TIFF_INCLUDES ${JPEG12_INCLUDE_DIR})
668 endif()
669 if(JBIG_INCLUDE_DIR)
670   list(APPEND TIFF_INCLUDES ${JBIG_INCLUDE_DIR})
671 endif()
672 if(LIBLZMA_INCLUDE_DIRS)
673   list(APPEND TIFF_INCLUDES ${LIBLZMA_INCLUDE_DIRS})
674 endif()
675 if(ZSTD_INCLUDE_DIR)
676   list(APPEND TIFF_INCLUDES ${ZSTD_INCLUDE_DIR})
677 endif()
678 if(WEBP_INCLUDE_DIR)
679   list(APPEND TIFF_INCLUDES ${WEBP_INCLUDE_DIR})
680 endif()
681
682 # Libraries required by libtiff
683 set(TIFF_LIBRARY_DEPS)
684 if(M_LIBRARY)
685   list(APPEND TIFF_LIBRARY_DEPS ${M_LIBRARY})
686 endif()
687 if(ZLIB_LIBRARIES)
688   list(APPEND TIFF_LIBRARY_DEPS ${ZLIB_LIBRARIES})
689 endif()
690 if(JPEG_LIBRARIES)
691   list(APPEND TIFF_LIBRARY_DEPS ${JPEG_LIBRARIES})
692 endif()
693 if(JPEG12_LIBRARIES)
694   list(APPEND TIFF_LIBRARY_DEPS ${JPEG12_LIBRARIES})
695 endif()
696 if(JBIG_LIBRARIES)
697   list(APPEND TIFF_LIBRARY_DEPS ${JBIG_LIBRARIES})
698 endif()
699 if(LIBLZMA_LIBRARIES)
700   list(APPEND TIFF_LIBRARY_DEPS ${LIBLZMA_LIBRARIES})
701 endif()
702 if(ZSTD_LIBRARIES)
703   list(APPEND TIFF_LIBRARY_DEPS ${ZSTD_LIBRARIES})
704 endif()
705 if(WEBP_LIBRARIES)
706   list(APPEND TIFF_LIBRARY_DEPS ${WEBP_LIBRARIES})
707 endif()
708
709 #report_values(TIFF_INCLUDES TIFF_LIBRARY_DEPS)
710
711 # Process subdirectories
712 add_subdirectory(port)
713 add_subdirectory(libtiff)
714 add_subdirectory(tools)
715 add_subdirectory(test)
716 add_subdirectory(contrib)
717 add_subdirectory(build)
718 add_subdirectory(man)
719 add_subdirectory(html)
720
721 #message(STATUS "EXTRA_DIST: ${EXTRA_DIST}")
722
723 message(STATUS "")
724 message(STATUS "Libtiff is now configured for ${host}")
725 message(STATUS "")
726 message(STATUS "  Installation directory:             ${prefix}")
727 message(STATUS "  Documentation directory:            ${LIBTIFF_DOCDIR}")
728 message(STATUS "  C compiler:                         ${CMAKE_C_COMPILER}")
729 message(STATUS "  C++ compiler:                       ${CMAKE_CXX_COMPILER}")
730 message(STATUS "  Build shared libraries:             ${BUILD_SHARED_LIBS}")
731 message(STATUS "  Enable linker symbol versioning:    ${HAVE_LD_VERSION_SCRIPT}")
732 message(STATUS "  Support Microsoft Document Imaging: ${mdi}")
733 message(STATUS "  Use win32 IO:                       ${USE_WIN32_FILEIO}")
734 message(STATUS "")
735 message(STATUS " Support for internal codecs:")
736 message(STATUS "  CCITT Group 3 & 4 algorithms:       ${ccitt}")
737 message(STATUS "  Macintosh PackBits algorithm:       ${packbits}")
738 message(STATUS "  LZW algorithm:                      ${lzw}")
739 message(STATUS "  ThunderScan 4-bit RLE algorithm:    ${thunder}")
740 message(STATUS "  NeXT 2-bit RLE algorithm:           ${next}")
741 message(STATUS "  LogLuv high dynamic range encoding: ${logluv}")
742 message(STATUS "")
743 message(STATUS " Support for external codecs:")
744 message(STATUS "  ZLIB support:                       ${zlib} (requested) ${ZLIB_FOUND} (availability)")
745 message(STATUS "  Pixar log-format algorithm:         ${pixarlog} (requested) ${PIXARLOG_SUPPORT} (availability)")
746 message(STATUS "  JPEG support:                       ${jpeg} (requested) ${JPEG_FOUND} (availability)")
747 message(STATUS "  Old JPEG support:                   ${old-jpeg} (requested) ${JPEG_FOUND} (availability)")
748 message(STATUS "  JPEG 8/12 bit dual mode:            ${jpeg12} (requested) ${JPEG12_FOUND} (availability)")
749 message(STATUS "  ISO JBIG support:                   ${jbig} (requested) ${JBIG_FOUND} (availability)")
750 message(STATUS "  LZMA2 support:                      ${lzma} (requested) ${LIBLZMA_FOUND} (availability)")
751 message(STATUS "  ZSTD support:                       ${zstd} (requested) ${ZSTD_FOUND} (availability)")
752 message(STATUS "  WEBP support:                       ${webp} (requested) ${WEBP_FOUND} (availability)")
753 message(STATUS "")
754 message(STATUS "  C++ support:                        ${cxx} (requested) ${CXX_SUPPORT} (availability)")
755 message(STATUS "")
756 # message(STATUS "  X Athena Widgets support:           ${HAVE_XAW}")
757 message(STATUS "  OpenGL support:                     ${HAVE_OPENGL}")
758 message(STATUS "")