Skip to content

Commit 56fb36d

Browse files
committed
Improve optional example and test suite options in CMakeLists.txt
1 parent c19a02b commit 56fb36d

File tree

2 files changed

+113
-81
lines changed

2 files changed

+113
-81
lines changed

CMakeLists.txt

+93-81
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
cmake_minimum_required (VERSION 3.1)
2-
project (valijson)
1+
cmake_minimum_required(VERSION 3.1)
2+
project(valijson)
33

44
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
55

@@ -27,12 +27,7 @@ else()
2727
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
2828
endif()
2929

30-
add_definitions(-DBOOST_ALL_DYN_LINK)
31-
set(Boost_USE_STATIC_LIBS OFF)
32-
set(Boost_USE_MULTITHREADED ON)
33-
set(Boost_USE_STATIC_RUNTIME OFF)
34-
35-
find_package(Boost 1.54.0 REQUIRED)
30+
find_package(curlpp)
3631
find_package(Poco OPTIONAL_COMPONENTS JSON)
3732
find_package(Qt5Core)
3833

@@ -53,13 +48,8 @@ add_library(json11
5348
target_include_directories(json11 SYSTEM PRIVATE thirdparty/json11-ec4e452)
5449
set_target_properties(json11 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/thirdparty/json11-ec4e452)
5550

56-
# Build local gtest
57-
set(gtest_force_shared_crt ON)
58-
add_subdirectory(thirdparty/gtest-1.7.0)
59-
60-
# Include path
61-
include_directories(include)
62-
include_directories(SYSTEM
51+
# Not all of these are required for examples build it doesn't hurt to include them
52+
include_directories(include SYSTEM
6353
thirdparty/gtest-1.7.0/include
6454
thirdparty/json11-ec4e452
6555
thirdparty/jsoncpp-0.9.4/include
@@ -68,81 +58,103 @@ include_directories(SYSTEM
6858
thirdparty/nlohmann-json-3.1.2
6959
${Boost_INCLUDE_DIRS}
7060
${Qt5Core_INCLUDE_DIRS}
71-
)
72-
73-
# Custom schema validation example
74-
add_executable(custom_schema
75-
examples/custom_schema.cpp
76-
)
77-
78-
# External schema validation example
79-
add_executable(external_schema
80-
examples/external_schema.cpp
81-
)
82-
83-
add_executable(array_iteration_basics
84-
examples/array_iteration_basics.cpp
85-
)
61+
)
62+
63+
if(valijson_BUILD_TESTS)
64+
find_package(Boost 1.54.0 REQUIRED)
65+
if(Boost_FOUND)
66+
add_definitions(-DBOOST_ALL_DYN_LINK)
67+
set(Boost_USE_STATIC_LIBS OFF)
68+
set(Boost_USE_MULTITHREADED ON)
69+
set(Boost_USE_STATIC_RUNTIME OFF)
70+
endif()
71+
72+
# Build local gtest
73+
set(gtest_force_shared_crt ON)
74+
add_subdirectory(thirdparty/gtest-1.7.0)
75+
76+
set(TEST_SOURCES
77+
tests/test_adapter_comparison.cpp
78+
tests/test_fetch_document_callback.cpp
79+
tests/test_json_pointer.cpp
80+
tests/test_json11_adapter.cpp
81+
tests/test_jsoncpp_adapter.cpp
82+
tests/test_nlohmann_json_adapter.cpp
83+
tests/test_property_tree_adapter.cpp
84+
tests/test_rapidjson_adapter.cpp
85+
tests/test_picojson_adapter.cpp
86+
tests/test_poco_json_adapter.cpp
87+
tests/test_poly_constraint.cpp
88+
tests/test_validation_errors.cpp
89+
tests/test_validator.cpp
90+
)
91+
92+
if(Qt5Core_FOUND)
93+
list(APPEND TEST_SOURCES tests/test_qtjson_adapter.cpp)
94+
endif()
95+
96+
# Unit tests executable
97+
add_executable(test_suite ${TEST_SOURCES})
98+
99+
# Definition for using picojson
100+
set_target_properties(test_suite PROPERTIES COMPILE_DEFINITIONS "PICOJSON_USE_INT64")
101+
102+
set(TEST_LIBS gtest gtest_main jsoncpp json11)
103+
104+
if(Qt5Core_FOUND)
105+
list(APPEND TEST_LIBS Qt5::Core)
106+
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTERS")
107+
endif()
108+
109+
if(Poco_FOUND)
110+
list(APPEND TEST_LIBS ${Poco_Foundation_LIBRARIES} ${Poco_JSON_LIBRARIES})
111+
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTERS")
112+
endif()
113+
114+
target_link_libraries(test_suite ${TEST_LIBS} ${Boost_LIBRARIES})
115+
endif()
86116

87-
add_executable(array_iteration_template_fn
88-
examples/array_iteration_template_fn.cpp
89-
)
117+
if(valijson_BUILD_EXAMPLES)
118+
include_directories(SYSTEM)
90119

91-
add_executable(object_iteration
92-
examples/object_iteration.cpp
93-
)
120+
add_executable(custom_schema
121+
examples/custom_schema.cpp
122+
)
94123

95-
add_executable(json_pointers
96-
examples/json_pointers.cpp
97-
)
124+
add_executable(external_schema
125+
examples/external_schema.cpp
126+
)
98127

99-
add_executable(remote_resolution
100-
examples/remote_resolution.cpp
101-
)
128+
add_executable(array_iteration_basics
129+
examples/array_iteration_basics.cpp
130+
)
102131

103-
set(TEST_SOURCES
104-
tests/test_adapter_comparison.cpp
105-
tests/test_fetch_document_callback.cpp
106-
tests/test_json_pointer.cpp
107-
tests/test_json11_adapter.cpp
108-
tests/test_jsoncpp_adapter.cpp
109-
tests/test_nlohmann_json_adapter.cpp
110-
tests/test_property_tree_adapter.cpp
111-
tests/test_rapidjson_adapter.cpp
112-
tests/test_picojson_adapter.cpp
113-
tests/test_poco_json_adapter.cpp
114-
tests/test_validation_errors.cpp
115-
tests/test_validator.cpp
116-
tests/test_poly_constraint.cpp
117-
)
132+
add_executable(array_iteration_template_fn
133+
examples/array_iteration_template_fn.cpp
134+
)
118135

119-
if(Qt5Core_FOUND)
120-
list(APPEND TEST_SOURCES tests/test_qtjson_adapter.cpp)
121-
endif()
136+
add_executable(object_iteration
137+
examples/object_iteration.cpp
138+
)
122139

123-
# Unit tests executable
124-
add_executable(test_suite ${TEST_SOURCES})
140+
add_executable(json_pointers
141+
examples/json_pointers.cpp
142+
)
125143

126-
# Definition for using picojson
127-
set_target_properties(test_suite PROPERTIES COMPILE_DEFINITIONS "PICOJSON_USE_INT64")
144+
if(curlpp_FOUND)
145+
include_directories(${curlpp_INCLUDE_DIR})
128146

129-
set(TEST_LIBS gtest gtest_main jsoncpp json11)
147+
add_executable(remote_resolution
148+
examples/remote_resolution.cpp
149+
)
130150

131-
if (Qt5Core_FOUND)
132-
list(APPEND TEST_LIBS Qt5::Core)
133-
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTERS")
134-
endif()
151+
target_link_libraries(remote_resolution curl ${curlpp_LIBRARIES})
152+
endif()
135153

136-
if(Poco_FOUND)
137-
list(APPEND TEST_LIBS ${Poco_Foundation_LIBRARIES} ${Poco_JSON_LIBRARIES})
138-
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTERS")
154+
target_link_libraries(custom_schema ${Boost_LIBRARIES})
155+
target_link_libraries(external_schema ${Boost_LIBRARIES})
156+
target_link_libraries(array_iteration_basics jsoncpp)
157+
target_link_libraries(array_iteration_template_fn jsoncpp)
158+
target_link_libraries(object_iteration jsoncpp)
159+
target_link_libraries(json_pointers)
139160
endif()
140-
141-
target_link_libraries(test_suite ${TEST_LIBS} ${Boost_LIBRARIES})
142-
target_link_libraries(custom_schema ${Boost_LIBRARIES})
143-
target_link_libraries(external_schema ${Boost_LIBRARIES})
144-
target_link_libraries(array_iteration_basics jsoncpp)
145-
target_link_libraries(array_iteration_template_fn jsoncpp)
146-
target_link_libraries(object_iteration jsoncpp)
147-
target_link_libraries(json_pointers)
148-
target_link_libraries(remote_resolution curl curlpp)

cmake/Findcurlpp.cmake

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
include(FindPkgConfig)
2+
include(FindPackageHandleStandardArgs)
3+
4+
pkg_check_modules(curlpp_PKGCONF REQUIRED curlpp)
5+
6+
find_path(curlpp_INCLUDE_DIR
7+
NAMES curlpp/cURLpp.hpp
8+
PATHS ${curlpp_PKGCONF_INCLUDE_DIRS}
9+
)
10+
11+
find_library(curlpp_LIBRARIES
12+
NAMES curlpp
13+
PATHS ${curlpp_PKGCONF_LIBRARY_DIRS}
14+
)
15+
16+
if(curlpp_PKGCONF_FOUND)
17+
set(curlpp_FOUND yes)
18+
else()
19+
set(curlpp_FOUND no)
20+
endif()

0 commit comments

Comments
 (0)