Tidy up handling of optional dependencies

This commit is contained in:
Tristan Penman 2019-08-27 12:19:27 +10:00
parent 757e2fa2aa
commit dbe09e0bab
6 changed files with 98 additions and 81 deletions

View File

@ -23,7 +23,7 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DVALIJSON_BUILD_CXX11_ADAPTERS=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
@ -61,7 +61,7 @@ include_directories(include SYSTEM
if(valijson_BUILD_TESTS)
if(NOT valijson_EXCLUDE_BOOST)
find_package(Boost 1.54.0)
find_package(Boost)
endif()
# Build local gtest
@ -77,22 +77,11 @@ if(valijson_BUILD_TESTS)
tests/test_nlohmann_json_adapter.cpp
tests/test_rapidjson_adapter.cpp
tests/test_picojson_adapter.cpp
tests/test_poco_json_adapter.cpp
tests/test_poly_constraint.cpp
tests/test_validation_errors.cpp
tests/test_validator.cpp
)
if(Qt5Core_FOUND)
include_directories(${Qt5Core_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_qtjson_adapter.cpp)
endif()
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_property_tree_adapter.cpp)
endif()
# Unit tests executable
add_executable(test_suite ${TEST_SOURCES})
@ -102,20 +91,27 @@ if(valijson_BUILD_TESTS)
set(TEST_LIBS gtest gtest_main jsoncpp json11)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_property_tree_adapter.cpp)
add_definitions(-DBOOST_ALL_DYN_LINK)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
endif()
if(Qt5Core_FOUND)
list(APPEND TEST_LIBS Qt5::Core)
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTERS")
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_PROPERTY_TREE_ADAPTER")
endif()
if(Poco_FOUND)
include_directories(${Poco_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_poco_json_adapter.cpp)
list(APPEND TEST_LIBS ${Poco_Foundation_LIBRARIES} ${Poco_JSON_LIBRARIES})
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTERS")
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTER")
endif()
if(Qt5Core_FOUND)
include_directories(${Qt5Core_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_qtjson_adapter.cpp)
list(APPEND TEST_LIBS Qt5::Core)
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTER")
endif()
target_link_libraries(test_suite ${TEST_LIBS} ${Boost_LIBRARIES})

View File

@ -2,35 +2,32 @@
#include <gtest/gtest.h>
#include <valijson/adapters/jsoncpp_adapter.hpp>
#include <valijson/adapters/property_tree_adapter.hpp>
#include <valijson/adapters/rapidjson_adapter.hpp>
#include <valijson/adapters/picojson_adapter.hpp>
#include <valijson/utils/jsoncpp_utils.hpp>
#include <valijson/utils/property_tree_utils.hpp>
#include <valijson/utils/rapidjson_utils.hpp>
#include <valijson/utils/picojson_utils.hpp>
#ifdef VALIJSON_BUILD_CXX11_ADAPTERS
#include <valijson/adapters/json11_adapter.hpp>
#include <valijson/utils/json11_utils.hpp>
#include <valijson/adapters/jsoncpp_adapter.hpp>
#include <valijson/adapters/nlohmann_json_adapter.hpp>
#include <valijson/adapters/picojson_adapter.hpp>
#include <valijson/adapters/rapidjson_adapter.hpp>
#include <valijson/utils/json11_utils.hpp>
#include <valijson/utils/jsoncpp_utils.hpp>
#include <valijson/utils/nlohmann_json_utils.hpp>
#include <valijson/utils/picojson_utils.hpp>
#include <valijson/utils/rapidjson_utils.hpp>
#endif // VALIJSON_BUILD_CXX11_ADAPTERS
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
#include <valijson/adapters/property_tree_adapter.hpp>
#include <valijson/utils/property_tree_utils.hpp>
#endif
#ifdef VALIJSON_BUILD_QT_ADAPTERS
#ifdef VALIJSON_BUILD_QT_ADAPTER
#include <valijson/adapters/qtjson_adapter.hpp>
#include <valijson/utils/qtjson_utils.hpp>
#endif
#endif // VALIJSON_BUILD_QT_ADAPTERS
#ifdef VALIJSON_BUILD_POCO_ADAPTERS
#ifdef VALIJSON_BUILD_POCO_ADAPTER
#include <valijson/adapters/poco_json_adapter.hpp>
#include <valijson/utils/poco_json_utils.hpp>
#endif // VALIJSON_BUILD_POCO_ADAPTERS
#endif
#define TEST_DATA_DIR "../tests/data/documents/"
@ -136,6 +133,10 @@ protected:
std::vector<TestAdapterComparison::JsonFile> TestAdapterComparison::jsonFiles;
//
// JsonCppAdapter vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, JsonCppVsJsonCpp)
{
testComparison<
@ -150,6 +151,8 @@ TEST_F(TestAdapterComparison, JsonCppVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, JsonCppVsPropertyTree)
{
testComparison<
@ -157,6 +160,8 @@ TEST_F(TestAdapterComparison, JsonCppVsPropertyTree)
valijson::adapters::PropertyTreeAdapter>();
}
#endif
TEST_F(TestAdapterComparison, JsonCppVsRapidJson)
{
testComparison<
@ -173,6 +178,12 @@ TEST_F(TestAdapterComparison, JsonCppVsRapidJsonCrtAlloc)
rapidjson::CrtAllocator> > >();
}
//
// PropertyTreeAdapter vs X
// ------------------------------------------------------------------------------------------------
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, PropertyTreeVsPicoJson)
{
testComparison<
@ -203,6 +214,12 @@ TEST_F(TestAdapterComparison, PropertyTreeVsRapidJsonCrtAlloc)
rapidjson::CrtAllocator> > >();
}
#endif
//
// RapidJson vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, RapidJsonVsRapidJson)
{
testComparison<
@ -226,6 +243,10 @@ TEST_F(TestAdapterComparison, RapidJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
//
// PicoJsonAdapter vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, PicoJsonVsPicoJson)
{
testComparison<
@ -253,7 +274,9 @@ TEST_F(TestAdapterComparison, RapidJsonCrtAllocVsRapidJsonCrtAlloc)
rapidjson::CrtAllocator> > >();
}
#ifdef VALIJSON_BUILD_CXX11_ADAPTERS
//
// Json11Adapter vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, Json11VsJson11)
{
@ -293,6 +316,8 @@ TEST_F(TestAdapterComparison, Json11VsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, Json11VsPropertyTree)
{
testComparison<
@ -300,6 +325,12 @@ TEST_F(TestAdapterComparison, Json11VsPropertyTree)
valijson::adapters::PropertyTreeAdapter>();
}
#endif // VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
//
// NlohmannJsonAdapter vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, NlohmannJsonVsNlohmannJson) {
testComparison<
valijson::adapters::NlohmannJsonAdapter,
@ -344,6 +375,8 @@ TEST_F(TestAdapterComparison, NlohmannJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, NlohmannJsonVsPropertyTree)
{
testComparison<
@ -351,9 +384,13 @@ TEST_F(TestAdapterComparison, NlohmannJsonVsPropertyTree)
valijson::adapters::PropertyTreeAdapter>();
}
#endif // VALIJSON_BUILD_CXX11_ADAPTERS
#endif // VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
#ifdef VALIJSON_BUILD_QT_ADAPTERS
//
// QtJsonAdapter vs X
// ------------------------------------------------------------------------------------------------
#ifdef VALIJSON_BUILD_QT_ADAPTER
TEST_F(TestAdapterComparison, QtJsonVsQtJson) {
testComparison<
@ -391,6 +428,8 @@ TEST_F(TestAdapterComparison, QtJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, QtJsonVsPropertyTree)
{
testComparison<
@ -398,9 +437,7 @@ TEST_F(TestAdapterComparison, QtJsonVsPropertyTree)
valijson::adapters::PropertyTreeAdapter>();
}
#endif // VALIJSON_BUILD_QT_ADAPTERS
#if defined(VALIJSON_BUILD_QT_ADAPTERS) && defined(VALIJSON_BUILD_CXX11_ADAPTERS)
#endif // VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, QtJsonVsJson11)
{
@ -416,9 +453,13 @@ TEST_F(TestAdapterComparison, QtJsonVsNlohmannJson)
valijson::adapters::NlohmannJsonAdapter>();
}
#endif
#endif // VALIJSON_BUILD_QT_ADAPTER
#ifdef VALIJSON_BUILD_POCO_ADAPTERS
//
// PocoJsonAdapter vs X
// ------------------------------------------------------------------------------------------------
#ifdef VALIJSON_BUILD_POCO_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsPocoJson)
{
@ -457,6 +498,8 @@ TEST_F(TestAdapterComparison, PocoJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsPropertyTree)
{
testComparison<
@ -464,9 +507,7 @@ TEST_F(TestAdapterComparison, PocoJsonVsPropertyTree)
valijson::adapters::PropertyTreeAdapter>();
}
#endif
#if defined(VALIJSON_BUILD_POCO_ADAPTERS) && defined(VALIJSON_BUILD_CXX11_ADAPTERS)
#endif // VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsJson11)
{
@ -482,9 +523,7 @@ TEST_F(TestAdapterComparison, PocoJsonVsNlohmannJsonAdapter)
valijson::adapters::NlohmannJsonAdapter>();
}
#endif
#if defined(VALIJSON_BUILD_POCO_ADAPTERS) && defined(VALIJSON_BUILD_QT_ADAPTERS)
#ifdef VALIJSON_BUILD_QT_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsQtJson)
{
@ -493,4 +532,6 @@ TEST_F(TestAdapterComparison, PocoJsonVsQtJson)
valijson::adapters::QtJsonAdapter>();
}
#endif
#endif // VALIJSON_BUILD_QT_ADAPTER
#endif // VALIJSON_BUILD_POCO_ADAPTER

View File

@ -1,5 +1,3 @@
#ifdef VALIJSON_BUILD_CXX11_ADAPTERS
#include <gtest/gtest.h>
#include <valijson/adapters/json11_adapter.hpp>
@ -82,6 +80,3 @@ TEST_F(TestJson11Adapter, BasicObjectIteration)
// Ensure that the correct number of elements were iterated over
EXPECT_EQ( numElements, expectedValue );
}
#endif // VALIJSON_BUILD_CXX11_ADAPTERS

View File

@ -1,5 +1,3 @@
#ifdef VALIJSON_BUILD_CXX11_ADAPTERS
#include <gtest/gtest.h>
#include <valijson/adapters/nlohmann_json_adapter.hpp>
@ -79,6 +77,3 @@ TEST_F(TestNlohmannJsonAdapter, BasicObjectIteration)
// Ensure that the correct number of elements were iterated over
EXPECT_EQ( numElements, expectedValue );
}
#endif // VALIJSON_BUILD_CXX11_ADAPTERS

View File

@ -1,5 +1,3 @@
#ifdef VALIJSON_BUILD_POCO_ADAPTERS
#include <gtest/gtest.h>
#include <valijson/adapters/poco_json_adapter.hpp>
@ -15,7 +13,7 @@ TEST_F(TestPocoJsonAdapter, BasicArrayIteration)
// Create a Json document that consists of an array of numbers
Poco::JSON::Array::Ptr documentImpl = new Poco::JSON::Array();
for (unsigned int i = 0; i < numElements; i++) {
documentImpl->set(i, static_cast<double>(i));
}
@ -84,6 +82,3 @@ TEST_F(TestPocoJsonAdapter, BasicObjectIteration)
// Ensure that the correct number of elements were iterated over
EXPECT_EQ( numElements, expectedValue );
}
#endif // VALIJSON_BUILD_POCO_ADAPTERS

View File

@ -4,26 +4,23 @@
#include <gtest/gtest.h>
#include <valijson/adapters/json11_adapter.hpp>
#include <valijson/adapters/jsoncpp_adapter.hpp>
#include <valijson/adapters/rapidjson_adapter.hpp>
#include <valijson/adapters/picojson_adapter.hpp>
#include <valijson/utils/json11_utils.hpp>
#include <valijson/utils/jsoncpp_utils.hpp>
#include <valijson/utils/rapidjson_utils.hpp>
#include <valijson/utils/picojson_utils.hpp>
#include <valijson/utils/rapidjson_utils.hpp>
#include <valijson/schema.hpp>
#include <valijson/schema_parser.hpp>
#include <valijson/validation_results.hpp>
#include <valijson/validator.hpp>
#ifdef VALIJSON_BUILD_CXX11_ADAPTERS
#include <valijson/adapters/json11_adapter.hpp>
#include <valijson/utils/json11_utils.hpp>
#endif // VALIJSON_BUILD_CXX11_ADAPTERS
#ifdef VALIJSON_BUILD_POCO_ADAPTERS
#ifdef VALIJSON_BUILD_POCO_ADAPTER
#include <valijson/adapters/poco_json_adapter.hpp>
#include <valijson/utils/poco_json_utils.hpp>
#endif // VALIJSON_BUILD_POCO_ADAPTERS
#endif
#define REMOTES_DIR "../thirdparty/JSON-Schema-Test-Suite/remotes/"
@ -172,13 +169,11 @@ protected:
processTestFile<valijson::adapters::JsonCppAdapter>(testFile, version);
processTestFile<valijson::adapters::RapidJsonAdapter>(testFile, version);
processTestFile<valijson::adapters::PicoJsonAdapter>(testFile, version);
#ifdef VALIJSON_BUILD_CXX11_ADAPTERS
processTestFile<valijson::adapters::Json11Adapter>(testFile, version);
#endif // VALIJSON_BUILD_CXX11_ADAPTERS
#ifdef VALIJSON_BUILD_POCO_ADAPTERS
#ifdef VALIJSON_BUILD_POCO_ADAPTER
processTestFile<valijson::adapters::PocoJsonAdapter>(testFile, version);
#endif // VALIJSON_BUILD_POCO_ADAPTERS
#endif // VALIJSON_BUILD_POCO_ADAPTER
}
void processDraft3TestFile(const std::string &testFile)