diff --git a/src/cli/config.h.in b/src/cli/config.h.in index 30f51d9..719ccb2 100644 --- a/src/cli/config.h.in +++ b/src/cli/config.h.in @@ -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@" diff --git a/src/cli/main.cpp b/src/cli/main.cpp index 21a6481..563d78d 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -4,13 +4,27 @@ #include #include +#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()->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(); if (mc_path.empty()) { std::cerr << "No input memory card specified, run with --help for usage\n"; diff --git a/src/cli/meson.build b/src/cli/meson.build index 5d644a6..ce2e29f 100644 --- a/src/cli/meson.build +++ b/src/cli/meson.build @@ -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',