Skip to content

Commit 05b259f

Browse files
committed
Merge pull request opencv#10344 from tomoaki0705:fixBuildLibtiff
2 parents e29de5d + c057d29 commit 05b259f

File tree

2 files changed

+59
-24
lines changed

2 files changed

+59
-24
lines changed

3rdparty/libtiff/CMakeLists.txt

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,27 @@ if(NOT MSVC)
3535
check_include_file(unistd.h HAVE_UNISTD_H)
3636
endif()
3737

38-
if(MSVC)
39-
set(INLINE_KEYWORD "inline")
40-
else()
41-
# Inspired from /usr/share/autoconf/autoconf/c.m4
42-
foreach(inline_keyword "inline" "__inline__" "__inline")
43-
if(NOT DEFINED C_INLINE)
44-
set(CMAKE_REQUIRED_DEFINITIONS_SAVE ${CMAKE_REQUIRED_DEFINITIONS})
45-
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
46-
"-Dinline=${inline_keyword}")
47-
check_c_source_compiles("
48-
typedef int foo_t;
49-
static inline foo_t static_foo() {return 0;}
50-
foo_t foo(){return 0;}
51-
int main(int argc, char *argv[]) {return 0;}"
52-
C_HAS_${inline_keyword})
53-
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS_SAVE})
54-
if(C_HAS_${inline_keyword})
55-
set(C_INLINE TRUE)
56-
set(INLINE_KEYWORD "${inline_keyword}")
57-
endif()
58-
endif()
59-
endforeach()
38+
# Inspired from /usr/share/autoconf/autoconf/c.m4
39+
foreach(inline_keyword "inline" "__inline__" "__inline")
6040
if(NOT DEFINED C_INLINE)
61-
set(INLINE_KEYWORD)
62-
endif()
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)
6359
endif()
6460

6561

@@ -414,6 +410,7 @@ set(lib_srcs
414410
tif_write.c
415411
tif_zip.c
416412
tif_stream.cxx
413+
snprintf.c
417414
t4.h
418415
tif_dir.h
419416
tif_fax3.h

3rdparty/libtiff/snprintf.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Workaround for lack of snprintf(3) in Visual Studio. See
3+
* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010/8712996#8712996
4+
* It's a trivial wrapper around the builtin _vsnprintf_s and
5+
* _vscprintf functions.
6+
*/
7+
8+
#ifdef _MSC_VER
9+
10+
#include <stdio.h>
11+
#include <stdarg.h>
12+
13+
int _TIFF_vsnprintf_f(char* str, size_t size, const char* format, va_list ap)
14+
{
15+
int count = -1;
16+
17+
if (size != 0)
18+
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
19+
if (count == -1)
20+
count = _vscprintf(format, ap);
21+
22+
return count;
23+
}
24+
25+
int _TIFF_snprintf_f(char* str, size_t size, const char* format, ...)
26+
{
27+
int count;
28+
va_list ap;
29+
30+
va_start(ap, format);
31+
count = vsnprintf(str, size, format, ap);
32+
va_end(ap);
33+
34+
return count;
35+
}
36+
37+
#endif // _MSC_VER
38+

0 commit comments

Comments
 (0)