blob: 545c9886de82e3fccba3d74ab906c8a8f64def38 [file] [log] [blame]
Jason M. Billsd6087ae2023-10-09 11:54:13 -07001gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
2gmock_dep = dependency('gmock', disabler: true, required: false)
3if 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. Bills28836072024-05-17 12:47:15 -070011 ],
Jason M. Billsd6087ae2023-10-09 11:54:13 -070012 )
13 gmock_dep = gtest_proj.dependency('gmock')
Jason M. Bills28836072024-05-17 12:47:15 -070014 else
Jason M. Billsd6087ae2023-10-09 11:54:13 -070015 assert(
16 not get_option('tests').enabled(),
Jason M. Bills28836072024-05-17 12:47:15 -070017 'Googletest is required if tests are enabled',
Jason M. Billsd6087ae2023-10-09 11:54:13 -070018 )
Jason M. Bills28836072024-05-17 12:47:15 -070019 endif
Jason M. Billsd6087ae2023-10-09 11:54:13 -070020endif
21
Jason M. Bills28836072024-05-17 12:47:15 -070022unit_tests = []
Jason M. Billsd6087ae2023-10-09 11:54:13 -070023
24if get_option('tests').enabled()
25 # generate the test executable
26 foreach unit_test : unit_tests
Jason M. Bills28836072024-05-17 12:47:15 -070027 test(
Jason M. Billsd6087ae2023-10-09 11:54:13 -070028 unit_test,
Jason M. Bills28836072024-05-17 12:47:15 -070029 executable(
30 unit_test,
31 unit_test + '.cpp',
32 include_directories: incs,
33 dependencies: deps
34 + [
35 gtest_dep,
36 gmock_dep,
37 ],
38 ),
Jason M. Billsd6087ae2023-10-09 11:54:13 -070039 )
40 endforeach
Jason M. Bills28836072024-05-17 12:47:15 -070041endif