Skip to content
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

Separate third party libraries; resolves #79 #119

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably instead of SHARED or STATIC, INTERFACE would be the choice for Header-Only-Lib
https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries

add_library(reflectcpp SHARED)
else()
add_library(reflectcpp STATIC)
endif()
endif()

set_target_properties(reflectcpp PROPERTIES LINKER_LANGUAGE CXX)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, probably could use the LANGUAGES section of project
https://cmake.org/cmake/help/latest/command/project.html

But setting it just to CXX, as this is a C++ project, gives trouble with the yyjson.c .
I guess it could be a C++ wrapper around it.
Maybe like

// yyjson.cpp
extern C {
  #include "yyjson.c"
}

Quick test shows, that at least clangd is happy with it, and uses the right compiler and flags.

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>)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the thirdparty folder as set as extra include here, there should be no need to have the checks in the header files. I guess. Compiler should use the first header it finds, so if thirdparty is first, it should be okay.

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
Loading