From 9b9d2bb2da3c02855c6cc09ab4fddfb8eec61073 Mon Sep 17 00:00:00 2001 From: ichenq Date: Tue, 23 Dec 2014 15:32:49 +0800 Subject: [PATCH 1/2] Work around MSVC's C99 support inline ==> __inline snprintf ==> _snprintf strncasecmp ==> _strnicmp --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c17239b2..ca263814 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,13 @@ else() set(_lua_module_dir "${_lua_lib_dir}/lua/5.1") endif() +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + add_definitions(-Dinline=__inline) + add_definitions(-Dsnprintf=_snprintf) + add_definitions(-Dstrncasecmp=_strnicmp) +endif() + add_library(cjson MODULE lua_cjson.c strbuf.c ${FPCONV_SOURCES}) set_target_properties(cjson PROPERTIES PREFIX "") target_link_libraries(cjson ${_MODULE_LINK}) From d8485decd41cad682f873f9979dfd08659d66ac2 Mon Sep 17 00:00:00 2001 From: ichenq Date: Mon, 29 Dec 2014 10:54:47 +0800 Subject: [PATCH 2/2] CJSON_EXPORT for msvc --- lua_cjson.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua_cjson.c b/lua_cjson.c index c14a1c5c..d4622473 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -54,6 +54,12 @@ #define CJSON_VERSION "2.1devel" #endif +#ifdef _MSC_VER +#define CJSON_EXPORT __declspec(dllexport) +#else +#define CJSON_EXPORT extern +#endif + /* Workaround for Solaris platforms missing isinf() */ #if !defined(isinf) && (defined(USE_INTERNAL_ISINF) || defined(MISSING_ISINF)) #define isinf(x) (!isnan(x) && isnan((x) - (x))) @@ -1407,7 +1413,7 @@ static int lua_cjson_safe_new(lua_State *l) return 1; } -int luaopen_cjson(lua_State *l) +CJSON_EXPORT int luaopen_cjson(lua_State *l) { lua_cjson_new(l); @@ -1421,7 +1427,7 @@ int luaopen_cjson(lua_State *l) return 1; } -int luaopen_cjson_safe(lua_State *l) +CJSON_EXPORT int luaopen_cjson_safe(lua_State *l) { lua_cjson_safe_new(l);