Skip to content

Commit

Permalink
Use the C++17 standards <filesystem> header if available, otherwise f…
Browse files Browse the repository at this point in the history
…allback to the pre-C++17 draft header <experimental/filesystem>.

If none of these is available, use boost.filesystem.
Change LDFLAGS to use a general purpose FILESYSTEM_LIBS instead of BOOST_FILESYSTEM_LIBS. FILESYSTEM_LIBS will be using BOOST_*
in case we don't have a C++17 filesystem library.
Remove references to BOOST_REGEX_LIBS, which we don't use anymore.
  • Loading branch information
codereader committed Aug 19, 2017
1 parent cb7e704 commit c857682
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 38 deletions.
6 changes: 6 additions & 0 deletions configure.ac
Expand Up @@ -182,16 +182,22 @@ BOOST_REQUIRE([1.46.1])
BOOST_FORMAT
BOOST_TOKENIZER

FILESYSTEM_LIBS=''

# Require Boost Filesystem if the C++17-style header is not present
if test "$use_boost_filesystem" = "yes"
then
AC_MSG_NOTICE([Will check for boost.filesystem library since std::filesystem is not available])
BOOST_FILESYSTEM
BOOST_SYSTEM
FILESYSTEM_LIBS="$(BOOST_FILESYSTEM_LIBS) $(BOOST_SYSTEM_LIBS)"
else
AC_MSG_NOTICE([Will use std::filesystem instead of boost.filesystem])
FILESYSTEM_LIBS="-lstdc++fs"
fi

AC_SUBST([FILESYSTEM_LIBS])

BOOST_TEST

# Boost.Python if required
Expand Down
26 changes: 20 additions & 6 deletions libs/os/fs.h
Expand Up @@ -2,17 +2,31 @@
* \file
* Helper header for std::filesystem feature set. Includes the relevant headers
* and defines the common "fs" namespace alias.
* If the compiler library supports the C++17 feature std::filesystem, it will
* include the corresponding headers. All other compilers will refer to the
* headers provided by boost::filesystem.
* If the compiler library supports the C++17 feature std::filesystem, it includes
* the corresponding headers, or fall back to std::experimental::filesystem::v1.
* All other compilers will refer to the headers provided by boost::filesystem.
*/
#pragma once

// At the time of writing C++17 is still in draft state, but compilers
// We need the HAVE_* symbols created by the configure script
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// If C++17 <filesystem> is available, use that one
#ifdef HAVE_STD_FILESYSTEM

#include <filesystem>
namespace fs = std::filesystem;
#define DR_USE_STD_FILESYSTEM

// At the time of writing C++17 is still in draft state, but some compilers
// provide the features through the std::experimental namespace.
#if _MSC_VER >= 1900
// In Linux, the configure script will check for the header and define the
// HAVE_EXPERIMENTAL_FILESYSTEM symbol for us.
#elif _MSC_VER >= 1900 || defined(HAVE_EXPERIMENTAL_FILESYSTEM)

// Visual Studio 2015 onwards supplies the experimental/filesystem header
// Visual Studio 2015+ and GCC 5.3+ supply the experimental/filesystem header
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;
#define DR_USE_STD_FILESYSTEM
Expand Down
3 changes: 1 addition & 2 deletions libs/wxutil/Makefile.am
Expand Up @@ -14,8 +14,7 @@ libwxutil_la_LDFLAGS = -release @PACKAGE_VERSION@ \
$(LIBSIGC_LIBS) \
$(WX_LIBS) \
$(GL_LIBS) \
$(BOOST_FILESYSTEM_LIBS) \
$(BOOST_SYSTEM_LIBS) \
$(FILESYSTEM_LIBS) \
$(GLU_LIBS) \
$(FTGL_LIBS)
libwxutil_la_LIBADD = $(top_builddir)/libs/xmlutil/libxmlutil.la \
Expand Down
2 changes: 1 addition & 1 deletion plugins/archivezip/Makefile.am
Expand Up @@ -3,6 +3,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(LIBSIGC_CFLAGS)
modulesdir = $(pkglibdir)/modules
modules_LTLIBRARIES = archivezip.la

archivezip_la_LDFLAGS = -module -avoid-version $(Z_LIBS) $(LIBSIGC_LIBS)
archivezip_la_LDFLAGS = -module -avoid-version $(Z_LIBS) $(LIBSIGC_LIBS) $(FILESYSTEM_LIBS)
archivezip_la_SOURCES = ZipArchive.cpp pkzip.cpp plugin.cpp zlibstream.cpp

