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:
Patrick Lühne 2018-03-25 16:59:15 +02:00
parent 50ebf3c6de
commit e01506f9ff
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
7 changed files with 51 additions and 50 deletions

View File

@ -3,7 +3,7 @@ FROM archimg/base-devel:latest
ARG toolchain
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
VOLUME /app

View File

@ -3,7 +3,7 @@ FROM ubuntu:18.04
ARG toolchain
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}" = "clang" ]; then apt-get install -y clang; fi

3
.gitmodules vendored
View File

@ -4,3 +4,6 @@
[submodule "lib/catch"]
path = lib/catch
url = https://github.com/catchorg/Catch2
[submodule "lib/cxxopts"]
path = lib/cxxopts
url = https://github.com/jarro2783/cxxopts

View File

@ -16,7 +16,7 @@ With the option `--simplify`, output formulas are simplified by applying several
## 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).
```bash

View File

@ -1,7 +1,5 @@
set(target anthem-app)
find_package(Boost 1.55.0 COMPONENTS program_options system filesystem REQUIRED)
file(GLOB core_sources "*.cpp")
file(GLOB core_headers "*.h")
@ -11,11 +9,10 @@ set(sources
)
set(includes
${Boost_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/lib/cxxopts/include
)
set(libraries
${Boost_LIBRARIES}
anthem
)

View File

@ -1,6 +1,6 @@
#include <iostream>
#include <boost/program_options.hpp>
#include <cxxopts.hpp>
#include <anthem/AST.h>
#include <anthem/Context.h>
@ -10,63 +10,70 @@ int main(int argc, char **argv)
{
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");
description.add_options()
("help,h", "Display this help message")
("version,v", "Display version information")
("input,i", po::value<std::vector<std::string>>(), "Input files")
("simplify,s", po::bool_switch(&context.performSimplification), "Simplify the output")
("complete,c", po::bool_switch(&context.performCompletion), "Perform completion")
("color", po::value<std::string>()->default_value("auto"), "Colorize output (always, never, auto)")
("parentheses", po::value<std::string>()->default_value("normal"), "Parenthesis style (normal, full)")
("log-priority,p", po::value<std::string>()->default_value("warning"), "Log messages starting from this priority (debug, info, warning, error)");
options.add_options()
("h,help", "Display this help message")
("v,version", "Display version information")
("i,input", "Input files", cxxopts::value<std::vector<std::string>>())
("s,simplify", "Simplify the output")
("c,complete", "Perform completion")
("color", "Colorize output (always, never, auto)", cxxopts::value<std::string>()->default_value("auto"))
("parentheses", "Parenthesis style (normal, full)", cxxopts::value<std::string>()->default_value("normal"))
("p,log-priority", "Log messages starting from this priority (debug, info, warning, error)", cxxopts::value<std::string>()->default_value("info"));
po::positional_options_description positionalOptionsDescription;
positionalOptionsDescription.add("input", -1);
po::variables_map variablesMap;
options.parse_positional("input");
options.positional_help("[<input file...>]");
const auto printHelp =
[&]()
{
std::cout
<< "Usage: anthem [options] file..." << std::endl
<< "Translate ASP programs to the language of first-order theorem provers." << std::endl << std::endl
<< description;
std::cout << options.help();
};
bool help;
bool version;
std::vector<std::string> inputFiles;
std::string colorPolicyString;
std::string parenthesisStyleString;
std::string logPriorityString;
try
{
po::store(po::command_line_parser(argc, argv)
.options(description)
.positional(positionalOptionsDescription)
.run(),
variablesMap);
po::notify(variablesMap);
const auto parseResult = options.parse(argc, argv);
help = (parseResult.count("help") > 0);
version = (parseResult.count("version") > 0);
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();
return EXIT_FAILURE;
}
if (variablesMap.count("help"))
if (help)
{
printHelp();
return EXIT_SUCCESS;
}
if (variablesMap.count("version"))
if (version)
{
std::cout << "anthem version 0.1.7-git" << std::endl;
return EXIT_SUCCESS;
}
const auto colorPolicyString = variablesMap["color"].as<std::string>();
if (colorPolicyString == "auto")
context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Auto);
else if (colorPolicyString == "never")
@ -81,22 +88,18 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
const auto parenthesisStyle = variablesMap["parentheses"].as<std::string>();
if (parenthesisStyle == "normal")
if (parenthesisStyleString == "normal")
context.parenthesisStyle = anthem::ast::ParenthesisStyle::Normal;
else if (parenthesisStyle == "full")
else if (parenthesisStyleString == "full")
context.parenthesisStyle = anthem::ast::ParenthesisStyle::Full;
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;
printHelp();
return EXIT_FAILURE;
}
const auto logPriorityString = variablesMap["log-priority"].as<std::string>();
try
{
const auto logPriority = anthem::output::priorityFromName(logPriorityString.c_str());
@ -112,11 +115,8 @@ int main(int argc, char **argv)
try
{
if (variablesMap.count("input"))
{
const auto &inputFiles = variablesMap["input"].as<std::vector<std::string>>();
if (!inputFiles.empty())
anthem::translate(inputFiles, context);
}
else
anthem::translate("std::cin", std::cin, context);
}

1
lib/cxxopts Submodule

@ -0,0 +1 @@
Subproject commit 8893afe13cc47dd0be4f25b5ae491e652c146098