-
Notifications
You must be signed in to change notification settings - Fork 886
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
542 lines (490 loc) · 28 KB
/
CMakeLists.txt
File metadata and controls
542 lines (490 loc) · 28 KB
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
# GoogleTest builds with /MT(d) by default, which is incompatible with Valhalla's /MD(d) builds.
#
# /MD(d) links the C++ runtime dynamically, while /MT(d) links it statically.
#
# Force it to use the same CRT as Valhalla /MD(d). Technically Valhalla doesn't enforce /MD(d) but
# it is the CMake default. It can be switched by MSVC_RUNTIME_LIBRARY, but GoogleTest is ignoring
# this.
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# don't install googletest
# unless you want the test library
set(INSTALL_GTEST ${INSTALL_TEST_LIB})
add_subdirectory(${VALHALLA_SOURCE_DIR}/third_party/googletest ${CMAKE_BINARY_DIR}/googletest)
set_target_properties(gtest PROPERTIES FOLDER "Dependencies")
set_target_properties(gtest_main PROPERTIES FOLDER "Dependencies")
set_target_properties(gmock PROPERTIES FOLDER "Dependencies")
set_target_properties(gmock_main PROPERTIES FOLDER "Dependencies")
enable_testing()
include(GoogleTest)
# common things that the tests need
find_package(Threads)
set(TEST_SRCS test.cc)
set(TEST_HDRS test.h)
if(ENABLE_DATA_TOOLS)
list(APPEND TEST_SRCS gurka/gurka.cc)
list(APPEND TEST_HDRS gurka/gurka.h)
endif()
if(ENABLE_HTTP AND ENABLE_SERVICES)
list(APPEND TEST_SRCS tile_server.cc)
list(APPEND TEST_HDRS tile_server.h)
endif()
add_library(valhalla_test
${TEST_SRCS}
${TEST_HDRS}
${VALHALLA_SOURCE_DIR}/third_party/microtar/src/microtar.h
${VALHALLA_SOURCE_DIR}/third_party/microtar/src/microtar.c
)
target_include_directories(valhalla_test PUBLIC
${VALHALLA_SOURCE_DIR}/test
${VALHALLA_SOURCE_DIR}/test/gurka)
target_include_directories(valhalla_test SYSTEM PUBLIC
${unordered_dense_include_dir}
${VALHALLA_SOURCE_DIR}/third_party/just_gtfs/include
${libosmium_include_dirs}
${VALHALLA_SOURCE_DIR}/third_party/microtar/src
${vtzero_include_dirs})
target_link_libraries(valhalla_test
valhalla gtest gtest_main gmock
$<$<BOOL:${ENABLE_COVERAGE}>:gcov>
${CMAKE_THREAD_LIBS_INIT} ${lz4_target})
target_compile_definitions(valhalla_test PUBLIC
VALHALLA_SOURCE_DIR="${VALHALLA_SOURCE_DIR}/"
VALHALLA_BUILD_DIR="${VALHALLA_BUILD_DIR}/")
if(ENABLE_DATA_TOOLS)
target_link_libraries(valhalla_test PkgConfig::GEOS)
endif()
if (ENABLE_GEOTIFF)
find_package(GDAL QUIET)
if (GDAL_FOUND)
target_link_libraries(valhalla_test GDAL::GDAL)
endif()
endif()
# optionally install the test library as well
if (INSTALL_TEST_LIB)
install(TARGETS valhalla_test
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shared NAMELINK_SKIP
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT development)
install(FILES ${TEST_HDRS}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/valhalla"
COMPONENT development)
endif()
# stop if the user just wants the library
if (NOT ENABLE_TESTS)
return()
endif()
## Lists tests
set(tests aabb2 access_restriction actor admin attributes_controller configuration datetime directededge
distanceapproximator double_bucket_queue edgecollapser edgeinfo edgestatus ellipse encode
enhancedtrippath factory graphid graphtile graphtileheader gridded_data grid_range_query grid_traversal instructions json laneconnectivity linesegment2 logging maneuversbuilder map_matcher_factory mapmatch_config
narrative_dictionary nodeinfo nodetransition obb2 openlr optimizer parse_request point2 pointll pointtileindex
polyline2 predictedspeeds queue routing sample sequence sign signs statsd streetname streetnames streetnames_factory
streetnames_us streetname_us tilehierarchy tiles transitdeparture transitroute transitschedule
transitstop turn turnlanes util_midgard util_skadi vector2 verbal_text_formatter verbal_text_formatter_us
verbal_text_formatter_us_co verbal_text_formatter_us_tx viterbi_search compression traffictile
incident_loading worker_nullptr_tiles curl_tilegetter filesystem_utils narrativebuilder util_odin)
if(ENABLE_DATA_TOOLS)
list(APPEND tests astar multimodal_astar complexrestriction countryaccess graphbuilder graphparser
graphtilebuilder graphreader hierarchylimits isochrone predictive_traffic idtable mapmatch matrix matrix_bss minbb multipoint_routes
names node_search reach recover_shortcut refs servicedays shape_attributes signinfo summary urban tar_index
thor_worker timedep_paths timeparsing trivial_paths uniquenames util_mjolnir utrecht lua alternates)
if(ENABLE_HTTP AND ENABLE_SERVICES)
list(APPEND tests http_tiles)
# TODO: fix https://github.com/valhalla/valhalla/issues/3740
# list(APPEND tests http_tiles elevation_builder)
endif()
endif()
if(ENABLE_SERVICES)
list(APPEND tests loki_service skadi_service)
endif()
## Add executable targets
foreach(test ${tests})
add_executable(${test} EXCLUDE_FROM_ALL ${test}.cc )
if (UNIX AND ENABLE_SINGLE_FILES_WERROR)
set_source_files_properties(${test}.cc PROPERTIES COMPILE_FLAGS "-Wall -Werror")
endif()
set_target_properties(${test} PROPERTIES FOLDER "Tests")
create_source_groups("Source Files" ${test}.cc)
target_link_libraries(${test} valhalla_test)
if (LUAJIT_FOUND AND APPLE AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
# Using LuaJIT on macOS on Intel processors requires a couple of extra linker flags
# Any tool that needs interact with Lua will need these flags on macOS
target_link_options(${test} PUBLIC -pagezero_size 10000 -image_base 100000000)
endif()
endforeach()
## Cost tests
set(cost_inline_test_sources
${VALHALLA_SOURCE_DIR}/src/sif/autocost.cc
${VALHALLA_SOURCE_DIR}/src/sif/bicyclecost.cc
${VALHALLA_SOURCE_DIR}/src/sif/motorcyclecost.cc
${VALHALLA_SOURCE_DIR}/src/sif/motorscootercost.cc
${VALHALLA_SOURCE_DIR}/src/sif/pedestriancost.cc
${VALHALLA_SOURCE_DIR}/src/sif/transitcost.cc
${VALHALLA_SOURCE_DIR}/src/sif/truckcost.cc)
add_executable(cost_inline_tests EXCLUDE_FROM_ALL ${cost_inline_test_sources})
set_target_properties(cost_inline_tests PROPERTIES
FOLDER "Tests"
COMPILE_DEFINITIONS INLINE_TEST)
create_source_groups("Source Files" ${cost_inline_test_sources})
target_link_libraries(cost_inline_tests valhalla_test)
gtest_discover_tests(cost_inline_tests TEST_PREFIX "CostInline.")
## Tyr tests
set(tyr_inline_test_sources
${VALHALLA_SOURCE_DIR}/src/tyr/route_serializer_osrm.cc)
add_executable(tyr_inline_tests EXCLUDE_FROM_ALL ${tyr_inline_test_sources})
set_target_properties(tyr_inline_tests PROPERTIES
FOLDER "Tests"
COMPILE_DEFINITIONS INLINE_TEST)
create_source_groups("Source Files" ${tyr_inline_test_sources})
target_link_libraries(tyr_inline_tests valhalla_test)
gtest_discover_tests(tyr_inline_tests TEST_PREFIX "TyrInline.")
## Test-specific data, properties and dependencies
target_compile_definitions(logging PRIVATE LOGGING_LEVEL_ALL)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/tz.sqlite
DEPENDS ${VALHALLA_SOURCE_DIR}/scripts/valhalla_build_timezones
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/
COMMAND ${VALHALLA_SOURCE_DIR}/scripts/valhalla_build_timezones > ${CMAKE_BINARY_DIR}/test/data/tz.sqlite.tmp
COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_BINARY_DIR}/test/data/tz.sqlite.tmp ${CMAKE_BINARY_DIR}/test/data/tz.sqlite
COMMENT "Building tz.sqlite..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_target(build_timezones DEPENDS ${CMAKE_BINARY_DIR}/test/data/tz.sqlite)
set_target_properties(build_timezones PROPERTIES FOLDER "Tests")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/utrecht_tiles/traffic.tar
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/utrecht_tiles/
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/utrecht_tiles","timezone":"test/data/tz.sqlite","admin":"${VALHALLA_SOURCE_DIR}/test/data/netherlands_admin.sqlite","include_construction":true,"hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""},"data_processing":{"grid_divisions_within_tile":32}}}'
-s initialize -e parseways
${VALHALLA_SOURCE_DIR}/test/data/utrecht_netherlands.osm.pbf
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/utrecht_tiles","timezone":"test/data/tz.sqlite","admin":"${VALHALLA_SOURCE_DIR}/test/data/netherlands_admin.sqlite","include_construction":true,"hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
-s parserelations -e parserelations
${VALHALLA_SOURCE_DIR}/test/data/utrecht_netherlands.osm.pbf
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/utrecht_tiles","timezone":"test/data/tz.sqlite","admin":"${VALHALLA_SOURCE_DIR}/test/data/netherlands_admin.sqlite","include_construction":true,"hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
-s parsenodes -e parsenodes
${VALHALLA_SOURCE_DIR}/test/data/utrecht_netherlands.osm.pbf
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/utrecht_tiles","timezone":"test/data/tz.sqlite","admin":"${VALHALLA_SOURCE_DIR}/test/data/netherlands_admin.sqlite","include_construction":true,"hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
-s build -e cleanup
${VALHALLA_SOURCE_DIR}/test/data/utrecht_netherlands.osm.pbf
COMMAND ${CMAKE_BINARY_DIR}/valhalla_add_predicted_traffic
--inline-config '{"mjolnir":{"tile_dir":"test/data/utrecht_tiles","concurrency":1,"logging":{"type":""}}}'
-t ${VALHALLA_SOURCE_DIR}/test/data/traffic_tiles/
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_extract
--inline-config '{"mjolnir":{"tile_dir":"test/data/utrecht_tiles","tile_extract":"test/data/utrecht_tiles/tiles.tar","traffic_extract":"test/data/utrecht_tiles/traffic.tar","concurrency":1,"logging":{"type":""}}}'
--with-traffic --overwrite
COMMENT "Building Utrecht Tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles valhalla_add_predicted_traffic build_timezones ${VALHALLA_SOURCE_DIR}/test/data/utrecht_netherlands.osm.pbf ${CMAKE_BINARY_DIR}/valhalla_build_extract)
add_custom_target(utrecht_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/utrecht_tiles/traffic.tar)
set_target_properties(utrecht_tiles PROPERTIES FOLDER "Tests")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/whitelion_tiles/2/000/814/309.gph
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/whitelion_tiles","hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
${VALHALLA_SOURCE_DIR}/test/data/whitelion_bristol_uk.osm.pbf
COMMENT "Building Whitelion Tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles ${VALHALLA_SOURCE_DIR}/test/data/whitelion_bristol_uk.osm.pbf)
add_custom_target(whitelion_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/whitelion_tiles/2/000/814/309.gph)
set_target_properties(whitelion_tiles PROPERTIES FOLDER "Tests")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/whitelion_tiles_reverse/2/000/814/309.gph
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/whitelion_tiles_reverse","hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
${VALHALLA_SOURCE_DIR}/test/data/whitelion_bristol_uk_reversed_oneway.osm.pbf
COMMENT "Building reversed Whitelion Tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles ${VALHALLA_SOURCE_DIR}/test/data/whitelion_bristol_uk_reversed_oneway.osm.pbf)
add_custom_target(reversed_whitelion_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/whitelion_tiles_reverse/2/000/814/309.gph)
set_target_properties(reversed_whitelion_tiles PROPERTIES FOLDER "Tests")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/bayfront_singapore_tiles/1/033/043.gph
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/bayfront_singapore_tiles","hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
${VALHALLA_SOURCE_DIR}/test/data/bayfront_singapore.osm.pbf
COMMENT "Building Singapore, Bayfront tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles ${VALHALLA_SOURCE_DIR}/test/data/bayfront_singapore.osm.pbf)
add_custom_target(bayfront_singapore_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/bayfront_singapore_tiles/1/033/043.gph)
set_target_properties(bayfront_singapore_tiles PROPERTIES FOLDER "Tests")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/roma_tiles/1/047/352.gph
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/roma_tiles/
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/roma_tiles","timezone":"test/data/tz.sqlite","hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
${VALHALLA_SOURCE_DIR}/test/data/via_montebello_roma_italy.osm.pbf
COMMENT "Building Roma Tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles valhalla_add_predicted_traffic build_timezones ${VALHALLA_SOURCE_DIR}/test/data/via_montebello_roma_italy.osm.pbf)
add_custom_target(roma_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/roma_tiles/1/047/352.gph)
set_target_properties(roma_tiles PROPERTIES FOLDER "Tests")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/paris_bss_tiles/0/003/105.gph
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/paris_bss_tiles/
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/paris_bss_tiles","timezone":"test/data/tz.sqlite","hierarchy": true,"import_bike_share_stations": true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
${VALHALLA_SOURCE_DIR}/test/data/paris_bss.osm.pbf
COMMENT "Building Paris BSS Tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles ${VALHALLA_SOURCE_DIR}/test/data/paris_bss.osm.pbf)
add_custom_target(paris_bss_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/paris_bss_tiles/0/003/105.gph)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/melborne_tiles/0/001/251.gph
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/melborne_tiles/
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/melborne_tiles","timezone":"test/data/tz.sqlite","hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
${VALHALLA_SOURCE_DIR}/test/data/melborne.osm.pbf
COMMENT "Building Melborne Tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles valhalla_add_predicted_traffic build_timezones ${VALHALLA_SOURCE_DIR}/test/data/melborne.osm.pbf)
add_custom_target(melborne_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/melborne_tiles/0/001/251.gph)
set_target_properties(melborne_tiles PROPERTIES FOLDER "Tests")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/ny_ar_tiles/2/000/752/104.gph
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/ny_ar_tiles/
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/ny_ar_tiles","timezone":"test/data/tz.sqlite","hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
${VALHALLA_SOURCE_DIR}/test/data/ny-access-restriction.osm.pbf
COMMENT "Building New York Access Restriction Tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles build_timezones ${VALHALLA_SOURCE_DIR}/test/data/ny-access-restriction.osm.pbf)
add_custom_target(ny_ar_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/ny_ar_tiles/2/000/752/104.gph)
set_target_properties(ny_ar_tiles PROPERTIES FOLDER "Tests")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/pa_ar_tiles/2/000/749/212.gph
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/pa_ar_tiles/
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/pa_ar_tiles","timezone":"test/data/tz.sqlite","hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
${VALHALLA_SOURCE_DIR}/test/data/pa-access-restriction.osm.pbf
COMMENT "Building PA Access Restriction Tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles build_timezones ${VALHALLA_SOURCE_DIR}/test/data/pa-access-restriction.osm.pbf)
add_custom_target(pa_ar_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/pa_ar_tiles/2/000/749/212.gph)
set_target_properties(pa_ar_tiles PROPERTIES FOLDER "Tests")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/nh_ar_tiles/2/000/765/074.gph
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/nh_ar_tiles/
COMMAND ${CMAKE_BINARY_DIR}/valhalla_build_tiles
--inline-config '{"mjolnir":{"id_table_size":1000,"tile_dir":"test/data/nh_ar_tiles","timezone":"test/data/tz.sqlite","hierarchy":true,"shortcuts":true,"concurrency":1,"logging":{"type":""}}}'
${VALHALLA_SOURCE_DIR}/test/data/nh-access-restriction.osm.pbf
COMMENT "Building New Hampshire Access Restriction Tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles build_timezones ${VALHALLA_SOURCE_DIR}/test/data/nh-access-restriction.osm.pbf)
add_custom_target(nh_ar_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/nh_ar_tiles/2/000/765/074.gph)
set_target_properties(nh_ar_tiles PROPERTIES FOLDER "Tests")
file(GLOB locales "${VALHALLA_SOURCE_DIR}/locales/*.json")
add_custom_command(OUTPUT .locales.timestamp
COMMAND /bin/bash -c "for loc in $(jq --raw-output .posix_locale *.json); do \
$<$<NOT:$<BOOL:${APPLE}>>: localedef -i $\{loc\%.\*\} -f $\{loc\#\#\*.\} ./$\{loc\} ; > \
$<$<BOOL:${APPLE}>: localedef -i /usr/share/locale/$\{loc\} ./$\{loc\} || true ; > \
done \
&& touch ${CMAKE_CURRENT_BINARY_DIR}/.locales.timestamp"
WORKING_DIRECTORY ${VALHALLA_SOURCE_DIR}/locales
DEPENDS ${locales}
COMMENT "Compile locale definition files..."
VERBATIM)
add_custom_target(localedef DEPENDS .locales.timestamp)
set_target_properties(localedef PROPERTIES FOLDER "Tests")
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test/data)
add_custom_command(OUTPUT test/data/sample/N00
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/sample/N00
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/sample/N40
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/samplegz/N40
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/samplelz4/N40
COMMAND ${CMAKE_COMMAND} -E make_directory test/data/service
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Creating test directories")
add_custom_target(test_directories DEPENDS test/data/sample/N00)
set_target_properties(test_directories PROPERTIES FOLDER "Tests")
set (source "${CMAKE_BINARY_DIR}/test/data/utrecht_tiles")
set (destination "${CMAKE_BINARY_DIR}/test/data/tile_src")
# TODO: fix https://github.com/valhalla/valhalla/issues/3740
#set (elevationbuild_test "${CMAKE_BINARY_DIR}/test/data/elevationbuild/tile_dir")
#add_custom_command(
# TARGET utrecht_tiles POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E make_directory ${destination}
# COMMAND ${CMAKE_COMMAND} -E make_directory ${elevationbuild_test}
# COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/test/data/elevation_dst"
# COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/test/data/elevation_src"
# COMMAND ${CMAKE_COMMAND} -E copy_directory ${source} ${destination}
# COMMAND ${CMAKE_COMMAND} -E copy_directory ${source} ${elevationbuild_test}
# DEPENDS ${destination}
# COMMENT "tiles copied from ${source} to ${destination}"
#)
## Test run targets
foreach(test ${tests} ${cost_inline_tests} ${tyr_inline_tests})
add_custom_command(OUTPUT ${test}.log
COMMAND ${CMAKE_COMMAND} -E env LOCPATH=${VALHALLA_SOURCE_DIR}/locales ${VALHALLA_SOURCE_DIR}/scripts/run_single_test.sh ${CMAKE_CURRENT_BINARY_DIR}/${test}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS ${test}
VERBATIM)
add_custom_target(run-${test} DEPENDS ${test}.log)
endforeach()
## Run test dependencies
## TODO: fix apple tests!
if(NOT APPLE)
add_dependencies(run-util_odin localedef)
add_dependencies(run-narrativebuilder localedef)
endif()
add_dependencies(run-sample test_directories)
if(ENABLE_DATA_TOOLS)
add_dependencies(run-actor utrecht_tiles)
add_dependencies(run-mapmatch utrecht_tiles)
add_dependencies(run-hierarchylimits utrecht_tiles)
add_dependencies(run-isochrone utrecht_tiles)
add_dependencies(run-matrix utrecht_tiles)
add_dependencies(run-matrix_bss paris_bss_tiles)
add_dependencies(run-timedep_paths utrecht_tiles)
add_dependencies(run-trivial_paths utrecht_tiles)
add_dependencies(predictive_traffic utrecht_tiles)
add_dependencies(run-multipoint_routes utrecht_tiles)
add_dependencies(run-reach utrecht_tiles)
add_dependencies(run-shape_attributes utrecht_tiles)
add_dependencies(run-summary utrecht_tiles)
add_dependencies(run-urban utrecht_tiles)
add_dependencies(run-thor_worker utrecht_tiles)
add_dependencies(run-recover_shortcut utrecht_tiles)
add_dependencies(run-minbb utrecht_tiles)
add_dependencies(run-multimodal_astar paris_bss_tiles utrecht_tiles)
add_dependencies(run-astar whitelion_tiles roma_tiles reversed_whitelion_tiles bayfront_singapore_tiles ny_ar_tiles pa_ar_tiles nh_ar_tiles melborne_tiles utrecht_tiles)
add_dependencies(run-alternates utrecht_tiles)
add_dependencies(run-tar_index utrecht_tiles)
add_dependencies(run-graphtile utrecht_tiles)
add_dependencies(run-graphbuilder build_timezones)
if(ENABLE_HTTP AND ENABLE_SERVICES)
# http_tiles needs the proper .tar file with index.bin
add_dependencies(run-http_tiles utrecht_tiles run-scripts)
endif()
endif()
if(ENABLE_SERVICES)
add_dependencies(run-skadi_service test_directories)
endif()
# ENABLE_DATA_TOOLS is needed for utrecht_tiles
if(ENABLE_PYTHON_BINDINGS AND ENABLE_DATA_TOOLS)
# Prefer .venv Python if available (better compatibility with DYLD_INSERT_LIBRARIES on macOS)
set(TEST_PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
if(EXISTS "${VALHALLA_SOURCE_DIR}/.venv/bin/python3")
set(TEST_PYTHON_EXECUTABLE "${VALHALLA_SOURCE_DIR}/.venv/bin/python3")
message(STATUS "Using .venv Python for tests: ${TEST_PYTHON_EXECUTABLE}")
endif()
# Find ASan runtime library for LD_PRELOAD (if sanitizers are enabled)
# This approach avoids false positives from NumPy's internal allocations by preloading
# the ASan runtime before Python starts, allowing ASan to intercept all allocations.
# On Linux, both libasan and the C++ standard library must be preloaded together.
# See: https://github.com/wjakob/nanobind/blob/master/docs/lowlevel.rst#sanitizing-python-sessions
set(ASAN_PRELOAD_ENV "")
if(ENABLE_SANITIZERS)
# Step 1: Find ASan library (try Clang naming, then GCC naming on Linux)
if(APPLE)
set(san_candidates "libclang_rt.asan_osx_dynamic.dylib")
else()
set(san_candidates "libclang_rt.asan.so" "libasan.so")
endif()
foreach(san_libname ${san_candidates})
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${san_libname}
OUTPUT_VARIABLE san_libpath
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Check if we got a real path (not just the input echoed back)
if(san_libpath AND NOT san_libpath STREQUAL san_libname)
break() # Found it
endif()
endforeach()
if(san_libpath AND NOT san_libpath STREQUAL san_libname)
# Step 2: On Linux, also find C++ standard library (libstdc++ or libc++)
if(NOT APPLE)
foreach(cxx_libname "libstdc++.so" "libc++.so")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${cxx_libname}
OUTPUT_VARIABLE cxx_libpath
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(cxx_libpath AND NOT cxx_libpath STREQUAL cxx_libname)
break() # Found it
endif()
endforeach()
if(cxx_libpath AND NOT cxx_libpath STREQUAL cxx_libname)
set(ASAN_PRELOAD_ENV "LD_PRELOAD=${san_libpath}:${cxx_libpath}")
else()
message(WARNING "Could not find libstdc++.so or libc++.so. Python tests may fail with __cxa_throw errors.")
set(ASAN_PRELOAD_ENV "LD_PRELOAD=${san_libpath}")
endif()
else()
# macOS: Only ASan library needed
set(ASAN_PRELOAD_ENV "DYLD_INSERT_LIBRARIES=${san_libpath}")
endif()
message(STATUS "Python tests will use sanitizer preload: ${ASAN_PRELOAD_ENV}")
else()
message(WARNING "Sanitizers enabled but ASan runtime not found. Python tests may fail.")
endif()
endif()
# Build environment variables into bash export statements
# We use bash for output redirection/error handling, so we export variables within bash
set(PYTHON_TEST_EXPORTS "export LOCPATH=${VALHALLA_SOURCE_DIR}/locales; export PYTHONPATH=${CMAKE_BINARY_DIR}/src/bindings/python;")
# Add sanitizer-specific options only when sanitizers are enabled
if(ENABLE_SANITIZERS)
set(PYTHON_TEST_EXPORTS "${PYTHON_TEST_EXPORTS} export ASAN_OPTIONS=detect_leaks=0:symbolize=1;")
# Add preload if library was found
if(ASAN_PRELOAD_ENV)
set(PYTHON_TEST_EXPORTS "${PYTHON_TEST_EXPORTS} export ${ASAN_PRELOAD_ENV};")
endif()
endif()
# Call Python with exports in a single bash command (simpler than wrapper script)
add_custom_command(OUTPUT python_valhalla.log
COMMAND /bin/bash -cx "\
${PYTHON_TEST_EXPORTS} \
${TEST_PYTHON_EXECUTABLE} -m unittest discover \
-s ${VALHALLA_SOURCE_DIR}/test/bindings/python \
-v \
2>&1 | tee ${CMAKE_BINARY_DIR}/test/python_valhalla.log"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS
${VALHALLA_SOURCE_DIR}/test/bindings/python/test_actor.py
${VALHALLA_SOURCE_DIR}/test/bindings/python/test_config.py
${VALHALLA_SOURCE_DIR}/test/bindings/python/test_graph_utils.py
${VALHALLA_SOURCE_DIR}/test/bindings/python/test_predicted_speeds.py
${VALHALLA_SOURCE_DIR}/test/bindings/python/valhalla.json
utrecht_tiles
_valhalla
_graph_utils
predicted_speeds
VERBATIM)
add_custom_target(run-python_valhalla DEPENDS python_valhalla.log)
set_target_properties(run-python_valhalla PROPERTIES FOLDER "Python Bindings")
set(python_tests python_valhalla)
endif()
if(ENABLE_NODE_BINDINGS AND ENABLE_DATA_TOOLS)
find_program(NODE_EXECUTABLE NAMES node nodejs)
if(NOT NODE_EXECUTABLE)
message(WARNING "Node.js executable not found, Node.js tests will be skipped")
else()
# Dynamically find the ASan library path if sanitizer is enabled
# it is important to preload ASan this way when running `node`, so that ASan is able to set its interceptors even before any code was able to run
if(ENABLE_ADDRESS_SANITIZER)
execute_process(
COMMAND ${CMAKE_C_COMPILER} -print-file-name=libasan.so
OUTPUT_VARIABLE LIBASAN_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(ASAN_PRELOAD "LD_PRELOAD=${LIBASAN_PATH}")
else()
set(ASAN_PRELOAD "")
endif()
add_custom_command(OUTPUT nodejs_valhalla.log
COMMAND
${ASAN_PRELOAD}
NODE_PATH=${CMAKE_BINARY_DIR}/src/bindings/nodejs/lib
/bin/bash -cx "${NODE_EXECUTABLE} ${VALHALLA_SOURCE_DIR}/test/bindings/nodejs/tests.js > ${CMAKE_BINARY_DIR}/test/nodejs_valhalla.log 2>&1 || (cat ${CMAKE_BINARY_DIR}/test/nodejs_valhalla.log && exit 1)"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS
${VALHALLA_SOURCE_DIR}/test/bindings/nodejs/tests.js
${VALHALLA_SOURCE_DIR}/test/bindings/nodejs/valhalla.json
utrecht_tiles
valhalla_node
VERBATIM)
add_custom_target(run-nodejs_valhalla DEPENDS nodejs_valhalla.log)
set_target_properties(run-nodejs_valhalla PROPERTIES FOLDER "Node.js Bindings")
set(nodejs_tests nodejs_valhalla)
endif()
endif()
## High-level targets
string(REGEX REPLACE "([^;]+)" "run-\\1" test_targets "${tests};${cost_tests};${tyr_tests};${python_tests};${nodejs_tests}")
add_custom_target(check DEPENDS ${test_targets})
set_target_properties(check PROPERTIES FOLDER "Tests")
add_custom_target(tests DEPENDS ${tests} ${cost_tests} ${tyr_tests})
set_target_properties(tests PROPERTIES FOLDER "Tests")
add_subdirectory(gurka)
add_subdirectory(scripts)