Skip to content

Commit

Permalink
Add plumb meson version into ashuffle.
Browse files Browse the repository at this point in the history
We use Meson's `configure_file` to fill in a string variable in a new
`libversion` library. This value is printed when a version flag is
provided.
  • Loading branch information
joshkunz committed Mar 14, 2021
1 parent d2e7a64 commit 31b6a66
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
29 changes: 24 additions & 5 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# vim: set sw=2 ts=2:
project('ashuffle', ['c', 'cpp'], default_options: ['cpp_std=c++17', 'warning_level=2'])
project(
'ashuffle',
['c', 'cpp'],
version: 'v3.10.1',
default_options: ['cpp_std=c++17', 'warning_level=2']
)

add_global_arguments(
[
Expand Down Expand Up @@ -71,6 +76,22 @@ else
endif
libmpdclient = dependency('libmpdclient')

src_inc = include_directories('src')

version_cc = configure_file(
configuration: {
'VERSION': meson.project_version(),
},
input: 'src/version.cc.in',
output: 'version.cc',
)

libversion = static_library(
'version',
[version_cc],
include_directories: src_inc,
)

sources = files(
'src/ashuffle.cc',
'src/load.cc',
Expand All @@ -82,14 +103,12 @@ sources = files(

executable_sources = sources + files('src/mpd_client.cc', 'src/main.cc')

src_inc = include_directories('src')
root_inc = include_directories('.')

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

clang_tidy = run_target('ashuffle-clang-tidy',
Expand Down
5 changes: 3 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "load.h"
#include "mpd_client.h"
#include "shuffle.h"
#include "version.h"

using namespace ashuffle;

Expand All @@ -41,8 +42,8 @@ int main(int argc, const char* argv[]) {
case ParseError::Type::kVersion:
// Don't print help in this case, since the user specifically
// requested we print the version.
std::cout << "version: Unknown" << std::endl;
exit(EXIT_FAILURE);
std::cout << "ashuffle version: " << kVersion << std::endl;
exit(EXIT_SUCCESS);
case ParseError::Type::kUnknown:
std::cerr << "unknown option parsing error. Please file a bug "
<< "at https://github.com/joshkunz/ashuffle"
Expand Down
8 changes: 8 additions & 0 deletions src/version.cc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "version.h"

namespace ashuffle {

// Filled in by Meson.
const char* kVersion = "@VERSION@";

} // namespace ashuffle
13 changes: 13 additions & 0 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#ifndef __ASHUFFLE_VERSION_H__
#define __ASHUFFLE_VERSION_H__

namespace ashuffle {

// kVersion is filled in by the build system to contain the version of
// ashuffle.
extern const char* kVersion;

} // namespace ashuffle

#endif // __ASHUFFLE_VERSION_H__

0 comments on commit 31b6a66

Please sign in to comment.