Disables shared libraries for WASI only and makes sure compat doesn't redefine builtins.pull/825/head
| @@ -65,6 +65,10 @@ include(CMakePackageConfigHelpers) | |||||
| option(BUILD_SHARED_LIBS "Default to building shared libraries" ON) | option(BUILD_SHARED_LIBS "Default to building shared libraries" ON) | ||||
| option(BUILD_STATIC_LIBS "Default to building static libraries" ON) | option(BUILD_STATIC_LIBS "Default to building static libraries" ON) | ||||
| if (CMAKE_SYSTEM_NAME STREQUAL "WASI") | |||||
| set(BUILD_SHARED_LIBS OFF) | |||||
| endif() | |||||
| if (BUILD_SHARED_LIBS) | if (BUILD_SHARED_LIBS) | ||||
| add_definitions(-D JSON_C_DLL) | add_definitions(-D JSON_C_DLL) | ||||
| endif() | endif() | ||||
| @@ -560,6 +564,7 @@ install(FILES ${JSON_C_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_FULL_INCLUDED | |||||
| if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING AND | if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING AND | ||||
| (NOT MSVC OR NOT (MSVC_VERSION LESS 1800)) # Tests need at least VS2013 | (NOT MSVC OR NOT (MSVC_VERSION LESS 1800)) # Tests need at least VS2013 | ||||
| AND NOT (CMAKE_SYSTEM_NAME STREQUAL "WASI") | |||||
| ) | ) | ||||
| add_subdirectory(tests) | add_subdirectory(tests) | ||||
| endif() | endif() | ||||
| @@ -13,29 +13,35 @@ | |||||
| #include <float.h> | #include <float.h> | ||||
| #define isnan(x) _isnan(x) | #define isnan(x) _isnan(x) | ||||
| #else | #else | ||||
| #ifndef __wasi__ | |||||
| /* On platforms like AIX and "IBM i" we need to provide our own isnan */ | /* On platforms like AIX and "IBM i" we need to provide our own isnan */ | ||||
| #define isnan(x) ((x) != (x)) | #define isnan(x) ((x) != (x)) | ||||
| #endif | #endif | ||||
| #endif | #endif | ||||
| #endif | |||||
| #ifndef HAVE_DECL_ISINF | #ifndef HAVE_DECL_ISINF | ||||
| #ifdef HAVE_DECL__FINITE | #ifdef HAVE_DECL__FINITE | ||||
| #include <float.h> | #include <float.h> | ||||
| #define isinf(x) (!_finite(x)) | #define isinf(x) (!_finite(x)) | ||||
| #else | #else | ||||
| #ifndef __wasi__ | |||||
| #include <float.h> | #include <float.h> | ||||
| /* On platforms like AIX and "IBM i" we need to provide our own isinf */ | /* On platforms like AIX and "IBM i" we need to provide our own isinf */ | ||||
| #define isinf(x) ((x) < -DBL_MAX || (x) > DBL_MAX) | #define isinf(x) ((x) < -DBL_MAX || (x) > DBL_MAX) | ||||
| #endif | #endif | ||||
| #endif | #endif | ||||
| #endif | |||||
| #ifndef HAVE_DECL_INFINITY | #ifndef HAVE_DECL_INFINITY | ||||
| #ifndef __wasi__ | |||||
| #include <float.h> | #include <float.h> | ||||
| #define INFINITY (DBL_MAX + DBL_MAX) | #define INFINITY (DBL_MAX + DBL_MAX) | ||||
| #define HAVE_DECL_INFINITY | #define HAVE_DECL_INFINITY | ||||
| #endif | #endif | ||||
| #endif | |||||
| #ifndef HAVE_DECL_NAN | |||||
| #if !defined(HAVE_DECL_NAN) && !defined(__wasi__) | |||||
| #define NAN (INFINITY - INFINITY) | #define NAN (INFINITY - INFINITY) | ||||
| #define HAVE_DECL_NAN | #define HAVE_DECL_NAN | ||||
| #endif | #endif | ||||
| @@ -34,6 +34,27 @@ static int json_c_snprintf(char *str, size_t size, const char *format, ...) | |||||
| } | } | ||||
| #define snprintf json_c_snprintf | #define snprintf json_c_snprintf | ||||
| #elif (defined(__wasi__)) | |||||
| static int json_c_vsnprintf(char *str, size_t size, const char *format, va_list ap) | |||||
| { | |||||
| int ret; | |||||
| ret = vsnprintf(str, size, format, ap); | |||||
| str[size - 1] = '\0'; | |||||
| return ret; | |||||
| } | |||||
| #define vsnprintf json_c_vsnprintf | |||||
| __attribute__((unused)) | |||||
| static int json_c_snprintf(char *str, size_t size, const char *format, ...) | |||||
| { | |||||
| va_list ap; | |||||
| int ret; | |||||
| va_start(ap, format); | |||||
| ret = json_c_vsnprintf(str, size, format, ap); | |||||
| va_end(ap); | |||||
| return ret; | |||||
| } | |||||
| #define snprintf json_c_snprintf | |||||
| #elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */ | #elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */ | ||||
| #error snprintf is required but was not found | #error snprintf is required but was not found | ||||
| #endif /* !HAVE_SNPRINTF && defined(WIN32) */ | #endif /* !HAVE_SNPRINTF && defined(WIN32) */ | ||||