Update CMakeLists.txt to check for boost/json.hpp before building tests

This commit is contained in:
Tristan Penman 2021-10-06 20:23:57 +11:00
parent 5da8973097
commit 7b6d22f166
2 changed files with 130 additions and 86 deletions

View File

@ -112,8 +112,23 @@ if(valijson_BUILD_TESTS)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_boost_json_adapter.cpp)
# Property Trees have been in Boost since 1.41.0, so we just assume they're present
list(APPEND TEST_SOURCES tests/test_property_tree_adapter.cpp)
# Boost.JSON was introduced in Boost 1.75.0, so we should check for its presence before
# including the unit tests for boost_json_adapter
include(CheckIncludeFileCXX)
set (CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIRS})
check_include_file_cxx("boost/json.hpp" BOOST_JSON_HPP_FOUND)
if(${BOOST_JSON_HPP_FOUND})
list(APPEND TEST_SOURCES tests/test_boost_json_adapter.cpp)
else()
message(WARNING
"boost/json.hpp not found; tests for boost_json_adapter will not be built. "
"If you have recently upgraded Boost to 1.75.0 or later, you may need to clear "
"your CMake cache for the header to be found.")
endif()
endif()
if(Poco_FOUND)
@ -154,7 +169,10 @@ if(valijson_BUILD_TESTS)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_BOOST_ADAPTERS")
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER")
if(${BOOST_JSON_HPP_FOUND})
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_BOOST_JSON_ADAPTER")
endif()
endif()
if(Poco_FOUND)

View File

