Skip to content

Commit

Permalink
Merge pull request #66 from DaveGamble/v1
Browse files Browse the repository at this point in the history
Release version 1.0.0
  • Loading branch information
FSMaxB authored Nov 17, 2016
2 parents 0d10e27 + 3a2151d commit aafb64a
Show file tree
Hide file tree
Showing 11 changed files with 575 additions and 203 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ test
*.patch
tags
*.dylib
build/
113 changes: 92 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,110 @@
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
cmake_minimum_required(VERSION 2.8)

set(PROJ_CJSON cJSON)
include(GNUInstallDirs)

project(${PROJ_CJSON} C)
project(cJSON C)

set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)
set(CJSON_VERSION_SO 1)
set(CJSON_UTILS_VERSION_SO 1)
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

option(ENABLE_CUSTOM_COMPILER_FLAGS ON)
if (ENABLE_CUSTOM_COMPILER_FLAGS)
if(("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang"))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89 -pedantic -Wall -Wextra -Werror -Wstrict-prototypes -Wwrite-strings")
endif()
endif()

#variables for pkg-config
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(libdir "${CMAKE_INSTALL_LIBDIR}")
set(version "${PROJECT_VERSION}")
set(includedir "${CMAKE_INSTALL_INCLUDEDIR}")

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ENABLE_TARGET_EXPORT "Enable exporting of CMake targets. Disable when it causes problems!" ON)

#cJSON
set(CJSON_LIB cjson)

file(GLOB HEADERS cJSON.h)
set(SOURCES cJSON.c)

add_library(${PROJ_CJSON} ${HEADERS} ${SOURCES})
add_library("${CJSON_LIB}" "${HEADERS}" "${SOURCES}")
if (NOT WIN32)
target_link_libraries(${PROJ_CJSON} m)
target_link_libraries("${CJSON_LIB}" m)
endif()

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libcjson.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" @ONLY)

install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(TARGETS "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_LIB}")
if(ENABLE_TARGET_EXPORT)
# export library information for CMake projects
install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
endif()

set(PROJ_CJSON_UTILS cJSON_utils)
set_target_properties("${CJSON_LIB}"
PROPERTIES
SOVERSION "${CJSON_VERSION_SO}"
VERSION "${PROJECT_VERSION}")

#cJSON_Utils
option(ENABLE_CJSON_UTILS "Enable building the cJSON_Utils library." OFF)
if(ENABLE_CJSON_UTILS)
set(CJSON_UTILS_LIB cjson_utils)

file(GLOB HEADERS_UTILS cJSON_Utils.h)
set(SOURCES_UTILS cJSON_Utils.c)

project(${PROJ_CJSON_UTILS} C)
add_library("${CJSON_UTILS_LIB}" "${HEADERS_UTILS}" "${SOURCES_UTILS}")
target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}")

file(GLOB HEADERS_UTILS cJSON_Utils.h)
set(SOURCES_UTILS cJSON_Utils.c)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libcjson_utils.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY)

install(TARGETS "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_UTILS_LIB}")
install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
if(ENABLE_TARGET_EXPORT)
# export library information for CMake projects
install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
endif()

set_target_properties("${CJSON_UTILS_LIB}"
PROPERTIES
SOVERSION "${CJSON_UTILS_VERSION_SO}"
VERSION "${PROJECT_VERSION}")
endif()

add_library(${PROJ_CJSON_UTILS} ${HEADERS_UTILS} ${SOURCES_UTILS})
target_link_libraries(${PROJ_CJSON_UTILS} ${PROJ_CJSON})
# create the other package config files
configure_file(
cJSONConfig.cmake.in
${PROJECT_BINARY_DIR}/cJSONConfig.cmake @ONLY)
configure_file(
cJSONConfigVersion.cmake.in
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake @ONLY)

install (TARGETS ${PROJ_CJSON} DESTINATION lib${LIB_SUFFIX})
install (FILES cJSON.h DESTINATION include/cJSON)
install (TARGETS ${PROJ_CJSON_UTILS} DESTINATION lib${LIB_SUFFIX})
install (FILES cJSON_Utils.h DESTINATION include/cJSON)
# Install package config files
install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")

option(ENABLE_CJSON_TEST "Enable building cJSON test" OFF)
option(ENABLE_CJSON_TEST "Enable building cJSON test" ON)
if(ENABLE_CJSON_TEST)
set(TEST_CJSON cJSON_test)
add_executable(${TEST_CJSON} test.c)
target_link_libraries(${TEST_CJSON} ${PROJ_CJSON})
set(TEST_CJSON cJSON_test)
add_executable("${TEST_CJSON}" test.c)
target_link_libraries("${TEST_CJSON}" "${CJSON_LIB}")

