summaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindStdFilesystem.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /cmake/modules/FindStdFilesystem.cmake
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cmake/modules/FindStdFilesystem.cmake')
-rw-r--r--cmake/modules/FindStdFilesystem.cmake51
1 files changed, 51 insertions, 0 deletions
diff --git a/cmake/modules/FindStdFilesystem.cmake b/cmake/modules/FindStdFilesystem.cmake
new file mode 100644
index 00000000..6a6cd029
--- /dev/null
+++ b/cmake/modules/FindStdFilesystem.cmake
@@ -0,0 +1,51 @@
+set(_std_filesystem_test_src
+ ${CMAKE_CURRENT_LIST_DIR}/FindStdFilesystem_test.cc)
+
+macro(try_std_filesystem_library _library _result)
+ if(CMAKE_VERSION VERSION_LESS "3.8")
+ # abuse the definition flags, because they are quite
+ # the same as CMAKE_C_FLAGS: they are passed to the
+ # compiler.
+ set(_std_filesystem_try_compile_arg
+ COMPILE_DEFINITIONS "-std=c++17")
+ else()
+ set(_std_filesystem_try_compile_arg
+ CXX_STANDARD 17)
+ 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})
+ 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()
+
+unset(_std_filesystem_test_src)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(StdFilesystem
+ FOUND_VAR StdFilesystem_FOUND
+ REQUIRED_VARS StdFilesystem_LIBRARY)
+
+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
+ INTERFACE_LINK_LIBRARIES ${StdFilesystem_LIBRARY})
+endif()