From 5bf860315e87cb86fa0c2a9f26a0df738e5c35f5 Mon Sep 17 00:00:00 2001 From: Gert Van Hoey Date: Tue, 4 Jul 2017 21:41:17 +0200 Subject: [PATCH] Build on Windows using Visual Studio and export symbols from DLL --- CMakeLists.txt | 7 ++++--- src/json-schema.hpp | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0954145..dd1fe45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,10 +33,13 @@ target_compile_features(json-schema-validator cxx_range_for) # for C++11 - flags target_compile_options(json-schema-validator PUBLIC - -Wall -Wextra) # bad, better use something else based on compiler type + -Wall) # bad, better use something else based on compiler type target_link_libraries(json-schema-validator PUBLIC json-hpp) +target_compile_definitions(json-schema-validator + PRIVATE + -DJSON_SCHEMA_VALIDATOR_EXPORTS) # regex with boost if gcc < 4.8 - default is std::regex if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") @@ -113,5 +116,3 @@ else() message(STATUS "Consider setting JSON_SCHEMA_TEST_SUITE_PATH to a path in which JSON-Schema-Test-Suite is located (github.com/json-schema-org/JSON-Schema-Test-Suite).") endif() - - diff --git a/src/json-schema.hpp b/src/json-schema.hpp index f3e228d..51f521b 100644 --- a/src/json-schema.hpp +++ b/src/json-schema.hpp @@ -26,6 +26,16 @@ #ifndef NLOHMANN_JSON_SCHEMA_HPP__ #define NLOHMANN_JSON_SCHEMA_HPP__ +#ifdef _WIN32 +# ifdef JSON_SCHEMA_VALIDATOR_EXPORTS +# define JSON_SCHEMA_VALIDATOR_API __declspec(dllexport) +# else +# define JSON_SCHEMA_VALIDATOR_API __declspec(dllimport) +# endif +#else +# define JSON_SCHEMA_VALIDATOR_API +#endif + #include // make yourself a home - welcome to nlohmann's namespace @@ -83,7 +93,7 @@ public: // // This is done implement the requirements described in section 8.2. // -class json_uri +class JSON_SCHEMA_VALIDATOR_API json_uri { std::string urn_; @@ -155,7 +165,7 @@ namespace json_schema_draft4 extern json draft4_schema_builtin; -class json_validator +class JSON_SCHEMA_VALIDATOR_API json_validator { std::vector> schema_store_; std::shared_ptr root_schema_;