Skip to content

Commit 00098ef

Browse files
committed
Merge branch 'json-c:master' into master
2 parents 9b53c92 + cd7109f commit 00098ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2427
-1360
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
# It's not good practice to build directly in the source tree
7171
# but ignore cmake auto-generated files anyway:
7272
/json_config.h
73+
/json.h
7374
/config.h
7475
/json-c.pc
7576
/Makefile
@@ -83,7 +84,7 @@
8384
/Testing/
8485

8586
# ...and build artifacts.
86-
/doc
87+
/doc/html
8788
/libjson-c.a
8889
/libjson-c.so
8990
/libjson-c.so.*

AUTHORS

+11
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ Christopher Head <[email protected]>
77
Chris Wolfe <[email protected]>
88
C. Watford ([email protected])
99
Darjan Krijan <[email protected]>
10+
David McCann <[email protected]>
11+
12+
Eric Haszlakiewicz <[email protected]>
1013
Eric Hawicz <[email protected]>
14+
Gianluigi Tiesi <[email protected]>
1115
16+
1217
Ivan Romanov <[email protected]>
1318
Jaap Keuter <[email protected]>
1419
@@ -18,13 +23,19 @@ Jonathan Wiens <[email protected]>
1823
Jose Bollo <[email protected]>
1924
Keith Holman <[email protected]>
2025
Liang, Gao <[email protected]>
26+
2127
28+
Micah Snyder <[email protected]>
2229
Michael Clark <[email protected]>
2330
31+
Pascal Cuoq <[email protected]>
2432
Pierce Lopez <[email protected]>
2533
Po-Chuan Hsieh <[email protected]>
2634
Ramiro Polla <[email protected]>
2735
Rikard Falkeborn <[email protected]>
2836
2937
Rubasri Kalidas <[email protected]>
38+
Simon McVittie <[email protected]>
39+
Tobias Stoeckmann <[email protected]>
40+
Tudor Brindus <[email protected]>
3041
Unmanned Player <[email protected]>

CMakeLists.txt

+99-43
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ if(POLICY CMP0048)
77
endif()
88

99
# JSON-C library is C only project.
10-
project(json-c LANGUAGES C VERSION 0.14.99)
10+
if (CMAKE_VERSION VERSION_LESS 3.0)
11+
project(json-c)
12+
set(PROJECT_VERSION_MAJOR "0")
13+
set(PROJECT_VERSION_MINOR "15")
14+
set(PROJECT_VERSION_PATCH "99")
15+
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
16+
else()
17+
project(json-c LANGUAGES C VERSION 0.15.99)
18+
endif()
1119

1220
# If we've got 3.0 then it's good, let's provide support. Otherwise, leave it be.
1321
if(POLICY CMP0038)
@@ -71,6 +79,10 @@ include(CMakePackageConfigHelpers)
7179
option(BUILD_SHARED_LIBS "Default to building shared libraries" ON)
7280
option(BUILD_STATIC_LIBS "Default to building static libraries" ON)
7381

82+
if (BUILD_SHARED_LIBS)
83+
add_definitions(-D JSON_C_DLL)
84+
endif()
85+
7486
# Generate a release merge and test it to verify the correctness of republishing the package.
7587
ADD_CUSTOM_TARGET(distcheck
7688
COMMAND make package_source
@@ -83,10 +95,15 @@ COMMAND make package_source
8395
)
8496

8597
# Enable or disable features. By default, all features are turned off.
86-
option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed" OFF)
87-
option(ENABLE_THREADING "Enable partial threading support." OFF)
88-
option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors" OFF)
89-
option(DISABLE_BSYMBOLIC "Avoid linking with -Bsymbolic-function" OFF)
98+
option(DISABLE_BSYMBOLIC "Avoid linking with -Bsymbolic-function." OFF)
99+
option(DISABLE_THREAD_LOCAL_STORAGE "Disable using Thread-Local Storage (HAVE___THREAD)." OFF)
100+
option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors." OFF)
101+
option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed." OFF)
102+
option(ENABLE_THREADING "Enable partial threading support." OFF)
103+
option(OVERRIDE_GET_RANDOM_SEED "Override json_c_get_random_seed() with custom code." OFF)
104+
option(DISABLE_EXTRA_LIBS "Avoid linking against extra libraries, such as libbsd." OFF)
105+
option(DISABLE_JSON_POINTER "Disable JSON pointer (RFC6901) support." OFF)
106+
90107

