Skip to content

Commit 351c8c9

Browse files
committed
tests: Move subproject conditional toplevel.
1 parent eebe77a commit 351c8c9

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ import('pkgconfig').generate(
5757
subdirs: ['.']
5858
)
5959

60-
if get_option('tests')
60+
if get_option('tests') and not meson.is_subproject()
6161
subdir('tests')
6262
endif

tests/meson.build

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
# SPDX-License-Identifier: BSL-1.0
22

3-
if not meson.is_subproject()
4-
5-
catch2_dep = dependency('catch2', required : get_option('system-catch2'))
6-
if not catch2_dep.found()
7-
catch2_dep = declare_dependency(compile_args: ['-DBUNDLED_CATCH2'])
8-
else
9-
if catch2_dep.version().version_compare('>=3.0')
10-
catch2_dep = [catch2_dep, declare_dependency(compile_args: ['-DCATCH3'])]
11-
endif
3+
catch2_dep = dependency('catch2', required : get_option('system-catch2'))
4+
if not catch2_dep.found()
5+
catch2_dep = declare_dependency(compile_args: ['-DBUNDLED_CATCH2'])
6+
else
7+
if catch2_dep.version().version_compare('>=3.0')
8+
catch2_dep = [catch2_dep, declare_dependency(compile_args: ['-DCATCH3'])]
129
endif
10+
endif
1311

14-
testlib = static_library('testlib', 'catch_main.cpp', dependencies: [catch2_dep])
15-
testdep_socket = []
16-
if host_machine.system() == 'sunos'
17-
testdep_socket = cxx.find_library('socket')
18-
endif
12+
testlib = static_library('testlib', 'catch_main.cpp', dependencies: [catch2_dep])
13+
testdep_socket = []
14+
if host_machine.system() == 'sunos'
15+
testdep_socket = cxx.find_library('socket')
16+
endif
1917

20-
test_cpp_args = []
21-
feraiseexcept_test_code = '''
18+
test_cpp_args = []
19+
feraiseexcept_test_code = '''
2220
#define _GNU_SOURCE
2321
#include <fenv.h>
2422
@@ -27,27 +25,26 @@ int main() {
2725
feraiseexcept(FE_DIVBYZERO);
2826
}
2927
'''
30-
if cxx.links(feraiseexcept_test_code,
31-
name: 'feraiseexcept')
32-
test_cpp_args += ['-DTEST_ENABLE_FERAISEEXCEPT']
33-
endif
34-
35-
test_no_opts_cpp_args = []
28+
if cxx.links(feraiseexcept_test_code,
29+
name: 'feraiseexcept')
30+
test_cpp_args += ['-DTEST_ENABLE_FERAISEEXCEPT']
31+
endif
3632

37-
# The tests are by necessity made using undefined behavior (after all it needs to test what happens in situations that
38-
# are, for good reason, undefined behavior).
39-
# To make this a bit more likely to work, just disable link time optimization if possible.
40-
if cxx.has_argument('-fno-lto')
41-
test_no_opts_cpp_args += ['-fno-lto', '-O0']
42-
endif
33+
test_no_opts_cpp_args = []
4334

44-
verbose_kwargs = {}
45-
if meson.version().version_compare('>=0.62')
46-
verbose_kwargs += {'verbose': true}
47-
endif
35+
# The tests are by necessity made using undefined behavior (after all it needs to test what happens in situations that
36+
# are, for good reason, undefined behavior).
37+
# To make this a bit more likely to work, just disable link time optimization if possible.
38+
if cxx.has_argument('-fno-lto')
39+
test_no_opts_cpp_args += ['-fno-lto', '-O0']
40+
endif
4841

49-
test('tests', executable('tests', 'tests.cpp', link_with: [testlib],
50-
dependencies: [posixsignalmanager_dep, qt5_dep, librt, catch2_dep, testdep_socket],
51-
cpp_args: test_cpp_args + test_no_opts_cpp_args),
52-
kwargs: verbose_kwargs)
42+
verbose_kwargs = {}
43+
if meson.version().version_compare('>=0.62')
44+
verbose_kwargs += {'verbose': true}
5345
endif
46+
47+
test('tests', executable('tests', 'tests.cpp', link_with: [testlib],
48+
dependencies: [posixsignalmanager_dep, qt5_dep, librt, catch2_dep, testdep_socket],
49+
cpp_args: test_cpp_args + test_no_opts_cpp_args),
50+
kwargs: verbose_kwargs)

0 commit comments

Comments
 (0)