Add command line help/verbose options to gui too.
Refactor code to reduce code duplication across the two programs.
This commit is contained in:
parent
f86032d2b4
commit
5d5cba5e3f
10 changed files with 186 additions and 34 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
build
|
||||
tags
|
||||
compile_commands.json
|
||||
|
|
20
meson.build
20
meson.build
|
@ -9,7 +9,25 @@ if get_option('buildtype').startswith('debug')
|
|||
is_debug_build = 1
|
||||
endif
|
||||
|
||||
cxxopts_incl = include_directories('subprojects/cxxopts/include')
|
||||
cpp = meson.get_compiler('cpp')
|
||||
|
||||
conf = configuration_data()
|
||||
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())
|
||||
conf.set('COPYRIGHT_YEAR', '2020')
|
||||
project_config_file = configure_file(
|
||||
input: 'src/config.h.in',
|
||||
output: 'config.h',
|
||||
configuration: conf
|
||||
)
|
||||
app_config_model = files('src/app_config.h.in')
|
||||
|
||||
cxxopts_incl = include_directories('subprojects/cxxopts/include', '.')
|
||||
|
||||
memcard_proj = subproject('memcard')
|
||||
memcard_dep = memcard_proj.get_variable('memcard_dep')
|
||||
|
|
|
@ -17,9 +17,5 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#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@"
|
||||
#define APP_NAME "@APP_NAME@"
|
||||
#define APP_SHORT_DESC "@APP_SHORT_DESC@"
|
|
@ -17,27 +17,18 @@
|
|||
|
||||
#include "memcard.hpp"
|
||||
#include "config.h"
|
||||
#include "app_config.h"
|
||||
#include <iostream>
|
||||
#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 std::string;
|
||||
|
||||
cxxopts::Options options(PROJECT_NAME, "PSX memory card inspector");
|
||||
cxxopts::Options options(APP_NAME, APP_SHORT_DESC);
|
||||
options.add_options()
|
||||
("h,help", "Show this help and quit")
|
||||
("version", "Print version info")
|
||||
|
@ -61,7 +52,7 @@ int main(int argc, char* argv[]) {
|
|||
std::cout << PROJECT_NAME << " v" << project_ver()
|
||||
<< " built with " COMPILER_NAME " " COMPILER_VERSION
|
||||
<< '\n';
|
||||
std::cout << "Copyright (C) 2020 Michele Santullo\n";
|
||||
std::cout << "Copyright (C) " COPYRIGHT_YEAR " Michele Santullo\n";
|
||||
std::cout << "This is free software; see the source for copying conditions. There is NO\n";
|
||||
std::cout << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." << std::endl;
|
||||
|
||||
|
|
|
@ -1,22 +1,17 @@
|
|||
cpp = meson.get_compiler('cpp')
|
||||
|
||||
app_name = meson.project_name()
|
||||
conf = configuration_data()
|
||||
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())
|
||||
conf.set('APP_NAME', app_name)
|
||||
conf.set('APP_SHORT_DESC', 'PSX memory card inspector')
|
||||
config_file = configure_file(
|
||||
input: 'config.h.in',
|
||||
output: 'config.h',
|
||||
input: app_config_model,
|
||||
output: 'app_config.h',
|
||||
configuration: conf
|
||||
)
|
||||
|
||||
executable(meson.project_name(),
|
||||
executable(app_name,
|
||||
'main.cpp',
|
||||
'memcard.cpp',
|
||||
project_config_file,
|
||||
config_file,
|
||||
dependencies: [
|
||||
memcard_dep
|
||||
|
|
47
src/config.h.in
Normal file
47
src/config.h.in
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* Copyright 2020, Michele Santullo
|
||||
* This file is part of memoserv.
|
||||
*
|
||||
* Memoserv is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Memoserv is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Memoserv. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#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@"
|
||||
#define COPYRIGHT_YEAR "@COPYRIGHT_YEAR@"
|
||||
|
||||
#if !defined(STRINGIZE)
|
||||
# define STRINGIZE_IMPL(s) #s
|
||||
# define STRINGIZE(s) STRINGIZE_IMPL(s)
|
||||
# define CONFIG_UNDEF_STRINGIZE
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
constexpr
|
||||
#endif
|
||||
inline const char* project_ver() {
|
||||
return STRINGIZE(PROJECT_VERSION_MAJOR) "."
|
||||
STRINGIZE(PROJECT_VERSION_MINOR) "."
|
||||
STRINGIZE(PROJECT_VERSION_PATCH);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_UNDEF_STRINGIZE)
|
||||
# undef CONFIG_UNDEF_STRINGIZE
|
||||
# undef STRINGIZE_IMPL
|
||||
# undef STRINGIZE
|
||||
#endif
|
57
src/gui/command_line.cpp
Normal file
57
src/gui/command_line.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* Copyright 2020, Michele Santullo
|
||||
* This file is part of memoserv.
|
||||
*
|
||||
* Memoserv is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Memoserv is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Memoserv. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "command_line.hpp"
|
||||
#include "config.h"
|
||||
#include "app_config.h"
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
namespace mc {
|
||||
CommandLineResult::CommandLineResult() :
|
||||
should_quit(false)
|
||||
{
|
||||
}
|
||||
|
||||
CommandLineResult parse_command_line (int argc, char* argv[]) {
|
||||
cxxopts::Options options(APP_NAME, APP_SHORT_DESC);
|
||||
options.add_options()
|
||||
("h,help", "Show this help and quit")
|
||||
("version", "Print version info")
|
||||
;
|
||||
auto command = options.parse(argc, argv);
|
||||
CommandLineResult retval;
|
||||
|
||||
if (command.count("help")) {
|
||||
std::cout << options.help() << std::endl;
|
||||
retval.should_quit = true;
|
||||
return retval;
|
||||
}
|
||||
|
||||
if (command.count("version")) {
|
||||
std::cout << PROJECT_NAME << " v" << project_ver()
|
||||
<< " built with " COMPILER_NAME " " COMPILER_VERSION
|
||||
<< '\n';
|
||||
std::cout << "Copyright (C) " COPYRIGHT_YEAR " Michele Santullo\n";
|
||||
std::cout << "This is free software; see the source for copying conditions. There is NO\n";
|
||||
std::cout << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." << std::endl;
|
||||
retval.should_quit = true;
|
||||
return retval;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
} //namespace mc
|
28
src/gui/command_line.hpp
Normal file
28
src/gui/command_line.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* Copyright 2020, Michele Santullo
|
||||
* This file is part of memoserv.
|
||||
*
|
||||
* Memoserv is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Memoserv is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Memoserv. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace mc {
|
||||
struct CommandLineResult {
|
||||
CommandLineResult();
|
||||
|
||||
bool should_quit;
|
||||
};
|
||||
|
||||
CommandLineResult parse_command_line (int argc, char* argv[]);
|
||||
} //namespace mc
|
|
@ -19,6 +19,7 @@
|
|||
#include "widget/block_grid.hpp"
|
||||
#include "make_nana_animation.hpp"
|
||||
#include "memcard/make_memory_card.hpp"
|
||||
#include "command_line.hpp"
|
||||
#include <nana/gui.hpp>
|
||||
#include <nana/gui/widgets/label.hpp>
|
||||
#include <iostream>
|
||||
|
@ -32,8 +33,13 @@ namespace {
|
|||
const constexpr int g_def_icon_fps = 3;
|
||||
} //unnamed namespace
|
||||
|
||||
int main() {
|
||||
int main(int argc, char* argv[]) {
|
||||
using mc::psx::MemoryCard;
|
||||
|
||||
auto command = mc::parse_command_line(argc, argv);
|
||||
if (command.should_quit)
|
||||
return 0;
|
||||
|
||||
nana::form frm;
|
||||
|
||||
const MemoryCard mc1(mc::psx::make_memory_card("/home/michele/dev/code/cpp/memoserv/epsxe000_xa2.mcr"));
|
||||
|
|
|
@ -19,11 +19,24 @@ libfontconfig_dep = dependency('fontconfig')
|
|||
libthread_dep = dependency('threads')
|
||||
fslib_dep = cpp.find_library('stdc++fs', required: false)
|
||||
|
||||
executable(meson.project_name() + 'gui',
|
||||
app_name = meson.project_name() + 'gui'
|
||||
conf = configuration_data()
|
||||
conf.set('APP_NAME', app_name)
|
||||
conf.set('APP_SHORT_DESC', 'PSX memory card inspector')
|
||||
config_file = configure_file(
|
||||
input: app_config_model,
|
||||
output: 'app_config.h',
|
||||
configuration: conf
|
||||
)
|
||||
|
||||
executable(app_name,
|
||||
'main.cpp',
|
||||
'widget/block_grid.cpp',
|
||||
'make_nana_animation.cpp',
|
||||
'animation_with_size.cpp',
|
||||
'command_line.cpp',
|
||||
config_file,
|
||||
project_config_file,
|
||||
dependencies: [
|
||||
nana_dep,
|
||||
x11_dep,
|
||||
|
@ -36,5 +49,5 @@ executable(meson.project_name() + 'gui',
|
|||
fslib_dep,
|
||||
],
|
||||
install: true,
|
||||
include_directories: nana_incl_search,
|
||||
include_directories: [nana_incl_search, cxxopts_incl]
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue