diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -291,6 +291,29 @@ endif() endif() +check_cxx_source_compiles(" + #include + namespace fs = std::filesystem; + int main() { + (void)fs::current_path().root_name(); + return 0; + } +" HAVE_STD_FILESYSTEM) + +if(!HAVE_STD_FILESYSTEM) + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG(-lstdc++fs ${REQUIRES_STDCXXFS}) + if(!REQUIRES_STDCXXFS) + CHECK_CXX_COMPILER_FLAG(-lc++fs ${REQUIRES_CXXFS}) + if(!REQUIRES_CXXFS) + message(FATAL_ERROR "cannot figure out how to use std::filesystem") + else() + link_libraries(c++fs) + endif() + else() + link_libraries(stdc++fs) + endif() +endif() # Make sure that all the global compiler and linker flags are set BEFORE # including the libraries so they apply as needed.