generated from cpp-best-practices/gui_starter_template
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathCMakeLists.txt
212 lines (178 loc) · 7.25 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
cmake_minimum_required(VERSION 3.15...3.23)
project(CmakeConfigPackageTests LANGUAGES CXX)
# ---- Test as standalone project the exported config package ----
if(PROJECT_IS_TOP_LEVEL OR TEST_INSTALLED_VERSION)
enable_testing()
find_package(myproject CONFIG REQUIRED) # for intro, json2cpp_options, ...
if(NOT TARGET myjson2cpp_options)
message(FATAL_ERROR "Requiered config package not found!")
return() # be strictly paranoid for Template Janitor github action! CK
endif()
endif()
# ---- Dependencies ----
include(${Catch2_SOURCE_DIR}/extras/Catch.cmake)
set(BASE_NAME "${CMAKE_CURRENT_BINARY_DIR}/test_json")
add_custom_command(
DEPENDS json2cpp
OUTPUT "${BASE_NAME}_impl.hpp" "${BASE_NAME}.hpp" "${BASE_NAME}.cpp"
COMMAND json2cpp "test_json" "${CMAKE_SOURCE_DIR}/examples/test.json" "${BASE_NAME}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(tests tests.cpp "${BASE_NAME}.cpp")
target_include_directories(tests PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_include_directories(tests PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(tests PRIVATE json2cpp_warnings json2cpp_options Catch2::Catch2WithMain)
# automatically discover tests that are defined in catch based test files you can modify the unittests. Set TEST_PREFIX
# to whatever you want, or use different for different binaries
catch_discover_tests(
tests
TEST_PREFIX
"unittests."
REPORTER
XML
OUTPUT_DIR
.
OUTPUT_PREFIX
"unittests."
OUTPUT_SUFFIX
.xml)
set(SCHEMA_BASE_NAME "${CMAKE_CURRENT_BINARY_DIR}/allof_integers_and_numbers.schema")
add_custom_command(
DEPENDS json2cpp
OUTPUT "${SCHEMA_BASE_NAME}_impl.hpp" "${SCHEMA_BASE_NAME}.hpp" "${SCHEMA_BASE_NAME}.cpp"
COMMAND json2cpp "allof_integers_and_numbers_schema"
"${CMAKE_SOURCE_DIR}/examples/allof_integers_and_numbers.schema.json" "${SCHEMA_BASE_NAME}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
set(INT_BASE_NAME "${CMAKE_CURRENT_BINARY_DIR}/array_integers_10_20_30_40")
add_custom_command(
DEPENDS json2cpp
OUTPUT "${INT_BASE_NAME}_impl.hpp" "${INT_BASE_NAME}.hpp" "${INT_BASE_NAME}.cpp"
COMMAND json2cpp "array_integers_10_20_30_40" "${CMAKE_SOURCE_DIR}/examples/array_integers_10_20_30_40.json"
"${INT_BASE_NAME}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
set(DOUBLE_BASE_NAME "${CMAKE_CURRENT_BINARY_DIR}/array_doubles_10_20_30_40")
add_custom_command(
DEPENDS json2cpp
OUTPUT "${DOUBLE_BASE_NAME}_impl.hpp" "${DOUBLE_BASE_NAME}.hpp" "${DOUBLE_BASE_NAME}.cpp"
COMMAND json2cpp "array_doubles_10_20_30_40" "${CMAKE_SOURCE_DIR}/examples/array_doubles_10_20_30_40.json"
"${DOUBLE_BASE_NAME}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(
valijson_tests
valijson_tests.cpp
${SCHEMA_BASE_NAME}.cpp
${DOUBLE_BASE_NAME}.cpp
${INT_BASE_NAME}.cpp)
target_include_directories(valijson_tests PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_include_directories(valijson_tests PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(
valijson_tests
PRIVATE json2cpp_warnings
json2cpp_options)
target_link_system_libraries(
valijson_tests
PRIVATE Catch2::Catch2WithMain
ValiJSON::valijson)
# automatically discover tests that are defined in catch based test files you can modify the unittests. Set TEST_PREFIX
# to whatever you want, or use different for different binaries
catch_discover_tests(
valijson_tests
TEST_PREFIX
"unittests."
REPORTER
XML
OUTPUT_DIR
.
OUTPUT_PREFIX
"unittests."
OUTPUT_SUFFIX
.xml)
# Add a file containing a set of constexpr tests
add_executable(constexpr_tests constexpr_tests.cpp "${BASE_NAME}_impl.hpp")
target_link_libraries(constexpr_tests PRIVATE json2cpp_options json2cpp_warnings Catch2::Catch2WithMain)
target_include_directories(constexpr_tests PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_include_directories(constexpr_tests PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
catch_discover_tests(
constexpr_tests
TEST_PREFIX
"constexpr."
REPORTER
XML
OUTPUT_DIR
.
OUTPUT_PREFIX
"constexpr."
OUTPUT_SUFFIX
.xml)
# Disable the constexpr portion of the test, and build again this allows us to have an executable that we can debug when
# things go wrong with the constexpr testing
add_executable(relaxed_constexpr_tests constexpr_tests.cpp "${BASE_NAME}_impl.hpp")
target_link_libraries(relaxed_constexpr_tests PRIVATE json2cpp_options json2cpp_warnings Catch2::Catch2WithMain)
target_compile_definitions(relaxed_constexpr_tests PRIVATE -DCATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
target_include_directories(relaxed_constexpr_tests PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_include_directories(relaxed_constexpr_tests PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
catch_discover_tests(
relaxed_constexpr_tests
TEST_PREFIX
"relaxed_constexpr."
REPORTER
XML
OUTPUT_DIR
.
OUTPUT_PREFIX
"relaxed_constexpr."
OUTPUT_SUFFIX
.xml)
if(json2cpp_ENABLE_LARGE_TESTS)
set(BASE_NAME "${CMAKE_CURRENT_BINARY_DIR}/schema")
add_custom_command(
DEPENDS json2cpp
OUTPUT "${BASE_NAME}_impl.hpp" "${BASE_NAME}.hpp" "${BASE_NAME}.cpp"
COMMAND json2cpp "schema" "${CMAKE_SOURCE_DIR}/examples/Energy+.schema.epJSON" "${BASE_NAME}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
# Add a file containing a set of constexpr_schema tests
add_executable(constexpr_schema_tests constexpr_schema_tests.cpp "${BASE_NAME}_impl.hpp")
target_link_libraries(constexpr_schema_tests PRIVATE json2cpp_options json2cpp_warnings Catch2::Catch2WithMain)
target_include_directories(constexpr_schema_tests PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_include_directories(constexpr_schema_tests PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
if(MSVC)
target_compile_options(constexpr_schema_tests PRIVATE "/bigobj")
endif()
# disable analysis for these very large generated bits of code
set_target_properties(constexpr_schema_tests PROPERTIES CXX_CPPCHECK "" CXX_CLANG_TIDY "")
catch_discover_tests(
constexpr_schema_tests
TEST_PREFIX
"constexpr_schema."
REPORTER
XML
OUTPUT_DIR
.
OUTPUT_PREFIX
"constexpr_schema."
OUTPUT_SUFFIX
.xml)
# Disable the constexpr_schema portion of the test, and build again this allows us to have an executable that we can debug when
# things go wrong with the constexpr_schema testing
add_executable(relaxed_constexpr_schema_tests constexpr_schema_tests.cpp "${BASE_NAME}_impl.hpp")
target_link_libraries(relaxed_constexpr_schema_tests PRIVATE json2cpp_options json2cpp_warnings Catch2::Catch2WithMain)
target_compile_definitions(relaxed_constexpr_schema_tests PRIVATE -DCATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
target_include_directories(relaxed_constexpr_schema_tests PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_include_directories(relaxed_constexpr_schema_tests PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
if(MSVC)
target_compile_options(relaxed_constexpr_schema_tests PRIVATE "/bigobj")
endif()
# disable analysis for these very large generated bits of code
set_target_properties(relaxed_constexpr_schema_tests PROPERTIES CXX_CPPCHECK "" CXX_CLANG_TIDY "")
catch_discover_tests(
relaxed_constexpr_schema_tests
TEST_PREFIX
"relaxed_constexpr_schema."
REPORTER
XML
OUTPUT_DIR
.
OUTPUT_PREFIX
"relaxed_constexpr_schema."
OUTPUT_SUFFIX
.xml)
endif()