George Liu | c7d70b6 | 2021-05-17 16:02:18 +0800 | [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'), |
| 11 | ] |
| 12 | ) |
| 13 | gmock_dep = gtest_proj.dependency('gmock') |
| 14 | else |
| 15 | assert( |
| 16 | not get_option('tests').enabled(), |
| 17 | 'Googletest is required if tests are enabled' |
| 18 | ) |
| 19 | endif |
| 20 | endif |
| 21 | |
| 22 | test_sources = [ |
| 23 | '../physical.cpp', |
| 24 | '../sysfs.cpp', |
| 25 | ] |
| 26 | |
| 27 | tests = [ |
| 28 | 'physical.cpp', |
| 29 | 'sysfs.cpp', |
| 30 | ] |
| 31 | |
| 32 | foreach t : tests |
| 33 | test(t, |
| 34 | executable( |
| 35 | t.underscorify(), |
| 36 | t, |
| 37 | test_sources, |
| 38 | include_directories: ['..'], |
| 39 | dependencies: [ |
| 40 | gtest_dep, |
| 41 | gmock_dep, |
| 42 | deps |
| 43 | ] |
| 44 | ) |
| 45 | ) |
| 46 | endforeach |