diff --git a/CMakeLists.txt b/CMakeLists.txt index ac48ae242..0c784f5c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -343,36 +343,17 @@ include_directories("${CMAKE_SOURCE_DIR}/src" ${CMAKE_BINARY_DIR}) include(CheckSymbolExists) check_symbol_exists(wordexp wordexp.h HAVE_WORDEXP) check_include_files(byteswap.h HAVE_BYTESWAP_H) -try_compile(HAVE_FILESYSTEM ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxfs.cpp") -check_include_file_cxx(experimental/filesystem HAVE_EXPERIMENTAL_FILESYSTEM) -if((NOT HAVE_FILESYSTEM) AND HAVE_EXPERIMENTAL_FILESYSTEM) - # Try compile without linking against any library - try_compile(CXXFSLIB ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxfsexp.cpp") - - if(CXXFSLIB) - # Nothing to do, linking is not explicitly required +find_package(Filesystem) +if(Filesystem_FOUND) + if(CXX_FILESYSTEM_IS_EXPERIMENTAL) + set(HAVE_EXPERIMENTAL_FILESYSTEM ON) else() - # Find the filesystem lib we need to link against - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - find_library(CLANG_FS_LIBRARY "c++fs") - if(CLANG_FS_LIBRARY) - set(FS_LIBRARY c++fs) - else() - set(FS_LIBRARY stdc++fs) - endif() - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(FS_LIBRARY stdc++fs) - endif() - - try_compile(CXXFSLIB ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxfs.cpp" LINK_LIBRARIES "${FS_LIBRARY}") - if(CXXFSLIB) - link_libraries("${FS_LIBRARY}") - else() - set(HAVE_EXPERIMENTAL_FILESYSTEM OFF) - message(WARNING "C++ experimental filesystem library is unusable!\nWill use own implementation.") - endif() + set(HAVE_FILESYSTEM ON) endif() + link_libraries(std::filesystem) +else() + message(WARNING "C++ experimental filesystem library is unusable!\nWill use own implementation.") endif() try_compile(HAVE_STRING_VIEW ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/checks/cxxsv.cpp") diff --git a/checks/cxxfs.cpp b/checks/cxxfs.cpp deleted file mode 100644 index 95208244e..000000000 --- a/checks/cxxfs.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main() -{ - std::error_code ec; - throw std::filesystem::filesystem_error("test", ec); -} diff --git a/checks/cxxfsexp.cpp b/checks/cxxfsexp.cpp deleted file mode 100644 index 10016e228..000000000 --- a/checks/cxxfsexp.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main() -{ - std::error_code ec; - throw std::experimental::filesystem::filesystem_error("test", ec); -}