Add core/FileSystem.hpp for accessing std::filesystem

This file enables access to std::filesystem as `fs` namespace
or injects third-party drop-in replacement on build configs
where std::filesystem is not available.
This commit is contained in:
Paweł Bylica 2019-11-19 14:39:20 +01:00
parent 5a8a7fe7ba
commit 45002d723a
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
/// @file
/// This file enables access to std::filesystem as `fs` namespace
/// or injects third-party drop-in replacement on build configs
/// where std::filesystem is not available.
#pragma once
// Find out if std::filesystem is available:
#if defined(_MSC_VER) // Visual Studio supports <filesystem>
# define HAVE_STD_FILESYSTEM 1
#elif defined(__APPLE__) // XCode has the header, but reports error when included.
# define HAVE_STD_FILESYSTEM 0
#elif defined(__has_include) // For GCC/Clang check if the header exists.
# if __has_include(<filesystem>)
# define HAVE_STD_FILESYSTEM 1
# else
# define HAVE_STD_FILESYSTEM 0
# endif
#else // By default assume not supported.
# define HAVE_STD_FILESYSTEM 0
#endif
#if HAVE_STD_FILESYSTEM
# include <filesystem>
namespace fs = std::filesystem;
#else
# include "../thirdparty/filesystem.hpp"
namespace fs = ghc::filesystem;
#endif
#undef HAVE_STD_FILESYSTEM // Not needed any more, don't make it public.