From be9ddf2ae1ba49c02288e37adb7b0614dd69b13e Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Tue, 19 May 2020 23:14:21 -0300 Subject: [PATCH] Bring back ghc::filesystem for broke AF macos macOS doesn't provide `` support when targetting anything earlier than 10.15. --- .gitmodules | 3 +++ CMakeLists.txt | 4 +++- cmake/check_for_std_filesystem.cmake | 13 ++++++++++++- external/ghc-filesystem | 1 + llarp/config/config.cpp | 1 - llarp/util/fs.hpp | 5 +++++ 6 files changed, 24 insertions(+), 3 deletions(-) create mode 160000 external/ghc-filesystem diff --git a/.gitmodules b/.gitmodules index eb0cdbfdd..83ff3c3c3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,9 @@ [submodule "external/cxxopts"] path = external/cxxopts url = https://github.com/jarro2783/cxxopts.git +[submodule "external/ghc-filesystem"] + path = external/ghc-filesystem + url = https://github.com/gulrak/filesystem.git [submodule "test/Catch2"] path = test/Catch2 url = https://github.com/catchorg/Catch2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 10f33cbe2..455ca699c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.10) # bionic's cmake version -set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13) # Has to be set before `project()`, and ignored on non-macos +# Has to be set before `project()`, and ignored on non-macos: +set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13 CACHE STRING "macOS deployment target (Apple clang only)") find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) @@ -261,6 +262,7 @@ if(SUBMODULE_CHECK) check_submodule(external/nlohmann) check_submodule(external/googletest) check_submodule(external/cxxopts) + check_submodule(external/ghc-filesystem) check_submodule(external/date) check_submodule(external/pybind11) check_submodule(external/libuv) diff --git a/cmake/check_for_std_filesystem.cmake b/cmake/check_for_std_filesystem.cmake index 2c66822ff..aef0448ec 100644 --- a/cmake/check_for_std_filesystem.cmake +++ b/cmake/check_for_std_filesystem.cmake @@ -15,6 +15,13 @@ int main() { } ]]) +if(CMAKE_CXX_COMPILER STREQUAL "AppleClang" AND CMAKE_OSX_DEPLOYMENT_TARGET) + # It seems that check_cxx_source_compiles doesn't respect the CMAKE_OSX_DEPLOYMENT_TARGET, so this + # check would pass on Catalina (10.15) and then later compilation would fail because you aren't + # allowed to use when the deployment target is anything before 10.15. + set(CMAKE_REQUIRED_FLAGS -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}) +endif() + check_cxx_source_compiles("${filesystem_code}" filesystem_compiled) if(filesystem_compiled) message(STATUS "No extra link flag needed for std::filesystem") @@ -35,5 +42,9 @@ unset(CMAKE_REQUIRED_LIBRARIES) if(filesystem_is_good EQUAL 1) message(STATUS "we have std::filesystem") else() - message(FATAL_ERROR "we don't have std::filesystem") + # Probably broken AF macos + message(STATUS "std::filesystem is not available, apparently this compiler isn't C++17 compliant; falling back to ghc::filesystem") + add_subdirectory(external/ghc-filesystem) + target_link_libraries(filesystem INTERFACE ghc_filesystem) + target_compile_definitions(filesystem INTERFACE USE_GHC_FILESYSTEM) endif() diff --git a/external/ghc-filesystem b/external/ghc-filesystem new file mode 160000 index 000000000..e63a58c5b --- /dev/null +++ b/external/ghc-filesystem @@ -0,0 +1 @@ +Subproject commit e63a58c5bac94a3a75a7083f87bb092531407a92 diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 22b826be2..a5b17d0b6 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -16,7 +16,6 @@ #include #include #include -#include namespace llarp { diff --git a/llarp/util/fs.hpp b/llarp/util/fs.hpp index 132e5f132..dfd28375c 100644 --- a/llarp/util/fs.hpp +++ b/llarp/util/fs.hpp @@ -9,8 +9,13 @@ #define PATH_SEP "/" #endif +#ifdef USE_GHC_FILESYSTEM +#include +namespace fs = ghc::filesystem; +#else #include namespace fs = std::filesystem; +#endif #ifndef _MSC_VER #include