William A. Kennington III | a2d67e2 | 2020-02-19 12:17:39 -0800 | [diff] [blame] | 1 | gtest = dependency('gtest', main: true, disabler: true, required: false) |
| 2 | gmock = dependency('gmock', disabler: true, required: false) |
| 3 | if not gtest.found() or not gmock.found() |
| 4 | gtest_proj = import('cmake').subproject('googletest', required: false) |
| 5 | if gtest_proj.found() |
| 6 | gtest = declare_dependency( |
| 7 | dependencies: [ |
| 8 | dependency('threads'), |
| 9 | gtest_proj.dependency('gtest'), |
| 10 | gtest_proj.dependency('gtest_main'), |
| 11 | ]) |
| 12 | gmock = gtest_proj.dependency('gmock') |
| 13 | else |
| 14 | assert(not build_tests.enabled(), 'Googletest is required') |
| 15 | endif |
| 16 | endif |
William A. Kennington III | 15982f6 | 2019-01-31 14:43:41 -0800 | [diff] [blame] | 17 | |
William A. Kennington III | 245495e | 2020-02-13 13:07:30 -0800 | [diff] [blame^] | 18 | gtests = [ |
William A. Kennington III | 15982f6 | 2019-01-31 14:43:41 -0800 | [diff] [blame] | 19 | 'signal', |
William A. Kennington III | e847ef8 | 2018-11-02 17:29:15 -0700 | [diff] [blame] | 20 | 'handle/copyable', |
William A. Kennington III | 7a5e232 | 2018-11-02 17:28:35 -0700 | [diff] [blame] | 21 | 'handle/managed', |
William A. Kennington III | bff0b0f | 2018-11-16 19:56:10 -0800 | [diff] [blame] | 22 | 'util/cexec', |
William A. Kennington III | 4ef36e7 | 2019-06-27 12:48:59 -0700 | [diff] [blame] | 23 | 'util/string', |
William A. Kennington III | 15982f6 | 2019-01-31 14:43:41 -0800 | [diff] [blame] | 24 | ] |
| 25 | |
William A. Kennington III | 245495e | 2020-02-13 13:07:30 -0800 | [diff] [blame^] | 26 | foreach t : gtests |
William A. Kennington III | 15982f6 | 2019-01-31 14:43:41 -0800 | [diff] [blame] | 27 | test(t, executable(t.underscorify(), t + '.cpp', |
William A. Kennington III | 15982f6 | 2019-01-31 14:43:41 -0800 | [diff] [blame] | 28 | implicit_include_directories: false, |
William A. Kennington III | 97e3947 | 2019-04-03 13:22:32 -0700 | [diff] [blame] | 29 | dependencies: [stdplus, gtest, gmock])) |
William A. Kennington III | 15982f6 | 2019-01-31 14:43:41 -0800 | [diff] [blame] | 30 | endforeach |
William A. Kennington III | 245495e | 2020-02-13 13:07:30 -0800 | [diff] [blame^] | 31 | |
| 32 | # catch2 might not have a pkg-config. It is header only so just make |
| 33 | # sure we can access the needed symbols from the header. |
| 34 | catch2_dep = dependency('Catch2', required: false) |
| 35 | has_catch2 = meson.get_compiler('cpp').has_header_symbol( |
| 36 | 'catch2/catch.hpp', |
| 37 | 'Approx', |
| 38 | dependencies: catch2_dep, |
| 39 | required: false) |
| 40 | if not has_catch2 |
| 41 | catch2_proj = import('cmake').subproject( |
| 42 | 'Catch2', |
| 43 | cmake_options: [ |
| 44 | '-DBUILD_TESTING=OFF' |
| 45 | ], |
| 46 | required: false) |
| 47 | if catch2_proj.found() |
| 48 | catch2_dep = catch2_proj.dependency('Catch2') |
| 49 | has_catch2 = true |
| 50 | else |
| 51 | assert(not build_tests.enabled(), 'Catch2 is required') |
| 52 | endif |
| 53 | endif |
| 54 | |
| 55 | catch2_tests = [ |
| 56 | ] |
| 57 | |
| 58 | if has_catch2 |
| 59 | libcatch2 = static_library( |
| 60 | 'catch2', 'catch2_main.cpp', |
| 61 | implicit_include_directories: false, |
| 62 | build_by_default: false, |
| 63 | dependencies: catch2_dep) |
| 64 | |
| 65 | foreach t : catch2_tests |
| 66 | test(t, executable(t.underscorify(), t + '.cpp', |
| 67 | implicit_include_directories: false, |
| 68 | link_with: libcatch2, |
| 69 | dependencies: [stdplus, catch2_dep])) |
| 70 | endforeach |
| 71 | endif |