From b2b87c7459981a924f1d8623cc9b0c70a8fe8e98 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 19 Mar 2020 22:13:55 +0100 Subject: [PATCH] Add a CLI program to access the memoserv lib. --- .gitmodules | 3 +++ meson.build | 10 ++++++++-- src/cli/config.h.in | 3 +++ src/cli/main.cpp | 30 ++++++++++++++++++++++++++++++ src/cli/meson.build | 19 +++++++++++++++++++ src/gui/meson.build | 9 ++++----- src/meson.build | 1 + subprojects/cxxopts | 1 + 8 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 src/cli/config.h.in create mode 100644 src/cli/main.cpp create mode 100644 src/cli/meson.build create mode 160000 subprojects/cxxopts diff --git a/.gitmodules b/.gitmodules index e69de29..4251c0f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "subprojects/cxxopts"] + path = subprojects/cxxopts + url = https://github.com/jarro2783/cxxopts.git diff --git a/meson.build b/meson.build index 099ab4b..84155a2 100644 --- a/meson.build +++ b/meson.build @@ -1,11 +1,17 @@ -project('memoserv', 'cpp', default_options:['debug=true', 'cpp_std=c++17', 'b_ndebug=if-release']) +project('memoserv', 'cpp', + version: '0.1.0', + meson_version: '>=0.49.2', + default_options:['debug=true', 'cpp_std=c++17', 'b_ndebug=if-release'] +) is_debug_build = 0 if get_option('buildtype').startswith('debug') is_debug_build = 1 endif +cxxopts_incl = include_directories('subprojects/cxxopts/include') + memcard_proj = subproject('memcard') memcard_dep = memcard_proj.get_variable('memcard_dep') -subdir('src/gui') +subdir('src') diff --git a/src/cli/config.h.in b/src/cli/config.h.in new file mode 100644 index 0000000..30f51d9 --- /dev/null +++ b/src/cli/config.h.in @@ -0,0 +1,3 @@ +#pragma once + +#define APP_NAME "@APP_NAME@" diff --git a/src/cli/main.cpp b/src/cli/main.cpp new file mode 100644 index 0000000..21a6481 --- /dev/null +++ b/src/cli/main.cpp @@ -0,0 +1,30 @@ +#include "memcard/memorycard.hpp" +#include "config.h" +#include +#include +#include + +int main(int argc, char* argv[]) { + using mc::MemoryCard; + using std::string; + + cxxopts::Options options(APP_NAME, "PSX memory card inspector"); + options.add_options() + ("h,help", "Show this help and quit") + ("i,input", "Path to the input memory card file", cxxopts::value()->default_value("")) + ; + auto command = options.parse(argc, argv); + + if (command.count("help")) { + std::cout << options.help() << 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"; + return 2; + } + + return 0; +} diff --git a/src/cli/meson.build b/src/cli/meson.build new file mode 100644 index 0000000..5d644a6 --- /dev/null +++ b/src/cli/meson.build @@ -0,0 +1,19 @@ +#add_project_link_arguments(['-lstdc++fs'], language: 'cpp') + +conf = configuration_data() +conf.set('APP_NAME', meson.project_name()) +config_file = configure_file( + input: 'config.h.in', + output: 'config.h', + configuration: conf +) + +executable(meson.project_name(), + 'main.cpp', + config_file, + dependencies: [ + memcard_dep + ], + install: true, + include_directories: cxxopts_incl +) diff --git a/src/gui/meson.build b/src/gui/meson.build index c6b533a..e7fda6c 100644 --- a/src/gui/meson.build +++ b/src/gui/meson.build @@ -1,5 +1,3 @@ -add_project_link_arguments(['-lstdc++fs'], language: 'cpp') - if get_option('nanaroot') != '' nana_lib_search = [get_option('nanaroot')] else @@ -13,15 +11,15 @@ endif cpp = meson.get_compiler('cpp') nana_dep = cpp.find_library('nana', dirs: nana_lib_search) -private_incl = include_directories('.') x11_dep = dependency('x11') libjpeg_dep = dependency('libjpeg') libpng_dep = dependency('libpng') libxft_dep = dependency('xft') libfontconfig_dep = dependency('fontconfig') libthread_dep = dependency('threads') +fslib_dep = cpp.find_library('stdc++fs', required: false) -executable('gui', +executable(meson.project_name() + 'gui', 'main.cpp', 'widget/block_grid.cpp', 'make_nana_animation.cpp', @@ -35,7 +33,8 @@ executable('gui', libfontconfig_dep, libthread_dep, memcard_dep, + fslib_dep, ], install: true, - include_directories: [private_incl] + nana_incl_search, + include_directories: nana_incl_search, ) diff --git a/src/meson.build b/src/meson.build index 7b350d7..39c5308 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1 +1,2 @@ subdir('gui') +subdir('cli') diff --git a/subprojects/cxxopts b/subprojects/cxxopts new file mode 160000 index 0000000..b0f67a0 --- /dev/null +++ b/subprojects/cxxopts @@ -0,0 +1 @@ +Subproject commit b0f67a06de3446aa97a4943ad0ad6086460b2b61