@ -20,13 +20,16 @@
#include <valijson/utils/picojson_utils.hpp>
#include <valijson/utils/rapidjson_utils.hpp>
#ifdef VALIJSON_BUILD_BOOST_ADAPTERS
#include <valijson/adapters/property_tree_adapter.hpp>
#include <valijson/utils/property_tree_utils.hpp>
#ifdef VALIJSON_BUILD_BOOST_JSON_ADAPTER
#include <valijson/adapters/boost_json_adapter.hpp>
#include <valijson/utils/boost_json_utils.hpp>
#endif
#ifdef VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
#include <valijson/adapters/property_tree_adapter.hpp>
#include <valijson/utils/property_tree_utils.hpp>
#endif
#ifdef VALIJSON_BUILD_QT_ADAPTER
#include <valijson/adapters/qtjson_adapter.hpp>
#include <valijson/utils/qtjson_utils.hpp>
@ -159,14 +162,7 @@ TEST_F(TestAdapterComparison, JsonCppVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_BOOST_ADAPTERS
TEST_F(TestAdapterComparison, JsonCppVsPropertyTree)
{
testComparison<
valijson::adapters::JsonCppAdapter,
valijson::adapters::PropertyTreeAdapter>();
}
#ifdef VALIJSON_BUILD_BOOST_JSON_ADAPTER
TEST_F(TestAdapterComparison, JsonCppVsBoostJson)
{
@ -175,7 +171,18 @@ TEST_F(TestAdapterComparison, JsonCppVsBoostJson)
valijson::adapters::BoostJsonAdapter>();
}
#endif
#endif // VALIJSON_BUILD_BOOST_JSON_ADAPTER
#ifdef VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, JsonCppVsPropertyTree)
{
testComparison<
valijson::adapters::JsonCppAdapter,
valijson::adapters::PropertyTreeAdapter>();
}
#endif // VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, JsonCppVsRapidJson)
{
@ -193,41 +200,7 @@ TEST_F(TestAdapterComparison, JsonCppVsRapidJsonCrtAlloc)
rapidjson::CrtAllocator> > >();
}
#ifdef VALIJSON_BUILD_BOOST_ADAPTERS
//
// PropertyTreeAdapter vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, PropertyTreeVsPicoJson)
{
testComparison<
valijson::adapters::PropertyTreeAdapter,
valijson::adapters::PicoJsonAdapter>();
}
TEST_F(TestAdapterComparison, PropertyTreeVsPropertyTree)
{
testComparison<
valijson::adapters::PropertyTreeAdapter,
valijson::adapters::PropertyTreeAdapter>();
}
TEST_F(TestAdapterComparison, PropertyTreeVsRapidJson)
{
testComparison<
valijson::adapters::PropertyTreeAdapter,
valijson::adapters::RapidJsonAdapter>();
}
TEST_F(TestAdapterComparison, PropertyTreeVsRapidJsonCrtAlloc)
{
testComparison<
valijson::adapters::PropertyTreeAdapter,
valijson::adapters::GenericRapidJsonAdapter<
rapidjson::GenericValue<rapidjson::UTF8<>,
rapidjson::CrtAllocator> > >();
}
#ifdef VALIJSON_BUILD_BOOST_JSON_ADAPTER
//
// BoostJsonAdapter vs X
@ -263,7 +236,44 @@ TEST_F(TestAdapterComparison, BoostJsonVsRapidJsonCrtAlloc)
rapidjson::CrtAllocator> > >();
}
#endif
#endif // VALIJSON_BUILD_BOOST_JSON_ADAPTER
#ifdef VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
//
// PropertyTreeAdapter vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, PropertyTreeVsPicoJson)
{
testComparison<
valijson::adapters::PropertyTreeAdapter,
valijson::adapters::PicoJsonAdapter>();
}
TEST_F(TestAdapterComparison, PropertyTreeVsPropertyTree)
{
testComparison<
valijson::adapters::PropertyTreeAdapter,
valijson::adapters::PropertyTreeAdapter>();
}
TEST_F(TestAdapterComparison, PropertyTreeVsRapidJson)
{
testComparison<
valijson::adapters::PropertyTreeAdapter,
valijson::adapters::RapidJsonAdapter>();
}
TEST_F(TestAdapterComparison, PropertyTreeVsRapidJsonCrtAlloc)
{
testComparison<
valijson::adapters::PropertyTreeAdapter,
valijson::adapters::GenericRapidJsonAdapter<
rapidjson::GenericValue<rapidjson::UTF8<>,
rapidjson::CrtAllocator> > >();
}
#endif // VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
//
// RapidJson vs X
@ -365,14 +375,7 @@ TEST_F(TestAdapterComparison, Json11VsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_BOOST_ADAPTERS
TEST_F(TestAdapterComparison, Json11VsPropertyTree)
{
testComparison<
valijson::adapters::Json11Adapter,
valijson::adapters::PropertyTreeAdapter>();
}
#ifdef VALIJSON_BUILD_BOOST_JSON_ADAPTER
TEST_F(TestAdapterComparison, Json11VsBoostJson)
{
@ -381,7 +384,18 @@ TEST_F(TestAdapterComparison, Json11VsBoostJson)
valijson::adapters::BoostJsonAdapter>();
}
#endif // VALIJSON_BUILD_BOOST_ADAPTERS
#endif // VALIJSON_BUILD_BOOST_JSON_ADAPTER
#ifdef VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, Json11VsPropertyTree)
{
testComparison<
valijson::adapters::Json11Adapter,
valijson::adapters::PropertyTreeAdapter>();
}
#endif // VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
//
// NlohmannJsonAdapter vs X
@ -431,14 +445,7 @@ TEST_F(TestAdapterComparison, NlohmannJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_BOOST_ADAPTERS
TEST_F(TestAdapterComparison, NlohmannJsonVsPropertyTree)
{
testComparison<
valijson::adapters::NlohmannJsonAdapter,
valijson::adapters::PropertyTreeAdapter>();
}
#ifdef VALIJSON_BUILD_BOOST_JSON_ADAPTER
TEST_F(TestAdapterComparison, NlohmannJsonVsBoostJson)
{
@ -447,7 +454,18 @@ TEST_F(TestAdapterComparison, NlohmannJsonVsBoostJson)
valijson::adapters::BoostJsonAdapter>();
}
#endif // VALIJSON_BUILD_BOOST_ADAPTERS
#endif // VALIJSON_BUILD_BOOST_JSON_ADAPTER
#ifdef VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, NlohmannJsonVsPropertyTree)
{
testComparison<
valijson::adapters::NlohmannJsonAdapter,
valijson::adapters::PropertyTreeAdapter>();
}
#endif // VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
//
// QtJsonAdapter vs X
@ -491,14 +509,7 @@ TEST_F(TestAdapterComparison, QtJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_BOOST_ADAPTERS
TEST_F(TestAdapterComparison, QtJsonVsPropertyTree)
{
testComparison<
valijson::adapters::QtJsonAdapter,
valijson::adapters::PropertyTreeAdapter>();
}
#ifdef VALIJSON_BUILD_BOOST_JSON_ADAPTER
TEST_F(TestAdapterComparison, QtJsonVsBoostJson)
{
@ -507,7 +518,18 @@ TEST_F(TestAdapterComparison, QtJsonVsBoostJson)
valijson::adapters::BoostJsonAdapter>();
}
#endif // VALIJSON_BUILD_BOOST_ADAPTERS
#endif // VALIJSON_BUILD_BOOST_JSON_ADAPTER
#ifdef VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, QtJsonVsPropertyTree)
{
testComparison<
valijson::adapters::QtJsonAdapter,
valijson::adapters::PropertyTreeAdapter>();
}
#endif // VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, QtJsonVsJson11)
{
@ -568,14 +590,7 @@ TEST_F(TestAdapterComparison, PocoJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_BOOST_ADAPTERS
TEST_F(TestAdapterComparison, PocoJsonVsPropertyTree)
{
testComparison<
valijson::adapters::PocoJsonAdapter,
valijson::adapters::PropertyTreeAdapter>();
}
#ifdef VALIJSON_BUILD_BOOST_JSON_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsBoostJson)
{
@ -584,7 +599,18 @@ TEST_F(TestAdapterComparison, PocoJsonVsBoostJson)
valijson::adapters::BoostJsonAdapter>();
}
#endif // VALIJSON_BUILD_BOOST_ADAPTERS
#endif // VALIJSON_BUILD_BOOST_JSON_ADAPTER
#ifdef VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsPropertyTree)
{
testComparison<
valijson::adapters::PocoJsonAdapter,
valijson::adapters::PropertyTreeAdapter>();
}
#endif // VALIJSON_BUILD_BOOST_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsJson11)
{