2 changes: 1 addition & 1 deletion plugins/dm.conversation/Makefile.am
Expand Up @@ -7,7 +7,7 @@ plugins_LTLIBRARIES = dm_conversation.la
dm_conversation_la_LIBADD = $(top_builddir)/libs/wxutil/libwxutil.la \
$(top_builddir)/libs/xmlutil/libxmlutil.la
dm_conversation_la_LDFLAGS = -module -avoid-version \
$(WX_LIBS) $(XML_LIBS) $(BOOST_REGEX_LIBS)
$(WX_LIBS) $(XML_LIBS)
dm_conversation_la_SOURCES = plugin.cpp \
ConversationKeyExtractor.cpp \
ConversationCommandInfo.cpp \
Expand Down
4 changes: 1 addition & 3 deletions plugins/dm.editing/Makefile.am
Expand Up @@ -9,9 +9,7 @@ dm_editing_la_LIBADD = $(top_builddir)/libs/wxutil/libwxutil.la \
dm_editing_la_LDFLAGS = -module -avoid-version \
$(WX_LIBS) \
$(XML_LIBS) \
$(BOOST_FILESYSTEM_LIBS) \
$(BOOST_SYSTEM_LIBS) \
$(BOOST_REGEX_LIBS)
$(FILESYSTEM_LIBS)
dm_editing_la_SOURCES = plugin.cpp \
AIHeadPropertyEditor.cpp \
AIEditingPanel.cpp \
Expand Down
3 changes: 1 addition & 2 deletions plugins/dm.gui/Makefile.am
Expand Up @@ -12,8 +12,7 @@ dm_gui_la_LDFLAGS = -module -avoid-version \
$(XML_LIBS) \
$(GLEW_LIBS) \
$(GL_LIBS) \
$(BOOST_SYSTEM_LIBS) \
$(BOOST_FILESYSTEM_LIBS)
$(FILESYSTEM_LIBS)
dm_gui_la_SOURCES = GuiSelector.cpp \
plugin.cpp \
ReadableEditorDialog.cpp \
Expand Down
2 changes: 1 addition & 1 deletion plugins/dm.objectives/Makefile.am
Expand Up @@ -7,7 +7,7 @@ plugins_LTLIBRARIES = dm_objectives.la
dm_objectives_la_LIBADD = $(top_builddir)/libs/wxutil/libwxutil.la \
$(top_builddir)/libs/xmlutil/libxmlutil.la
dm_objectives_la_LDFLAGS = -module -avoid-version \
$(BOOST_REGEX_LIBS) $(WX_LIBS) $(XML_LIBS)
$(WX_LIBS) $(XML_LIBS)
dm_objectives_la_SOURCES = ObjectivesEditor.cpp \
objectives.cpp \
SpecifierType.cpp \
Expand Down
2 changes: 1 addition & 1 deletion plugins/dm.stimresponse/Makefile.am
Expand Up @@ -7,7 +7,7 @@ plugins_LTLIBRARIES = dm_stimresponse.la
dm_stimresponse_la_LIBADD = $(top_builddir)/libs/xmlutil/libxmlutil.la \
$(top_builddir)/libs/wxutil/libwxutil.la
dm_stimresponse_la_LDFLAGS = -module -avoid-version \
$(BOOST_REGEX_LIBS) $(WX_LIBS) $(XML_LIBS)
$(WX_LIBS) $(XML_LIBS)
dm_stimresponse_la_SOURCES = ResponseEditor.cpp \
plugin.cpp \
StimResponse.cpp \
Expand Down
2 changes: 1 addition & 1 deletion plugins/eventmanager/Makefile.am
Expand Up @@ -8,7 +8,7 @@ modules_LTLIBRARIES = eventmgr.la
eventmgr_la_LIBADD = $(top_builddir)/libs/xmlutil/libxmlutil.la \
$(top_builddir)/libs/wxutil/libwxutil.la
eventmgr_la_LDFLAGS = -module -avoid-version \
$(LIBSIGC_LIBS) $(XML_LIBS) $(WX_LIBS) $(BOOST_REGEX_LIBS)
$(LIBSIGC_LIBS) $(XML_LIBS) $(WX_LIBS)
eventmgr_la_SOURCES = Accelerator.cpp \
Statement.cpp \
EventManager.cpp \
Expand Down
2 changes: 1 addition & 1 deletion plugins/filters/Makefile.am
Expand Up @@ -6,6 +6,6 @@ modules_LTLIBRARIES = filters.la

filters_la_LIBADD = $(top_builddir)/libs/xmlutil/libxmlutil.la
filters_la_LDFLAGS = -module -avoid-version \
$(BOOST_REGEX_LIBS) $(XML_LIBS) $(LIBSIGC_LIBS)
$(XML_LIBS) $(LIBSIGC_LIBS)
filters_la_SOURCES = XMLFilter.cpp BasicFilterSystem.cpp filters.cpp

