diff --git a/.gitignore b/.gitignore index 593c5e8..52074e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build tags +compile_commands.json diff --git a/meson.build b/meson.build index 84155a2..2e45960 100644 --- a/meson.build +++ b/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') diff --git a/src/cli/config.h.in b/src/app_config.h.in similarity index 71% rename from src/cli/config.h.in rename to src/app_config.h.in index 6c383a5..894d5c3 100644 --- a/src/cli/config.h.in +++ b/src/app_config.h.in @@ -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@" diff --git a/src/cli/main.cpp b/src/cli/main.cpp index 1b9a88e..81fd4ba 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -17,27 +17,18 @@ #include "memcard.hpp" #include "config.h" +#include "app_config.h" #include #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 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; diff --git a/src/cli/meson.build b/src/cli/meson.build index 8552b98..f3f8142 100644 --- a/src/cli/meson.build +++ b/src/cli/meson.build @@ -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 diff --git a/src/config.h.in b/src/config.h.in new file mode 100644 index 0000000..bd230fa --- /dev/null +++ b/src/config.h.in @@ -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 . + */ + +#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 diff --git a/src/gui/command_line.cpp b/src/gui/command_line.cpp new file mode 100644 index 0000000..8ad9f48 --- /dev/null +++ b/src/gui/command_line.cpp @@ -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 . + */ + +#include "command_line.hpp" +#include "config.h" +#include "app_config.h" +#include + +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 diff --git a/src/gui/command_line.hpp b/src/gui/command_line.hpp new file mode 100644 index 0000000..bee4d53 --- /dev/null +++ b/src/gui/command_line.hpp @@ -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 . + */ + +#pragma once + +namespace mc { + struct CommandLineResult { + CommandLineResult(); + + bool should_quit; + }; + + CommandLineResult parse_command_line (int argc, char* argv[]); +} //namespace mc diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 4330b30..539118a 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -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 #include #include @@ -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")); diff --git a/src/gui/meson.build b/src/gui/meson.build index e7fda6c..96b4eb8 100644 --- a/src/gui/meson.build +++ b/src/gui/meson.build @@ -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] )