generated from NOAA-OWP/owp-open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 63
/
CMakeLists.txt
546 lines (486 loc) · 14.2 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
add_subdirectory(googletest)
add_compile_definitions(NGEN_BMI_CPP_LIB_TESTS_ACTIVE)
# =============================================================================
# If ${NGEN_ROOT_DIR} and ${PROJECT_BINARY_DIR} are the same, then we have an in-source build
# and this is not necessary.
if(NOT NGEN_ROOT_DIR STREQUAL PROJECT_BINARY_DIR)
# Create a symlink between the root data directory in the source tree and the build tree
file(CREATE_LINK "${NGEN_ROOT_DIR}/data" "${PROJECT_BINARY_DIR}/data" SYMBOLIC)
# Create a symlink between the test data directory in the source tree and the build tree
file(CREATE_LINK "${CMAKE_CURRENT_LIST_DIR}/data" "${PROJECT_BINARY_DIR}/test/data" SYMBOLIC)
# Create a symlink between the extern directory in the source tree and the build tree
file(CREATE_LINK "${NGEN_ROOT_DIR}/extern" "${PROJECT_BINARY_DIR}/extern" SYMBOLIC)
file(CREATE_LINK "${NGEN_ROOT_DIR}/extern" "${PROJECT_BINARY_DIR}/test/extern" SYMBOLIC)
endif()
# =============================================================================
git_update_submodule("${NGEN_EXT_DIR}/bmi-cxx")
add_external_subdirectory(
SOURCE "${NGEN_EXT_DIR}/test_bmi_cpp"
OUTPUT "${NGEN_EXT_DIR}/test_bmi_cpp/cmake_build"
IMPORTS testbmicppmodel
)
if (NGEN_WITH_PYTHON)
add_compile_definitions(NGEN_BMI_PY_TESTS_ACTIVE)
endif()
if(NGEN_WITH_MPI)
add_compile_definitions(NGEN_MPI_TESTS_ACTIVE)
endif()
if(NGEN_WITH_BMI_C)
add_compile_definitions(NGEN_BMI_C_LIB_TESTS_ACTIVE)
add_external_subdirectory(
SOURCE "${NGEN_EXT_DIR}/test_bmi_c"
OUTPUT "${NGEN_EXT_DIR}/test_bmi_c/cmake_build"
IMPORTS testbmicmodel
)
endif()
if(NGEN_WITH_BMI_FORTRAN)
add_compile_definitions(NGEN_BMI_FORTRAN_LIB_TESTS_ACTIVE)
add_external_subdirectory(
SOURCE "${NGEN_EXT_DIR}/test_bmi_fortran"
OUTPUT "${NGEN_EXT_DIR}/test_bmi_fortran/cmake_build"
IMPORTS testbmifortranmodel
)
endif()
if(NGEN_WITH_ROUTING)
add_compile_definitions(ROUTING_PYBIND_TESTS_ACTIVE)
endif()
# =============================================================================
add_executable(test_all)
target_link_libraries(test_all PRIVATE gtest gtest_main)
set_target_properties(test_all PROPERTIES FOLDER test)
target_include_directories(test_all PRIVATE ${CMAKE_CURRENT_LIST_DIR}/bmi)
# =============================================================================
#[==[
ngen_add_test(<test name> OBJECTS <source>...
LIBRARIES <library>...
[REQUIRES <varname>...]
[DEPENDS <dependency>...])
Adds an executable test (i.e. a target) called <test name>.
`OBJECTS`
Source files containing the test cases/fixtures.
`LIBRARIES`
Library targets that this test requires linking to.
`REQUIRES`
Variable names that this test's creation is dependent on.
If a given variable is not defined or is FALSE/OFF/etc. then
the corresponding <test name> target is not created.
`DEPENDS`
Additional targets that a test executable depends on. For each
dependent target given, add_dependencies(<test name> <dependency>...)
is called.
#]==]
function(ngen_add_test TESTNAME)
set(multiValueArgs OBJECTS LIBRARIES REQUIRES DEPENDS)
cmake_parse_arguments(NGEN_TEST "" "" "${multiValueArgs}" ${ARGN})
list(REMOVE_DUPLICATES NGEN_TEST_LIBRARIES)
set(NGEN_TEST_CREATE ON)
foreach(requirement_var IN LISTS NGEN_TEST_REQUIRES)
if(NOT ${requirement_var})
set(NGEN_TEST_CREATE OFF)
break()
endif()
endforeach()
if(NGEN_TEST_CREATE)
add_executable(${TESTNAME} ${NGEN_TEST_OBJECTS})
target_include_directories(${TESTNAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/bmi)
target_link_libraries(${TESTNAME} PRIVATE gtest gtest_main ${NGEN_TEST_LIBRARIES})
set_target_properties(${TESTNAME} PROPERTIES FOLDER test)
# Iterate over each dependency, and add as a dependency for the test
# IF the dependency is a target.
foreach(dependency IN LISTS NGEN_TEST_DEPENDS)
if(TARGET ${dependency})
add_dependencies(${TESTNAME} ${dependency})
endif()
endforeach()
gtest_discover_tests(
${TESTNAME}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
)
# ---------------------------------------------------------------------
target_sources(test_all PRIVATE ${NGEN_TEST_OBJECTS})
target_link_libraries(test_all PRIVATE ${NGEN_TEST_LIBRARIES})
# ---------------------------------------------------------------------
endif()
endfunction()
########################## Individual tests ##########################
########################## GeoJSON Unit Tests
ngen_add_test(
test_geojson
OBJECTS
geojson/JSONProperty_Test.cpp
geojson/JSONGeometry_Test.cpp
geojson/Feature_Test.cpp
geojson/FeatureCollection_Test.cpp
LIBRARIES
NGen::geojson
)
########################## GeoPackage Unit Tests
ngen_add_test(
test_geopackage
OBJECTS
geopackage/WKB_Test.cpp
geopackage/SQLite_Test.cpp
geopackage/GeoPackage_Test.cpp
LIBRARIES
NGen::geopackage
REQUIRES
NGEN_WITH_SQLITE
)
########################## Realization Config Unit Tests
ngen_add_test(
test_realization_config
OBJECTS
realizations/Formulation_Manager_Test.cpp
LIBRARIES
NGen::core
NGen::realizations_catchment
NGen::core_mediator
NGen::forcing
NGen::ngen_bmi
DEPENDS
testbmicppmodel
)
ngen_add_test(
test_gridselector
OBJECTS
forcing/GridDataSelector_Test.cpp
LIBRARIES
NGen::forcing
NGen::geojson
)
ngen_add_test(
test_forcings_engine
OBJECTS
forcing/ForcingsEngineDataProvider_Test.cpp
forcing/ForcingsEngineLumpedDataProvider_Test.cpp
LIBRARIES
NGen::forcing
REQUIRES
NGEN_WITH_PYTHON
)
if(TARGET test_forcings_engine)
set(FORCINGS_ENGINE_SCRATCH_DIR "${CMAKE_CURRENT_BINARY_DIR}/forcings_engine_scratch")
file(MAKE_DIRECTORY "${FORCINGS_ENGINE_SCRATCH_DIR}")
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/../data/forcing/forcings-engine/config_aorc.yml.in" # Input
"${CMAKE_CURRENT_BINARY_DIR}/config_aorc.yml"
)
# Use global add instead of target add so that both `test_forcings_engine` and `test_all`
# receive this compile definition.
add_compile_definitions(NGEN_LUMPED_CONFIG_PATH="${CMAKE_CURRENT_BINARY_DIR}/config_aorc.yml")
endif()
########################## Series Unit Tests
ngen_add_test(
test_mdarray
OBJECTS
utils/mdarray_Test.cpp
utils/mdframe_Test.cpp
utils/mdframe_netcdf_Test.cpp
utils/mdframe_csv_Test.cpp
LIBRARIES
NGen::mdarray
NGen::mdframe
)
########################## Logging Unit Tests
ngen_add_test(
test_logging
OBJECTS
utils/logging_Test.cpp
LIBRARIES
NGen::logging
)
########################## Nexus Tests
ngen_add_test(
test_nexus
OBJECTS
core/nexus/NexusTests.cpp
LIBRARIES
NGen::core_nexus
)
########################## MPI Remote Nexus Tests
ngen_add_test(
test_remote_nexus
OBJECTS
core/nexus/NexusRemoteTests.cpp
LIBRARIES
NGen::core_nexus
REQUIRES
NGEN_WITH_MPI
)
########################## Partitioning Tests
ngen_add_test(
test_partition
OBJECTS
utils/Partition_Test.cpp
LIBRARIES
gmock
NGen::core
NGen::geojson
# REQUIRES
# NGEN_WITH_MPI
)
########################## Partition_One Tests
ngen_add_test(
test_partition_one
OBJECTS
utils/Partition_One_Test.cpp
LIBRARIES
gmock
NGen::core
NGen::geojson
NGen::geopackage
REQUIRES
NGEN_WITH_SQLITE
)
########################## MultiLayer Tests
ngen_add_test(
test_multilayer
OBJECTS
core/multilayer/MultiLayerParserTest.cpp
LIBRARIES
NGen::core
NGen::geojson
NGen::realizations_catchment
NGen::core_mediator
NGen::forcing
REQUIRES
NGEN_WITH_NETCDF
NGEN_WITH_BMI_FORTRAN
)
########################## BMI C++ Tests
ngen_add_test(
test_bmi_cpp
OBJECTS
bmi/Bmi_Cpp_Adapter_Test.cpp
realizations/catchments/Bmi_Cpp_Formulation_Test.cpp
LIBRARIES
NGen::core
NGen::realizations_catchment
NGen::core_mediator
NGen::forcing
NGen::ngen_bmi
DEPENDS
testbmicppmodel
)
########################## BMI C Tests
ngen_add_test(
test_bmi_c
OBJECTS
bmi/Bmi_C_Adapter_Test.cpp
realizations/catchments/Bmi_C_Formulation_Test.cpp
LIBRARIES
gmock
NGen::core
NGen::realizations_catchment
NGen::core_mediator
NGen::forcing
NGen::ngen_bmi
REQUIRES
NGEN_WITH_BMI_C
DEPENDS
testbmicmodel
)
########################## BMI Fortran Tests
ngen_add_test(
test_bmi_fortran
OBJECTS
bmi/Bmi_Fortran_Adapter_Test.cpp
realizations/catchments/Bmi_Fortran_Formulation_Test.cpp
LIBRARIES
NGen::core
NGen::realizations_catchment
NGen::core_mediator
NGen::forcing
NGen::ngen_bmi
REQUIRES
NGEN_WITH_BMI_FORTRAN
DEPENDS
testbmifortranmodel
)
########################## BMI Python Tests
ngen_add_test(
test_bmi_python
OBJECTS
bmi/Bmi_Py_Adapter_Test.cpp
realizations/catchments/Bmi_Py_Formulation_Test.cpp
LIBRARIES
NGen::core
NGen::realizations_catchment
NGen::core_mediator
NGen::forcing
NGen::ngen_bmi
REQUIRES
NGEN_WITH_PYTHON
)
########################## BMI Multi Tests
ngen_add_test(
test_bmi_multi
OBJECTS
realizations/catchments/Bmi_Multi_Formulation_Test.cpp
realizations/catchments/Bmi_Cpp_Multi_Array_Test.cpp
LIBRARIES
NGen::core
NGen::realizations_catchment
NGen::core_mediator
NGen::forcing
NGen::ngen_bmi
REQUIRES
NGEN_WITH_BMI_C
NGEN_WITH_BMI_FORTRAN
NGEN_WITH_PYTHON
DEPENDS
testbmicppmodel
testbmicmodel
testbmifortranmodel
)
########################## All BMI Unit Tests
ngen_add_test(
test_bmi_unit_all
OBJECTS
bmi/Bmi_C_Adapter_Test.cpp
realizations/catchments/Bmi_C_Formulation_Test.cpp
bmi/Bmi_Fortran_Adapter_Test.cpp
realizations/catchments/Bmi_Fortran_Formulation_Test.cpp
bmi/Bmi_Py_Adapter_Test.cpp
realizations/catchments/Bmi_Py_Formulation_Test.cpp
realizations/catchments/Bmi_Multi_Formulation_Test.cpp
LIBRARIES
gmock
NGen::core
NGen::realizations_catchment
NGen::core_mediator
NGen::forcing
NGen::ngen_bmi
REQUIRES
NGEN_WITH_BMI_C
NGEN_WITH_BMI_FORTRAN
NGEN_WITH_PYTHON
)
########################## Comparison tests for the BMI PET implementation
# TODO: this probably needs to be added to integration testing also
ngen_add_test(
compare_pet
OBJECTS
realizations/catchments/Bmi_C_Pet_IT.cpp
LIBRARIES
NGen::core
NGen::realizations_catchment
NGen::core_mediator
NGen::forcing
NGen::ngen_bmi
DEPENDS
petbmi
)
########################## Routing Tests
ngen_add_test(
test_routing_pybind
OBJECTS
routing/Routing_Py_Bind_Test.cpp
LIBRARIES
NGen::core # for filechecker utility
NGen::routing
pybind11::embed
REQUIRES
NGEN_WITH_ROUTING
)
########################## Network Class Tests
ngen_add_test(
test_network
OBJECTS
core/NetworkTests.cpp
LIBRARIES
NGen::core
NGen::geojson
)
########################### Netcdf Forcing Tests
ngen_add_test(
test_netcdf_forcing
OBJECTS
forcing/NetCDFPerFeatureDataProvider_Test.cpp
LIBRARIES
NGen::core
NGen::core_nexus
NGen::core_mediator
NGen::forcing
NGen::geojson
NGen::realizations_catchment
REQUIRES
NGEN_WITH_NETCDF
)
########################## Primary Combined Unit Test Target
ngen_add_test(
test_unit
OBJECTS
geojson/JSONProperty_Test.cpp
geojson/JSONGeometry_Test.cpp
geojson/Feature_Test.cpp
geojson/FeatureCollection_Test.cpp
forcing/CsvPerFeatureForcingProvider_Test.cpp
forcing/OptionalWrappedDataProvider_Test.cpp
forcing/NetCDFPerFeatureDataProvider_Test.cpp
forcing/GridDataSelector_Test.cpp
core/mediator/UnitsHelper_Tests.cpp
simulation_time/Simulation_Time_Test.cpp
core/NetworkTests.cpp
utils/include/StreamOutputTest.cpp
realizations/Formulation_Manager_Test.cpp
utils/Partition_Test.cpp
utils/mdarray_Test.cpp
utils/mdframe_Test.cpp
utils/mdframe_netcdf_Test.cpp
utils/mdframe_csv_Test.cpp
utils/logging_Test.cpp
LIBRARIES
gmock
NGen::core
NGen::core_nexus
NGen::core_mediator
NGen::forcing
NGen::geojson
NGen::realizations_catchment
NGen::mdarray
NGen::mdframe
NGen::logging
NGen::ngen_bmi
testbmicppmodel
)
# Discover for test_all
gtest_discover_tests(
test_all
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
)
if(NGEN_WITH_COVERAGE)
setup_target_for_coverage_gcovr_html(
NAME
ngen_coverage_html
EXECUTABLE
test/test_all
DEPENDENCIES
test_all
EXCLUDE
"${BOOST_ROOT}"
"${CMAKE_CURRENT_LIST_DIR}"
"${NGEN_EXT_DIR}"
)
add_custom_command(
TARGET ngen_coverage_html
PRE_BUILD
COMMAND
)
setup_target_for_coverage_gcovr_xml(
NAME
ngen_coverage_xml
EXECUTABLE
test/test_all
DEPENDENCIES
test_all
EXCLUDE
"${BOOST_ROOT}"
"${CMAKE_CURRENT_LIST_DIR}"
"${NGEN_EXT_DIR}"
)
endif()