1 # ----------------------------------------------------------------------------
2 # CMake file for libtiff. See root CMakeLists.txt
4 # ----------------------------------------------------------------------------
5 project(${TIFF_LIBRARY})
7 include(CheckCSourceCompiles)
8 include(CheckFunctionExists)
9 include(CheckIncludeFile)
12 # Find libm, if available
13 find_library(M_LIBRARY m)
15 check_include_file(assert.h HAVE_ASSERT_H)
17 check_include_file(dlfcn.h HAVE_DLFCN_H)
19 check_include_file(fcntl.h HAVE_FCNTL_H)
20 check_include_file(inttypes.h HAVE_INTTYPES_H)
21 check_include_file(io.h HAVE_IO_H)
22 check_include_file(limits.h HAVE_LIMITS_H)
23 check_include_file(malloc.h HAVE_MALLOC_H)
24 check_include_file(memory.h HAVE_MEMORY_H)
25 check_include_file(search.h HAVE_SEARCH_H)
26 check_include_file(stdint.h HAVE_STDINT_H)
27 check_include_file(string.h HAVE_STRING_H)
29 check_include_file(strings.h HAVE_STRINGS_H)
30 check_include_file(sys/time.h HAVE_SYS_TIME_H)
32 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
34 check_include_file(unistd.h HAVE_UNISTD_H)
37 # Inspired from /usr/share/autoconf/autoconf/c.m4
38 foreach(inline_keyword "inline" "__inline__" "__inline")
39 if(NOT DEFINED C_INLINE)
40 set(CMAKE_REQUIRED_DEFINITIONS_SAVE ${CMAKE_REQUIRED_DEFINITIONS})
41 set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
42 "-Dinline=${inline_keyword}")
43 check_c_source_compiles("
45 static inline foo_t static_foo() {return 0;}
46 foo_t foo(){return 0;}
47 int main(int argc, char *argv[]) {return 0;}"
48 C_HAS_${inline_keyword})
49 set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS_SAVE})
50 if(C_HAS_${inline_keyword})
52 set(INLINE_KEYWORD "${inline_keyword}")
56 if(NOT DEFINED C_INLINE)
62 # NOTE: Could be replaced with C99 <stdint.h>
63 check_type_size("signed short" SIZEOF_SIGNED_SHORT)
64 check_type_size("unsigned short" SIZEOF_UNSIGNED_SHORT)
65 check_type_size("signed int" SIZEOF_SIGNED_INT)
66 check_type_size("unsigned int" SIZEOF_UNSIGNED_INT)
67 check_type_size("signed long" SIZEOF_SIGNED_LONG)
68 check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
69 check_type_size("signed long long" SIZEOF_SIGNED_LONG_LONG)
70 check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG)
71 check_type_size("unsigned char *" SIZEOF_UNSIGNED_CHAR_P)
73 set(CMAKE_EXTRA_INCLUDE_FILES_SAVE ${CMAKE_EXTRA_INCLUDE_FILES})
74 set(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES} "stddef.h")
75 check_type_size("size_t" SIZEOF_SIZE_T)
76 check_type_size("ptrdiff_t" SIZEOF_PTRDIFF_T)
77 set(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES_SAVE})
79 set(TIFF_INT8_T "signed char")
80 set(TIFF_UINT8_T "unsigned char")
82 set(TIFF_INT16_T "signed short")
83 set(TIFF_UINT16_T "unsigned short")
85 if(SIZEOF_SIGNED_INT EQUAL 4)
86 set(TIFF_INT32_T "signed int")
87 set(TIFF_INT32_FORMAT "%d")
88 elseif(SIZEOF_SIGNED_LONG EQUAL 4)
89 set(TIFF_INT32_T "signed long")
90 set(TIFF_INT32_FORMAT "%ld")
93 if(SIZEOF_UNSIGNED_INT EQUAL 4)
94 set(TIFF_UINT32_T "unsigned int")
95 set(TIFF_UINT32_FORMAT "%u")
96 elseif(SIZEOF_UNSIGNED_LONG EQUAL 4)
97 set(TIFF_UINT32_T "unsigned long")
98 set(TIFF_UINT32_FORMAT "%lu")
101 if(SIZEOF_SIGNED_LONG EQUAL 8)
102 set(TIFF_INT64_T "signed long")
103 set(TIFF_INT64_FORMAT "%ld")
104 elseif(SIZEOF_SIGNED_LONG_LONG EQUAL 8)
105 set(TIFF_INT64_T "signed long long")
107 set(TIFF_INT64_FORMAT "%I64d")
109 set(TIFF_INT64_FORMAT "%lld")
113 if(SIZEOF_UNSIGNED_LONG EQUAL 8)
114 set(TIFF_UINT64_T "unsigned long")
115 set(TIFF_UINT64_FORMAT "%lu")
116 elseif(SIZEOF_UNSIGNED_LONG_LONG EQUAL 8)
117 set(TIFF_UINT64_T "unsigned long long")
119 set(TIFF_UINT64_FORMAT "%I64u")
121 set(TIFF_UINT64_FORMAT "%llu")
125 if(SIZEOF_UNSIGNED_INT EQUAL SIZEOF_SIZE_T)
126 set(TIFF_SIZE_T "unsigned int")
127 set(TIFF_SIZE_FORMAT "%u")
128 elseif(SIZEOF_UNSIGNED_LONG EQUAL SIZEOF_SIZE_T)
129 set(TIFF_SIZE_T "unsigned long")
130 set(TIFF_SIZE_FORMAT "%lu")
131 elseif(SIZEOF_UNSIGNED_LONG_LONG EQUAL SIZEOF_SIZE_T)
132 set(TIFF_SIZE_T "unsigned long")
134 set(TIFF_SIZE_FORMAT "%I64u")
136 set(TIFF_SIZE_FORMAT "%llu")
140 if(SIZEOF_SIGNED_INT EQUAL SIZEOF_UNSIGNED_CHAR_P)
141 set(TIFF_SSIZE_T "signed int")
142 set(TIFF_SSIZE_FORMAT "%d")
143 elseif(SIZEOF_SIGNED_LONG EQUAL SIZEOF_UNSIGNED_CHAR_P)
144 set(TIFF_SSIZE_T "signed long")
145 set(TIFF_SSIZE_FORMAT "%ld")
146 elseif(SIZEOF_SIGNED_LONG_LONG EQUAL SIZEOF_UNSIGNED_CHAR_P)
147 set(TIFF_SSIZE_T "signed long long")
149 set(TIFF_SSIZE_FORMAT "%I64d")
151 set(TIFF_SSIZE_FORMAT "%lld")
155 if(NOT SIZEOF_PTRDIFF_T)
156 set(TIFF_PTRDIFF_T "${TIFF_SSIZE_T}")
157 set(TIFF_PTRDIFF_FORMAT "${SSIZE_FORMAT}")
159 set(TIFF_PTRDIFF_T "ptrdiff_t")
160 set(TIFF_PTRDIFF_FORMAT "%ld")
163 # Nonstandard int types
165 check_type_size(INT8 int8)
166 set(HAVE_INT8 ${INT8})
167 check_type_size(INT16 int16)
168 set(HAVE_INT16 ${INT16})
169 check_type_size(INT32 int32)
170 set(HAVE_INT32 ${INT32})
175 set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
176 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${M_LIBRARY})
177 check_function_exists(floor HAVE_FLOOR)
178 check_function_exists(pow HAVE_POW)
179 check_function_exists(sqrt HAVE_SQRT)
180 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
184 check_function_exists(isascii HAVE_ISASCII)
185 check_function_exists(memset HAVE_MEMSET)
186 check_function_exists(mmap HAVE_MMAP)
187 check_function_exists(getopt HAVE_GETOPT)
189 check_function_exists(memmove HAVE_MEMMOVE)
190 check_function_exists(setmode HAVE_SETMODE)
191 check_function_exists(strcasecmp HAVE_STRCASECMP)
192 check_function_exists(strchr HAVE_STRCHR)
193 check_function_exists(strrchr HAVE_STRRCHR)
194 check_function_exists(strstr HAVE_STRSTR)
195 check_function_exists(strtol HAVE_STRTOL)
196 check_function_exists(strtol HAVE_STRTOUL)
197 check_function_exists(strtoull HAVE_STRTOULL)
198 check_function_exists(lfind HAVE_LFIND)
200 # May be inlined, so check it compiles:
201 check_c_source_compiles("
205 snprintf(buf, 10, \"Test %d\", 1);
210 if(NOT HAVE_SNPRINTF)
211 add_definitions(-DNEED_LIBPORT)
215 set(fillorder FILLORDER_MSB2LSB)
216 if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i.*86.*" OR
217 CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*" OR
218 CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64.*")
219 set(fillorder FILLORDER_LSB2MSB)
221 set(HOST_FILLORDER ${fillorder} CACHE STRING "Native CPU bit order")
222 mark_as_advanced(HOST_FILLORDER)
225 include(TestBigEndian)
226 test_big_endian(bigendian)
232 set(HOST_BIG_ENDIAN ${bigendian} CACHE STRING "Native CPU bit order")
233 mark_as_advanced(HOST_BIG_ENDIAN)
235 set(HOST_BIG_ENDIAN 1)
237 set(HOST_BIG_ENDIAN 0)
240 # IEEE floating point
241 set(HAVE_IEEEFP 1 CACHE STRING "IEEE floating point is available")
242 mark_as_advanced(HAVE_IEEEFP)
246 # This might not catch every possibility catered for by
248 add_definitions(-D_FILE_OFFSET_BITS=64)
249 set(FILE_OFFSET_BITS 64)
252 # Documentation install directory (default to cmake project docdir)
253 set(LIBTIFF_DOCDIR "${CMAKE_INSTALL_FULL_DOCDIR}")
255 # Options to enable and disable internal codecs
257 option(ccitt "support for CCITT Group 3 & 4 algorithms" ON)
258 set(CCITT_SUPPORT ${ccitt})
260 option(packbits "support for Macintosh PackBits algorithm" ON)
261 set(PACKBITS_SUPPORT ${packbits})
263 option(lzw "support for LZW algorithm" ON)
264 set(LZW_SUPPORT ${lzw})
266 option(thunder "support for ThunderScan 4-bit RLE algorithm" ON)
267 set(THUNDER_SUPPORT ${thunder})
269 option(next "support for NeXT 2-bit RLE algorithm" ON)
270 set(NEXT_SUPPORT ${next})
272 option(logluv "support for LogLuv high dynamic range algorithm" ON)
273 set(LOGLUV_SUPPORT ${logluv})
275 # Option for Microsoft Document Imaging
276 option(mdi "support for Microsoft Document Imaging" ON)
277 set(MDI_SUPPORT ${mdi})
284 set(ZIP_SUPPORT ${ZLIB_SUPPORT})
286 set(PIXARLOG_SUPPORT FALSE)
289 set(JPEG_SUPPORT FALSE)
291 set(JPEG_SUPPORT TRUE)
292 include_directories(${JPEG_INCLUDE_DIR})
295 option(old-jpeg "support for Old JPEG compression (read-only)" OFF) # OpenCV: changed to OFF
296 set(OJPEG_SUPPORT FALSE)
297 if(JPEG_SUPPORT AND old-jpeg)
298 set(OJPEG_SUPPORT TRUE)
303 set(LZMA_SUPPORT 0) # OpenCV: turned off
304 set(JPEG12_FOUND FALSE) # OpenCV: turned off
305 set(STRIPCHOP_DEFAULT)
306 set(STRIP_SIZE_DEFAULT 8192)
310 if(WIN32 AND NOT WINRT)
313 set(USE_WIN32_FILEIO ${win32_io} CACHE BOOL "Use win32 IO system (Microsoft Windows only)")
315 set(USE_WIN32_FILEIO TRUE)
317 set(USE_WIN32_FILEIO FALSE)
320 # Orthogonal features
323 set(SUBIFD_SUPPORT 1)
324 set(DEFAULT_EXTRASAMPLE_AS_ALPHA 1)
325 set(CHECK_JPEG_YCBCR_SUBSAMPLING 1)
328 list(APPEND TIFF_INCLUDES ${JPEG_INCLUDE_DIR})
330 if(JPEG12_INCLUDE_DIR)
331 list(APPEND TIFF_INCLUDES ${JPEG12_INCLUDE_DIR})
334 list(APPEND TIFF_INCLUDES ${JBIG_INCLUDE_DIR})
336 if(LIBLZMA_INCLUDE_DIRS)
337 list(APPEND TIFF_INCLUDES ${LIBLZMA_INCLUDE_DIRS})
340 # Libraries required by libtiff
341 set(TIFF_LIBRARY_DEPS)
343 list(APPEND TIFF_LIBRARY_DEPS ${M_LIBRARY})
346 list(APPEND TIFF_LIBRARY_DEPS ${ZLIB_LIBRARIES})
349 list(APPEND TIFF_LIBRARY_DEPS ${JPEG_LIBRARIES})
352 list(APPEND TIFF_LIBRARY_DEPS ${JPEG12_LIBRARIES})
355 list(APPEND TIFF_LIBRARY_DEPS ${JBIG_LIBRARIES})
357 if(LIBLZMA_LIBRARIES)
358 list(APPEND TIFF_LIBRARY_DEPS ${LIBLZMA_LIBRARIES})
363 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tif_config.h.cmake.in"
364 "${CMAKE_CURRENT_BINARY_DIR}/tif_config.h"
366 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tiffconf.h.cmake.in"
367 "${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h"
370 ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" ${ZLIB_INCLUDE_DIRS})
423 "${CMAKE_CURRENT_BINARY_DIR}/tif_config.h"
424 "${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h"
427 if(WIN32 AND NOT WINRT)
428 list(APPEND lib_srcs tif_win32.c)
430 list(APPEND lib_srcs tif_unix.c)
433 ocv_warnings_disable(CMAKE_C_FLAGS -Wno-unused-but-set-variable -Wmissing-prototypes -Wmissing-declarations -Wundef -Wunused -Wsign-compare
434 -Wcast-align -Wshadow -Wno-maybe-uninitialized -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast
435 -Wmisleading-indentation
437 ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang
438 ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations -Wunused-parameter
439 -Wundef # tiffiop.h: #if __clang_major__ >= 4
441 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4018 /wd4100 /wd4127 /wd4311 /wd4701 /wd4706) # vs2005
442 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244) # vs2008
443 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4267 /wd4305 /wd4306) # vs2008 Win64
444 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4703) # vs2012
445 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4456 /wd4457 /wd4312) # vs2015
447 ocv_warnings_disable(CMAKE_C_FLAGS /wd4267 /wd4244 /wd4018 /wd4311 /wd4312)
449 if(UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR CV_ICC))
450 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
453 add_library(${TIFF_LIBRARY} STATIC ${lib_srcs})
454 target_link_libraries(${TIFF_LIBRARY} ${ZLIB_LIBRARIES})
456 set_target_properties(${TIFF_LIBRARY}
458 OUTPUT_NAME "${TIFF_LIBRARY}"
459 DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
460 COMPILE_PDB_NAME ${TIFF_LIBRARY}
461 COMPILE_PDB_NAME_DEBUG "${TIFF_LIBRARY}${OPENCV_DEBUG_POSTFIX}"
462 ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
465 if(ENABLE_SOLUTION_FOLDERS)
466 set_target_properties(${TIFF_LIBRARY} PROPERTIES FOLDER "3rdparty")
469 if(NOT BUILD_SHARED_LIBS)
470 ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)