From c7dd1dad255baf76b767560e5e13cc5c2346223f Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Thu, 7 May 2020 18:52:21 +0200 Subject: [PATCH] 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... --- meson.build | 134 ++++++++++++++++++++++++++-------------------- meson_options.txt | 2 +- 2 files changed, 76 insertions(+), 60 deletions(-) diff --git a/meson.build b/meson.build index b1d9fbbc..e898156c 100644 --- a/meson.build +++ b/meson.build @@ -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', ) @@ -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 diff --git a/meson_options.txt b/meson_options.txt index 2587a7e0..db44977a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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')