get the version number from the cmake project

This commit is contained in:
Frédéric Mangano-Tarumi 2018-10-31 18:21:47 -04:00
parent 65aad6f62a
commit a3e7624866
4 changed files with 14 additions and 6 deletions

View File

@ -12,6 +12,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FindPkgConfig)
pkg_check_modules(OGG REQUIRED ogg)
configure_file(config.h.in config.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(opustags opustags.cc)
target_compile_options(opustags PUBLIC ${OGG_CFLAGS})
target_link_libraries(opustags PUBLIC ${OGG_LIBRARIES})

2
config.h.in Normal file
View File

@ -0,0 +1,2 @@
#cmakedefine PROJECT_NAME "@PROJECT_NAME@"
#cmakedefine PROJECT_VERSION "@PROJECT_VERSION@"

View File

@ -1,3 +1,5 @@
#include <config.h>
#include <errno.h>
#include <getopt.h>
#include <limits.h>
@ -165,7 +167,7 @@ int write_page(ogg_page *og, FILE *stream){
return 0;
}
const char *version = "opustags version 1.1.1\n";
const char *version = PROJECT_NAME " version " PROJECT_VERSION "\n";
const char *usage =
"Usage: opustags --help\n"

View File

@ -4,22 +4,23 @@
use strict;
use warnings;
use Test::More tests => 6;
use Test::More tests => 7;
my $opustags = './opustags';
chomp(my $version = `git describe --tags --abbrev=0`);
BAIL_OUT("$opustags does not exist or is not executable") if (! -x $opustags);
chomp(my $version = `$opustags --help | head -n 1`);
like($version, qr/^opustags version \d+\.\d+\.\d+$/, 'get the version string');
is(`$opustags`, <<"EOF", 'no options show the usage');
opustags version $version
$version
Usage: opustags --help
opustags [OPTIONS] FILE
opustags OPTIONS FILE -o FILE
EOF
my $help = <<"EOF";
opustags version $version
$version
Usage: opustags --help
opustags [OPTIONS] FILE