Skip to content

Move string view decision to configure time - WIP #1608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions configure/configure.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#cmakedefine JSONCPP_HAS_STRING_VIEW
4 changes: 1 addition & 3 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
file(GLOB INCLUDE_FILES "json/*.h")
install(FILES
${INCLUDE_FILES}
${PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/json)

10 changes: 4 additions & 6 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@
#endif
#endif

#if __cplusplus >= 201703L
#define JSONCPP_HAS_STRING_VIEW 1
#endif

#include <array>
#include <exception>
#include <map>
#include <memory>
#include <string>
#include <vector>

#include "json/configure.h"

#ifdef JSONCPP_HAS_STRING_VIEW
#include <string_view>
#endif
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
20 changes: 3 additions & 17 deletions src/lib_json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -131,7 +118,7 @@ if(BUILD_SHARED_LIBS)

target_include_directories(${SHARED_LIB} PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
$<BUILD_INTERFACE:${JSONCPP_INCLUDE_DIR}>
)

list(APPEND CMAKE_TARGETS ${SHARED_LIB})
Expand Down Expand Up @@ -164,7 +151,7 @@ if(BUILD_STATIC_LIBS)

target_include_directories(${STATIC_LIB} PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
$<BUILD_INTERFACE:${JSONCPP_INCLUDE_DIR}>
)

list(APPEND CMAKE_TARGETS ${STATIC_LIB})
Expand All @@ -190,7 +177,7 @@ if(BUILD_OBJECT_LIBS)

target_include_directories(${OBJECT_LIB} PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
$<BUILD_INTERFACE:${JSONCPP_INCLUDE_DIR}>
)

list(APPEND CMAKE_TARGETS ${OBJECT_LIB})
Expand All @@ -202,4 +189,3 @@ install(TARGETS ${CMAKE_TARGETS} ${INSTALL_EXPORT}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

1 change: 0 additions & 1 deletion src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <limits>
#include <memory>
#include <set>
#include <sstream>
#include <utility>

#include <cstdio>
Expand Down
3 changes: 1 addition & 2 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#if !defined(JSON_IS_AMALGAMATION)
#include <json/assertions.h>
#include <json/configure.h>
#include <json/value.h>
#include <json/writer.h>
#endif // if !defined(JSON_IS_AMALGAMATION)
Expand All @@ -13,8 +14,6 @@
#include <cmath>
#include <cstddef>
#include <cstring>
#include <iostream>
#include <sstream>
#include <utility>

#ifdef JSONCPP_HAS_STRING_VIEW
Expand Down
2 changes: 0 additions & 2 deletions src/lib_json/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <memory>
#include <set>
#include <sstream>
#include <utility>

#if defined(_MSC_VER)
Expand Down
1 change: 0 additions & 1 deletion src/test_lib_json/fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <json/config.h>
#include <json/json.h>
#include <memory>
#include <string>

namespace Json {
class Exception;
Expand Down
2 changes: 0 additions & 2 deletions src/test_lib_json/jsontest.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <json/config.h>
#include <json/value.h>
#include <json/writer.h>
#include <sstream>
#include <string>

// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion src/test_lib_json/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "fuzz.h"
#include "jsontest.h"
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
Expand Down
Loading