]> git.proxmox.com Git - ceph.git/blame - ceph/cmake/modules/FindStdFilesystem.cmake
import 15.2.0 Octopus source
[ceph.git] / ceph / cmake / modules / FindStdFilesystem.cmake
CommitLineData
11fdf7f2
TL
1set(_std_filesystem_test_src
2 ${CMAKE_CURRENT_LIST_DIR}/FindStdFilesystem_test.cc)
3
4macro(try_std_filesystem_library _library _result)
9f95a23c
TL
5 set(_std_filesystem_try_compile_arg
6 CXX_STANDARD 17)
11fdf7f2
TL
7 try_compile(_std_filesystem_compiles
8 ${CMAKE_CURRENT_BINARY_DIR}
9 SOURCES ${_std_filesystem_test_src}
10 LINK_LIBRARIES ${_library}
11 ${_std_filesystem_try_compile_arg})
12 unset(_std_filesystem_try_compile_arg)
13 if(_std_filesystem_compiles)
14 set(${_result} ${_library})
15 endif()
16 unset(_std_filesystem_compiles)
17endmacro()
18
19
20if(NOT StdFilesystem_LIBRARY)
21 try_std_filesystem_library("stdc++fs" StdFilesystem_LIBRARY)
22endif()
23if(NOT StdFilesystem_LIBRARY)
24 try_std_filesystem_library("c++experimental" StdFilesystem_LIBRARY)
25endif()
26if(NOT StdFilesystem_LIBRARY)
27 try_std_filesystem_library("c++fs" StdFilesystem_LIBRARY)
28endif()
29
30unset(_std_filesystem_test_src)
31
32include(FindPackageHandleStandardArgs)
33find_package_handle_standard_args(StdFilesystem
34 FOUND_VAR StdFilesystem_FOUND
35 REQUIRED_VARS StdFilesystem_LIBRARY)
36
37mark_as_advanced(StdFilesystem_LIBRARY)
38
39if(StdFilesystem_FOUND AND NOT (TARGET StdFilesystem::filesystem))
40 add_library(StdFilesystem::filesystem INTERFACE IMPORTED)
41 set_target_properties(StdFilesystem::filesystem PROPERTIES
42 INTERFACE_LINK_LIBRARIES ${StdFilesystem_LIBRARY})
43endif()