91108
if (UNIX OR MINGW OR CYGWIN)
92109
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
@@ -101,6 +118,14 @@ if (MSVC)
101118
list(APPEND CMAKE_REQUIRED_FLAGS /wd4996)
102119
endif()
103120

121+
if (NOT DISABLE_STATIC_FPIC)
122+
# Use '-fPIC'/'-fPIE' option.
123+
# This will allow other libraries to statically link in libjson-c.a
124+
# which in turn prevents crashes in downstream apps that may use
125+
# a different JSON library with identical symbol names.
126+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
127+
endif()
128+
104129
check_include_file("fcntl.h" HAVE_FCNTL_H)
105130
check_include_file("inttypes.h" HAVE_INTTYPES_H)
106131
check_include_file(stdarg.h HAVE_STDARG_H)
@@ -125,6 +150,7 @@ check_include_file(stdint.h HAVE_STDINT_H)
125150
check_include_file(stdlib.h HAVE_STDLIB_H)
126151
check_include_file(sys/cdefs.h HAVE_SYS_CDEFS_H)
127152
check_include_file(sys/param.h HAVE_SYS_PARAM_H)
153+
check_include_file(sys/random.h HAVE_SYS_RANDOM_H)
128154
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
129155
check_include_file(xlocale.h HAVE_XLOCALE_H)
130156

@@ -150,6 +176,17 @@ check_symbol_exists(vasprintf "stdio.h" HAVE_VASPRINTF)
150176
check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF)
151177
check_symbol_exists(vprintf "stdio.h" HAVE_VPRINTF)
152178

179+
check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM)
180+
if (NOT HAVE_ARC4RANDOM AND DISABLE_EXTRA_LIBS STREQUAL "OFF")
181+
check_include_file(bsd/stdlib.h HAVE_BSD_STDLIB_H)
182+
if (HAVE_BSD_STDLIB_H)
183+
list(APPEND CMAKE_REQUIRED_LIBRARIES "-lbsd")
184+
link_libraries(bsd)
185+
unset(HAVE_ARC4RANDOM CACHE)
186+
check_symbol_exists(arc4random "bsd/stdlib.h" HAVE_ARC4RANDOM)
187+
endif()
188+
endif()
189+
153190
if (HAVE_FCNTL_H)
154191
check_symbol_exists(open "fcntl.h" HAVE_OPEN)
155192
endif()
@@ -171,6 +208,9 @@ endif()
171208
if (HAVE_SYSLOG_H)
172209
check_symbol_exists(vsyslog "syslog.h" HAVE_VSYSLOG)
173210
endif()
211+
if (HAVE_SYS_RANDOM_H)
212+
check_symbol_exists(getrandom "sys/random.h" HAVE_GETRANDOM)
213+
endif()
174214
if (HAVE_SYS_RESOURCE_H)
175215
check_symbol_exists(getrusage "sys/resource.h" HAVE_GETRUSAGE)
176216
endif()
@@ -204,27 +244,35 @@ check_type_size(int64_t SIZEOF_INT64_T)
204244
check_type_size(long SIZEOF_LONG)
205245
check_type_size("long long" SIZEOF_LONG_LONG)
206246
check_type_size("size_t" SIZEOF_SIZE_T)
247+
if (MSVC)
248+
list(APPEND CMAKE_EXTRA_INCLUDE_FILES BaseTsd.h)
249+
check_type_size("SSIZE_T" SIZEOF_SSIZE_T)
250+
else()
251+
check_type_size("ssize_t" SIZEOF_SSIZE_T)
252+
endif()
207253

