diff --git a/CMakeLists.txt b/CMakeLists.txt index 35949b11496c4..65a81c9e10030 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -626,7 +626,7 @@ set(WITH_MGR_ROOK_CLIENT WITH_MGR_DASHBOARD_FRONTEND) include_directories(SYSTEM ${PROJECT_BINARY_DIR}/include) find_package(Threads REQUIRED) -find_package(StdFilesystem) +find_package(StdFilesystem REQUIRED) option(WITH_SELINUX "build SELinux policy" OFF) if(WITH_SELINUX) diff --git a/cmake/modules/FindStdFilesystem.cmake b/cmake/modules/FindStdFilesystem.cmake index 8a1ec4264aeff..5d3336571ce98 100644 --- a/cmake/modules/FindStdFilesystem.cmake +++ b/cmake/modules/FindStdFilesystem.cmake @@ -1,43 +1,57 @@ set(_std_filesystem_test_src ${CMAKE_CURRENT_LIST_DIR}/FindStdFilesystem_test.cc) -macro(try_std_filesystem_library _library _result) +macro(try_std_filesystem_library _library _result _already_included) set(_std_filesystem_try_compile_arg CXX_STANDARD 17) + if(NOT _library STREQUAL "") + list(APPEND _std_filesystem_try_compile_arg + LINK_LIBRARIES ${_library}) + endif() try_compile(_std_filesystem_compiles ${CMAKE_CURRENT_BINARY_DIR} SOURCES ${_std_filesystem_test_src} - LINK_LIBRARIES ${_library} ${_std_filesystem_try_compile_arg}) unset(_std_filesystem_try_compile_arg) if(_std_filesystem_compiles) - set(${_result} ${_library}) + if(NOT _library STREQUAL "") + set(${_result} ${_library}) + else() + set(${_already_included} "included by standard library") + endif() endif() unset(_std_filesystem_compiles) endmacro() - -if(NOT StdFilesystem_LIBRARY) - try_std_filesystem_library("stdc++fs" StdFilesystem_LIBRARY) -endif() -if(NOT StdFilesystem_LIBRARY) - try_std_filesystem_library("c++experimental" StdFilesystem_LIBRARY) -endif() -if(NOT StdFilesystem_LIBRARY) - try_std_filesystem_library("c++fs" StdFilesystem_LIBRARY) -endif() +set(_std_filesystem_required_var "StdFilesystem_LIBRARY") +set(_std_filesystem_already_included FALSE) +foreach(library + "" + "stdc++fs" + "c++experimental" + "c++fs") + try_std_filesystem_library("${library}" StdFilesystem_LIBRARY _std_filesystem_already_included) + if(_std_filesystem_already_included) + set(_std_filesystem_required_var "_std_filesystem_already_included") + break() + elseif(StdFilesystem_LIBRARY) + break() + endif() +endforeach() unset(_std_filesystem_test_src) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(StdFilesystem FOUND_VAR StdFilesystem_FOUND - REQUIRED_VARS StdFilesystem_LIBRARY) + REQUIRED_VARS ${_std_filesystem_required_var}) mark_as_advanced(StdFilesystem_LIBRARY) if(StdFilesystem_FOUND AND NOT (TARGET StdFilesystem::filesystem)) add_library(StdFilesystem::filesystem INTERFACE IMPORTED) - set_target_properties(StdFilesystem::filesystem PROPERTIES + if(StdFilesystem_LIBRARY) + set_target_properties(StdFilesystem::filesystem PROPERTIES INTERFACE_LINK_LIBRARIES ${StdFilesystem_LIBRARY}) + endif() endif() diff --git a/src/test/admin_socket_output.cc b/src/test/admin_socket_output.cc index 76e6e567726fd..b178e3841cd3d 100644 --- a/src/test/admin_socket_output.cc +++ b/src/test/admin_socket_output.cc @@ -14,7 +14,6 @@ #include #include // For regex, regex_search -#include // For extension #include "common/admin_socket_client.h" // For AdminSocketClient #include "common/ceph_json.h" // For JSONParser, JSONObjIter diff --git a/src/test/admin_socket_output.h b/src/test/admin_socket_output.h index e8e65d69ed4f2..b09f05167c4f0 100644 --- a/src/test/admin_socket_output.h +++ b/src/test/admin_socket_output.h @@ -19,9 +19,13 @@ #include #include #include -#include // For path - +#if __has_include() // For extension +#include +namespace fs = std::filesystem; +#else +#include namespace fs = std::experimental::filesystem; +#endif using socket_results = std::map; using test_functions = diff --git a/src/test/common/test_util.cc b/src/test/common/test_util.cc index cf589bafc843c..6249d387656d3 100644 --- a/src/test/common/test_util.cc +++ b/src/test/common/test_util.cc @@ -16,12 +16,18 @@ #include "include/util.h" #include "gtest/gtest.h" +#if __has_include() +#include +namespace fs = std::filesystem; +#else #include +namespace fs = std::experimental::filesystem; +#endif #if defined(__linux__) TEST(util, collect_sys_info) { - if (!std::experimental::filesystem::exists("/etc/os-release")) { + if (!fs::exists("/etc/os-release")) { GTEST_SKIP() << "skipping as '/etc/os-release' does not exist"; } diff --git a/src/test/immutable_object_cache/test_object_store.cc b/src/test/immutable_object_cache/test_object_store.cc index 736928fe0e7dc..6d2875a7d3ed3 100644 --- a/src/test/immutable_object_cache/test_object_store.cc +++ b/src/test/immutable_object_cache/test_object_store.cc @@ -4,7 +4,13 @@ #include #include +#if __has_include() +#include +namespace fs = std::filesystem; +#else #include +namespace fs = std::experimental::filesystem; +#endif #include "gtest/gtest.h" #include "include/Context.h" @@ -18,7 +24,6 @@ #include "tools/immutable_object_cache/ObjectCacheStore.h" -namespace efs = std::experimental::filesystem; using namespace ceph::immutable_obj_cache; std::string test_cache_path("/tmp/test_ceph_immutable_shared_cache"); @@ -85,7 +90,7 @@ TEST_F(TestObjectStore, test_1) { std::string cache_path(test_cache_path); - efs::remove_all(test_cache_path); + fs::remove_all(test_cache_path); init_object_cache_store(m_temp_pool_name, m_temp_volume_name, 1000, true); diff --git a/src/tools/immutable_object_cache/ObjectCacheStore.cc b/src/tools/immutable_object_cache/ObjectCacheStore.cc index a0b2b27ce1629..cee1ca2b65dde 100644 --- a/src/tools/immutable_object_cache/ObjectCacheStore.cc +++ b/src/tools/immutable_object_cache/ObjectCacheStore.cc @@ -3,7 +3,13 @@ #include "ObjectCacheStore.h" #include "Utils.h" +#if __has_include() +#include +namespace fs = std::filesystem; +#else #include +namespace fs = std::experimental::filesystem; +#endif #define dout_context g_ceph_context #define dout_subsys ceph_subsys_immutable_obj_cache @@ -11,7 +17,6 @@ #define dout_prefix *_dout << "ceph::cache::ObjectCacheStore: " << this << " " \ << __func__ << ": " -namespace efs = std::experimental::filesystem; namespace ceph { namespace immutable_obj_cache { @@ -61,15 +66,15 @@ int ObjectCacheStore::init(bool reset) { // TODO(dehao): fsck and reuse existing cache objects if (reset) { try { - if (efs::exists(m_cache_root_dir)) { + if (fs::exists(m_cache_root_dir)) { // remove all sub folders - for (auto& p : efs::directory_iterator(m_cache_root_dir)) { - efs::remove_all(p.path()); + for (auto& p : fs::directory_iterator(m_cache_root_dir)) { + fs::remove_all(p.path()); } } else { - efs::create_directories(m_cache_root_dir); + fs::create_directories(m_cache_root_dir); } - } catch (const efs::filesystem_error& e) { + } catch (const fs::filesystem_error& e) { lderr(m_cct) << "failed to initialize cache store directory: " << e.what() << dendl; return -e.code().value(); @@ -287,12 +292,12 @@ std::string ObjectCacheStore::get_cache_file_path(std::string cache_file_name, ldout(m_cct, 20) << "creating cache dir: " << cache_file_dir <