blob: a63240fa1c04d329f0614e822b98931d866ff8b1 [file] [log] [blame]
William A. Kennington IIIa2d67e22020-02-19 12:17:39 -08001gtest = dependency('gtest', main: true, disabler: true, required: false)
2gmock = dependency('gmock', disabler: true, required: false)
3if not gtest.found() or not gmock.found()
William A. Kennington III83af3fa2021-01-31 15:22:54 -08004 gtest_proj = import('cmake').subproject(
5 'googletest',
6 cmake_options: [
7 '-DCMAKE_CXX_FLAGS=-Wno-pedantic',
8 ],
9 required: false)
William A. Kennington IIIa2d67e22020-02-19 12:17:39 -080010 if gtest_proj.found()
11 gtest = declare_dependency(
12 dependencies: [
13 dependency('threads'),
14 gtest_proj.dependency('gtest'),
15 gtest_proj.dependency('gtest_main'),
16 ])
17 gmock = gtest_proj.dependency('gmock')
18 else
19 assert(not build_tests.enabled(), 'Googletest is required')
20 endif
21endif
William A. Kennington III15982f62019-01-31 14:43:41 -080022
William A. Kennington III245495e2020-02-13 13:07:30 -080023gtests = [
William A. Kennington IIIe847ef82018-11-02 17:29:15 -070024 'handle/copyable',
William A. Kennington III7a5e2322018-11-02 17:28:35 -070025 'handle/managed',
William A. Kennington IIIbff0b0f2018-11-16 19:56:10 -080026 'util/cexec',
William A. Kennington III4ef36e72019-06-27 12:48:59 -070027 'util/string',
William A. Kennington III15982f62019-01-31 14:43:41 -080028]
29
William A. Kennington III83af3fa2021-01-31 15:22:54 -080030if gtest.found() and gmock.found()
31 foreach t : gtests
32 test(t, executable(t.underscorify(), t + '.cpp',
33 build_by_default: false,
34 implicit_include_directories: false,
35 dependencies: [stdplus, gtest, gmock]))
36 endforeach
37endif
William A. Kennington III245495e2020-02-13 13:07:30 -080038
39# catch2 might not have a pkg-config. It is header only so just make
40# sure we can access the needed symbols from the header.
41catch2_dep = dependency('Catch2', required: false)
42has_catch2 = meson.get_compiler('cpp').has_header_symbol(
43 'catch2/catch.hpp',
44 'Approx',
45 dependencies: catch2_dep,
46 required: false)
47if not has_catch2
48 catch2_proj = import('cmake').subproject(
49 'Catch2',
50 cmake_options: [
51 '-DBUILD_TESTING=OFF'
52 ],
53 required: false)
54 if catch2_proj.found()
55 catch2_dep = catch2_proj.dependency('Catch2')
56 has_catch2 = true
57 else
58 assert(not build_tests.enabled(), 'Catch2 is required')
59 endif
60endif
61
62catch2_tests = [
William A. Kennington III770c5562020-02-13 13:07:42 -080063 'signal',
William A. Kennington IIIe0990382019-10-18 02:10:25 -070064 'raw',
William A. Kennington III245495e2020-02-13 13:07:30 -080065]
66
67if has_catch2
68 libcatch2 = static_library(
69 'catch2', 'catch2_main.cpp',
70 implicit_include_directories: false,
71 build_by_default: false,
72 dependencies: catch2_dep)
73
74 foreach t : catch2_tests
75 test(t, executable(t.underscorify(), t + '.cpp',
William A. Kennington III31422352020-02-19 13:21:56 -080076 build_by_default: false,
William A. Kennington III245495e2020-02-13 13:07:30 -080077 implicit_include_directories: false,
78 link_with: libcatch2,
William A. Kennington IIIe0990382019-10-18 02:10:25 -070079 dependencies: [stdplus, span_dep, catch2_dep]))
William A. Kennington III245495e2020-02-13 13:07:30 -080080 endforeach
81endif