Skip to content

Commit c057d29

Browse files
committed
fix compilation error on Visual Studio 2013 and earlier
- fix compilation error about "inline" - fix linker error about "_TIFF_snprintf_f"
1 parent 6cedc82 commit c057d29

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
@@ -34,31 +34,27 @@ if(NOT MSVC)
3434
check_include_file(unistd.h HAVE_UNISTD_H)
3535
endif()
3636

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

6460

@@ -413,6 +409,7 @@ set(lib_srcs
413409
tif_write.c
414410
tif_zip.c
415411
tif_stream.cxx
412+
snprintf.c
416413
t4.h
417414
tif_dir.h
418415
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)