2019-08-20 03:11:42 +02:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
|
|
|
project(valijson)
|
2014-04-17 02:58:51 +02:00
|
|
|
|
2018-05-30 10:43:44 +02:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
2017-05-31 07:53:42 +02:00
|
|
|
|
2019-08-20 03:18:58 +02:00
|
|
|
option(valijson_INSTALL_HEADERS "Install valijson headers." FALSE)
|
|
|
|
option(valijson_BUILD_EXAMPLES "Build valijson examples." FALSE)
|
|
|
|
option(valijson_BUILD_TESTS "Build valijson test suite." TRUE)
|
|
|
|
option(valijson_EXCLUDE_BOOST "Exclude Boost when building test suite." FALSE)
|
2020-11-07 03:17:36 +01:00
|
|
|
option(valijson_USE_EXCEPTIONS "Use exceptions in valijson and included libs." TRUE)
|
2017-05-31 07:53:42 +02:00
|
|
|
|
2021-05-17 05:57:29 +02:00
|
|
|
if(MSVC)
|
|
|
|
add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
|
|
|
|
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
|
|
|
else()
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
|
|
|
if(!COMPILER_SUPPORTS_CXX11)
|
|
|
|
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
|
|
|
|
endif()
|
|
|
|
|
2021-05-24 02:00:16 +02:00
|
|
|
# Suppress boost warnings that aren't relevant to the test suite
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_BIND_GLOBAL_PLACEHOLDERS")
|
|
|
|
|
2021-05-17 05:57:29 +02:00
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
|
|
|
|
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
|
|
|
|
endif()
|
2017-05-31 07:53:42 +02:00
|
|
|
|
2020-07-09 18:24:41 +02:00
|
|
|
add_library(valijson INTERFACE)
|
|
|
|
# create alias, so that user could always write target_link_libraries(... ValiJSON::valijson)
|
|
|
|
# despite of valijson target is imported or not
|
|
|
|
add_library(ValiJSON::valijson ALIAS valijson)
|
|
|
|
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
target_include_directories(valijson INTERFACE
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
|
|
|
|
2018-09-01 22:27:29 +02:00
|
|
|
if(valijson_INSTALL_HEADERS)
|
2017-05-31 07:53:42 +02:00
|
|
|
install(DIRECTORY include/ DESTINATION include)
|
|
|
|
endif()
|
|
|
|
|
2018-09-01 22:27:29 +02:00
|
|
|
if(NOT valijson_BUILD_TESTS AND NOT valijson_BUILD_EXAMPLES)
|
2017-05-31 07:53:42 +02:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2020-11-07 03:17:36 +01:00
|
|
|
if(valijson_USE_EXCEPTIONS)
|
2020-11-09 02:18:14 +01:00
|
|
|
add_definitions(-DVALIJSON_USE_EXCEPTIONS=1)
|
2020-11-07 03:17:36 +01:00
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
|
2020-11-09 02:18:14 +01:00
|
|
|
add_definitions(-DBOOST_NO_EXCEPTIONS)
|
|
|
|
add_definitions(-DJSON_USE_EXCEPTION=0)
|
|
|
|
add_definitions(-DVALIJSON_USE_EXCEPTIONS=0)
|
2020-11-07 03:17:36 +01:00
|
|
|
endif()
|
|
|
|
|
2017-05-31 07:01:31 +02:00
|
|
|
find_package(Poco OPTIONAL_COMPONENTS JSON)
|
2017-03-06 16:38:02 +01:00
|
|
|
find_package(Qt5Core)
|
|
|
|
|
2014-04-17 02:58:51 +02:00
|
|
|
# jsoncpp library
|
|
|
|
add_library(jsoncpp
|
2020-11-06 02:11:35 +01:00
|
|
|
thirdparty/jsoncpp-1.9.4/src/lib_json/json_reader.cpp
|
|
|
|
thirdparty/jsoncpp-1.9.4/src/lib_json/json_value.cpp
|
|
|
|
thirdparty/jsoncpp-1.9.4/src/lib_json/json_writer.cpp
|
2014-04-17 02:58:51 +02:00
|
|
|
)
|
|
|
|
|
2020-11-06 02:11:35 +01:00
|
|
|
target_include_directories(jsoncpp SYSTEM PRIVATE thirdparty/jsoncpp-1.9.4/include)
|
|
|
|
set_target_properties(jsoncpp PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/thirdparty/jsoncpp-1.9.4)
|
2016-08-11 06:15:18 +02:00
|
|
|
|
|
|
|
add_library(json11
|
2017-09-23 01:36:01 +02:00
|
|
|
thirdparty/json11-ec4e452/json11.cpp
|
2016-08-11 06:15:18 +02:00
|
|
|
)
|
|
|
|
|
2017-09-23 01:36:01 +02:00
|
|
|
target_include_directories(json11 SYSTEM PRIVATE thirdparty/json11-ec4e452)
|
|
|
|
set_target_properties(json11 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/thirdparty/json11-ec4e452)
|
2016-01-26 05:19:40 +01:00
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
# Not all of these are required for examples build it doesn't hurt to include them
|
|
|
|
include_directories(include SYSTEM
|
2017-05-31 07:53:42 +02:00
|
|
|
thirdparty/gtest-1.7.0/include
|
2017-09-23 01:36:01 +02:00
|
|
|
thirdparty/json11-ec4e452
|
2020-11-06 02:11:35 +01:00
|
|
|
thirdparty/jsoncpp-1.9.4/include
|
2018-10-24 12:05:24 +02:00
|
|
|
thirdparty/rapidjson-1.1.0/include
|
2017-05-31 07:53:42 +02:00
|
|
|
thirdparty/picojson-1.3.0
|
2018-08-01 06:25:10 +02:00
|
|
|
thirdparty/nlohmann-json-3.1.2
|
2019-08-20 03:11:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
if(valijson_BUILD_TESTS)
|
2019-08-20 03:18:58 +02:00
|
|
|
if(NOT valijson_EXCLUDE_BOOST)
|
2019-08-27 04:19:27 +02:00
|
|
|
find_package(Boost)
|
2019-08-20 03:11:42 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Build local gtest
|
|
|
|
set(gtest_force_shared_crt ON)
|
|
|
|
add_subdirectory(thirdparty/gtest-1.7.0)
|
|
|
|
|
|
|
|
set(TEST_SOURCES
|
|
|
|
tests/test_adapter_comparison.cpp
|
|
|
|
tests/test_fetch_document_callback.cpp
|
|
|
|
tests/test_json_pointer.cpp
|
|
|
|
tests/test_json11_adapter.cpp
|
|
|
|
tests/test_jsoncpp_adapter.cpp
|
|
|
|
tests/test_nlohmann_json_adapter.cpp
|
|
|
|
tests/test_rapidjson_adapter.cpp
|
|
|
|
tests/test_picojson_adapter.cpp
|
|
|
|
tests/test_poly_constraint.cpp
|
|
|
|
tests/test_validation_errors.cpp
|
|
|
|
tests/test_validator.cpp
|
|
|
|
)
|
|
|
|
|
2020-07-06 04:37:05 +02:00
|
|
|
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)
|
|
|
|
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})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(Qt5Core_FOUND)
|
|
|
|
include_directories(${Qt5Core_INCLUDE_DIRS})
|
|
|
|
list(APPEND TEST_LIBS Qt5::Core)
|
|
|
|
list(APPEND TEST_SOURCES tests/test_qtjson_adapter.cpp)
|
|
|
|
endif()
|
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
# Unit tests executable
|
|
|
|
add_executable(test_suite ${TEST_SOURCES})
|
|
|
|
|
2021-05-17 05:57:29 +02:00
|
|
|
if(MSVC)
|
|
|
|
|
|
|
|
else()
|
|
|
|
set_target_properties(test_suite PROPERTIES COMPILE_FLAGS " -pedantic -Werror -Wshadow -Wunused")
|
|
|
|
endif()
|
2020-07-06 11:30:55 +02:00
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
# Definition for using picojson
|
|
|
|
set_target_properties(test_suite PROPERTIES COMPILE_DEFINITIONS "PICOJSON_USE_INT64")
|
|
|
|
|
2019-08-20 03:18:58 +02:00
|
|
|
if(Boost_FOUND)
|
2020-11-09 02:18:14 +01:00
|
|
|
add_definitions(-DBOOST_ALL_DYN_LINK)
|
2019-08-20 03:18:58 +02:00
|
|
|
set(Boost_USE_STATIC_LIBS OFF)
|
|
|
|
set(Boost_USE_MULTITHREADED ON)
|
|
|
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
2019-08-27 04:19:27 +02:00
|
|
|
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_PROPERTY_TREE_ADAPTER")
|
2019-08-20 03:11:42 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(Poco_FOUND)
|
2019-08-27 04:19:27 +02:00
|
|
|
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTER")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(Qt5Core_FOUND)
|
|
|
|
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTER")
|
2019-08-20 03:11:42 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
target_link_libraries(test_suite ${TEST_LIBS} ${Boost_LIBRARIES})
|
|
|
|
endif()
|
2017-07-10 04:57:14 +02:00
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
if(valijson_BUILD_EXAMPLES)
|
2020-12-02 10:01:36 +01:00
|
|
|
find_package(curlpp)
|
2019-08-20 03:11:42 +02:00
|
|
|
include_directories(SYSTEM)
|
2017-07-10 04:57:14 +02:00
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
add_executable(custom_schema
|
|
|
|
examples/custom_schema.cpp
|
|
|
|
)
|
2017-07-10 04:57:14 +02:00
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
add_executable(external_schema
|
|
|
|
examples/external_schema.cpp
|
|
|
|
)
|
2017-07-10 04:57:14 +02:00
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
add_executable(array_iteration_basics
|
|
|
|
examples/array_iteration_basics.cpp
|
|
|
|
)
|
2017-07-10 04:57:14 +02:00
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
add_executable(array_iteration_template_fn
|
|
|
|
examples/array_iteration_template_fn.cpp
|
|
|
|
)
|
2016-01-28 05:35:44 +01:00
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
add_executable(object_iteration
|
|
|
|
examples/object_iteration.cpp
|
|
|
|
)
|
2017-03-06 16:38:02 +01:00
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
add_executable(json_pointers
|
|
|
|
examples/json_pointers.cpp
|
|
|
|
)
|
2014-04-17 02:58:51 +02:00
|
|
|
|
2020-06-26 12:04:07 +02:00
|
|
|
add_executable(remote_resolution_local_file
|
|
|
|
examples/remote_resolution_local_file.cpp
|
|
|
|
)
|
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
if(curlpp_FOUND)
|
|
|
|
include_directories(${curlpp_INCLUDE_DIR})
|
2015-05-08 17:24:29 +02:00
|
|
|
|
2020-06-26 12:04:07 +02:00
|
|
|
add_executable(remote_resolution_url
|
|
|
|
examples/remote_resolution_url.cpp
|
2019-08-20 03:11:42 +02:00
|
|
|
)
|
2017-05-31 07:01:31 +02:00
|
|
|
|
2020-06-26 12:04:07 +02:00
|
|
|
target_link_libraries(remote_resolution_url curl ${curlpp_LIBRARIES})
|
2019-08-20 03:11:42 +02:00
|
|
|
endif()
|
2017-03-06 16:38:02 +01:00
|
|
|
|
2019-08-20 03:11:42 +02:00
|
|
|
target_link_libraries(custom_schema ${Boost_LIBRARIES})
|
|
|
|
target_link_libraries(external_schema ${Boost_LIBRARIES})
|
|
|
|
target_link_libraries(array_iteration_basics jsoncpp)
|
|
|
|
target_link_libraries(array_iteration_template_fn jsoncpp)
|
|
|
|
target_link_libraries(object_iteration jsoncpp)
|
|
|
|
target_link_libraries(json_pointers)
|
2017-05-31 07:01:31 +02:00
|
|
|
endif()
|