changeset 5:9870264521f7

jansson: fix MSVC 2015 compilation
author David Demelier <markand@malikania.fr>
date Thu, 25 Feb 2016 09:01:37 +0100
parents 2306f4b04790
children 51a817a269c5
files jansson/CMakeLists.txt jansson/cmake/jansson_private_config.h.cmake jansson/patch/snprintf.patch jansson/src/jansson_private.h
diffstat 4 files changed, 85 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/jansson/CMakeLists.txt	Wed Feb 24 21:19:28 2016 +0100
+++ b/jansson/CMakeLists.txt	Thu Feb 25 09:01:37 2016 +0100
@@ -40,17 +40,6 @@
 include(CheckIncludeFiles)
 include(CheckTypeSize)
 
-if (MSVC)
-	add_definitions("/W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /nologo")
-	
-	set(CMAKE_C_FLAGS_RELEASE "/MT")
-	set(CMAKE_C_FLAGS_DEBUG "/MTd")
-endif()
-
-if (NOT WIN32 AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX))
-	add_definitions("-fPIC")
-endif()
-
 check_include_files(endian.h HAVE_ENDIAN_H)
 check_include_files(fcntl.h HAVE_FCNTL_H)
 check_include_files(sched.h HAVE_SCHED_H)
@@ -272,3 +261,8 @@
 	PUBLIC ${jansson_BINARY_DIR}/include
 	PRIVATE ${jansson_BINARY_DIR}/private_include
 )
+
+if (MSVC)
+	target_compile_definitions(jansson PUBLIC _CRT_SECURE_NO_WARNINGS)
+	target_compile_options(jansson PUBLIC /W3 /D /wd4005 /wd4996 /wd4334 /wd4267)
+endif()
--- a/jansson/cmake/jansson_private_config.h.cmake	Wed Feb 24 21:19:28 2016 +0100
+++ b/jansson/cmake/jansson_private_config.h.cmake	Thu Feb 25 09:01:37 2016 +0100
@@ -49,6 +49,20 @@
 
 #cmakedefine HAVE_SNPRINTF 1
 
+/* snprintf should not be defined as macro with MSC_VER >= 1900 */
+#if defined(_WIN32) || defined(WIN32)
+#  if defined(_MSC_VER)  /* MS compiller */
+#    if (_MSC_VER < 1900)  /* snprintf not introduced */
+#      if !defined(snprintf)
+#        define snprintf _snprintf
+#        define HAVE_SNPRINTF 1 /* snprintf defined manually */
+#      endif
+#    else
+#      define HAVE_SNPRINTF 1 /* snprintf available via sdk */
+#    endif
+#  endif
+#endif
+
 #ifndef HAVE_SNPRINTF
 #  define snprintf @JSON_SNPRINTF@
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jansson/patch/snprintf.patch	Thu Feb 25 09:01:37 2016 +0100
@@ -0,0 +1,53 @@
+diff --git a/cmake/jansson_private_config.h.cmake b/cmake/jansson_private_config.h.cmake
+index ee1078f..ac7318f 100644
+--- a/cmake/jansson_private_config.h.cmake
++++ b/cmake/jansson_private_config.h.cmake
+@@ -49,6 +49,20 @@
+ 
+ #cmakedefine HAVE_SNPRINTF 1
+ 
++/* snprintf should not be defined as macro with MSC_VER >= 1900 */
++#if defined(_WIN32) || defined(WIN32)
++#  if defined(_MSC_VER)  /* MS compiller */
++#    if (_MSC_VER < 1900)  /* snprintf not introduced */
++#      if !defined(snprintf)
++#        define snprintf _snprintf
++#        define HAVE_SNPRINTF 1 /* snprintf defined manually */
++#      endif
++#    else
++#      define HAVE_SNPRINTF 1 /* snprintf available via sdk */
++#    endif
++#  endif
++#endif
++
+ #ifndef HAVE_SNPRINTF
+ #  define snprintf @JSON_SNPRINTF@
+ #endif
+diff --git a/src/jansson_private.h b/src/jansson_private.h
+index e100726..ccb3a57 100644
+--- a/src/jansson_private.h
++++ b/src/jansson_private.h
+@@ -90,10 +90,20 @@ char *jsonp_strndup(const char *str, size_t length);
+ char *jsonp_strdup(const char *str);
+ char *jsonp_strndup(const char *str, size_t len);
+ 
++
+ /* Windows compatibility */
+-#ifdef _WIN32
+-#define snprintf _snprintf
+-#define vsnprintf _vsnprintf
++#if defined(_WIN32) || defined(WIN32)
++#  if defined(_MSC_VER)  /* MS compiller */
++#    if (_MSC_VER < 1900) && !defined(snprintf)  /* snprintf not defined yet & not introduced */
++#      define snprintf _snprintf
++#    endif
++#    if (_MSC_VER < 1500) && !defined(vsnprintf)  /* vsnprintf not defined yet & not introduced */
++#      define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a)
++#    endif
++#  else  /* Other Windows compiller, old definition */
++#    define snprintf _snprintf
++#    define vsnprintf _vsnprintf
++#  endif
+ #endif
+ 
+ #endif
--- a/jansson/src/jansson_private.h	Wed Feb 24 21:19:28 2016 +0100
+++ b/jansson/src/jansson_private.h	Thu Feb 25 09:01:37 2016 +0100
@@ -90,10 +90,20 @@
 char *jsonp_strdup(const char *str);
 char *jsonp_strndup(const char *str, size_t len);
 
+
 /* Windows compatibility */
-#ifdef _WIN32
-#define snprintf _snprintf
-#define vsnprintf _vsnprintf
+#if defined(_WIN32) || defined(WIN32)
+#  if defined(_MSC_VER)  /* MS compiller */
+#    if (_MSC_VER < 1900) && !defined(snprintf)  /* snprintf not defined yet & not introduced */
+#      define snprintf _snprintf
+#    endif
+#    if (_MSC_VER < 1500) && !defined(vsnprintf)  /* vsnprintf not defined yet & not introduced */
+#      define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a)
+#    endif
+#  else  /* Other Windows compiller, old definition */
+#    define snprintf _snprintf
+#    define vsnprintf _vsnprintf
+#  endif
 #endif
 
 #endif