diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ab9c52a2..228e4dd8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,36 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(JSONCPP_HAS_STRING_VIEW_DEFAULT OFF) +if (${CMAKE_CXX_STANDARD} GREATER_EQUAL 17) + set(JSONCPP_HAS_STRING_VIEW_DEFAULT ON) +endif() + +option(JSONCPP_HAS_STRING_VIEW "Enable support for string view" ${JSONCPP_HAS_STRING_VIEW_DEFAULT}) + +configure_file(configure/configure.h.in include/json/configure.h) + +set(JSONCPP_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) + +file( + COPY include/json + DESTINATION ${JSONCPP_INCLUDE_DIR} + FILES_MATCHING + PATTERN "*.h" +) + +set(PUBLIC_HEADERS + ${JSONCPP_INCLUDE_DIR}/json/config.h + ${JSONCPP_INCLUDE_DIR}/json/configure.h + ${JSONCPP_INCLUDE_DIR}/json/forwards.h + ${JSONCPP_INCLUDE_DIR}/json/json_features.h + ${JSONCPP_INCLUDE_DIR}/json/value.h + ${JSONCPP_INCLUDE_DIR}/json/reader.h + ${JSONCPP_INCLUDE_DIR}/json/version.h + ${JSONCPP_INCLUDE_DIR}/json/writer.h + ${JSONCPP_INCLUDE_DIR}/json/assertions.h +) + # Ensure that CMAKE_BUILD_TYPE has a value specified for single configuration generators. if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE Release CACHE STRING diff --git a/configure/configure.h.in b/configure/configure.h.in new file mode 100644 index 000000000..c723381a0 --- /dev/null +++ b/configure/configure.h.in @@ -0,0 +1 @@ +#cmakedefine JSONCPP_HAS_STRING_VIEW diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index dc40d95e8..6b358a084 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,5 +1,3 @@ -file(GLOB INCLUDE_FILES "json/*.h") install(FILES - ${INCLUDE_FILES} + ${PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/json) - diff --git a/include/json/value.h b/include/json/value.h index 5f6544329..d7a356e34 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -39,10 +39,6 @@ #endif #endif -#if __cplusplus >= 201703L -#define JSONCPP_HAS_STRING_VIEW 1 -#endif - #include #include #include @@ -50,6 +46,8 @@ #include #include +#include "json/configure.h" + #ifdef JSONCPP_HAS_STRING_VIEW #include #endif @@ -581,7 +579,7 @@ class JSON_API Value { /// Do nothing if it did not exist. /// \pre type() is objectValue or nullValue /// \post type() is unchanged -#if JSONCPP_HAS_STRING_VIEW +#ifdef JSONCPP_HAS_STRING_VIEW void removeMember(std::string_view key); #else void removeMember(const char* key); @@ -595,7 +593,7 @@ class JSON_API Value { * \param key may contain embedded nulls. * \return true iff removed (no exceptions) */ -#if JSONCPP_HAS_STRING_VIEW +#ifdef JSONCPP_HAS_STRING_VIEW bool removeMember(std::string_view key, Value* removed); #else bool removeMember(String const& key, Value* removed); diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 3037eb020..46e26e602 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -25,19 +25,6 @@ if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALEC endif() endif() -set(JSONCPP_INCLUDE_DIR ../../include) - -set(PUBLIC_HEADERS - ${JSONCPP_INCLUDE_DIR}/json/config.h - ${JSONCPP_INCLUDE_DIR}/json/forwards.h - ${JSONCPP_INCLUDE_DIR}/json/json_features.h - ${JSONCPP_INCLUDE_DIR}/json/value.h - ${JSONCPP_INCLUDE_DIR}/json/reader.h - ${JSONCPP_INCLUDE_DIR}/json/version.h - ${JSONCPP_INCLUDE_DIR}/json/writer.h - ${JSONCPP_INCLUDE_DIR}/json/assertions.h -) - source_group("Public API" FILES ${PUBLIC_HEADERS}) set(JSONCPP_SOURCES @@ -131,7 +118,7 @@ if(BUILD_SHARED_LIBS) target_include_directories(${SHARED_LIB} PUBLIC $ - $ + $ ) list(APPEND CMAKE_TARGETS ${SHARED_LIB}) @@ -164,7 +151,7 @@ if(BUILD_STATIC_LIBS) target_include_directories(${STATIC_LIB} PUBLIC $ - $ + $ ) list(APPEND CMAKE_TARGETS ${STATIC_LIB}) @@ -190,7 +177,7 @@ if(BUILD_OBJECT_LIBS) target_include_directories(${OBJECT_LIB} PUBLIC $ - $ + $ ) list(APPEND CMAKE_TARGETS ${OBJECT_LIB}) @@ -202,4 +189,3 @@ install(TARGETS ${CMAKE_TARGETS} ${INSTALL_EXPORT} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR} ) - diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 5b6299906..2789ae5bf 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index a875d28b2..fde93f343 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -5,6 +5,7 @@ #if !defined(JSON_IS_AMALGAMATION) #include +#include #include #include #endif // if !defined(JSON_IS_AMALGAMATION) @@ -13,8 +14,6 @@ #include #include #include -#include -#include #include #ifdef JSONCPP_HAS_STRING_VIEW diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index ac14eb11f..a13277b4c 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -13,10 +13,8 @@ #include #include #include -#include #include #include -#include #include #if defined(_MSC_VER) diff --git a/src/test_lib_json/fuzz.cpp b/src/test_lib_json/fuzz.cpp index 5b75c22e6..0c65f59af 100644 --- a/src/test_lib_json/fuzz.cpp +++ b/src/test_lib_json/fuzz.cpp @@ -9,7 +9,6 @@ #include #include #include -#include namespace Json { class Exception; diff --git a/src/test_lib_json/jsontest.h b/src/test_lib_json/jsontest.h index 69e3264b9..743affb01 100644 --- a/src/test_lib_json/jsontest.h +++ b/src/test_lib_json/jsontest.h @@ -12,8 +12,6 @@ #include #include #include -#include -#include // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 60f149d5e..6311ef685 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -12,7 +12,6 @@ #include "fuzz.h" #include "jsontest.h" -#include #include #include #include