208254
check_c_source_compiles(
209-
[=[
255+
"
210256
extern void json_object_get();
211-
__asm__(".section .gnu.json_object_get\\n\\t.ascii \\"Please link against libjson-c instead of libjson\\"\\n\\t.text");
257+
__asm__(\".section .gnu.json_object_get\\n\\t.ascii \\\"Please link against libjson-c instead of libjson\\\"\\n\\t.text\");
212258
int main(int c, char *v) { return 0;}
213-
]=]
259+
"
214260
HAS_GNU_WARNING_LONG)
215261

216262
check_c_source_compiles(
217263
"int main() { int i, x = 0; i = __sync_add_and_fetch(&x,1); return x; }"
218264
HAVE_ATOMIC_BUILTINS)
219265

220-
check_c_source_compiles(
221-
"__thread int x = 0; int main() { return 0; }"
222-
HAVE___THREAD)
266+
if (NOT DISABLE_THREAD_LOCAL_STORAGE)
267+
check_c_source_compiles(
268+
"__thread int x = 0; int main() { return 0; }"
269+
HAVE___THREAD)
223270

224-
if (HAVE___THREAD)
225-
set(SPEC___THREAD __thread)
226-
elseif (MSVC)
227-
set(SPEC___THREAD __declspec(thread))
271+
if (HAVE___THREAD)
272+
set(SPEC___THREAD __thread)
273+
elseif (MSVC)
274+
set(SPEC___THREAD __declspec(thread))
275+
endif()
228276
endif()
229277

230278
# Hardware random number is not available on Windows? Says, config.h.win32. Best to preserve compatibility.
@@ -234,11 +282,11 @@ endif()
234282

235283
# Once we've done basic symbol/header searches let's add them in.
236284
configure_file(${PROJECT_SOURCE_DIR}/cmake/config.h.in ${PROJECT_BINARY_DIR}/config.h)
237-
message(STATUS "Written ${PROJECT_BINARY_DIR}/config.h")
285+
message(STATUS "Wrote ${PROJECT_BINARY_DIR}/config.h")
238286
configure_file(${PROJECT_SOURCE_DIR}/cmake/json_config.h.in ${PROJECT_BINARY_DIR}/json_config.h)
239-
message(STATUS "Written ${PROJECT_BINARY_DIR}/json_config.h")
287+
message(STATUS "Wrote ${PROJECT_BINARY_DIR}/json_config.h")
240288

241-
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
289+
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
242290
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections")
243291
if ("${DISABLE_WERROR}" STREQUAL "OFF")
244292
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
@@ -267,15 +315,15 @@ endif()
267315

268316
if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"))
269317
check_c_source_compiles(
270-
[=[
318+
"
271319
/* uClibc toolchains without threading barf when _REENTRANT is defined */
272320
#define _REENTRANT 1
273321
#include <sys/types.h>
274322
int main (void)
275323
{
276324
return 0;
277325
}
278-
]=]
326+
"
279327
REENTRANT_WORKS
280328
)
281329
if (REENTRANT_WORKS)
@@ -286,12 +334,12 @@ if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"))
286334
# Others may not support it, too.
287335
list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions")
288336
check_c_source_compiles(
289-
[=[
337+
"
290338
int main (void)
291339
{
292340
return 0;
293341
}
294-
]=]
342+
"
295343
BSYMBOLIC_WORKS
296344
)
297345
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions")
@@ -300,6 +348,22 @@ if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"))
300348
# XXX need cmake>=3.13 for this:
301349
#add_link_options("-Wl,-Bsymbolic-functions")
302350
endif()
351+
352+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/check-version-script.sym" "TEST { global: *; };")
353+
list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/check-version-script.sym")
354+
check_c_source_compiles(
355+
"
356+
int main (void)
357+
{
358+
return 0;
359+
}
360+
"
361+
VERSION_SCRIPT_WORKS
362+
)
363+
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/check-version-script.sym")
364+
if (VERSION_SCRIPT_WORKS)
365+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/json-c.sym")
366+
endif()
303367
endif()
304368

305369
if ($ENV{VALGRIND})
@@ -311,14 +375,13 @@ set(JSON_C_PUBLIC_HEADERS
311375
# Note: config.h is _not_ included here
312376
${PROJECT_BINARY_DIR}/json_config.h
313377

314-
${PROJECT_SOURCE_DIR}/json.h
378+
${PROJECT_BINARY_DIR}/json.h
315379
${PROJECT_SOURCE_DIR}/arraylist.h
316380
${PROJECT_SOURCE_DIR}/debug.h
317381
${PROJECT_SOURCE_DIR}/json_c_version.h
318382
${PROJECT_SOURCE_DIR}/json_inttypes.h
319383
${PROJECT_SOURCE_DIR}/json_object.h
320384
${PROJECT_SOURCE_DIR}/json_object_iterator.h
321-
${PROJECT_SOURCE_DIR}/json_pointer.h
322385
${PROJECT_SOURCE_DIR}/json_tokener.h
323386
${PROJECT_SOURCE_DIR}/json_types.h
324387
${PROJECT_SOURCE_DIR}/json_util.h
@@ -345,7 +408,6 @@ set(JSON_C_SOURCES
345408
${PROJECT_SOURCE_DIR}/json_c_version.c
346409
${PROJECT_SOURCE_DIR}/json_object.c
347410
${PROJECT_SOURCE_DIR}/json_object_iterator.c
348-
${PROJECT_SOURCE_DIR}/json_pointer.c
349411
${PROJECT_SOURCE_DIR}/json_tokener.c
350412
${PROJECT_SOURCE_DIR}/json_util.c
351413
${PROJECT_SOURCE_DIR}/json_visit.c
@@ -355,26 +417,20 @@ set(JSON_C_SOURCES
355417
${PROJECT_SOURCE_DIR}/strerror_override.c
356418
)
357419

358-
include_directories(${PROJECT_SOURCE_DIR})
359-
include_directories(${PROJECT_BINARY_DIR})
360-
361-
# generate doxygen documentation for json-c API
362-
363-
find_package(Doxygen)
364-
option(BUILD_DOCUMENTATION "Create and install the HTML based API documentation(requires Doxygen)" ${DOXYGEN_FOUND})
365-
366-
if (DOXYGEN_FOUND)
420+
if (NOT DISABLE_JSON_POINTER)
421+
set(JSON_C_PUBLIC_HEADERS ${JSON_C_PUBLIC_HEADERS} ${PROJECT_SOURCE_DIR}/json_pointer.h)
422+
set(JSON_C_SOURCES ${JSON_C_SOURCES} ${PROJECT_SOURCE_DIR}/json_pointer.c)
423+
set(JSON_H_JSON_POINTER "#include \"json_pointer.h\"")
424+
else()
425+
set(JSON_H_JSON_POINTER "")
426+
endif()
367427

368-
add_custom_target(doc
369-
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_SOURCE_DIR}/Doxyfile
370-
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
428+
configure_file(json.h.cmakein ${PROJECT_BINARY_DIR}/json.h @ONLY)
371429

372-
# request to configure the file
373-
configure_file(Doxyfile Doxyfile)
430+
include_directories(${PROJECT_SOURCE_DIR})
431+
include_directories(${PROJECT_BINARY_DIR})
374432

375-
else (DOXYGEN_FOUND)
376-
message("Warning: doxygen not found, the 'doc' target will not be included")
377-
endif(DOXYGEN_FOUND)
433+
add_subdirectory(doc)
378434

379435
# uninstall
380436
add_custom_target(uninstall
@@ -390,7 +446,7 @@ add_library(${PROJECT_NAME}
390446
${JSON_C_HEADERS}
391447
)
392448
set_target_properties(${PROJECT_NAME} PROPERTIES
393-
VERSION 5.0.0
449+
VERSION 5.1.0
394450
SOVERSION 5)
395451
list(APPEND CMAKE_TARGETS ${PROJECT_NAME})
396452
# If json-c is used as subroject it set to target correct interface -I flags and allow

0 commit comments

Comments
 (0)