Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using std::filesystem when not available #2317

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions include/cinder/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,31 @@

#pragma once

#if ( (! defined(__APPLE__)) && defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) && __has_include(<filesystem>)) || defined( _MSC_VER )
/*
Seems like MSVC does not define `__cplusplus` according to the picked `std=c++XX` prior to 2017.
Moreover, due to legacy code expecting it to still be `199711L` this is disabled by default and requires `/Zc:__cplusplus`.
> ref : https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/

Instead, we can additionally check `_MSVC_LANG` which always reports the c++ std version
Basically, when `/Zc:__cplusplus` is enabled: `__cplusplus == _MSVC_LANG`
> ref: https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170
*/

#ifndef __APPLE__
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) && __has_include(<filesystem>)
#define GHC_USE_STD_FS
#elif defined(_MSVC_LANG) && _MSVC_LANG >= 201703L && defined(__has_include) && __has_include(<filesystem>)
#define GHC_USE_STD_FS
#include <filesystem>
namespace cinder {
namespace fs = std::filesystem;
}
#endif
#endif

#ifndef GHC_USE_STD_FS
#ifdef GHC_USE_STD_FS
#include <filesystem>
namespace cinder {
namespace fs = std::filesystem;
}
#else
#define GHC_WIN_WSTRING_STRING_TYPE
#include <ghc/fs_fwd.hpp>
namespace cinder {
namespace fs = ghc::filesystem;
Expand Down
3 changes: 2 additions & 1 deletion proj/vc2019/cinder.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug_ANGLE|Win32">
Expand Down Expand Up @@ -765,6 +765,7 @@
<ClCompile Include="..\..\src\cinder\DataTarget.cpp" />
<ClCompile Include="..\..\src\cinder\Display.cpp" />
<ClCompile Include="..\..\src\cinder\Exception.cpp" />
<ClCompile Include="..\..\src\cinder\Filesystem.cpp" />
<ClCompile Include="..\..\src\cinder\FileWatcher.cpp" />
<ClCompile Include="..\..\src\cinder\Font.cpp" />
<ClCompile Include="..\..\src\cinder\Frustum.cpp" />
Expand Down
5 changes: 4 additions & 1 deletion proj/vc2019/cinder.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
Expand Down Expand Up @@ -1083,6 +1083,9 @@
<ClCompile Include="..\..\src\cinder\MediaTime.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\cinder\Filesystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\AntTweakBar\AntPerfTimer.h">
Expand Down
9 changes: 6 additions & 3 deletions src/cinder/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
POSSIBILITY OF SUCH DAMAGE.
*/

#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include)
#if (! defined(__APPLE__)) && __has_include(<filesystem>)
#ifndef __APPLE__
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) && __has_include(<filesystem>)
#define GHC_USE_STD_FS
#elif defined(_MSVC_LANG) && _MSVC_LANG >= 201703L && defined(__has_include) && __has_include(<filesystem>)
#define GHC_USE_STD_FS
#endif
#endif

#if ! defined( GHC_USE_STD_FS )
#ifndef GHC_USE_STD_FS
#undef GHC_FILESYSTEM_H
#define GHC_WIN_WSTRING_STRING_TYPE
#include <ghc/fs_impl.hpp>
#endif