Skip to content

Commit 83951fd

Browse files
Feature/shared exports msvc (#525)
1 parent 06988aa commit 83951fd

File tree

42 files changed

+212
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+212
-90
lines changed

.github/workflows/windows.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,39 @@ jobs:
6464
./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=canada >> $GITHUB_STEP_SUMMARY
6565
./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=licenses >> $GITHUB_STEP_SUMMARY
6666
echo '```' >> $GITHUB_STEP_SUMMARY
67+
windows-msvc-shared:
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
format: ["JSON", "AVRO", "CAPNPROTO", "CBOR", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML"]
72+
name: "windows-msvc-shared (${{ matrix.format }})"
73+
runs-on: windows-latest
74+
steps:
75+
- name: Checkout
76+
uses: actions/checkout@v4
77+
with:
78+
submodules: recursive
79+
fetch-depth: 0
80+
- name: Export GitHub Actions cache environment variables
81+
uses: actions/github-script@v7
82+
with:
83+
script: |
84+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
85+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
86+
- uses: ilammy/msvc-dev-cmd@v1
87+
- uses: lukka/run-vcpkg@v11
88+
- name: Compile tests (JSON)
89+
if: matrix.format == 'JSON'
90+
run: |
91+
cmake -S . -B build -DREFLECTCPP_BUILD_SHARED=ON -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
92+
cmake --build build --config Release -j4
93+
- name: Compile tests (Other formats)
94+
if: matrix.format != 'JSON'
95+
run: |
96+
cmake -S . -B build -DREFLECTCPP_BUILD_SHARED=ON -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_JSON=OFF -DREFLECTCPP_${{ matrix.format }}=ON -DCMAKE_BUILD_TYPE=Release
97+
cmake --build build --config Release -j4
98+
- name: Run tests
99+
run: |
100+
ctest --test-dir build --output-on-failure
67101
102+

CMakeLists.txt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,19 @@ else()
179179
)
180180
endif()
181181

182+
if(REFLECTCPP_BUILD_SHARED AND REFLECTCPP_USE_BUNDLED_DEPENDENCIES AND _REFLECTCPP_NEEDS_JSON_IMPL)
183+
target_compile_definitions(reflectcpp
184+
PRIVATE
185+
YYJSON_EXPORTS
186+
INTERFACE
187+
YYJSON_IMPORTS
188+
)
189+
endif()
190+
191+
if(REFLECTCPP_BUILD_SHARED)
192+
target_compile_definitions(reflectcpp PUBLIC RFL_BUILD_SHARED)
193+
endif()
194+
182195
if(REFLECTCPP_USE_STD_EXPECTED)
183196
target_compile_definitions(reflectcpp PUBLIC REFLECTCPP_USE_STD_EXPECTED)
184197
endif()
@@ -232,7 +245,20 @@ if (REFLECTCPP_AVRO)
232245
if (REFLECTCPP_USE_VCPKG)
233246
target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
234247
if (MSVC)
235-
target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/avro${CMAKE_STATIC_LIBRARY_SUFFIX}")
248+
set(_AVRO_STATIC_LIB "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/avro${CMAKE_STATIC_LIBRARY_SUFFIX}")
249+
if(REFLECTCPP_BUILD_SHARED)
250+
message(STATUS "With whole archive ${_AVRO_STATIC_LIB}")
251+
target_link_libraries(reflectcpp
252+
PUBLIC
253+
$<LINK_LIBRARY:WHOLE_ARCHIVE,${_AVRO_STATIC_LIB}>
254+
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/snappy${CMAKE_STATIC_LIBRARY_SUFFIX}"
255+
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/lzma${CMAKE_STATIC_LIBRARY_SUFFIX}"
256+
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/jansson${CMAKE_STATIC_LIBRARY_SUFFIX}"
257+
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/zlib${CMAKE_STATIC_LIBRARY_SUFFIX}"
258+
)
259+
else()
260+
target_link_libraries(reflectcpp PUBLIC "${_AVRO_STATIC_LIB}")
261+
endif()
236262
else ()
237263
target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libavro${CMAKE_STATIC_LIBRARY_SUFFIX}")
238264
endif ()
@@ -370,9 +396,11 @@ target_sources(reflectcpp PRIVATE ${REFLECT_CPP_SOURCES})
370396
target_precompile_headers(reflectcpp PRIVATE [["rfl.hpp"]] <iostream> <string> <functional>)
371397

372398
if (REFLECTCPP_BUILD_TESTS)
399+
add_library(reflectcpp_tests_crt INTERFACE)
400+
target_link_libraries(reflectcpp_tests_crt INTERFACE reflectcpp GTest::gtest_main)
401+
373402
enable_testing()
374403
find_package(GTest CONFIG REQUIRED)
375-
set(REFLECT_CPP_GTEST_LIB reflectcpp GTest::gtest_main)
376404
add_subdirectory(tests)
377405
endif ()
378406

include/rfl/Generic.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
#include "Object.hpp"
1212
#include "Result.hpp"
1313
#include "Variant.hpp"
14+
#include "common.hpp"
1415

1516
namespace rfl {
1617

17-
class Generic {
18+
class RFL_API Generic {
1819
public:
1920
constexpr static std::nullopt_t Null = std::nullopt;
2021

include/rfl/avro/SchemaImpl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
//#include "../Box.hpp"
99
//#include "../Result.hpp"
10+
#include "../common.hpp"
1011

1112
namespace rfl::avro {
1213

13-
class SchemaImpl {
14+
class RFL_API SchemaImpl {
1415
public:
1516
SchemaImpl(const std::string& _json_str);
1617

include/rfl/avro/Writer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
#include "../Vectorstring.hpp"
1616
#include "../always_false.hpp"
1717
#include "../internal/is_literal.hpp"
18+
#include "../common.hpp"
1819

1920
namespace rfl::avro {
2021

21-
class Writer {
22+
class RFL_API Writer {
2223
public:
2324
struct AVROOutputArray {
2425
avro_value_t val_;

include/rfl/avro/schema/Type.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
#include "../../Ref.hpp"
1111
#include "../../Rename.hpp"
1212
#include "../../Variant.hpp"
13+
#include "../../common.hpp"
1314

1415
namespace rfl::avro::schema {
1516

16-
struct Type {
17+
struct RFL_API Type {
1718
struct Null {
1819
Literal<"null"> type{};
1920
};

include/rfl/avro/to_schema.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
#include "Schema.hpp"
1515
#include "Writer.hpp"
1616
//#include "schema/Type.hpp"
17+
#include "../common.hpp"
1718

1819
namespace rfl::avro {
1920

20-
std::string to_json_representation(
21+
RFL_API std::string to_json_representation(
2122
const parsing::schema::Definition& internal_schema);
2223

2324
/// Returns the Avro schema for a class.

include/rfl/bson/Writer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
#include "../Vectorstring.hpp"
1818
#include "../always_false.hpp"
1919
#include "../internal/ptr_cast.hpp"
20+
#include "../common.hpp"
2021

2122
namespace rfl {
2223
namespace bson {
2324

2425
/// Please refer to https://mongoc.org/libbson/current/api.html
25-
class Writer {
26+
class RFL_API Writer {
2627
struct BSONType {
2728
bson_t val_;
2829
};

include/rfl/capnproto/Reader.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
#include "../always_false.hpp"
1414
#include "../internal/is_literal.hpp"
1515
#include "../internal/ptr_cast.hpp"
16+
#include "../common.hpp"
1617

1718
namespace rfl::capnproto {
1819

19-
class Reader {
20+
class RFL_API Reader {
2021
public:
2122
struct CapNProtoInputArray {
2223
capnp::DynamicList::Reader val_;

include/rfl/capnproto/SchemaImpl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
//#include "../Box.hpp"
99
//#include "../Result.hpp"
10+
#include "../common.hpp"
1011

1112
namespace rfl::capnproto {
1213

13-
class SchemaImpl {
14+
class RFL_API SchemaImpl {
1415
public:
1516
SchemaImpl(const std::string& _str);
1617

0 commit comments

Comments
 (0)