mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 12:58:00 +03:00
give CLI11 a try
This commit is contained in:
parent
70465c5346
commit
e5282db48c
8 changed files with 62 additions and 60 deletions
|
@ -18,7 +18,7 @@ command -v cmake >/dev/null 2>&1 || brew install cmake
|
|||
command -v qmake >/dev/null 2>&1 || brew install qt@5
|
||||
|
||||
# Install deps
|
||||
brew install icu4c yaml-cpp sqlite cxxopts
|
||||
brew install icu4c yaml-cpp sqlite cli11
|
||||
export PATH="/usr/local/opt/qt@5/bin:$PATH" # needed to use qmake in none default path as qt now points to qt6
|
||||
|
||||
ccache --version
|
||||
|
|
|
@ -40,7 +40,7 @@ if [[ $CI_OPENMW_USE_STATIC_DEPS ]]; then
|
|||
-DOPENMW_USE_SYSTEM_OSG=OFF
|
||||
-DOPENMW_USE_SYSTEM_BULLET=OFF
|
||||
-DOPENMW_USE_SYSTEM_SQLITE3=OFF
|
||||
-DOPENMW_USE_SYSTEM_CXXOPTS=OFF
|
||||
-DOPENMW_USE_SYSTEM_CLI11=OFF
|
||||
-DOPENMW_USE_SYSTEM_RECASTNAVIGATION=OFF
|
||||
)
|
||||
fi
|
||||
|
|
|
@ -1036,7 +1036,7 @@ add_cmake_opts -DOPENMW_MP_BUILD=on
|
|||
add_cmake_opts -DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}"
|
||||
add_cmake_opts -DOPENMW_USE_SYSTEM_SQLITE3=OFF
|
||||
add_cmake_opts -DOPENMW_USE_SYSTEM_YAML_CPP=OFF
|
||||
add_cmake_opts -DOPENMW_USE_SYSTEM_CXXOPTS=OFF
|
||||
add_cmake_opts -DOPENMW_USE_SYSTEM_CLI11=OFF
|
||||
if [ ! -z $CI ]; then
|
||||
case $STEP in
|
||||
components )
|
||||
|
|
|
@ -34,7 +34,7 @@ declare -rA GROUPED_DEPS=(
|
|||
|
||||
libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev
|
||||
libsdl2-dev libqt5opengl5-dev libopenal-dev libunshield-dev libtinyxml-dev
|
||||
libbullet-dev liblz4-dev libpng-dev libjpeg-dev libluajit-5.1-dev libcxxopts-dev
|
||||
libbullet-dev liblz4-dev libpng-dev libjpeg-dev libluajit-5.1-dev libcli11-dev
|
||||
librecast-dev libsqlite3-dev ca-certificates libicu-dev libyaml-cpp-dev
|
||||
"
|
||||
|
||||
|
|
|
@ -364,10 +364,10 @@ if (USE_SYSTEM_TINYXML)
|
|||
include_directories(SYSTEM ${TinyXML_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
# CXXOPTS
|
||||
option(OPENMW_USE_SYSTEM_CXXOPTS "Use system provided cxxopts library" ON)
|
||||
if(OPENMW_USE_SYSTEM_CXXOPTS)
|
||||
find_package(cxxopts CONFIG REQUIRED)
|
||||
# cli11
|
||||
option(OPENMW_USE_SYSTEM_CLI11 "Use system provided cli11 library" ON)
|
||||
if(OPENMW_USE_SYSTEM_CLI11)
|
||||
find_package(CLI11 CONFIG REQUIRED)
|
||||
endif()
|
||||
|
||||
# Platform specific
|
||||
|
|
|
@ -15,7 +15,7 @@ openmw_add_executable(openmw-iniimporter
|
|||
|
||||
target_link_libraries(openmw-iniimporter
|
||||
components
|
||||
cxxopts::cxxopts
|
||||
CLI11::CLI11
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
#include "CLI/CLI.hpp"
|
||||
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#include <components/files/conversion.hpp>
|
||||
|
@ -61,64 +61,66 @@ int wmain(int argc, wchar_t* wargv[])
|
|||
|
||||
try
|
||||
{
|
||||
cxxopts::Options options("Syntax: openmw-iniimporter <options> inifile configfile\nAllowed options");
|
||||
CLI::App app("Syntax: openmw-iniimporter inifile configfile");
|
||||
|
||||
// clang-format off
|
||||
options.add_options()
|
||||
("h,help", "produce help message")
|
||||
("v,verbose", "verbose output")
|
||||
("i,ini", "morrowind.ini file", cxxopts::value<Files::MaybeQuotedPath>())
|
||||
("c,cfg", "openmw.cfg file", cxxopts::value<Files::MaybeQuotedPath>())
|
||||
("o,output", "openmw.cfg file", cxxopts::value<Files::MaybeQuotedPath>()->default_value(""))
|
||||
("g,game-files", "import esm and esp files")
|
||||
("f,fonts", "import bitmap fonts")
|
||||
("A,no-archives", "disable bsa archives import")
|
||||
("e,encoding",
|
||||
"Character encoding used in OpenMW game messages\n"
|
||||
"\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, "
|
||||
"Croatian, Serbian (Latin script), Romanian and Albanian languages\n"
|
||||
"\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n"
|
||||
"\n\twin1252 - Western European (Latin) alphabet\n\n",
|
||||
cxxopts::value<std::string>()->default_value("win1252"))
|
||||
app.get_formatter()->column_width(40);
|
||||
app.get_formatter()->label("ARGUMENTS", "ARGUMENTS");
|
||||
|
||||
std::filesystem::path iniFile;
|
||||
app.add_option("-i, --ini", iniFile, "morrowind.ini file")->required()->check(CLI::ExistingFile);
|
||||
|
||||
std::filesystem::path cfgFile;
|
||||
app.add_option("-c, --cfg", cfgFile, "openmw.cfg file")->required()->check(CLI::NonexistentPath);
|
||||
|
||||
std::filesystem::path outputFile = "";
|
||||
app.add_option("-o,--output", outputFile, "openmw.cfg file")->default_str("")->check(CLI::NonexistentPath);
|
||||
|
||||
bool gameFiles = false;
|
||||
app.add_flag("-g,--game-files", gameFiles, "import esm and esp files");
|
||||
|
||||
bool fonts = false;
|
||||
app.add_flag("-f,--fonts", fonts, "import bitmap fonts");
|
||||
|
||||
bool noArchives = false;
|
||||
app.add_flag("-A,--no-archives", noArchives, "disable bsa archives import");
|
||||
|
||||
std::string gameEncoding = "win1252";
|
||||
app.add_option("-e,--encoding", gameEncoding,
|
||||
"Character encoding used in OpenMW game messages.\n"
|
||||
"\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, "
|
||||
"Croatian, Serbian (Latin script), Romanian and Albanian languages\n"
|
||||
"\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n"
|
||||
"\n\twin1252 - Western European (Latin) alphabet, used by default"
|
||||
)
|
||||
->default_str("win1252")->check(CLI::IsMember({"win1250", "win1251", "win1252"}, CLI::ignore_case));
|
||||
;
|
||||
// clang-format on
|
||||
|
||||
options.parse_positional({ "ini", "cfg" });
|
||||
bool verbose = false;
|
||||
app.add_flag("-v,--verbose", verbose, "verbose output");
|
||||
|
||||
auto result = options.parse(argc, argv);
|
||||
if (result.count("help") || !result.count("ini") || !result.count("cfg"))
|
||||
{
|
||||
std::cout << options.help() << std::endl;
|
||||
return 0;
|
||||
try {
|
||||
CLI11_PARSE(app, argc, argv)
|
||||
} catch (const CLI::ParseError& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
std::cout << app.help() << std::endl;
|
||||
return app.exit(e);
|
||||
}
|
||||
|
||||
std::filesystem::path iniFile(result["ini"].as<Files::MaybeQuotedPath>().u8string());
|
||||
std::filesystem::path cfgFile(result["cfg"].as<Files::MaybeQuotedPath>().u8string());
|
||||
std::filesystem::path outputFile = result["output"].as<Files::MaybeQuotedPath>().u8string();
|
||||
if (outputFile.empty())
|
||||
{
|
||||
outputFile = cfgFile;
|
||||
}
|
||||
|
||||
if (!std::filesystem::exists(iniFile))
|
||||
{
|
||||
std::cerr << "ini file does not exist" << std::endl;
|
||||
return -3;
|
||||
}
|
||||
if (!std::filesystem::exists(cfgFile))
|
||||
std::cerr << "cfg file does not exist" << std::endl;
|
||||
|
||||
MwIniImporter importer;
|
||||
importer.setVerbose(result["verbose"].as<bool>());
|
||||
importer.setVerbose(verbose);
|
||||
|
||||
// Font encoding settings
|
||||
std::string encoding(result["encoding"].as<std::string>());
|
||||
importer.setInputEncoding(ToUTF8::calculateEncoding(encoding));
|
||||
importer.setInputEncoding(ToUTF8::calculateEncoding(gameEncoding));
|
||||
|
||||
MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile);
|
||||
MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile);
|
||||
|
||||
if (!result["fonts"].as<bool>())
|
||||
if (!fonts)
|
||||
{
|
||||
ini.erase("Fonts:Font 0");
|
||||
ini.erase("Fonts:Font 1");
|
||||
|
@ -128,12 +130,12 @@ int wmain(int argc, wchar_t* wargv[])
|
|||
importer.merge(cfg, ini);
|
||||
importer.mergeFallback(cfg, ini);
|
||||
|
||||
if (result["game-files"].as<bool>())
|
||||
if (gameFiles)
|
||||
{
|
||||
importer.importGameFiles(cfg, ini, iniFile);
|
||||
}
|
||||
|
||||
if (!result["no-archives"].as<bool>())
|
||||
if (!noArchives)
|
||||
{
|
||||
importer.importArchives(cfg, ini);
|
||||
}
|
||||
|
|
16
extern/CMakeLists.txt
vendored
16
extern/CMakeLists.txt
vendored
|
@ -190,18 +190,18 @@ if(NOT OPENMW_USE_SYSTEM_RECASTNAVIGATION)
|
|||
FetchContent_MakeAvailableExcludeFromAll(recastnavigation)
|
||||
endif()
|
||||
|
||||
if(NOT OPENMW_USE_SYSTEM_CXXOPTS)
|
||||
if(NOT OPENMW_USE_SYSTEM_CLI11)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(cxxopts
|
||||
URL https://github.com/jarro2783/cxxopts/archive/refs/tags/v3.1.1.zip
|
||||
URL_HASH SHA512=df8a322f2ecef9bc0e2b17904b008e19e8f6d0384ba2ec95375c15be14953b008550cb119828f03a4eee12795c8df9a558a6eeb8c0e41ad7092b90270d517f5f
|
||||
SOURCE_DIR fetched/cxxopts
|
||||
FetchContent_Declare(CLI11
|
||||
URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.3.2.zip
|
||||
URL_HASH SHA512=cefa2bc275654d7ff73cdba8d4269c4b92d917986f223d1e290907087c3c7a82e64809c8430fbd2c3413819e95d267f1e246fb13816fbc3e7808c4ea1069cc19
|
||||
SOURCE_DIR fetched/cli11
|
||||
)
|
||||
FetchContent_MakeAvailableExcludeFromAll(cxxopts)
|
||||
FetchContent_MakeAvailableExcludeFromAll(CLI11)
|
||||
|
||||
### here is what makes all include directories -isystem
|
||||
get_target_property(CXXOPTS_IID cxxopts INTERFACE_INCLUDE_DIRECTORIES)
|
||||
set_target_properties(cxxopts PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${CXXOPTS_IID}")
|
||||
get_target_property(CLI11_IID CLI11 INTERFACE_INCLUDE_DIRECTORIES)
|
||||
set_target_properties(CLI11 PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${CLI11_IID}")
|
||||
### TODO: use SYSTEM option to FetchContent_Declare once CMake 3.25 is available and remove the above workaround
|
||||
endif()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue