fix compilation error on Visual Studio 2013 and earlier
[platform/upstream/opencv.git] / 3rdparty / libtiff / CMakeLists.txt
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
11
12 # Find libm, if available
13 find_library(M_LIBRARY m)
14
15 check_include_file(assert.h    HAVE_ASSERT_H)
16 if(NOT MSVC)
17   check_include_file(dlfcn.h     HAVE_DLFCN_H)
18 endif()
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)
28 if(NOT MSVC)
29   check_include_file(strings.h   HAVE_STRINGS_H)
30   check_include_file(sys/time.h  HAVE_SYS_TIME_H)
31 endif()
32 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
33 if(NOT MSVC)
34   check_include_file(unistd.h    HAVE_UNISTD_H)
35 endif()
36
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("
44         typedef int foo_t;
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})
51       set(C_INLINE TRUE)
52       set(INLINE_KEYWORD "${inline_keyword}")
53     endif()
54  endif()
55 endforeach()
56 if(NOT DEFINED C_INLINE)
57   set(INLINE_KEYWORD)
58 endif()
59
60
61 # Check type sizes
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)
72
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})
78
79 set(TIFF_INT8_T "signed char")
80 set(TIFF_UINT8_T "unsigned char")
81
82 set(TIFF_INT16_T "signed short")
83 set(TIFF_UINT16_T "unsigned short")
84
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")
91 endif()
92
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")
99 endif()
100
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")
106   if(MINGW)
107     set(TIFF_INT64_FORMAT "%I64d")
108   else()
109     set(TIFF_INT64_FORMAT "%lld")
110   endif()
111 endif()
112
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")
118   if(MINGW)
119     set(TIFF_UINT64_FORMAT "%I64u")
120   else()
121     set(TIFF_UINT64_FORMAT "%llu")
122   endif()
123 endif()
124
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")
133   if(MINGW)
134     set(TIFF_SIZE_FORMAT "%I64u")
135   else()
136     set(TIFF_SIZE_FORMAT "%llu")
137   endif()
138 endif()
139
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")
148   if(MINGW)
149     set(TIFF_SSIZE_FORMAT "%I64d")
150   else()
151     set(TIFF_SSIZE_FORMAT "%lld")
152   endif()
153 endif()
154
155 if(NOT SIZEOF_PTRDIFF_T)
156   set(TIFF_PTRDIFF_T "${TIFF_SSIZE_T}")
157   set(TIFF_PTRDIFF_FORMAT "${SSIZE_FORMAT}")
158 else()
159   set(TIFF_PTRDIFF_T "ptrdiff_t")
160   set(TIFF_PTRDIFF_FORMAT "%ld")
161 endif()
162
163 # Nonstandard int types
164 if(NOT MSVC)
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})
171 endif()
172
173 # Check functions
174 if(NOT MSVC)
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})
181 endif()
182
183 if(NOT MSVC)
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)
188 endif()
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)
199
200 # May be inlined, so check it compiles:
201 check_c_source_compiles("
202 #include <stdio.h>
203 int main(void) {
204   char buf[10];
205   snprintf(buf, 10, \"Test %d\", 1);
206   return 0;
207 }"
208   HAVE_SNPRINTF)
209
210 if(NOT HAVE_SNPRINTF)
211   add_definitions(-DNEED_LIBPORT)
212 endif()
213
214 # CPU bit order
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)
220 endif()
221 set(HOST_FILLORDER ${fillorder} CACHE STRING "Native CPU bit order")
222 mark_as_advanced(HOST_FILLORDER)
223
224 # CPU endianness
225 include(TestBigEndian)
226 test_big_endian(bigendian)
227 if(bigendian)
228   set(bigendian ON)
229 else()
230   set(bigendian OFF)
231 endif()
232 set(HOST_BIG_ENDIAN ${bigendian} CACHE STRING "Native CPU bit order")
233 mark_as_advanced(HOST_BIG_ENDIAN)
234 if(HOST_BIG_ENDIAN)
235   set(HOST_BIG_ENDIAN 1)
236 else()
237   set(HOST_BIG_ENDIAN 0)
238 endif()
239
240 # IEEE floating point
241 set(HAVE_IEEEFP 1 CACHE STRING "IEEE floating point is available")
242 mark_as_advanced(HAVE_IEEEFP)
243
244 # Large file support
245 if(UNIX OR MINGW)
246   # This might not catch every possibility catered for by
247   # AC_SYS_LARGEFILE.
248   add_definitions(-D_FILE_OFFSET_BITS=64)
249   set(FILE_OFFSET_BITS 64)
250 endif()
251
252 # Documentation install directory (default to cmake project docdir)
253 set(LIBTIFF_DOCDIR "${CMAKE_INSTALL_FULL_DOCDIR}")
254
255 # Options to enable and disable internal codecs
256
257 option(ccitt "support for CCITT Group 3 & 4 algorithms" ON)
258 set(CCITT_SUPPORT ${ccitt})
259
260 option(packbits "support for Macintosh PackBits algorithm" ON)
261 set(PACKBITS_SUPPORT ${packbits})
262
263 option(lzw "support for LZW algorithm" ON)
264 set(LZW_SUPPORT ${lzw})
265
266 option(thunder "support for ThunderScan 4-bit RLE algorithm" ON)
267 set(THUNDER_SUPPORT ${thunder})
268
269 option(next "support for NeXT 2-bit RLE algorithm" ON)
270 set(NEXT_SUPPORT ${next})
271
272 option(logluv "support for LogLuv high dynamic range algorithm" ON)
273 set(LOGLUV_SUPPORT ${logluv})
274
275 # Option for Microsoft Document Imaging
276 option(mdi "support for Microsoft Document Imaging" ON)
277 set(MDI_SUPPORT ${mdi})
278
279 # ZLIB
280 set(ZLIB_SUPPORT 0)
281 if(ZLIB_LIBRARY)
282   set(ZLIB_SUPPORT 1)
283 endif()
284 set(ZIP_SUPPORT ${ZLIB_SUPPORT})
285
286 set(PIXARLOG_SUPPORT FALSE)
287
288 # JPEG
289 set(JPEG_SUPPORT FALSE)
290 if(HAVE_JPEG)
291   set(JPEG_SUPPORT TRUE)
292   include_directories(${JPEG_INCLUDE_DIR})
293 endif()
294
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)
299 endif()
300
301 # OpenCV: turned off
302 set(JBIG_SUPPORT 0)
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)
307
308 # Win32 IO
309 set(win32_io FALSE)
310 if(WIN32 AND NOT WINRT)
311   set(win32_io TRUE)
312 endif()
313 set(USE_WIN32_FILEIO ${win32_io} CACHE BOOL "Use win32 IO system (Microsoft Windows only)")
314 if(USE_WIN32_FILEIO)
315   set(USE_WIN32_FILEIO TRUE)
316 else()
317   set(USE_WIN32_FILEIO FALSE)
318 endif()
319
320 # Orthogonal features
321
322 # OpenCV: turned ON
323 set(SUBIFD_SUPPORT 1)
324 set(DEFAULT_EXTRASAMPLE_AS_ALPHA 1)
325 set(CHECK_JPEG_YCBCR_SUBSAMPLING 1)
326
327 if(JPEG_INCLUDE_DIR)
328   list(APPEND TIFF_INCLUDES ${JPEG_INCLUDE_DIR})
329 endif()
330 if(JPEG12_INCLUDE_DIR)
331   list(APPEND TIFF_INCLUDES ${JPEG12_INCLUDE_DIR})
332 endif()
333 if(JBIG_INCLUDE_DIR)
334   list(APPEND TIFF_INCLUDES ${JBIG_INCLUDE_DIR})
335 endif()
336 if(LIBLZMA_INCLUDE_DIRS)
337   list(APPEND TIFF_INCLUDES ${LIBLZMA_INCLUDE_DIRS})
338 endif()
339
340 # Libraries required by libtiff
341 set(TIFF_LIBRARY_DEPS)
342 if(M_LIBRARY)
343   list(APPEND TIFF_LIBRARY_DEPS ${M_LIBRARY})
344 endif()
345 if(ZLIB_LIBRARIES)
346   list(APPEND TIFF_LIBRARY_DEPS ${ZLIB_LIBRARIES})
347 endif()
348 if(JPEG_LIBRARIES)
349   list(APPEND TIFF_LIBRARY_DEPS ${JPEG_LIBRARIES})
350 endif()
351 if(JPEG12_LIBRARIES)
352   list(APPEND TIFF_LIBRARY_DEPS ${JPEG12_LIBRARIES})
353 endif()
354 if(JBIG_LIBRARIES)
355   list(APPEND TIFF_LIBRARY_DEPS ${JBIG_LIBRARIES})
356 endif()
357 if(LIBLZMA_LIBRARIES)
358   list(APPEND TIFF_LIBRARY_DEPS ${LIBLZMA_LIBRARIES})
359 endif()
360
361
362
363 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tif_config.h.cmake.in"
364                "${CMAKE_CURRENT_BINARY_DIR}/tif_config.h"
365                @ONLY)
366 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tiffconf.h.cmake.in"
367                "${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h"
368                @ONLY)
369
370 ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" ${ZLIB_INCLUDE_DIRS})
371
372 set(lib_srcs
373     tif_aux.c
374     tif_close.c
375     tif_codec.c
376     tif_color.c
377     tif_compress.c
378     tif_dir.c
379     tif_dirinfo.c
380     tif_dirread.c
381     tif_dirwrite.c
382     tif_dumpmode.c
383     tif_error.c
384     tif_extension.c
385     tif_fax3.c
386     tif_fax3sm.c
387     tif_flush.c
388     tif_getimage.c
389     tif_jbig.c
390     tif_jpeg_12.c
391     tif_jpeg.c
392     tif_luv.c
393     tif_lzma.c
394     tif_lzw.c
395     tif_next.c
396     tif_ojpeg.c
397     tif_open.c
398     tif_packbits.c
399     tif_pixarlog.c
400     tif_predict.c
401     tif_print.c
402     tif_read.c
403     tif_strip.c
404     tif_swab.c
405     tif_thunder.c
406     tif_tile.c
407     tif_version.c
408     tif_warning.c
409     tif_write.c
410     tif_zip.c
411     tif_stream.cxx
412         snprintf.c
413     t4.h
414     tif_dir.h
415     tif_fax3.h
416     tiff.h
417     tiffio.h
418     tiffiop.h
419     tiffvers.h
420     tif_predict.h
421     uvcode.h
422     tiffio.hxx
423     "${CMAKE_CURRENT_BINARY_DIR}/tif_config.h"
424     "${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h"
425     )
426
427 if(WIN32 AND NOT WINRT)
428   list(APPEND lib_srcs tif_win32.c)
429 else()
430   list(APPEND lib_srcs tif_unix.c)
431 endif()
432
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
436 )
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
440 )
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
446
447 ocv_warnings_disable(CMAKE_C_FLAGS /wd4267 /wd4244 /wd4018 /wd4311 /wd4312)
448
449 if(UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR CV_ICC))
450   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
451 endif()
452
453 add_library(${TIFF_LIBRARY} STATIC ${lib_srcs})
454 target_link_libraries(${TIFF_LIBRARY} ${ZLIB_LIBRARIES})
455
456 set_target_properties(${TIFF_LIBRARY}
457     PROPERTIES
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}
463     )
464
465 if(ENABLE_SOLUTION_FOLDERS)
466   set_target_properties(${TIFF_LIBRARY} PROPERTIES FOLDER "3rdparty")
467 endif()
468
469 if(NOT BUILD_SHARED_LIBS)
470   ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
471 endif()