From 1ee12100b63344d228f2fa0533a551b71c27a85c Mon Sep 17 00:00:00 2001 From: Eric Hawicz Date: Sat, 5 Aug 2023 22:11:30 -0400 Subject: [PATCH] PR #679: add workaround for old compilers w/o stdint.h (i.e. VS2008 and earlier) --- CMakeLists.txt | 11 +++++++---- cmake/json_config.h.in | 3 +++ json_inttypes.h | 8 ++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d353c021..983148ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,11 +143,14 @@ check_include_file(sys/random.h HAVE_SYS_RANDOM_H) check_include_file(sys/stat.h HAVE_SYS_STAT_H) check_include_file(xlocale.h HAVE_XLOCALE_H) +# Set json-c specific vars to stamp into json_config.h +# in a way that hopefully won't conflict with other +# projects that use json-c. if (HAVE_INTTYPES_H) - # Set a json-c specific var to stamp into json_config.h - # in a way that hopefully won't conflict with other - # projects that use json-c. - set(JSON_C_HAVE_INTTYPES_H 1) + set(JSON_C_HAVE_INTTYPES_H 1) +endif() +if (HAVE_STDINT_H) + set(JSON_C_HAVE_STDINT_H 1) endif() check_symbol_exists(_isnan "float.h" HAVE_DECL__ISNAN) diff --git a/cmake/json_config.h.in b/cmake/json_config.h.in index f30d8a63..790fd7e3 100644 --- a/cmake/json_config.h.in +++ b/cmake/json_config.h.in @@ -1,2 +1,5 @@ /* Define to 1 if you have the header file. */ #cmakedefine JSON_C_HAVE_INTTYPES_H @JSON_C_HAVE_INTTYPES_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine JSON_C_HAVE_STDINT_H @JSON_C_HAVE_STDINT_H@ diff --git a/json_inttypes.h b/json_inttypes.h index a901a8ef..a33a31f1 100644 --- a/json_inttypes.h +++ b/json_inttypes.h @@ -13,7 +13,15 @@ #include #else +#ifdef JSON_C_HAVE_STDINT_H #include +#else +/* Really only valid for old MS compilers, VS2008 and earlier: */ +typedef __int32 int32_t; +typedef unsigned __int32 uint32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#endif #define PRId64 "I64d" #define SCNd64 "I64d" -- 2.39.5