]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | set(_std_filesystem_test_src |
2 | ${CMAKE_CURRENT_LIST_DIR}/FindStdFilesystem_test.cc) | |
3 | ||
4 | macro(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) | |
17 | endmacro() | |
18 | ||
19 | ||
20 | if(NOT StdFilesystem_LIBRARY) | |
21 | try_std_filesystem_library("stdc++fs" StdFilesystem_LIBRARY) | |
22 | endif() | |
23 | if(NOT StdFilesystem_LIBRARY) | |
24 | try_std_filesystem_library("c++experimental" StdFilesystem_LIBRARY) | |
25 | endif() | |
26 | if(NOT StdFilesystem_LIBRARY) | |
27 | try_std_filesystem_library("c++fs" StdFilesystem_LIBRARY) | |
28 | endif() | |
29 | ||
30 | unset(_std_filesystem_test_src) | |
31 | ||
32 | include(FindPackageHandleStandardArgs) | |
33 | find_package_handle_standard_args(StdFilesystem | |
34 | FOUND_VAR StdFilesystem_FOUND | |
35 | REQUIRED_VARS StdFilesystem_LIBRARY) | |
36 | ||
37 | mark_as_advanced(StdFilesystem_LIBRARY) | |
38 | ||
39 | if(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}) | |
43 | endif() |