set(TEST_CJSON_UTILS cJSON_test_utils)
add_executable(${TEST_CJSON_UTILS} test_utils.c)
target_link_libraries(${TEST_CJSON_UTILS} ${PROJ_CJSON_UTILS})
if(ENABLE_CJSON_UTILS)
set(TEST_CJSON_UTILS cJSON_test_utils)
add_executable("${TEST_CJSON_UTILS}" test_utils.c)
target_link_libraries("${TEST_CJSON_UTILS}" "${CJSON_UTILS_LIB}")
endif()
endif()
27 changes: 27 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Contributors
============

* [Ajay Bhargav](https://github.com/ajaybhargav)
* [Anton Sergeev](https://github.com/anton-sergeev)
* [Christian Schulze](https://github.com/ChristianSch)
* [Dave Gamble](https://github.com/DaveGamble)
* [dieyushi](https://github.com/dieyushi)
* [Dongwen Huang (黄东文)](https://github.com/DongwenHuang)
* Eswar Yaganti
* [Evan Todd](https://github.com/etodd)
* [Fabrice Fontaine](https://github.com/ffontaine)
* Ian Mobley
* Irwan Djadjadi
* [IvanVoid](https://github.com/npi3pak)
* [Jonathan Fether](https://github.com/jfether)
* [Kevin Branigan](https://github.com/kbranigan)
* [Linus Wallgren](https://github.com/ecksun)
* [Max Bruckner](https://github.com/FSMaxB)
* Mike Pontillo
* Paulo Antonio Alvarez
* [Rafael Leal Dias](https://github.com/rafaeldias)
* [Rod Vagg](https://github.com/rvagg)
* [Roland Meertens](https://github.com/rmeertens)
* [Weston Schmidt](https://github.com/schmidtw)

And probably more people on [SourceForge](https://sourceforge.net/p/cjson/bugs/search/?q=status%3Aclosed-rejected+or+status%3Aclosed-out-of-date+or+status%3Awont-fix+or+status%3Aclosed-fixed+or+status%3Aclosed&page=0)
159 changes: 120 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
OBJ = cJSON.o
LIBNAME = libcjson
TESTS = test
CJSON_OBJ = cJSON.o
UTILS_OBJ = cJSON_Utils.o
CJSON_LIBNAME = libcjson
UTILS_LIBNAME = libcjson_utils
CJSON_TEST = cJSON_test
UTILS_TEST = cJSON_test_utils

LDLIBS = -lm

LIBVERSION = 1.0.0
CJSON_SOVERSION = 1
UTILS_SOVERSION = 1

PREFIX ?= /usr/local
INCLUDE_PATH ?= include/cjson
Expand All @@ -11,54 +20,126 @@ INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH)

INSTALL ?= cp -a

R_CFLAGS = -fpic $(CFLAGS) -Wall -Werror -Wstrict-prototypes -Wwrite-strings -D_POSIX_C_SOURCE=200112L
R_CFLAGS = -fPIC -std=c89 -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings $(CFLAGS)

uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo false')
uname := $(shell sh -c 'uname -s 2>/dev/null || echo false')

## shared lib
DYLIBNAME = $(LIBNAME).so
DYLIBCMD = $(CC) -shared -o $(DYLIBNAME)
#library file extensions
SHARED = so
STATIC = a

## create dynamic (shared) library on Darwin (base OS for MacOSX and IOS)
ifeq (Darwin, $(uname_S))
DYLIBNAME = $(LIBNAME).dylib
## create dyanmic (shared) library on SunOS
else ifeq (SunOS, $(uname_S))
DYLIBCMD = $(CC) -G -o $(DYLIBNAME)
INSTALL = cp -r
ifeq (Darwin, $(uname))
SHARED = dylib
endif

## static lib
STLIBNAME = $(LIBNAME).a
#cJSON library names
CJSON_SHARED = $(CJSON_LIBNAME).$(SHARED)
CJSON_SHARED_VERSION = $(CJSON_LIBNAME).$(SHARED).$(LIBVERSION)
CJSON_SHARED_SO = $(CJSON_LIBNAME).$(SHARED).$(CJSON_SOVERSION)
CJSON_STATIC = $(CJSON_LIBNAME).$(STATIC)

.PHONY: all clean install
#cJSON_Utils library names
UTILS_SHARED = $(UTILS_LIBNAME).$(SHARED)
UTILS_SHARED_VERSION = $(UTILS_LIBNAME).$(SHARED).$(LIBVERSION)
UTILS_SHARED_SO = $(UTILS_LIBNAME).$(SHARED).$(UTILS_SOVERSION)
UTILS_STATIC = $(UTILS_LIBNAME).$(STATIC)

all: $(DYLIBNAME) $(STLIBNAME) $(TESTS)
SHARED_CMD = $(CC) -shared -o

$(DYLIBNAME): $(OBJ)
$(DYLIBCMD) $< $(LDFLAGS)

$(STLIBNAME): $(OBJ)
$(AR) rcs $@ $<
.PHONY: all shared static tests clean install

$(OBJ): cJSON.c cJSON.h
all: shared static tests

.c.o:
$(CC) -ansi -pedantic -c $(R_CFLAGS) $<
shared: $(CJSON_SHARED) $(UTILS_SHARED)

$(TESTS): cJSON.c cJSON.h test.c
$(CC) cJSON.c test.c -o test -lm -I.
static: $(CJSON_STATIC) $(UTILS_STATIC)

install: $(DYLIBNAME) $(STLIBNAME)
mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH)
$(INSTALL) cJSON.h $(INSTALL_INCLUDE_PATH)
$(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)
$(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH)
tests: $(CJSON_TEST) $(UTILS_TEST)

uninstall:
rm -rf $(INSTALL_LIBRARY_PATH)/$(DYLIBNAME)
rm -rf $(INSTALL_LIBRARY_PATH)/$(STLIBNAME)
rm -rf $(INSTALL_INCLUDE_PATH)/cJSON.h
test: tests
./$(CJSON_TEST)
./$(UTILS_TEST)

clean:
rm -rf $(DYLIBNAME) $(STLIBNAME) $(TESTS) *.o
.c.o:
$(CC) -ansi -pedantic -c $(R_CFLAGS) $<

#tests
#cJSON
$(CJSON_TEST): cJSON.c cJSON.h test.c
$(CC) $^ -o $@ $(LDLIBS) -I.
#cJSON_Utils
$(UTILS_TEST): cJSON.c cJSON.h test.c
$(CC) $^ -o $@ $(LDLIBS) -I.

#static libraries
#cJSON
$(CJSON_STATIC): $(CJSON_OBJ)
$(AR) rcs $@ $<
#cJSON_Utils
$(UTILS_STATIC): $(UTILS_OBJ)
$(AR) rcs $@ $<

#shared libraries .so.1.0.0
#cJSON
$(CJSON_SHARED_VERSION): $(CJSON_OBJ)
$(CC) -shared -o $@ $< $(LDFLAGS)
#cJSON_Utils
$(UTILS_SHARED_VERSION): $(UTILS_OBJ)
$(CC) -shared -o $@ $< $(LDFLAGS)

#objects
#cJSON
$(CJSON_OBJ): cJSON.c cJSON.h
#cJSON_Utils
$(UTILS_OBJ): cJSON_Utils.c cJSON_Utils.h


#links .so -> .so.1 -> .so.1.0.0
#cJSON
$(CJSON_SHARED_SO): $(CJSON_SHARED_VERSION)
ln -s $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO)
$(CJSON_SHARED): $(CJSON_SHARED_SO)
ln -s $(CJSON_SHARED_SO) $(CJSON_SHARED)
#cJSON_Utils
$(UTILS_SHARED_SO): $(UTILS_SHARED_VERSION)
ln -s $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO)
$(UTILS_SHARED): $(UTILS_SHARED_SO)
ln -s $(UTILS_SHARED_SO) $(UTILS_SHARED)

#install
#cJSON
install-cjson:
mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH)
$(INSTALL) cJSON.h $(INSTALL_INCLUDE_PATH)
$(INSTALL) $(CJSON_SHARED) $(CJSON_SHARED_SO) $(CJSON_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
#cJSON_Utils
install-utils: install-cjson
$(INSTALL) cJSON_Utils.h $(INSTALL_INCLUDE_PATH)
$(INSTALL) $(UTILS_SHARED) $(UTILS_SHARED_SO) $(UTILS_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)

install: install-cjson install-utils

#uninstall
#cJSON
uninstall-cjson: uninstall-utils
$(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED)
$(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED_VERSION)
$(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED_SO)
rmdir $(INSTALL_LIBRARY_PATH)
$(RM) $(INSTALL_INCLUDE_PATH)/cJSON.h
rmdir $(INSTALL_INCLUDE_PATH)
#cJSON_Utils
uninstall-utils:
$(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED)
$(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED_VERSION)
$(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED_SO)
$(RM) $(INSTALL_INCLUDE_PATH)/cJSON_Utils.h

uninstall: uninstall-utils uninstall-cjson

clean:
$(RM) $(CJSON_OBJ) $(UTILS_OBJ) #delete object files
$(RM) $(CJSON_SHARED) $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO) $(CJSON_STATIC) #delete cJSON
$(RM) $(UTILS_SHARED) $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO) $(UTILS_STATIC) #delete cJSON_Utils
$(RM) $(CJSON_TEST) $(UTILS_TEST) #delete tests
Loading

0 comments on commit aafb64a

Please sign in to comment.