From f9ac3a6e0045c99ba978700d32d4075f566da0a5 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 13 Jun 2024 00:09:02 +0200 Subject: [PATCH] Separate yyjson and ctre; #79 --- CMakeLists.txt | 31 +++++++++++++++++++++------ include/rfl/PatternValidator.hpp | 7 +++++- include/rfl/json/Reader.hpp | 4 ++++ include/rfl/json/Writer.hpp | 4 ++++ include/rfl/json/read.hpp | 4 ++++ include/rfl/json/save.hpp | 4 ++++ include/rfl/json/to_schema.hpp | 4 ++++ include/rfl/json/write.hpp | 4 ++++ include/{ => rfl/thirdparty}/ctre.hpp | 0 include/{ => rfl/thirdparty}/yyjson.h | 0 vcpkg.json | 8 +++++++ 11 files changed, 63 insertions(+), 7 deletions(-) rename include/{ => rfl/thirdparty}/ctre.hpp (100%) rename include/{ => rfl/thirdparty}/yyjson.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10cae097..e537c90c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,8 @@ option(REFLECTCPP_YAML "Enable YAML support" OFF) option(REFLECTCPP_BUILD_BENCHMARKS "Build benchmarks" OFF) option(REFLECTCPP_BUILD_TESTS "Build tests" OFF) +option(REFLECTCPP_USE_BUNDLED_DEPENDENCIES "Use the bundled dependencies" ON) + set(REFLECTCPP_USE_VCPKG_DEFAULT OFF) if (REFLECTCPP_BUILD_TESTS OR REFLECTCPP_BUILD_BENCHMARKS OR REFLECTCPP_BSON OR REFLECTCPP_CBOR OR REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_MSGPACK OR REFLECTCPP_XML OR REFLECTCPP_TOML OR REFLECTCPP_YAML) # enable vcpkg per default if require features other than JSON @@ -29,15 +31,32 @@ project(reflectcpp) set(CMAKE_CXX_STANDARD 20) -if (REFLECTCPP_BUILD_SHARED) - add_library(reflectcpp SHARED src/yyjson.c) -else () - add_library(reflectcpp STATIC src/yyjson.c) -endif () +if(REFLECTCPP_USE_BUNDLED_DEPENDENCIES) + if (REFLECTCPP_BUILD_SHARED) + add_library(reflectcpp SHARED src/yyjson.c) + else() + add_library(reflectcpp STATIC src/yyjson.c) + endif() +else() + if (REFLECTCPP_BUILD_SHARED) + add_library(reflectcpp SHARED) + else() + add_library(reflectcpp STATIC) + endif() +endif() +set_target_properties(reflectcpp PROPERTIES LINKER_LANGUAGE CXX) target_compile_features(reflectcpp PUBLIC cxx_std_20) -target_include_directories(reflectcpp PUBLIC $ $ ) +if(REFLECTCPP_USE_BUNDLED_DEPENDENCIES) + target_include_directories(reflectcpp PUBLIC $ $ $) +else() + target_include_directories(reflectcpp PUBLIC $ $ ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DREFLECTCPP_NO_BUNDLED_DEPENDENCIES") + find_package(ctre CONFIG REQUIRED) + find_package(yyjson CONFIG REQUIRED) + target_link_libraries(reflectcpp INTERFACE yyjson::yyjson) +endif() if (REFLECTCPP_BSON OR REFLECTCPP_BUILD_BENCHMARKS) find_package(bson-1.0 CONFIG REQUIRED) diff --git a/include/rfl/PatternValidator.hpp b/include/rfl/PatternValidator.hpp index 18af3b53..77ebdf46 100644 --- a/include/rfl/PatternValidator.hpp +++ b/include/rfl/PatternValidator.hpp @@ -3,7 +3,12 @@ #include -#include "../ctre.hpp" +#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES +#include +#else +#include "../thirdparty/ctre.hpp" +#endif + #include "Literal.hpp" #include "Result.hpp" #include "internal/StringLiteral.hpp" diff --git a/include/rfl/json/Reader.hpp b/include/rfl/json/Reader.hpp index 958df68f..4bf6c1a0 100644 --- a/include/rfl/json/Reader.hpp +++ b/include/rfl/json/Reader.hpp @@ -1,7 +1,11 @@ #ifndef RFL_JSON_READER_HPP_ #define RFL_JSON_READER_HPP_ +#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES #include +#else +#include "../thirdparty/yyjson.h" +#endif #include #include diff --git a/include/rfl/json/Writer.hpp b/include/rfl/json/Writer.hpp index 81d794f1..ef5774c7 100644 --- a/include/rfl/json/Writer.hpp +++ b/include/rfl/json/Writer.hpp @@ -1,7 +1,11 @@ #ifndef RFL_JSON_WRITER_HPP_ #define RFL_JSON_WRITER_HPP_ +#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES #include +#else +#include "../thirdparty/yyjson.h" +#endif #include #include diff --git a/include/rfl/json/read.hpp b/include/rfl/json/read.hpp index 30bef1be..a5c1edf3 100644 --- a/include/rfl/json/read.hpp +++ b/include/rfl/json/read.hpp @@ -1,7 +1,11 @@ #ifndef RFL_JSON_READ_HPP_ #define RFL_JSON_READ_HPP_ +#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES #include +#else +#include "../thirdparty/yyjson.h" +#endif #include #include diff --git a/include/rfl/json/save.hpp b/include/rfl/json/save.hpp index 9875df89..e6f66bc3 100644 --- a/include/rfl/json/save.hpp +++ b/include/rfl/json/save.hpp @@ -1,7 +1,11 @@ #ifndef RFL_JSON_SAVE_HPP_ #define RFL_JSON_SAVE_HPP_ +#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES #include +#else +#include "../thirdparty/yyjson.h" +#endif #include #include diff --git a/include/rfl/json/to_schema.hpp b/include/rfl/json/to_schema.hpp index 37ff2d58..d88affab 100644 --- a/include/rfl/json/to_schema.hpp +++ b/include/rfl/json/to_schema.hpp @@ -1,7 +1,11 @@ #ifndef RFL_JSON_TOSCHEMA_HPP_ #define RFL_JSON_TOSCHEMA_HPP_ +#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES #include +#else +#include "../thirdparty/yyjson.h" +#endif #include #include diff --git a/include/rfl/json/write.hpp b/include/rfl/json/write.hpp index 8f5bc50e..58776621 100644 --- a/include/rfl/json/write.hpp +++ b/include/rfl/json/write.hpp @@ -1,7 +1,11 @@ #ifndef RFL_JSON_WRITE_HPP_ #define RFL_JSON_WRITE_HPP_ +#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES #include +#else +#include "../thirdparty/yyjson.h" +#endif #include #include diff --git a/include/ctre.hpp b/include/rfl/thirdparty/ctre.hpp similarity index 100% rename from include/ctre.hpp rename to include/rfl/thirdparty/ctre.hpp diff --git a/include/yyjson.h b/include/rfl/thirdparty/yyjson.h similarity index 100% rename from include/yyjson.h rename to include/rfl/thirdparty/yyjson.h diff --git a/vcpkg.json b/vcpkg.json index 75a42685..a3e223ef 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -3,6 +3,10 @@ "version-string": "0.8.0", "builtin-baseline": "50bffcc62d7f6571eb32bc1a0b1807e77af1166c", "dependencies": [ + { + "name": "ctre", + "version>=": "3.8" + }, { "name": "flatbuffers", "version>=": "23.5.26#1" @@ -43,6 +47,10 @@ "name": "yaml-cpp", "version>=": "0.8.0#1" }, + { + "name": "yyjson", + "version>=": "0.8.0" + }, { "name": "benchmark", "version>=": "1.8.3"