Skip to content

Commit

Permalink
Separate third party libraries; resolves #79 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 authored Jun 12, 2024
1 parent d8549e8 commit 0342e5c
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 7 deletions.
31 changes: 25 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> )
if(REFLECTCPP_USE_BUNDLED_DEPENDENCIES)
target_include_directories(reflectcpp PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/rfl/thirdparty>)
else()
target_include_directories(reflectcpp PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> )
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)
Expand Down
7 changes: 6 additions & 1 deletion include/rfl/PatternValidator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

#include <string>

#include "../ctre.hpp"
#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES
#include <ctre.hpp>
#else
#include "thirdparty/ctre.hpp"
#endif

#include "Literal.hpp"
#include "Result.hpp"
#include "internal/StringLiteral.hpp"
Expand Down
4 changes: 4 additions & 0 deletions include/rfl/json/Reader.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef RFL_JSON_READER_HPP_
#define RFL_JSON_READER_HPP_

#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES
#include <yyjson.h>
#else
#include "../thirdparty/yyjson.h"
#endif

#include <array>
#include <concepts>
Expand Down
4 changes: 4 additions & 0 deletions include/rfl/json/Writer.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef RFL_JSON_WRITER_HPP_
#define RFL_JSON_WRITER_HPP_

#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES
#include <yyjson.h>
#else
#include "../thirdparty/yyjson.h"
#endif

#include <exception>
#include <map>
Expand Down
4 changes: 4 additions & 0 deletions include/rfl/json/read.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef RFL_JSON_READ_HPP_
#define RFL_JSON_READ_HPP_

#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES
#include <yyjson.h>
#else
#include "../thirdparty/yyjson.h"
#endif

#include <istream>
#include <string>
Expand Down
4 changes: 4 additions & 0 deletions include/rfl/json/save.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef RFL_JSON_SAVE_HPP_
#define RFL_JSON_SAVE_HPP_

#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES
#include <yyjson.h>
#else
#include "../thirdparty/yyjson.h"
#endif

#include <fstream>
#include <iostream>
Expand Down
4 changes: 4 additions & 0 deletions include/rfl/json/to_schema.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef RFL_JSON_TOSCHEMA_HPP_
#define RFL_JSON_TOSCHEMA_HPP_

#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES
#include <yyjson.h>
#else
#include "../thirdparty/yyjson.h"
#endif

#include <map>
#include <string>
Expand Down
4 changes: 4 additions & 0 deletions include/rfl/json/write.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef RFL_JSON_WRITE_HPP_
#define RFL_JSON_WRITE_HPP_

#ifdef REFLECTCPP_NO_BUNDLED_DEPENDENCIES
#include <yyjson.h>
#else
#include "../thirdparty/yyjson.h"
#endif

#include <ostream>
#include <sstream>
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -43,6 +47,10 @@
"name": "yaml-cpp",
"version>=": "0.8.0#1"
},
{
"name": "yyjson",
"version>=": "0.8.0"
},
{
"name": "benchmark",
"version>=": "1.8.3"
Expand Down

0 comments on commit 0342e5c

Please sign in to comment.