Skip to content

Commit

Permalink
build: Use external submodule for pre-Catalina filesystem support.
Browse files Browse the repository at this point in the history
Grab the submodule, pass -DENABLE_FILESYSTEM_COMPAT:bool=on.

Only really valid for macOS 10.13 and 10.14, which both lack native
support for C++17 std::filesystem.

Fixes #156.
  • Loading branch information
qyot27 committed May 20, 2020
1 parent 5ef7e50 commit dec3687
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "filesystem"]
path = filesystem
url = https://github.com/gulrak/filesystem
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if(NOT HEADERS_ONLY)

option(ENABLE_PLUGINS "Build set of default external plugins" ON)
option(ENABLE_INTEL_SIMD "Enable SIMD intrinsics for Intel processors" ON)
option(ENABLE_FILESYSTEM_COMPAT "Use compatibility shim for C++17 filesystem" OFF)

if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo)
Expand Down Expand Up @@ -211,6 +212,9 @@ if(NOT HEADERS_ONLY)
if(ENABLE_PLUGINS)
add_subdirectory("plugins")
endif()
if(ENABLE_FILESYSTEM_COMPAT)
add_subdirectory("filesystem")
endif()

else()

Expand Down
5 changes: 5 additions & 0 deletions avs_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
set(FSLIB "stdc++fs")
endif()

if (ENABLE_FILESYSTEM_COMPAT)
set(FSLIB "ghc_filesystem")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFILESYSTEM_COMPAT")
endif()

# Windows DLL dependencies
if (MSVC OR MINGW)
target_link_libraries("AvsCore" "uuid" "winmm" "vfw32" "msacm32" "gdi32" "user32" "advapi32" "ole32" "imagehlp")
Expand Down
18 changes: 17 additions & 1 deletion avs_core/core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
#include "strings.h"
#include "InternalEnvironment.h"
#include <cassert>
#include <filesystem>
#include "function.h"

#ifndef FILESYSTEM_COMPAT
#include <filesystem>

namespace fs = std::filesystem;
#else
#include <ghc/filesystem.hpp>

namespace fs = ghc::filesystem;
#endif // FILESYSTEM_COMPAT

#ifdef AVS_WINDOWS
#include <avs/win.h>
#else
Expand Down Expand Up @@ -628,7 +636,11 @@ void PluginManager::AutoloadPlugins()
#else
const char* binaryFilter = ".dll";
#endif
#ifndef FILESYSTEM_COMPAT
for (auto& file : fs::directory_iterator(dir, std::filesystem::directory_options::skip_permission_denied | std::filesystem::directory_options::follow_directory_symlink, ec))
#else
for (auto& file : fs::directory_iterator(dir, ghc::filesystem::directory_options::skip_permission_denied | ghc::filesystem::directory_options::follow_directory_symlink, ec))
#endif
{
const bool extensionsMatch =
#ifdef AVS_POSIX
Expand Down Expand Up @@ -663,7 +675,11 @@ void PluginManager::AutoloadPlugins()
}

const char* scriptFilter = ".avsi";
#ifndef FILESYSTEM_COMPAT
for (auto& file : fs::directory_iterator(dir, std::filesystem::directory_options::skip_permission_denied | std::filesystem::directory_options::follow_directory_symlink, ec)) // and not recursive_directory_iterator
#else
for (auto& file : fs::directory_iterator(dir, ghc::filesystem::directory_options::skip_permission_denied | ghc::filesystem::directory_options::follow_directory_symlink, ec)) // and not recursive_directory_iterator
#endif
{
const bool extensionsMatch =
#ifdef AVS_POSIX
Expand Down
17 changes: 15 additions & 2 deletions avs_core/core/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@
#include <fstream>
#include <unordered_map>
#include <array>
#include <iomanip>

#ifndef FILESYSTEM_COMPAT
#include <filesystem>
namespace fs = std::filesystem;

#else
#include <ghc/filesystem.hpp>

namespace fs = ghc::filesystem;
#endif // FILESYSTEM_COMPAT

#include "fonts/fixedfonts.h"
#include "strings.h"

namespace fs = std::filesystem;

// generate outline on-the-fly
// consider: thicker outline for font sizes over 24?
void BitmapFont::generateOutline(uint16_t* outlined, int fontindex) const
Expand Down Expand Up @@ -243,7 +252,11 @@ static BdfFont LoadBMF(std::string name, bool bold) {
//std::ifstream ss("c:\\Download\\terminus-font-4.48\\terminus-font-4.48\\ter-u16n.bdf");
std::ifstream ss;
// explicite font file name
#ifndef FILESYSTEM_COMPAT
auto fname = std::filesystem::path(name);
#else
auto fname = ghc::filesystem::path(name);
#endif

if (!fs::exists(name))
return fnt;
Expand Down
12 changes: 12 additions & 0 deletions avs_core/core/parser/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@
#include <cmath>
#include <vector>
#include <fstream>
#ifndef FILESYSTEM_COMPAT
#include <filesystem>

namespace fs = std::filesystem;
#else
#include <ghc/filesystem.hpp>

namespace fs = ghc::filesystem;
#endif

#ifdef AVS_WINDOWS
#include <io.h>
Expand Down Expand Up @@ -582,9 +588,15 @@ AVSValue Import(AVSValue args, void*, IScriptEnvironment* env)
}

#else // adapted from AvxSynth
#ifndef FILESYSTEM_COMPAT
std::string file_part = std::filesystem::path(script_name).filename().string();
std::string full_path = std::filesystem::path(script_name).remove_filename();
std::string dir_part = std::filesystem::path(script_name).parent_path();
#else
std::string file_part = ghc::filesystem::path(script_name).filename().string();
std::string full_path = ghc::filesystem::path(script_name).remove_filename();
std::string dir_part = ghc::filesystem::path(script_name).parent_path();
#endif

FILE* h = fopen(script_name, "r");
if(NULL == h)
Expand Down
1 change: 1 addition & 0 deletions filesystem
Submodule filesystem added at 3f1c18

0 comments on commit dec3687

Please sign in to comment.