Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/3rdparty/libtiff/CMakeLists.txt
16337 views
1
# ----------------------------------------------------------------------------
2
# CMake file for libtiff. See root CMakeLists.txt
3
#
4
# ----------------------------------------------------------------------------
5
project(${TIFF_LIBRARY})
6
7
include(CheckCSourceCompiles)
8
include(CheckFunctionExists)
9
include(CheckIncludeFile)
10
include(CheckTypeSize)
11
12
13
# Find libm, if available
14
find_library(M_LIBRARY m)
15
16
check_include_file(assert.h HAVE_ASSERT_H)
17
if(NOT MSVC)
18
check_include_file(dlfcn.h HAVE_DLFCN_H)
19
endif()
20
check_include_file(fcntl.h HAVE_FCNTL_H)
21
check_include_file(inttypes.h HAVE_INTTYPES_H)
22
check_include_file(io.h HAVE_IO_H)
23
check_include_file(limits.h HAVE_LIMITS_H)
24
check_include_file(malloc.h HAVE_MALLOC_H)
25
check_include_file(memory.h HAVE_MEMORY_H)
26
check_include_file(search.h HAVE_SEARCH_H)
27
check_include_file(stdint.h HAVE_STDINT_H)
28
check_include_file(string.h HAVE_STRING_H)
29
if(NOT MSVC)
30
check_include_file(strings.h HAVE_STRINGS_H)
31
check_include_file(sys/time.h HAVE_SYS_TIME_H)
32
endif()
33
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
34
if(NOT MSVC)
35
check_include_file(unistd.h HAVE_UNISTD_H)
36
endif()
37
38
# Inspired from /usr/share/autoconf/autoconf/c.m4
39
foreach(inline_keyword "inline" "__inline__" "__inline")
40
if(NOT DEFINED C_INLINE)
41
set(CMAKE_REQUIRED_DEFINITIONS_SAVE ${CMAKE_REQUIRED_DEFINITIONS})
42
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
43
"-Dinline=${inline_keyword}")
44
check_c_source_compiles("
45
typedef int foo_t;
46
static inline foo_t static_foo() {return 0;}
47
foo_t foo(){return 0;}
48
int main(int argc, char *argv[]) {return 0;}"
49
C_HAS_${inline_keyword})
50
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS_SAVE})
51
if(C_HAS_${inline_keyword})
52
set(C_INLINE TRUE)
53
set(INLINE_KEYWORD "${inline_keyword}")
54
endif()
55
endif()
56
endforeach()
57
if(NOT DEFINED C_INLINE)
58
set(INLINE_KEYWORD)
59
endif()
60
61
62
# Check type sizes
63
# NOTE: Could be replaced with C99 <stdint.h>
64
check_type_size("signed short" SIZEOF_SIGNED_SHORT)
65
check_type_size("unsigned short" SIZEOF_UNSIGNED_SHORT)
66
check_type_size("signed int" SIZEOF_SIGNED_INT)
67
check_type_size("unsigned int" SIZEOF_UNSIGNED_INT)
68
check_type_size("signed long" SIZEOF_SIGNED_LONG)
69
check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
70
check_type_size("signed long long" SIZEOF_SIGNED_LONG_LONG)
71
check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG)
72
check_type_size("unsigned char *" SIZEOF_UNSIGNED_CHAR_P)
73
74
set(CMAKE_EXTRA_INCLUDE_FILES_SAVE ${CMAKE_EXTRA_INCLUDE_FILES})
75
set(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES} "stddef.h")
76
check_type_size("size_t" SIZEOF_SIZE_T)
77
check_type_size("ptrdiff_t" SIZEOF_PTRDIFF_T)
78
set(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES_SAVE})
79
80
set(TIFF_INT8_T "signed char")
81
set(TIFF_UINT8_T "unsigned char")
82
83
set(TIFF_INT16_T "signed short")
84
set(TIFF_UINT16_T "unsigned short")
85
86
if(SIZEOF_SIGNED_INT EQUAL 4)
87
set(TIFF_INT32_T "signed int")
88
set(TIFF_INT32_FORMAT "%d")
89
elseif(SIZEOF_SIGNED_LONG EQUAL 4)
90
set(TIFF_INT32_T "signed long")
91
set(TIFF_INT32_FORMAT "%ld")
92
endif()
93
94
if(SIZEOF_UNSIGNED_INT EQUAL 4)
95
set(TIFF_UINT32_T "unsigned int")
96
set(TIFF_UINT32_FORMAT "%u")
97
elseif(SIZEOF_UNSIGNED_LONG EQUAL 4)
98
set(TIFF_UINT32_T "unsigned long")
99
set(TIFF_UINT32_FORMAT "%lu")
100
endif()
101
102
if(SIZEOF_SIGNED_LONG EQUAL 8)
103
set(TIFF_INT64_T "signed long")
104
set(TIFF_INT64_FORMAT "%ld")
105
elseif(SIZEOF_SIGNED_LONG_LONG EQUAL 8)
106
set(TIFF_INT64_T "signed long long")
107
if(MINGW)
108
set(TIFF_INT64_FORMAT "%I64d")
109
else()
110
set(TIFF_INT64_FORMAT "%lld")
111
endif()
112
endif()
113
114
if(SIZEOF_UNSIGNED_LONG EQUAL 8)
115
set(TIFF_UINT64_T "unsigned long")
116
set(TIFF_UINT64_FORMAT "%lu")
117
elseif(SIZEOF_UNSIGNED_LONG_LONG EQUAL 8)
118
set(TIFF_UINT64_T "unsigned long long")
119
if(MINGW)
120
set(TIFF_UINT64_FORMAT "%I64u")
121
else()
122
set(TIFF_UINT64_FORMAT "%llu")
123
endif()
124
endif()
125
126
if(SIZEOF_UNSIGNED_INT EQUAL SIZEOF_SIZE_T)
127
set(TIFF_SIZE_T "unsigned int")
128
set(TIFF_SIZE_FORMAT "%u")
129
elseif(SIZEOF_UNSIGNED_LONG EQUAL SIZEOF_SIZE_T)
130
set(TIFF_SIZE_T "unsigned long")
131
set(TIFF_SIZE_FORMAT "%lu")
132
elseif(SIZEOF_UNSIGNED_LONG_LONG EQUAL SIZEOF_SIZE_T)
133
set(TIFF_SIZE_T "unsigned long")
134
if(MINGW)
135
set(TIFF_SIZE_FORMAT "%I64u")
136
else()
137
set(TIFF_SIZE_FORMAT "%llu")
138
endif()
139
endif()
140
141
if(SIZEOF_SIGNED_INT EQUAL SIZEOF_UNSIGNED_CHAR_P)
142
set(TIFF_SSIZE_T "signed int")
143
set(TIFF_SSIZE_FORMAT "%d")
144
elseif(SIZEOF_SIGNED_LONG EQUAL SIZEOF_UNSIGNED_CHAR_P)
145
set(TIFF_SSIZE_T "signed long")
146
set(TIFF_SSIZE_FORMAT "%ld")
147
elseif(SIZEOF_SIGNED_LONG_LONG EQUAL SIZEOF_UNSIGNED_CHAR_P)
148
set(TIFF_SSIZE_T "signed long long")
149
if(MINGW)
150
set(TIFF_SSIZE_FORMAT "%I64d")
151
else()
152
set(TIFF_SSIZE_FORMAT "%lld")
153
endif()
154
endif()
155
156
if(NOT SIZEOF_PTRDIFF_T)
157
set(TIFF_PTRDIFF_T "${TIFF_SSIZE_T}")
158
set(TIFF_PTRDIFF_FORMAT "${SSIZE_FORMAT}")
159
else()
160
set(TIFF_PTRDIFF_T "ptrdiff_t")
161
set(TIFF_PTRDIFF_FORMAT "%ld")
162
endif()
163
164
# Nonstandard int types
165
if(NOT MSVC)
166
check_type_size(INT8 int8)
167
set(HAVE_INT8 ${INT8})
168
check_type_size(INT16 int16)
169
set(HAVE_INT16 ${INT16})
170
check_type_size(INT32 int32)
171
set(HAVE_INT32 ${INT32})
172
endif()
173
174
# Check functions
175
if(NOT MSVC)
176
set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
177
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${M_LIBRARY})
178
check_function_exists(floor HAVE_FLOOR)
179
check_function_exists(pow HAVE_POW)
180
check_function_exists(sqrt HAVE_SQRT)
181
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
182
endif()
183
184
if(NOT MSVC)
185
check_function_exists(isascii HAVE_ISASCII)
186
check_function_exists(memset HAVE_MEMSET)
187
check_function_exists(mmap HAVE_MMAP)
188
check_function_exists(getopt HAVE_GETOPT)
189
endif()
190
check_function_exists(memmove HAVE_MEMMOVE)
191
check_function_exists(setmode HAVE_SETMODE)
192
check_function_exists(strcasecmp HAVE_STRCASECMP)
193
check_function_exists(strchr HAVE_STRCHR)
194
check_function_exists(strrchr HAVE_STRRCHR)
195
check_function_exists(strstr HAVE_STRSTR)
196
check_function_exists(strtol HAVE_STRTOL)
197
check_function_exists(strtol HAVE_STRTOUL)
198
check_function_exists(strtoull HAVE_STRTOULL)
199
check_function_exists(lfind HAVE_LFIND)
200
201
# May be inlined, so check it compiles:
202
check_c_source_compiles("
203
#include <stdio.h>
204
int main(void) {
205
char buf[10];
206
snprintf(buf, 10, \"Test %d\", 1);
207
return 0;
208
}"
209
HAVE_SNPRINTF)
210
211
if(NOT HAVE_SNPRINTF)
212
add_definitions(-DNEED_LIBPORT)
213
endif()
214
215
# CPU bit order
216
set(fillorder FILLORDER_MSB2LSB)
217
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i.*86.*" OR
218
CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*" OR
219
CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64.*")
220
set(fillorder FILLORDER_LSB2MSB)
221
endif()
222
set(HOST_FILLORDER ${fillorder} CACHE STRING "Native CPU bit order")
223
mark_as_advanced(HOST_FILLORDER)
224
225
# CPU endianness
226
include(TestBigEndian)
227
test_big_endian(bigendian)
228
if(bigendian)
229
set(bigendian ON)
230
else()
231
set(bigendian OFF)
232
endif()
233
set(HOST_BIG_ENDIAN ${bigendian} CACHE STRING "Native CPU bit order")
234
mark_as_advanced(HOST_BIG_ENDIAN)
235
if(HOST_BIG_ENDIAN)
236
set(HOST_BIG_ENDIAN 1)
237
else()
238
set(HOST_BIG_ENDIAN 0)
239
endif()
240
241
# IEEE floating point
242
set(HAVE_IEEEFP 1 CACHE STRING "IEEE floating point is available")
243
mark_as_advanced(HAVE_IEEEFP)
244
245
# Large file support
246
if(UNIX OR MINGW)
247
if(ANDROID AND (ANDROID_NATIVE_API_LEVEL LESS 21) AND CV_GCC)
248
# Android NDK build problem: 'mmap' issue with GCC and API<21
249
else()
250
# This might not catch every possibility catered for by
251
# AC_SYS_LARGEFILE.
252
add_definitions(-D_FILE_OFFSET_BITS=64)
253
set(FILE_OFFSET_BITS 64)
254
endif()
255
endif()
256
257
# Documentation install directory (default to cmake project docdir)
258
set(LIBTIFF_DOCDIR "${CMAKE_INSTALL_FULL_DOCDIR}")
259
260
# Options to enable and disable internal codecs
261
262
option(ccitt "support for CCITT Group 3 & 4 algorithms" ON)
263
set(CCITT_SUPPORT ${ccitt})
264
265
option(packbits "support for Macintosh PackBits algorithm" ON)
266
set(PACKBITS_SUPPORT ${packbits})
267
268
option(lzw "support for LZW algorithm" ON)
269
set(LZW_SUPPORT ${lzw})
270
271
option(thunder "support for ThunderScan 4-bit RLE algorithm" ON)
272
set(THUNDER_SUPPORT ${thunder})
273
274
option(next "support for NeXT 2-bit RLE algorithm" ON)
275
set(NEXT_SUPPORT ${next})
276
277
option(logluv "support for LogLuv high dynamic range algorithm" ON)
278
set(LOGLUV_SUPPORT ${logluv})
279
280
# Option for Microsoft Document Imaging
281
option(mdi "support for Microsoft Document Imaging" ON)
282
set(MDI_SUPPORT ${mdi})
283
284
# ZLIB
285
set(ZLIB_SUPPORT 0)
286
if(ZLIB_LIBRARY)
287
set(ZLIB_SUPPORT 1)
288
endif()
289
set(ZIP_SUPPORT ${ZLIB_SUPPORT})
290
291
set(PIXARLOG_SUPPORT FALSE)
292
293
# JPEG
294
set(JPEG_SUPPORT FALSE)
295
if(HAVE_JPEG)
296
set(JPEG_SUPPORT TRUE)
297
if(TARGET ${JPEG_LIBRARY} AND DEFINED ${JPEG_LIBRARY}_BINARY_DIR)
298
include_directories("${${JPEG_LIBRARY}_BINARY_DIR}")
299
endif()
300
include_directories(${JPEG_INCLUDE_DIR})
301
endif()
302
303
option(old-jpeg "support for Old JPEG compression (read-only)" OFF) # OpenCV: changed to OFF
304
set(OJPEG_SUPPORT FALSE)
305
if(JPEG_SUPPORT AND old-jpeg)
306
set(OJPEG_SUPPORT TRUE)
307
endif()
308
309
# OpenCV: turned off
310
set(JBIG_SUPPORT 0)
311
set(LZMA_SUPPORT 0) # OpenCV: turned off
312
set(JPEG12_FOUND FALSE) # OpenCV: turned off
313
set(STRIPCHOP_DEFAULT)
314
set(STRIP_SIZE_DEFAULT 8192)
315
316
# Win32 IO
317
set(win32_io FALSE)
318
if(WIN32 AND NOT WINRT)
319
set(win32_io TRUE)
320
endif()
321
set(USE_WIN32_FILEIO ${win32_io} CACHE BOOL "Use win32 IO system (Microsoft Windows only)")
322
if(USE_WIN32_FILEIO)
323
set(USE_WIN32_FILEIO TRUE)
324
else()
325
set(USE_WIN32_FILEIO FALSE)
326
endif()
327
328
# Orthogonal features
329
330
# OpenCV: turned ON
331
set(SUBIFD_SUPPORT 1)
332
set(DEFAULT_EXTRASAMPLE_AS_ALPHA 1)
333
set(CHECK_JPEG_YCBCR_SUBSAMPLING 1)
334
335
if(JPEG_INCLUDE_DIR)
336
list(APPEND TIFF_INCLUDES ${JPEG_INCLUDE_DIR})
337
endif()
338
if(JPEG12_INCLUDE_DIR)
339
list(APPEND TIFF_INCLUDES ${JPEG12_INCLUDE_DIR})
340
endif()
341
if(JBIG_INCLUDE_DIR)
342
list(APPEND TIFF_INCLUDES ${JBIG_INCLUDE_DIR})
343
endif()
344
if(LIBLZMA_INCLUDE_DIRS)
345
list(APPEND TIFF_INCLUDES ${LIBLZMA_INCLUDE_DIRS})
346
endif()
347
348
# Libraries required by libtiff
349
set(TIFF_LIBRARY_DEPS)
350
if(M_LIBRARY)
351
list(APPEND TIFF_LIBRARY_DEPS ${M_LIBRARY})
352
endif()
353
if(ZLIB_LIBRARIES)
354
list(APPEND TIFF_LIBRARY_DEPS ${ZLIB_LIBRARIES})
355
endif()
356
if(JPEG_LIBRARIES)
357
list(APPEND TIFF_LIBRARY_DEPS ${JPEG_LIBRARIES})
358
endif()
359
if(JPEG12_LIBRARIES)
360
list(APPEND TIFF_LIBRARY_DEPS ${JPEG12_LIBRARIES})
361
endif()
362
if(JBIG_LIBRARIES)
363
list(APPEND TIFF_LIBRARY_DEPS ${JBIG_LIBRARIES})
364
endif()
365
if(LIBLZMA_LIBRARIES)
366
list(APPEND TIFF_LIBRARY_DEPS ${LIBLZMA_LIBRARIES})
367
endif()
368
369
370
371
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tif_config.h.cmake.in"
372
"${CMAKE_CURRENT_BINARY_DIR}/tif_config.h"
373
@ONLY)
374
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tiffconf.h.cmake.in"
375
"${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h"
376
@ONLY)
377
378
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" ${ZLIB_INCLUDE_DIRS})
379
380
set(lib_srcs
381
tif_aux.c
382
tif_close.c
383
tif_codec.c
384
tif_color.c
385
tif_compress.c
386
tif_dir.c
387
tif_dirinfo.c
388
tif_dirread.c
389
tif_dirwrite.c
390
tif_dumpmode.c
391
tif_error.c
392
tif_extension.c
393
tif_fax3.c
394
tif_fax3sm.c
395
tif_flush.c
396
tif_getimage.c
397
tif_jbig.c
398
tif_jpeg_12.c
399
tif_jpeg.c
400
tif_luv.c
401
tif_lzma.c
402
tif_lzw.c
403
tif_next.c
404
tif_ojpeg.c
405
tif_open.c
406
tif_packbits.c
407
tif_pixarlog.c
408
tif_predict.c
409
tif_print.c
410
tif_read.c
411
tif_strip.c
412
tif_swab.c
413
tif_thunder.c
414
tif_tile.c
415
tif_version.c
416
tif_warning.c
417
tif_write.c
418
tif_zip.c
419
tif_stream.cxx
420
snprintf.c
421
t4.h
422
tif_dir.h
423
tif_fax3.h
424
tiff.h
425
tiffio.h
426
tiffiop.h
427
tiffvers.h
428
tif_predict.h
429
uvcode.h
430
tiffio.hxx
431
"${CMAKE_CURRENT_BINARY_DIR}/tif_config.h"
432
"${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h"
433
)
434
435
if(WIN32 AND NOT WINRT)
436
list(APPEND lib_srcs tif_win32.c)
437
else()
438
list(APPEND lib_srcs tif_unix.c)
439
endif()
440
441
ocv_warnings_disable(CMAKE_C_FLAGS -Wno-unused-but-set-variable -Wmissing-prototypes -Wmissing-declarations -Wundef -Wunused -Wsign-compare
442
-Wcast-align -Wshadow -Wno-maybe-uninitialized -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast
443
-Wmisleading-indentation
444
-Wimplicit-fallthrough
445
)
446
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang
447
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations -Wunused-parameter
448
-Wundef # tiffiop.h: #if __clang_major__ >= 4
449
)
450
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4018 /wd4100 /wd4127 /wd4311 /wd4701 /wd4706) # vs2005
451
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244) # vs2008
452
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4267 /wd4305 /wd4306) # vs2008 Win64
453
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4703) # vs2012
454
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4456 /wd4457 /wd4312) # vs2015
455
456
ocv_warnings_disable(CMAKE_C_FLAGS /wd4267 /wd4244 /wd4018 /wd4311 /wd4312)
457
458
add_library(${TIFF_LIBRARY} STATIC ${lib_srcs})
459
target_link_libraries(${TIFF_LIBRARY} ${ZLIB_LIBRARIES})
460
461
set_target_properties(${TIFF_LIBRARY}
462
PROPERTIES
463
OUTPUT_NAME "${TIFF_LIBRARY}"
464
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
465
COMPILE_PDB_NAME ${TIFF_LIBRARY}
466
COMPILE_PDB_NAME_DEBUG "${TIFF_LIBRARY}${OPENCV_DEBUG_POSTFIX}"
467
ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
468
)
469
470
if(ENABLE_SOLUTION_FOLDERS)
471
set_target_properties(${TIFF_LIBRARY} PROPERTIES FOLDER "3rdparty")
472
endif()
473
474
if(NOT BUILD_SHARED_LIBS)
475
ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
476
endif()
477
478
ocv_install_3rdparty_licenses(libtiff COPYRIGHT)
479
480