Skip to content

Commit

Permalink
Allow using system absl
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
martinetd committed May 10, 2020
1 parent c3d4756 commit c7dd1da
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 60 deletions.
134 changes: 75 additions & 59 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
project('ashuffle', ['c', 'cpp'], default_options: ['cpp_std=c++17', 'warning_level=2'])

cmake = import('cmake')
cpp = meson.get_compiler('cpp')

absl = cmake.subproject('absl', cmake_options: [
'-DCMAKE_CXX_STANDARD=17',
])

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

# Via Strings:
absl.dependency('int128'),
absl.dependency('str_format_internal'),
absl.dependency('strings_internal'),
absl.dependency('strings'),
'int128',
'str_format_internal',
'strings_internal',
'strings'
]

absl_deps = []
if not get_option('unsupported_use_system_absl')
absl = cmake.subproject('absl', cmake_options: [
'-DCMAKE_CXX_STANDARD=17',
])

absl_deps = []
foreach lib : absl_libs
absl_deps += absl.dependency(lib)
endforeach
else
# note that the system's absl needs to be compiled for C++17 standard
# or final link will fail.
foreach lib : absl_libs
dep = cpp.find_library('absl_' + lib)
if dep.found()
absl_deps += dep
endif
endforeach
endif
libmpdclient = dependency('libmpdclient')

sources = files(
'src/ashuffle.cc',
'src/load.cc',
'src/args.cc',
'src/getpass.cc',
'src/rule.cc',
'src/args.cc',
'src/getpass.cc',
'src/rule.cc',
'src/shuffle.cc',
)

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

ashuffle = executable(
'ashuffle',
executable_sources,
dependencies: absl_all + [libmpdclient],
install: true
'ashuffle',
executable_sources,
dependencies: absl_deps + [libmpdclient],
install: true
)

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

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

googletest = cmake.subproject('googletest', cmake_options: [
'-DBUILD_GMOCK=ON',
'-DCMAKE_CXX_STANDARD=17',
])

gtest_deps = [
dependency('threads'),
googletest.dependency('gtest'),
googletest.dependency('gmock'),
googletest.dependency('gmock_main'),
]

mpdfake_inc = include_directories('t')
mpdfake_dep = declare_dependency(include_directories : mpdfake_inc)

test_options = [
'werror=true',
]

tests = {
'rule': ['t/rule_test.cc'],
'shuffle': ['t/shuffle_test.cc'],
'load': ['t/load_test.cc'],
'args': ['t/args_test.cc'],
'ashuffle': ['t/ashuffle_test.cc'],
}

foreach test_name, test_sources : tests
test_exe = executable(
test_name + '_test',
sources + test_sources,
include_directories : src_inc,
dependencies : absl_all + gtest_deps + [mpdfake_dep],
override_options : test_options,
)
test(test_name, test_exe)
endforeach
googletest = cmake.subproject('googletest', cmake_options: [
'-DBUILD_GMOCK=ON',
'-DCMAKE_CXX_STANDARD=17',
])

gtest_deps = [
dependency('threads'),
googletest.dependency('gtest'),
googletest.dependency('gmock'),
googletest.dependency('gmock_main'),
]

mpdfake_inc = include_directories('t')
mpdfake_dep = declare_dependency(include_directories : mpdfake_inc)

test_options = [
'werror=true',
]

tests = {
'rule': ['t/rule_test.cc'],
'shuffle': ['t/shuffle_test.cc'],
'load': ['t/load_test.cc'],
'args': ['t/args_test.cc'],
'ashuffle': ['t/ashuffle_test.cc'],
}

foreach test_name, test_sources : tests
test_exe = executable(
test_name + '_test',
sources + test_sources,
include_directories : src_inc,
dependencies : absl_deps, gtest_deps + [mpdfake_dep],
override_options : test_options,
)
test(test_name, test_exe)
endforeach

endif # tests feature
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
option('tidy_mode', type : 'feature', value : 'disabled')
option('tests', type : 'feature', value : 'disabled')
option('unsupported_use_system_absl', type : 'boolean', value : 'false')

0 comments on commit c7dd1da

Please sign in to comment.