Drop Boost dependency
Boost was only used for program option parsing. To avoid this huge dependency, this commit replaces boost::program_options with cxxopts, a header-only library with the same functionality. cxxopts is added as a submodule, and Boost is removed from the dependencies in the code and Travis configuration.
This commit is contained in:
parent
50ebf3c6de
commit
e01506f9ff
@ -3,7 +3,7 @@ FROM archimg/base-devel:latest
|
|||||||
ARG toolchain
|
ARG toolchain
|
||||||
|
|
||||||
RUN pacman -Sy
|
RUN pacman -Sy
|
||||||
RUN pacman -S --noconfirm boost cmake git ninja re2c
|
RUN pacman -S --noconfirm cmake git ninja re2c
|
||||||
RUN if [ "${toolchain}" = "clang" ]; then pacman -S --noconfirm clang; fi
|
RUN if [ "${toolchain}" = "clang" ]; then pacman -S --noconfirm clang; fi
|
||||||
|
|
||||||
VOLUME /app
|
VOLUME /app
|
||||||
|
@ -3,7 +3,7 @@ FROM ubuntu:18.04
|
|||||||
ARG toolchain
|
ARG toolchain
|
||||||
|
|
||||||
RUN apt-get update
|
RUN apt-get update
|
||||||
RUN apt-get install -y libboost-all-dev cmake git ninja-build re2c
|
RUN apt-get install -y cmake git ninja-build re2c
|
||||||
RUN if [ "${toolchain}" = "gcc" ]; then apt-get install -y g++; fi
|
RUN if [ "${toolchain}" = "gcc" ]; then apt-get install -y g++; fi
|
||||||
RUN if [ "${toolchain}" = "clang" ]; then apt-get install -y clang; fi
|
RUN if [ "${toolchain}" = "clang" ]; then apt-get install -y clang; fi
|
||||||
|
|
||||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -4,3 +4,6 @@
|
|||||||
[submodule "lib/catch"]
|
[submodule "lib/catch"]
|
||||||
path = lib/catch
|
path = lib/catch
|
||||||
url = https://github.com/catchorg/Catch2
|
url = https://github.com/catchorg/Catch2
|
||||||
|
[submodule "lib/cxxopts"]
|
||||||
|
path = lib/cxxopts
|
||||||
|
url = https://github.com/jarro2783/cxxopts
|
||||||
|
@ -16,7 +16,7 @@ With the option `--simplify`, output formulas are simplified by applying several
|
|||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
`anthem` requires [CMake](https://cmake.org/) and [Boost](http://www.boost.org/) for building.
|
`anthem` requires [CMake](https://cmake.org/) for building.
|
||||||
After installing the dependencies, `anthem` is built with a C++17 compiler (GCC ≥ 7.3 or clang ≥ 5.0).
|
After installing the dependencies, `anthem` is built with a C++17 compiler (GCC ≥ 7.3 or clang ≥ 5.0).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
set(target anthem-app)
|
set(target anthem-app)
|
||||||
|
|
||||||
find_package(Boost 1.55.0 COMPONENTS program_options system filesystem REQUIRED)
|
|
||||||
|
|
||||||
file(GLOB core_sources "*.cpp")
|
file(GLOB core_sources "*.cpp")
|
||||||
file(GLOB core_headers "*.h")
|
file(GLOB core_headers "*.h")
|
||||||
|
|
||||||
@ -11,11 +9,10 @@ set(sources
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(includes
|
set(includes
|
||||||
${Boost_INCLUDE_DIRS}
|
${PROJECT_SOURCE_DIR}/lib/cxxopts/include
|
||||||
)
|
)
|
||||||
|
|
||||||
set(libraries
|
set(libraries
|
||||||
${Boost_LIBRARIES}
|
|
||||||
anthem
|
anthem
|
||||||
)
|
)
|
||||||
|
|
||||||
|
86
app/main.cpp
86
app/main.cpp
@ -1,6 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <cxxopts.hpp>
|
||||||
|
|
||||||
#include <anthem/AST.h>
|
#include <anthem/AST.h>
|
||||||
#include <anthem/Context.h>
|
#include <anthem/Context.h>
|
||||||
@ -10,63 +10,70 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
anthem::Context context;
|
anthem::Context context;
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
cxxopts::Options options("anthem", "Translate ASP programs to the language of first-order theorem provers.");
|
||||||
|
|
||||||
po::options_description description("Allowed options");
|
options.add_options()
|
||||||
description.add_options()
|
("h,help", "Display this help message")
|
||||||
("help,h", "Display this help message")
|
("v,version", "Display version information")
|
||||||
("version,v", "Display version information")
|
("i,input", "Input files", cxxopts::value<std::vector<std::string>>())
|
||||||
("input,i", po::value<std::vector<std::string>>(), "Input files")
|
("s,simplify", "Simplify the output")
|
||||||
("simplify,s", po::bool_switch(&context.performSimplification), "Simplify the output")
|
("c,complete", "Perform completion")
|
||||||
("complete,c", po::bool_switch(&context.performCompletion), "Perform completion")
|
("color", "Colorize output (always, never, auto)", cxxopts::value<std::string>()->default_value("auto"))
|
||||||
("color", po::value<std::string>()->default_value("auto"), "Colorize output (always, never, auto)")
|
("parentheses", "Parenthesis style (normal, full)", cxxopts::value<std::string>()->default_value("normal"))
|
||||||
("parentheses", po::value<std::string>()->default_value("normal"), "Parenthesis style (normal, full)")
|
("p,log-priority", "Log messages starting from this priority (debug, info, warning, error)", cxxopts::value<std::string>()->default_value("info"));
|
||||||
("log-priority,p", po::value<std::string>()->default_value("warning"), "Log messages starting from this priority (debug, info, warning, error)");
|
|
||||||
|
|
||||||
po::positional_options_description positionalOptionsDescription;
|
options.parse_positional("input");
|
||||||
positionalOptionsDescription.add("input", -1);
|
options.positional_help("[<input file...>]");
|
||||||
|
|
||||||
po::variables_map variablesMap;
|
|
||||||
|
|
||||||
const auto printHelp =
|
const auto printHelp =
|
||||||
[&]()
|
[&]()
|
||||||
{
|
{
|
||||||
std::cout
|
std::cout << options.help();
|
||||||
<< "Usage: anthem [options] file..." << std::endl
|
|
||||||
<< "Translate ASP programs to the language of first-order theorem provers." << std::endl << std::endl
|
|
||||||
<< description;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool help;
|
||||||
|
bool version;
|
||||||
|
std::vector<std::string> inputFiles;
|
||||||
|
std::string colorPolicyString;
|
||||||
|
std::string parenthesisStyleString;
|
||||||
|
std::string logPriorityString;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
po::store(po::command_line_parser(argc, argv)
|
const auto parseResult = options.parse(argc, argv);
|
||||||
.options(description)
|
|
||||||
.positional(positionalOptionsDescription)
|
help = (parseResult.count("help") > 0);
|
||||||
.run(),
|
version = (parseResult.count("version") > 0);
|
||||||
variablesMap);
|
|
||||||
po::notify(variablesMap);
|
if (parseResult.count("input") > 0)
|
||||||
|
inputFiles = parseResult["input"].as<std::vector<std::string>>();
|
||||||
|
|
||||||
|
context.performSimplification = (parseResult.count("simplify") > 0);
|
||||||
|
context.performCompletion = (parseResult.count("complete") > 0);
|
||||||
|
colorPolicyString = parseResult["color"].as<std::string>();
|
||||||
|
parenthesisStyleString = parseResult["parentheses"].as<std::string>();
|
||||||
|
logPriorityString = parseResult["log-priority"].as<std::string>();
|
||||||
}
|
}
|
||||||
catch (const po::error &e)
|
catch (const std::exception &exception)
|
||||||
{
|
{
|
||||||
context.logger.log(anthem::output::Priority::Error) << e.what();
|
context.logger.log(anthem::output::Priority::Error) << exception.what();
|
||||||
|
context.logger.errorStream() << std::endl;
|
||||||
printHelp();
|
printHelp();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (variablesMap.count("help"))
|
if (help)
|
||||||
{
|
{
|
||||||
printHelp();
|
printHelp();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (variablesMap.count("version"))
|
if (version)
|
||||||
{
|
{
|
||||||
std::cout << "anthem version 0.1.7-git" << std::endl;
|
std::cout << "anthem version 0.1.7-git" << std::endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto colorPolicyString = variablesMap["color"].as<std::string>();
|
|
||||||
|
|
||||||
if (colorPolicyString == "auto")
|
if (colorPolicyString == "auto")
|
||||||
context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Auto);
|
context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Auto);
|
||||||
else if (colorPolicyString == "never")
|
else if (colorPolicyString == "never")
|
||||||
@ -81,22 +88,18 @@ int main(int argc, char **argv)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto parenthesisStyle = variablesMap["parentheses"].as<std::string>();
|
if (parenthesisStyleString == "normal")
|
||||||
|
|
||||||
if (parenthesisStyle == "normal")
|
|
||||||
context.parenthesisStyle = anthem::ast::ParenthesisStyle::Normal;
|
context.parenthesisStyle = anthem::ast::ParenthesisStyle::Normal;
|
||||||
else if (parenthesisStyle == "full")
|
else if (parenthesisStyleString == "full")
|
||||||
context.parenthesisStyle = anthem::ast::ParenthesisStyle::Full;
|
context.parenthesisStyle = anthem::ast::ParenthesisStyle::Full;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
context.logger.log(anthem::output::Priority::Error) << "unknown parenthesis style “" << parenthesisStyle << "”";
|
context.logger.log(anthem::output::Priority::Error) << "unknown parenthesis style “" << parenthesisStyleString << "”";
|
||||||
context.logger.errorStream() << std::endl;
|
context.logger.errorStream() << std::endl;
|
||||||
printHelp();
|
printHelp();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto logPriorityString = variablesMap["log-priority"].as<std::string>();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const auto logPriority = anthem::output::priorityFromName(logPriorityString.c_str());
|
const auto logPriority = anthem::output::priorityFromName(logPriorityString.c_str());
|
||||||
@ -112,11 +115,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (variablesMap.count("input"))
|
if (!inputFiles.empty())
|
||||||
{
|
|
||||||
const auto &inputFiles = variablesMap["input"].as<std::vector<std::string>>();
|
|
||||||
anthem::translate(inputFiles, context);
|
anthem::translate(inputFiles, context);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
anthem::translate("std::cin", std::cin, context);
|
anthem::translate("std::cin", std::cin, context);
|
||||||
}
|
}
|
||||||
|
1
lib/cxxopts
Submodule
1
lib/cxxopts
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 8893afe13cc47dd0be4f25b5ae491e652c146098
|
Loading…
Reference in New Issue
Block a user