Jason M. Bills | d6087ae | 2023-10-09 11:54:13 -0700 | [diff] [blame] | 1 | gtest_dep = dependency('gtest', main: true, disabler: true, required: false) |
| 2 | gmock_dep = dependency('gmock', disabler: true, required: false) |
| 3 | if not gtest_dep.found() or not gmock_dep.found() |
| 4 | gtest_proj = import('cmake').subproject('googletest', required: false) |
| 5 | if gtest_proj.found() |
| 6 | gtest_dep = declare_dependency( |
| 7 | dependencies: [ |
| 8 | dependency('threads'), |
| 9 | gtest_proj.dependency('gtest'), |
| 10 | gtest_proj.dependency('gtest_main'), |
Jason M. Bills | 2883607 | 2024-05-17 12:47:15 -0700 | [diff] [blame] | 11 | ], |
Jason M. Bills | d6087ae | 2023-10-09 11:54:13 -0700 | [diff] [blame] | 12 | ) |
| 13 | gmock_dep = gtest_proj.dependency('gmock') |
Jason M. Bills | 2883607 | 2024-05-17 12:47:15 -0700 | [diff] [blame] | 14 | else |
Jason M. Bills | d6087ae | 2023-10-09 11:54:13 -0700 | [diff] [blame] | 15 | assert( |
| 16 | not get_option('tests').enabled(), |
Jason M. Bills | 2883607 | 2024-05-17 12:47:15 -0700 | [diff] [blame] | 17 | 'Googletest is required if tests are enabled', |
Jason M. Bills | d6087ae | 2023-10-09 11:54:13 -0700 | [diff] [blame] | 18 | ) |
Jason M. Bills | 2883607 | 2024-05-17 12:47:15 -0700 | [diff] [blame] | 19 | endif |
Jason M. Bills | d6087ae | 2023-10-09 11:54:13 -0700 | [diff] [blame] | 20 | endif |
| 21 | |
Jason M. Bills | 2883607 | 2024-05-17 12:47:15 -0700 | [diff] [blame] | 22 | unit_tests = [] |
Jason M. Bills | d6087ae | 2023-10-09 11:54:13 -0700 | [diff] [blame] | 23 | |
| 24 | if get_option('tests').enabled() |
| 25 | # generate the test executable |
| 26 | foreach unit_test : unit_tests |
Jason M. Bills | 2883607 | 2024-05-17 12:47:15 -0700 | [diff] [blame] | 27 | test( |
Jason M. Bills | d6087ae | 2023-10-09 11:54:13 -0700 | [diff] [blame] | 28 | unit_test, |
Jason M. Bills | 2883607 | 2024-05-17 12:47:15 -0700 | [diff] [blame] | 29 | executable( |
| 30 | unit_test, |
| 31 | unit_test + '.cpp', |
Jason M. Bills | 5fe348b | 2024-05-15 09:13:26 -0700 | [diff] [blame] | 32 | '../src/host_error_monitor.cpp', |
| 33 | cpp_args: '-DUNIT_TEST', |
Jason M. Bills | 2883607 | 2024-05-17 12:47:15 -0700 | [diff] [blame] | 34 | include_directories: incs, |
| 35 | dependencies: deps |
| 36 | + [ |
| 37 | gtest_dep, |
| 38 | gmock_dep, |
| 39 | ], |
| 40 | ), |
Jason M. Bills | d6087ae | 2023-10-09 11:54:13 -0700 | [diff] [blame] | 41 | ) |
| 42 | endforeach |
Jason M. Bills | 2883607 | 2024-05-17 12:47:15 -0700 | [diff] [blame] | 43 | endif |