diff --git a/CMakeLists.txt b/CMakeLists.txt index eeb2a78..304cb3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,50 +1,50 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.14) -SET(Project minijson) -PROJECT(${Project} C CXX) - -SET(SOURCE_DIR ${${Project}_SOURCE_DIR}) -SET(CMAKE_C_STANDARD 99) -SET(CMAKE_CXX_STANDARD 11) -SET(CMAKE_POSITION_INDEPENDENT_CODE on) -SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/") - -MESSAGE("Compiling minijson") -MESSAGE(STATUS "Source directory is " ${SOURCE_DIR}) -MESSAGE("Project = ${Project}") -MESSAGE("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}") -MESSAGE("COVERAGE = ${COVERAGE}") +cmake_minimum_required(VERSION 3.14) +set(Project minijson) +project(${Project} C CXX) + +set(SOURCE_DIR ${${Project}_SOURCE_DIR}) +set(CMAKE_C_STANDARD 99) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_POSITION_INDEPENDENT_CODE on) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/") + +message("Compiling minijson") +message(STATUS "Source directory is " ${SOURCE_DIR}) +message("Project = ${Project}") +message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}") +message("COVERAGE = ${COVERAGE}") # supress MSVC/GCC warnings -IF(${CMAKE_HOST_WIN32}) - SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251") -ENDIF() +if(${CMAKE_HOST_WIN32}) + set(CMAKE_CXX_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251") +endif() # define headers and sources -SET(Headers Json.h) -SET(Sources Json.cpp) +set(Headers Json.h) +set(Sources Json.cpp) # build a dynamic library -MESSAGE("Build dynamic library ${MINIJSON_DYNAMIC_LIBRARY_TARGET}") -SET(MINIJSON_DYNAMIC_LIBRARY_TARGET ${Project}) -ADD_LIBRARY(${MINIJSON_DYNAMIC_LIBRARY_TARGET} SHARED ${Sources} ${Headers}) +message("Build dynamic library ${MINIJSON_DYNAMIC_LIBRARY_TARGET}") +set(MINIJSON_DYNAMIC_LIBRARY_TARGET ${Project}) +add_library(${MINIJSON_DYNAMIC_LIBRARY_TARGET} SHARED ${Sources} ${Headers}) # to generate export library when build dynamic library -TARGET_COMPILE_DEFINITIONS(${MINIJSON_DYNAMIC_LIBRARY_TARGET} PRIVATE -DLIBRARY_EXPORT) +target_compile_definitions(${MINIJSON_DYNAMIC_LIBRARY_TARGET} PRIVATE -DLIBRARY_EXPORT) # build a static library -MESSAGE("Build static library ${MINIJSON_STATIC_LIBRARY_TARGET}") -SET(MINIJSON_STATIC_LIBRARY_TARGET ${Project}_static) -ADD_LIBRARY(${MINIJSON_STATIC_LIBRARY_TARGET} STATIC ${Sources} ${Headers}) +message("Build static library ${MINIJSON_STATIC_LIBRARY_TARGET}") +set(MINIJSON_STATIC_LIBRARY_TARGET ${Project}_static) +add_library(${MINIJSON_STATIC_LIBRARY_TARGET} STATIC ${Sources} ${Headers}) # set -DCMAKE_BUILD_TYPE=Debug to enable LLT, set -DCOVERAGE=ON to enable code coverage -IF (CMAKE_BUILD_TYPE STREQUAL "Debug") +if (CMAKE_BUILD_TYPE STREQUAL "Debug") # these config must be put at the level of source code in order to append compile flags - IF (${COVERAGE} STREQUAL "lcov" OR ${COVERAGE} STREQUAL "gcovr") - MESSAGE("code coverage is enabled, COVERAGE = ${COVERAGE}, append coverage compiler flags") + if (${COVERAGE} STREQUAL "lcov" OR ${COVERAGE} STREQUAL "gcovr") + message("code coverage is enabled, COVERAGE = ${COVERAGE}, append coverage compiler flags") INCLUDE(${SOURCE_DIR}/test/CodeCoverage.cmake) APPEND_COVERAGE_COMPILER_FLAGS() - ENDIF() + endif() - ENABLE_TESTING() - ADD_SUBDIRECTORY("test") -ENDIF() \ No newline at end of file + enable_testing() + add_subdirectory("test") +endif() \ No newline at end of file diff --git a/Json.h b/Json.h index b6381f1..45c19f3 100644 --- a/Json.h +++ b/Json.h @@ -5,7 +5,6 @@ * Author: XUranus * Date: 2022-11-21 * Description: a tiny C++ Json library -* https://github.com/XUranus/minicpp * ================================================================*/ @@ -135,7 +134,6 @@ class MINIJSON_API JsonElement: public Serializable { explicit JsonElement(char const *str); JsonElement(const JsonObject& object); JsonElement(const JsonArray& array); - JsonElement(const JsonElement& ele); explicit JsonElement(JsonElement&& ele); JsonElement& operator = (const JsonElement& ele); diff --git a/README.md b/README.md index f39167d..7e96823 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,15 @@ # MiniJson > a mini Json library C++ implement +
+minijson  +C++14  +Windows  +Linux  +MSVC 2015+  +GCC 4.9+  +
+ ## build & test build static/dynamic library: ``` diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b44f28d..a08fd0a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,60 +1,60 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.14) -SET(Project "minijson_test") -SET(${Project} C CXX) +cmake_minimum_required(VERSION 3.14) +set(Project "minijson_test") +set(${Project} C CXX) -SET(Headers StructSample.h) -SET(Sources MiniJsonTest.cpp) -SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(Headers StructSample.h) +set(Sources MiniJsonTest.cpp) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # build test and run code coverage -ENABLE_TESTING() +enable_testing() # auto fetch googletest -INCLUDE(FetchContent) +include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip ) # For Windows: Prevent overriding the parent project's compiler/linker settings -SET(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) -ADD_EXECUTABLE(${Project} ${Sources} ${Headers}) +add_executable(${Project} ${Sources} ${Headers}) -TARGET_LINK_LIBRARIES(${Project} PUBLIC +target_link_libraries(${Project} PUBLIC minijson_static GTest::gtest_main ) -ADD_TEST( +add_test( NAME ${Project} COMMAND ${Project} ) -INCLUDE(GoogleTest) +include(GoogleTest) gtest_discover_tests(${Project}) # configure code coverage -IF (${COVERAGE} STREQUAL "lcov") - MESSAGE("code coverage is enabled, using lcov") - INCLUDE(CodeCoverage.cmake) +if (${COVERAGE} STREQUAL "lcov") + message("code coverage is enabled, using lcov") + include(CodeCoverage.cmake) APPEND_COVERAGE_COMPILER_FLAGS() - SETUP_TARGET_FOR_COVERAGE_LCOV( + setUP_TARGET_FOR_COVERAGE_LCOV( NAME "minijson_coverage_test" EXECUTABLE make test EXCLUDE "${PROJECT_SOURCE_DIR}/test/*" "/usr/include/*" "*googlemock*" "*googletest*" ) -ENDIF() +endif() -IF (${COVERAGE} STREQUAL "gcovr") - MESSAGE("code coverage is enabled, using gcovr") - INCLUDE(CodeCoverage.cmake) +if (${COVERAGE} STREQUAL "gcovr") + message("code coverage is enabled, using gcovr") + include(CodeCoverage.cmake) APPEND_COVERAGE_COMPILER_FLAGS() - SETUP_TARGET_FOR_COVERAGE_GCOVR_HTML( + setUP_TARGET_FOR_COVERAGE_GCOVR_HTML( NAME "minijson_coverage_test" EXECUTABLE make test BASE_DIRECTORY "${PROJECT_SOURCE_DIR}" EXCLUDE "${PROJECT_SOURCE_DIR}/test/*" "/usr/include/*" "*googlemock*" "*googletest*" "*build*" ) -ENDIF() \ No newline at end of file +endif() \ No newline at end of file