Skip to content

FR: header-only amalgamation #981

@GitMensch

Description

@GitMensch

This could be done in three ways:

  1. documentation only "how to create that (may include 2 and/or 3)"
  2. release-only: a real single header file, created automatically (for example via Make) and uploaded to the release, either with a separate name like cjson_amalg.h / cjson_standalone.h or under cJSON.h
  3. a single file stored in this repo - either with a separate name like cjson_amalg.h / cjson_standalone.h or as plain cJSON.h

The following works for a single-header wrapper:

#define CJSON_HIDE_SYMBOLS
#include <cJSON/cJSON.h>
#include <cJSON/cJSON.c>

along with the following

cJSON.h (which could be a separate condition, of course):

 #if defined(CJSON_HIDE_SYMBOLS)
-#define CJSON_PUBLIC(type)   type CJSON_STDCALL
+#define CJSON_PUBLIC(type)   static type CJSON_STDCALL
 #elif defined(CJSON_EXPORT_SYMBOLS)

cJSON.c (which possibly should be declared as static instead of nothing or CJSON_PUBLIC in any case):

 /* Duplication */
-cJSON * cJSON_Duplicate_rec(const cJSON *item, size_t depth, cJSON_bool recurse);
+CJSON_PUBLIC(cJSON *) cJSON_Duplicate_rec(const cJSON *item, size_t depth, cJSON_bool recurse);
 
 CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse)
 {
     return cJSON_Duplicate_rec(item, 0, recurse );
 }
 
-cJSON * cJSON_Duplicate_rec(const cJSON *item, size_t depth, cJSON_bool recurse)
+CJSON_PUBLIC(cJSON *) cJSON_Duplicate_rec(const cJSON *item, size_t depth, cJSON_bool recurse)
 {

Use case: mostly "closed" environments where I can't easily adjust the build system to include cJSON.c (=currently need to do it each time)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions