2020-05-15 13:32:24 +00:00
|
|
|
# Figure out if we need -lstdc++fs or -lc++fs and add it to the `filesystem` interface, if needed
|
|
|
|
# (otherwise just leave it an empty interface library; linking to it will do nothing). The former
|
|
|
|
# is needed for gcc before v9, and the latter with libc++ before llvm v9. But this gets more
|
|
|
|
# complicated than just using the compiler, because clang on linux by default uses libstdc++, so
|
|
|
|
# we'll just give up and see what works.
|
|
|
|
|
|
|
|
add_library(filesystem INTERFACE)
|
|
|
|
|
|
|
|
set(filesystem_code [[
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
auto cwd = std::filesystem::current_path();
|
|
|
|
return !cwd.string().empty();
|
|
|
|
}
|
|
|
|
]])
|
|
|
|
|
2020-05-20 02:14:21 +00:00
|
|
|
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 <filesystem> when the deployment target is anything before 10.15.
|
|
|
|
set(CMAKE_REQUIRED_FLAGS -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET})
|
|
|
|
endif()
|
|
|
|
|
2020-05-15 13:32:24 +00:00
|
|
|
check_cxx_source_compiles("${filesystem_code}" filesystem_compiled)
|
|
|
|
if(filesystem_compiled)
|
|
|
|
message(STATUS "No extra link flag needed for std::filesystem")
|
|
|
|
set(filesystem_is_good 1)
|
|
|
|
else()
|
|
|
|
foreach(fslib stdc++fs c++fs)
|
|
|
|
set(CMAKE_REQUIRED_LIBRARIES -l${fslib})
|
|
|
|
check_cxx_source_compiles("${filesystem_code}" filesystem_compiled_${fslib})
|
|
|
|
if (filesystem_compiled_${fslib})
|
|
|
|
message(STATUS "Using -l${fslib} for std::filesystem support")
|
|
|
|
target_link_libraries(filesystem INTERFACE ${fslib})
|
|
|
|
set(filesystem_is_good 1)
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
unset(CMAKE_REQUIRED_LIBRARIES)
|
|
|
|
if(filesystem_is_good EQUAL 1)
|
|
|
|
message(STATUS "we have std::filesystem")
|
|
|
|
else()
|
2020-05-20 02:14:21 +00:00
|
|
|
# Probably broken AF macos
|
|
|
|
message(STATUS "std::filesystem is not available, apparently this compiler isn't C++17 compliant; falling back to ghc::filesystem")
|
2022-06-22 21:56:35 +00:00
|
|
|
set(GHC_FILESYSTEM_WITH_INSTALL OFF CACHE INTERNAL "")
|
2020-05-20 02:14:21 +00:00
|
|
|
add_subdirectory(external/ghc-filesystem)
|
|
|
|
target_link_libraries(filesystem INTERFACE ghc_filesystem)
|
|
|
|
target_compile_definitions(filesystem INTERFACE USE_GHC_FILESYSTEM)
|
2020-05-15 13:32:24 +00:00
|
|
|
endif()
|