Skip to content

Commit c7dd1da

Browse files
committed
Allow using system absl
Most distros don't like projects embedding subprojects, so we need to be capable of building using the system's absl. It is not going to work easily because the system's absl needs to be built with the C++17 standard to work, so ultimately this might not be such a good idea, but it works for me on nixos...
1 parent c3d4756 commit c7dd1da

File tree

2 files changed

+76
-60
lines changed

2 files changed

+76
-60
lines changed

meson.build

Lines changed: 75 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
11
project('ashuffle', ['c', 'cpp'], default_options: ['cpp_std=c++17', 'warning_level=2'])
22

33
cmake = import('cmake')
4+
cpp = meson.get_compiler('cpp')
45

5-
absl = cmake.subproject('absl', cmake_options: [
6-
'-DCMAKE_CXX_STANDARD=17',
7-
])
8-
9-
# Note: Unfortunately, meson does not pull in the "dependent" libraries
10-
# correctly so we have to list them here. If you take a dependency on some
11-
# addtional absl features, you will probably need to add more `dependency`
12-
# lines here. This could also be broken on upgrades.
13-
absl_all = [
6+
# absl dependencies need to be explicited...
7+
# It might be possible to use cmake dependencies (e.g. "absl:string"
8+
# defined in abslTargets.cmake in the future but that does not seem
9+
# worth the time trying to figure that out.
10+
absl_libs = [
1411
# Via Base:
15-
absl.dependency('raw_logging_internal'),
12+
'raw_logging_internal',
1613

1714
# Via Strings:
18-
absl.dependency('int128'),
19-
absl.dependency('str_format_internal'),
20-
absl.dependency('strings_internal'),
21-
absl.dependency('strings'),
15+
'int128',
16+
'str_format_internal',
17+
'strings_internal',
18+
'strings'
2219
]
2320

21+
absl_deps = []
22+
if not get_option('unsupported_use_system_absl')
23+
absl = cmake.subproject('absl', cmake_options: [
24+
'-DCMAKE_CXX_STANDARD=17',
25+
])
26+
27+
absl_deps = []
28+
foreach lib : absl_libs
29+
absl_deps += absl.dependency(lib)
30+
endforeach
31+
else
32+
# note that the system's absl needs to be compiled for C++17 standard
33+
# or final link will fail.
34+
foreach lib : absl_libs
35+
dep = cpp.find_library('absl_' + lib)
36+
if dep.found()
37+
absl_deps += dep
38+
endif
39+
endforeach
40+
endif
2441
libmpdclient = dependency('libmpdclient')
2542

2643
sources = files(
2744
'src/ashuffle.cc',
2845
'src/load.cc',
29-
'src/args.cc',
30-
'src/getpass.cc',
31-
'src/rule.cc',
46+
'src/args.cc',
47+
'src/getpass.cc',
48+
'src/rule.cc',
3249
'src/shuffle.cc',
3350
)
3451

@@ -38,55 +55,54 @@ src_inc = include_directories('src')
3855
root_inc = include_directories('.')
3956

4057
ashuffle = executable(
41-
'ashuffle',
42-
executable_sources,
43-
dependencies: absl_all + [libmpdclient],
44-
install: true
58+
'ashuffle',
59+
executable_sources,
60+
dependencies: absl_deps + [libmpdclient],
61+
install: true
4562
)
4663

4764
clang_tidy = run_target('ashuffle-clang-tidy',
4865
command : files('scripts/run-clang-tidy') + executable_sources
4966
)
5067

51-
# We only generate tests if we are *not running in tidy mode
5268
if get_option('tests').enabled()
5369

54-
googletest = cmake.subproject('googletest', cmake_options: [
55-
'-DBUILD_GMOCK=ON',
56-
'-DCMAKE_CXX_STANDARD=17',
57-
])
58-
59-
gtest_deps = [
60-
dependency('threads'),
61-
googletest.dependency('gtest'),
62-
googletest.dependency('gmock'),
63-
googletest.dependency('gmock_main'),
64-
]
65-
66-
mpdfake_inc = include_directories('t')
67-
mpdfake_dep = declare_dependency(include_directories : mpdfake_inc)
68-
69-
test_options = [
70-
'werror=true',
71-
]
72-
73-
tests = {
74-
'rule': ['t/rule_test.cc'],
75-
'shuffle': ['t/shuffle_test.cc'],
76-
'load': ['t/load_test.cc'],
77-
'args': ['t/args_test.cc'],
78-
'ashuffle': ['t/ashuffle_test.cc'],
79-
}
80-
81-
foreach test_name, test_sources : tests
82-
test_exe = executable(
83-
test_name + '_test',
84-
sources + test_sources,
85-
include_directories : src_inc,
86-
dependencies : absl_all + gtest_deps + [mpdfake_dep],
87-
override_options : test_options,
88-
)
89-
test(test_name, test_exe)
90-
endforeach
70+
googletest = cmake.subproject('googletest', cmake_options: [
71+
'-DBUILD_GMOCK=ON',
72+
'-DCMAKE_CXX_STANDARD=17',
73+
])
74+
75+
gtest_deps = [
76+
dependency('threads'),
77+
googletest.dependency('gtest'),
78+
googletest.dependency('gmock'),
79+
googletest.dependency('gmock_main'),
80+
]
81+
82+
mpdfake_inc = include_directories('t')
83+
mpdfake_dep = declare_dependency(include_directories : mpdfake_inc)
84+
85+
test_options = [
86+
'werror=true',
87+
]
88+
89+
tests = {
90+
'rule': ['t/rule_test.cc'],
91+
'shuffle': ['t/shuffle_test.cc'],
92+
'load': ['t/load_test.cc'],
93+
'args': ['t/args_test.cc'],
94+
'ashuffle': ['t/ashuffle_test.cc'],
95+
}
96+
97+
foreach test_name, test_sources : tests
98+
test_exe = executable(
99+
test_name + '_test',
100+
sources + test_sources,
101+
include_directories : src_inc,
102+
dependencies : absl_deps, gtest_deps + [mpdfake_dep],
103+
override_options : test_options,
104+
)
105+
test(test_name, test_exe)
106+
endforeach
91107

92108
endif # tests feature

meson_options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
option('tidy_mode', type : 'feature', value : 'disabled')
21
option('tests', type : 'feature', value : 'disabled')
2+
option('unsupported_use_system_absl', type : 'boolean', value : 'false')

0 commit comments

Comments
 (0)