Add --version to cli

This commit is contained in:
King_DuckZ 2020-03-19 22:28:45 +01:00
parent b2b87c7459
commit 2a7eab3170
3 changed files with 36 additions and 4 deletions

View file

@ -1,3 +1,8 @@
#pragma once
#define APP_NAME "@APP_NAME@"
#define PROJECT_NAME "@PROJECT_NAME@"
#define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define COMPILER_NAME "@COMPILER_NAME@"
#define COMPILER_VERSION "@COMPILER_VERSION@"

View file

@ -4,13 +4,27 @@
#include <cxxopts.hpp>
#include <string>
#if !defined(STRINGIZE)
# define STRINGIZE_IMPL(s) #s
# define STRINGIZE(s) STRINGIZE_IMPL(s)
#endif
namespace {
constexpr const char* project_ver() {
return STRINGIZE(PROJECT_VERSION_MAJOR) "."
STRINGIZE(PROJECT_VERSION_MINOR) "."
STRINGIZE(PROJECT_VERSION_PATCH);
}
} //unnamed namespace
int main(int argc, char* argv[]) {
using mc::MemoryCard;
using std::string;
cxxopts::Options options(APP_NAME, "PSX memory card inspector");
cxxopts::Options options(PROJECT_NAME, "PSX memory card inspector");
options.add_options()
("h,help", "Show this help and quit")
("version", "Print version info")
("i,input", "Path to the input memory card file", cxxopts::value<string>()->default_value(""))
;
auto command = options.parse(argc, argv);
@ -20,6 +34,13 @@ int main(int argc, char* argv[]) {
return 0;
}
if (command.count("version")) {
std::cout << PROJECT_NAME << " v" << project_ver()
<< " built with " COMPILER_NAME " " COMPILER_VERSION
<< std::endl;
return 0;
}
std::string mc_path = command["input"].as<string>();
if (mc_path.empty()) {
std::cerr << "No input memory card specified, run with --help for usage\n";

View file

@ -1,7 +1,13 @@
#add_project_link_arguments(['-lstdc++fs'], language: 'cpp')
cpp = meson.get_compiler('cpp')
conf = configuration_data()
conf.set('APP_NAME', meson.project_name())
version_arr = meson.project_version().split('.')
conf.set('PROJECT_NAME', meson.project_name())
conf.set('PROJECT_VERSION_MAJOR', version_arr[0])
conf.set('PROJECT_VERSION_MINOR', version_arr[1])
conf.set('PROJECT_VERSION_PATCH', version_arr[2])
conf.set('COMPILER_NAME', cpp.get_id())
conf.set('COMPILER_VERSION', cpp.version())
config_file = configure_file(
input: 'config.h.in',
output: 'config.h',