From c520faed6d0e5e9472622f848ad8512b6c71c8e0 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 13 Oct 2022 18:37:44 -0300 Subject: feat: add gulrak/filesystem submodule ... for old macs that don't have std::filesystem in their stdlib. Signed-off-by: flow --- launcher/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'launcher') diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index c5894268..d04f3e4d 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -976,6 +976,7 @@ target_link_libraries(Launcher_logic BuildConfig Katabasis Qt${QT_VERSION_MAJOR}::Widgets + ghc_filesystem ) if (UNIX AND NOT CYGWIN AND NOT APPLE) -- cgit From 124097d3a50ba4ae97478ce7d33e5d33690cef75 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 13 Oct 2022 18:38:52 -0300 Subject: feat!: use ghc/filesystem in place of std's one if needed Signed-off-by: flow --- launcher/FileSystem.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'launcher') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 5d179641..c2db0dbc 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -59,7 +59,24 @@ #include #endif +// Snippet from https://github.com/gulrak/filesystem#using-it-as-single-file-header + +#ifdef __APPLE__ +#include // for deployment target to support pre-catalina targets without std::fs +#endif // __APPLE__ + +#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) +#if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) +#define GHC_USE_STD_FS #include +namespace fs = std::filesystem; +#endif // MacOS min version check +#endif // Other OSes version check + +#ifndef GHC_USE_STD_FS +#include +namespace fs = ghc::filesystem; +#endif #if defined Q_OS_WIN32 @@ -147,7 +164,7 @@ bool ensureFolderPathExists(QString foldernamepath) bool copy::operator()(const QString& offset) { - using copy_opts = std::filesystem::copy_options; + using copy_opts = fs::copy_options; // NOTE always deep copy on windows. the alternatives are too messy. #if defined Q_OS_WIN32 @@ -159,7 +176,7 @@ bool copy::operator()(const QString& offset) std::error_code err; - std::filesystem::copy_options opt = copy_opts::none; + fs::copy_options opt = copy_opts::none; // The default behavior is to follow symlinks if (!m_followSymlinks) @@ -182,7 +199,7 @@ bool copy::operator()(const QString& offset) auto dst_path = PathCombine(dst, relative_path); ensureFilePathExists(dst_path); - std::filesystem::copy(toStdString(src_path), toStdString(dst_path), opt, err); + fs::copy(toStdString(src_path), toStdString(dst_path), opt, err); if (err) { qWarning() << "Failed to copy files:" << QString::fromStdString(err.message()); qDebug() << "Source file:" << src_path; @@ -197,7 +214,7 @@ bool deletePath(QString path) { std::error_code err; - std::filesystem::remove_all(toStdString(path), err); + fs::remove_all(toStdString(path), err); if (err) { qWarning() << "Failed to remove files:" << QString::fromStdString(err.message()); @@ -376,15 +393,15 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na bool overrideFolder(QString overwritten_path, QString override_path) { - using copy_opts = std::filesystem::copy_options; + using copy_opts = fs::copy_options; if (!FS::ensureFolderPathExists(overwritten_path)) return false; std::error_code err; - std::filesystem::copy_options opt = copy_opts::recursive | copy_opts::overwrite_existing; + fs::copy_options opt = copy_opts::recursive | copy_opts::overwrite_existing; - std::filesystem::copy(toStdString(override_path), toStdString(overwritten_path), opt, err); + fs::copy(toStdString(override_path), toStdString(overwritten_path), opt, err); if (err) { qCritical() << QString("Failed to apply override from %1 to %2").arg(override_path, overwritten_path); -- cgit From 303628bb0579f13d3ceac915b3caaf4d7fc9b2db Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 15 Oct 2022 13:13:34 +0200 Subject: refactor: support system ghc-filesystem Signed-off-by: Sefa Eyeoglu --- CMakeLists.txt | 17 ++++++++++++----- launcher/CMakeLists.txt | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'launcher') diff --git a/CMakeLists.txt b/CMakeLists.txt index 45dd691d..310cec59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -189,13 +189,13 @@ if (Qt5_POSITION_INDEPENDENT_CODE) SET(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() -# Find toml++ if(NOT Launcher_FORCE_BUNDLED_LIBS) + # Find toml++ find_package(tomlplusplus 3.2.0 QUIET) -endif() -# Workaround ghc::filesystem bug -set(GHC_FILESYSTEM_WITH_INSTALL OFF) + # Find ghc_filesystem + find_package(ghc_filesystem QUIET) +endif() ####################################### Program Info ####################################### @@ -326,7 +326,14 @@ endif() add_subdirectory(libraries/katabasis) # An OAuth2 library that tried to do too much add_subdirectory(libraries/gamemode) add_subdirectory(libraries/murmur2) # Hash for usage with the CurseForge API -add_subdirectory(libraries/filesystem) # Implementation of std::filesystem for old C++, for usage in old macOS +if (NOT ghc_filesystem_FOUND) + message(STATUS "Using bundled ghc_filesystem") + set(GHC_FILESYSTEM_WITH_INSTALL OFF) # Workaround ghc::filesystem bug + add_subdirectory(libraries/filesystem) # Implementation of std::filesystem for old C++, for usage in old macOS + add_library(ghcFilesystem::ghc_filesystem ALIAS ghc_filesystem) +else() + message(STATUS "Using system ghc_filesystem") +endif() ############################### Built Artifacts ############################### diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index d04f3e4d..c7d0d68c 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -976,7 +976,7 @@ target_link_libraries(Launcher_logic BuildConfig Katabasis Qt${QT_VERSION_MAJOR}::Widgets - ghc_filesystem + ghcFilesystem::ghc_filesystem ) if (UNIX AND NOT CYGWIN AND NOT APPLE) -- cgit