diff --git a/CMakeLists.txt b/CMakeLists.txt index c20ea3a..be16680 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,9 @@ add_library(xtl INTERFACE) target_include_directories(xtl INTERFACE $ $) +# xtl requires C++14 support! +target_compile_features(xtl INTERFACE cxx_std_14) + OPTION(BUILD_TESTS "xtl test suite" OFF) OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c2de281..0b20bc5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,6 +12,7 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) project(xtl-test) find_package(xtl REQUIRED CONFIG) + find_package(nlohmann_json QUIET CONFIG) set(XTL_INCLUDE_DIR ${xtl_INCLUDE_DIRS}) endif () @@ -22,6 +23,10 @@ include(CheckCXXCompilerFlag) string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE) +if(nlohmann_json_FOUND) + add_definitions(-DHAVE_NLOHMANN_JSON) +endif() + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder -Wconversion") @@ -30,13 +35,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" if (HAS_MARCH_NATIVE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") endif() - - CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG) - if (HAS_CPP14_FLAG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") - else() - message(FATAL_ERROR "Unsupported compiler -- xtl requires C++14 support!") - endif() endif() if(MSVC) @@ -110,7 +108,17 @@ add_executable(${XTL_TARGET} ${XTL_TESTS} ${XTL_HEADERS}) if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) add_dependencies(${XTL_TARGET} gtest_main) endif() -target_link_libraries(${XTL_TARGET} xtl nlohmann_json ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(${XTL_TARGET} xtl ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) + +if(nlohmann_json_FOUND) + # Version up to 3.1.2 export the target `nlohmann_json` + if(TARGET nlohmann_json) + target_link_libraries(${XTL_TARGET} nlohmann_json) + # Newer versions export the namespaced target `nlohmann_json::nlohmann_json` + elseif(TARGET nlohmann_json::nlohmann_json) + target_link_libraries(${XTL_TARGET} nlohmann_json::nlohmann_json) + endif() +endif() add_custom_target(xtest COMMAND test_xtl DEPENDS ${XTL_TARGET}) diff --git a/test/test_xoptional.cpp b/test/test_xoptional.cpp index 8100453..2ac1857 100644 --- a/test/test_xoptional.cpp +++ b/test/test_xoptional.cpp @@ -15,7 +15,11 @@ #include "xtl/xany.hpp" #include "xtl/xoptional.hpp" + +#ifdef HAVE_NLOHMANN_JSON #include "xtl/xjson.hpp" +#endif + #include "xtl/xoptional_sequence.hpp" namespace xtl @@ -276,6 +280,7 @@ namespace xtl EXPECT_EQ(res.has_value(), o.has_value()); } +#ifdef HAVE_NLOHMANN_JSON TEST(xoptional, json) { xoptional m1 = missing(); @@ -287,4 +292,5 @@ namespace xtl nlohmann::json j2 = m2; EXPECT_EQ(j2.get>(), 3.0); } +#endif }