Skip to content

Commit

Permalink
Use C++17; Use host utfcpp / utf8cpp; Drop bundled mapbox::variant
Browse files Browse the repository at this point in the history
  • Loading branch information
TinoDidriksen committed Sep 10, 2024
1 parent b942eae commit 08d077b
Show file tree
Hide file tree
Showing 27 changed files with 141 additions and 2,281 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ install-sh
missing
config.log
config.status
*~
src/.deps/
src/*.o
/src/divvun-suggest
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ this package.
## For just `divvun-suggest` and `divvun-blanktag`

- gcc >=5.0.0 with libstdc++-5-dev (or similarly recent version of
clang, with full C++11 support)
clang, with full C++17 support)
- libxml2-utils (just for xmllint)
- utfcpp (also known as utf8cpp)
- libhfst >=3.12.2
- libpugixml >=1.7.2 (optional)

Expand All @@ -170,8 +171,9 @@ that library. Alternatively, you can run ./configure with
## If you also want `divvun-checker`

- gcc >=5.0.0 with libstdc++-5-dev (or similarly recent version of
clang, with full C++11 support)
clang, with full C++17 support)
- libxml2-utils (just for xmllint)
- utfcpp (also known as utf8cpp)
- libhfst >=3.12.2
- libpugixml >=1.7.2
- libcg3-dev >=1.1.2.12327
Expand Down Expand Up @@ -1403,7 +1405,7 @@ then your C++ compiler is too old. See [Prerequisites](#org6558baf).

If you get

configure: error: 'g++ -std=c++11 -Wall -I/usr/include/hfst/ @GLIB_CFLAGS@ -I/usr/include/ ' does not accept ISO C++11
configure: error: 'g++ -std=c++17 -Wall -I/usr/include/hfst/ @GLIB_CFLAGS@ -I/usr/include/ ' does not accept ISO C++17

then you may be at the receiving end of
<https://github.com/hfst/hfst/issues/366>. A workaround is to edit
Expand Down
25 changes: 15 additions & 10 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,24 @@ AX_CHECK_COMPILE_FLAG([-Wall], [], AC_MSG_ERROR([compiler doesn't accept -Wall -
AX_CHECK_COMPILE_FLAG([-fstack-protector-strong], [CXXFLAGS="$CXXFLAGS -fstack-protector-strong"])


AC_CHECK_HEADER(["$HOMEBREW_PREFIX/include/utf8cpp/utf8.h"], [CPPFLAGS="-I$HOMEBREW_PREFIX/include/utf8cpp/ $CPPFLAGS"], [
AC_CHECK_HEADER([utf8cpp/utf8.h], [CPPFLAGS="-I/usr/include/utf8cpp/ $CPPFLAGS"], [
AC_CHECK_HEADER([utf8.h], [], [AC_MSG_ERROR([You don't have utfcpp installed.])])
])
])


dnl ====================
dnl Checks C++11 support
dnl Checks C++17 support
dnl ====================
AX_CHECK_COMPILE_FLAG([-std=c++17], [CXXFLAGS="$CXXFLAGS -std=c++17"], [
AX_CHECK_COMPILE_FLAG([-std=c++1z], [CXXFLAGS="$CXXFLAGS -std=c++1z"], [
AX_CHECK_COMPILE_FLAG([-std=c++14], [CXXFLAGS="$CXXFLAGS -std=c++14"], [
AX_CHECK_COMPILE_FLAG([-std=c++1y], [CXXFLAGS="$CXXFLAGS -std=c++1y"], [
AX_CHECK_COMPILE_FLAG([-std=c++11], [CXXFLAGS="$CXXFLAGS -std=c++11"], [
AC_MSG_ERROR([compiler doesn't accept any -std=c++11, please upgrade your compiler])])
])
])
])
for version in 26 2c 23 2b 20 2a 17; do
version_flag="-std=c++${version}"
AX_CHECK_COMPILE_FLAG([${version_flag}], [break], [version_flag=none])
done
AS_IF([test "$version_flag" = none], [
AC_MSG_ERROR([Could not enable at least C++17 - upgrade your compiler])
])
CXXFLAGS="$CXXFLAGS ${version_flag}"


dnl ==================
Expand Down
3 changes: 1 addition & 2 deletions python/libdivvun.i
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
%{
#include "../src/checkertypes.hpp"
#include "../src/checker.hpp"
#include "../src/utf8.h"
#include <utf8.h>
%}

#ifdef _MSC_VER
Expand All @@ -58,7 +58,6 @@ wrap_unique_ptr(CheckerUniquePtr, divvun::Checker);

%include "../src/checkertypes.hpp"
%include "../src/checker.hpp"
%include "../src/utf8.h"

%template(StringVector) std::vector<std::string>;
%template(StringSet) std::set<std::string>;
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ libdivvun_module = Extension(
include_dirs=['@top_srcdir@/src'],
library_dirs=['@top_srcdir@/src/.libs'],
libraries=['divvun'],
extra_compile_args=getenv_list('CPPFLAGS') + getenv_list('CXXFLAGS'),
extra_compile_args='@CPPFLAGS@'.split() + '@CXXFLAGS@'.split() + getenv_list('CPPFLAGS') + getenv_list('CXXFLAGS'),
extra_link_args=getenv_list('LDFLAGS'))


Expand Down
3 changes: 0 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ datadir = $(prefix)/share/libdivvun
AM_CPPFLAGS = -DPREFIX="\"$(prefix)\""

noinst_HEADERS=util.hpp hfst_util.hpp json.hpp \
utf8.h utf8/checked.h utf8/core.h utf8/unchecked.h \
mapbox/variant.hpp mapbox/recursive_wrapper.hpp \
mapbox/variant_visitor.hpp \
cxxopts.hpp
# divvun-suggest binary:
divvun_suggest_SOURCES = main_suggest.cpp suggest.cpp suggest.hpp
Expand Down
4 changes: 2 additions & 2 deletions src/blanktag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
#include <hfst/implementations/optimized-lookup/pmatch.h>
#include <hfst/implementations/optimized-lookup/pmatch_tokenize.h>
// variants:
#include "mapbox/variant.hpp"
#include <variant>

namespace divvun {

using mapbox::util::variant;
using std::variant;
using std::string;
using std::vector;
using std::unique_ptr;
Expand Down
9 changes: 7 additions & 2 deletions src/cgspell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ void print_cg_subreading(size_t indent,
}
if(indent == 1) {
os << " <W:" << w << ">";
mw_a.match([] (Nothing) {},
[&os] (Weight w_a) { os << " <WA:" << w_a << ">"; });
std::visit([&](auto&& arg){
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, Nothing>) {}
if constexpr (std::is_same_v<T, Weight>) {
os << " <WA:" << arg << ">";
}
}, mw_a);
os << " " << errtag;
os << " \"" << form << "\"S";
}
Expand Down
4 changes: 2 additions & 2 deletions src/cgspell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
// hfst:
#include <ZHfstOspeller.h>
// variants:
#include "mapbox/variant.hpp"
#include <variant>

namespace divvun {

using mapbox::util::variant;
using std::variant;
using std::string;
using std::vector;
using std::pair;
Expand Down
14 changes: 8 additions & 6 deletions src/checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ std::set<string> searchPaths() {
"/usr/share/voikko/4",
"/usr/local/share/voikko/4"
};
expanduser().match(
[](Nothing){ },
[&](string home) {
dirs.insert(home + "/.voikko/4");
std::visit([&](auto&& arg){
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, Nothing>) {}
if constexpr (std::is_same_v<T, string>) {
dirs.insert(arg + "/.voikko/4");
// TODO: getenv freedesktop stuff
dirs.insert(home + "/.config/voikko/4");
});
dirs.insert(arg + "/.config/voikko/4");
}
}, expanduser());
return dirs;
}

Expand Down
16 changes: 8 additions & 8 deletions src/cxxopts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ namespace cxxopts
{
public:
option_exists_error(const std::string& option)
: OptionSpecException(u8"Option ‘" + option + u8"’ already exists")
: OptionSpecException("Option ‘" + option + "’ already exists")
{
}
};
Expand All @@ -312,7 +312,7 @@ namespace cxxopts
{
public:
invalid_option_format_error(const std::string& format)
: OptionSpecException(u8"Invalid option format ‘" + format + u8"")
: OptionSpecException("Invalid option format ‘" + format + "")
{
}
};
Expand All @@ -321,7 +321,7 @@ namespace cxxopts
{
public:
option_not_exists_exception(const std::string& option)
: OptionParseException(u8"Option ‘" + option + u8"’ does not exist")
: OptionParseException("Option ‘" + option + "’ does not exist")
{
}
};
Expand All @@ -330,7 +330,7 @@ namespace cxxopts
{
public:
missing_argument_exception(const std::string& option)
: OptionParseException(u8"Option ‘" + option + u8"’ is missing an argument")
: OptionParseException("Option ‘" + option + "’ is missing an argument")
{
}
};
Expand All @@ -339,7 +339,7 @@ namespace cxxopts
{
public:
option_requires_argument_exception(const std::string& option)
: OptionParseException(u8"Option ‘" + option + u8"’ requires an argument")
: OptionParseException("Option ‘" + option + "’ requires an argument")
{
}
};
Expand All @@ -353,7 +353,7 @@ namespace cxxopts
const std::string& arg
)
: OptionParseException(
u8"Option ‘" + option + u8"’ does not take an argument, but argument‘"
"Option ‘" + option + "’ does not take an argument, but argument‘"
+ arg + "’ given")
{
}
Expand All @@ -363,7 +363,7 @@ namespace cxxopts
{
public:
option_not_present_exception(const std::string& option)
: OptionParseException(u8"Option ‘" + option + u8"’ not present")
: OptionParseException("Option ‘" + option + "’ not present")
{
}
};
Expand All @@ -376,7 +376,7 @@ namespace cxxopts
const std::string& arg
)
: OptionParseException(
u8"Argument ‘" + arg + u8"’ failed to parse"
"Argument ‘" + arg + "’ failed to parse"
)
{
}
Expand Down
Loading

0 comments on commit 08d077b

Please sign in to comment.