4 changes: 1 addition & 3 deletions plugins/fonts/Makefile.am
Expand Up @@ -10,9 +10,7 @@ fonts_la_LDFLAGS = -module -avoid-version \
$(XML_LIBS) \
$(GL_LIBS) \
$(GLU_LIBS) \
$(BOOST_FILESYSTEM_LIBS) \
$(BOOST_SYSTEM_LIBS) \
$(BOOST_REGEX_LIBS) \
$(FILESYSTEM_LIBS) \
$(LIBSIGC_LIBS)
fonts_la_SOURCES = plugin.cpp \
FontLoader.cpp \
Expand Down
3 changes: 1 addition & 2 deletions plugins/mapdoom3/Makefile.am
Expand Up @@ -11,8 +11,7 @@ mapdoom3_la_LIBADD = $(top_builddir)/libs/wxutil/libwxutil.la \
mapdoom3_la_LDFLAGS = -module -avoid-version \
$(WX_LIBS) \
$(XML_LIBS) \
$(BOOST_FILESYSTEM_LIBS) \
$(BOOST_SYSTEM_LIBS) \
$(FILESYSTEM_LIBS) \
$(GLEW_LIBS) \
$(GL_LIBS)
mapdoom3_la_SOURCES = Doom3MapFormat.cpp \
Expand Down
4 changes: 1 addition & 3 deletions plugins/particles/Makefile.am
Expand Up @@ -7,9 +7,7 @@ particles_la_LDFLAGS = -module -avoid-version \
-lpthread \
$(GL_LIBS) \
$(WX_LIBS) \
$(BOOST_FILESYSTEM_LIBS) \
$(BOOST_REGEX_LIBS) \
$(BOOST_SYSTEM_LIBS)
$(FILESYSTEM_LIBS)
particles_la_LIBADD = $(top_builddir)/libs/math/libmath.la \
$(top_builddir)/libs/scene/libscenegraph.la \
$(top_builddir)/libs/wxutil/libwxutil.la
Expand Down
3 changes: 1 addition & 2 deletions plugins/script/Makefile.am
Expand Up @@ -14,8 +14,7 @@ modulesdir = $(pkglibdir)/modules
modules_LTLIBRARIES = script.la

script_la_LDFLAGS = -module -avoid-version \
$(BOOST_SYSTEM_LIBS) \
$(BOOST_FILESYSTEM_LIBS) \
$(FILESYSTEM_LIBS) \
$(PYTHON_LIBS) \
$(WX_LIBS)
script_la_LIBADD = $(top_builddir)/libs/math/libmath.la \
Expand Down
3 changes: 1 addition & 2 deletions plugins/uimanager/Makefile.am
Expand Up @@ -7,8 +7,7 @@ modules_LTLIBRARIES = uimanager.la
uimanager_la_LDFLAGS = -module -avoid-version \
$(WX_LIBS) \
$(XML_LIBS) \
$(BOOST_FILESYSTEM_LIBS) \
$(BOOST_SYSTEM_LIBS) \
$(FILESYSTEM_LIBS) \
$(GLEW_LIBS) \
$(GL_LIBS)
uimanager_la_LIBADD = $(top_builddir)/libs/wxutil/libwxutil.la \
Expand Down
3 changes: 1 addition & 2 deletions plugins/vfspk3/Makefile.am
Expand Up @@ -7,8 +7,7 @@ modules_LTLIBRARIES = vfspk3.la
vfspk3_la_LDFLAGS = -module -avoid-version \
$(GLIB_LIBS) \
$(XML_LIBS) \
$(BOOST_SYSTEM_LIBS) \
$(BOOST_FILESYSTEM_LIBS) \
$(FILESYSTEM_LIBS) \
$(LIBSIGC_LIBS)
vfspk3_la_SOURCES = vfspk3.cpp Doom3FileSystem.cpp DirectoryArchive.cpp

3 changes: 1 addition & 2 deletions plugins/xmlregistry/Makefile.am
Expand Up @@ -9,8 +9,7 @@ xmlregistry_la_LIBADD = $(top_builddir)/libs/xmlutil/libxmlutil.la
xmlregistry_la_LDFLAGS = -module -avoid-version \
$(XML_LIBS) \
$(WX_LIBS) \
$(BOOST_FILESYSTEM_LIBS) \
$(BOOST_SYSTEM_LIBS) \
$(FILESYSTEM_LIBS) \
$(LIBSIGC_LIBS)
xmlregistry_la_SOURCES = RegistryTree.cpp XMLRegistry.cpp XMLRegistryModule.cpp

4 changes: 1 addition & 3 deletions radiant/Makefile.am
Expand Up @@ -16,9 +16,7 @@ darkradiant_LDFLAGS = $(XML_LIBS) \
$(GLU_LIBS) \
$(FTGL_LIBS) \
$(LIBSIGC_LIBS) \
$(BOOST_FILESYSTEM_LIBS) \
$(BOOST_SYSTEM_LIBS) \
$(BOOST_REGEX_LIBS) \
$(FILESYSTEM_LIBS) \
$(DL_LIBS) \
$(INTL_LIBS) \
$(WX_LIBS)
Expand Down

0 comments on commit c857682

Please sign in to comment.