Improve optional example and test suite options in CMakeLists.txt

This commit is contained in:
Tristan Penman 2019-08-20 11:11:42 +10:00
parent c19a02bff0
commit 56fb36dff9
2 changed files with 110 additions and 78 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 3.1) cmake_minimum_required(VERSION 3.1)
project (valijson) project(valijson)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@ -27,12 +27,7 @@ else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif() endif()
add_definitions(-DBOOST_ALL_DYN_LINK) find_package(curlpp)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.54.0 REQUIRED)
find_package(Poco OPTIONAL_COMPONENTS JSON) find_package(Poco OPTIONAL_COMPONENTS JSON)
find_package(Qt5Core) find_package(Qt5Core)
@ -53,13 +48,8 @@ add_library(json11
target_include_directories(json11 SYSTEM PRIVATE thirdparty/json11-ec4e452) target_include_directories(json11 SYSTEM PRIVATE thirdparty/json11-ec4e452)
set_target_properties(json11 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/thirdparty/json11-ec4e452) set_target_properties(json11 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/thirdparty/json11-ec4e452)
# Build local gtest # Not all of these are required for examples build it doesn't hurt to include them
set(gtest_force_shared_crt ON) include_directories(include SYSTEM
add_subdirectory(thirdparty/gtest-1.7.0)
# Include path
include_directories(include)
include_directories(SYSTEM
thirdparty/gtest-1.7.0/include thirdparty/gtest-1.7.0/include
thirdparty/json11-ec4e452 thirdparty/json11-ec4e452
thirdparty/jsoncpp-0.9.4/include thirdparty/jsoncpp-0.9.4/include
@ -68,81 +58,103 @@ include_directories(SYSTEM
thirdparty/nlohmann-json-3.1.2 thirdparty/nlohmann-json-3.1.2
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${Qt5Core_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS}
) )
# Custom schema validation example if(valijson_BUILD_TESTS)
add_executable(custom_schema find_package(Boost 1.54.0 REQUIRED)
examples/custom_schema.cpp if(Boost_FOUND)
) add_definitions(-DBOOST_ALL_DYN_LINK)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
endif()
# External schema validation example # Build local gtest
add_executable(external_schema set(gtest_force_shared_crt ON)
examples/external_schema.cpp add_subdirectory(thirdparty/gtest-1.7.0)
)
add_executable(array_iteration_basics set(TEST_SOURCES
examples/array_iteration_basics.cpp 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_property_tree_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
)
add_executable(array_iteration_template_fn if(Qt5Core_FOUND)
examples/array_iteration_template_fn.cpp list(APPEND TEST_SOURCES tests/test_qtjson_adapter.cpp)
) endif()
add_executable(object_iteration # Unit tests executable
examples/object_iteration.cpp add_executable(test_suite ${TEST_SOURCES})
)
add_executable(json_pointers # Definition for using picojson
examples/json_pointers.cpp set_target_properties(test_suite PROPERTIES COMPILE_DEFINITIONS "PICOJSON_USE_INT64")
)
add_executable(remote_resolution set(TEST_LIBS gtest gtest_main jsoncpp json11)
examples/remote_resolution.cpp
)
set(TEST_SOURCES if(Qt5Core_FOUND)
tests/test_adapter_comparison.cpp list(APPEND TEST_LIBS Qt5::Core)
tests/test_fetch_document_callback.cpp target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTERS")
tests/test_json_pointer.cpp endif()
tests/test_json11_adapter.cpp
tests/test_jsoncpp_adapter.cpp
tests/test_nlohmann_json_adapter.cpp
tests/test_property_tree_adapter.cpp
tests/test_rapidjson_adapter.cpp
tests/test_picojson_adapter.cpp
tests/test_poco_json_adapter.cpp
tests/test_validation_errors.cpp
tests/test_validator.cpp
tests/test_poly_constraint.cpp
)
if(Qt5Core_FOUND) if(Poco_FOUND)
list(APPEND TEST_SOURCES tests/test_qtjson_adapter.cpp) list(APPEND TEST_LIBS ${Poco_Foundation_LIBRARIES} ${Poco_JSON_LIBRARIES})
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTERS")
endif()
target_link_libraries(test_suite ${TEST_LIBS} ${Boost_LIBRARIES})
endif() endif()
# Unit tests executable if(valijson_BUILD_EXAMPLES)
add_executable(test_suite ${TEST_SOURCES}) include_directories(SYSTEM)
# Definition for using picojson add_executable(custom_schema
set_target_properties(test_suite PROPERTIES COMPILE_DEFINITIONS "PICOJSON_USE_INT64") examples/custom_schema.cpp
)
set(TEST_LIBS gtest gtest_main jsoncpp json11) add_executable(external_schema
examples/external_schema.cpp
)
if (Qt5Core_FOUND) add_executable(array_iteration_basics
list(APPEND TEST_LIBS Qt5::Core) examples/array_iteration_basics.cpp
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTERS") )
add_executable(array_iteration_template_fn
examples/array_iteration_template_fn.cpp
)
add_executable(object_iteration
examples/object_iteration.cpp
)
add_executable(json_pointers
examples/json_pointers.cpp
)
if(curlpp_FOUND)
include_directories(${curlpp_INCLUDE_DIR})
add_executable(remote_resolution
examples/remote_resolution.cpp
)
target_link_libraries(remote_resolution curl ${curlpp_LIBRARIES})
endif()
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)
endif() endif()
if(Poco_FOUND)
list(APPEND TEST_LIBS ${Poco_Foundation_LIBRARIES} ${Poco_JSON_LIBRARIES})
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTERS")
endif()
target_link_libraries(test_suite ${TEST_LIBS} ${Boost_LIBRARIES})
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)
target_link_libraries(remote_resolution curl curlpp)

20
cmake/Findcurlpp.cmake Normal file
View File

@ -0,0 +1,20 @@
include(FindPkgConfig)
include(FindPackageHandleStandardArgs)
pkg_check_modules(curlpp_PKGCONF REQUIRED curlpp)
find_path(curlpp_INCLUDE_DIR
NAMES curlpp/cURLpp.hpp
PATHS ${curlpp_PKGCONF_INCLUDE_DIRS}
)
find_library(curlpp_LIBRARIES
NAMES curlpp
PATHS ${curlpp_PKGCONF_LIBRARY_DIRS}
)
if(curlpp_PKGCONF_FOUND)
set(curlpp_FOUND yes)
else()
set(curlpp_FOUND no)
endif()