]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/cmake/FindStdFilesystem.cmake
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / cmake / FindStdFilesystem.cmake
CommitLineData
11fdf7f2
TL
1#
2# This file is open source software, licensed to you under the terms
3# of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4# distributed with this work for additional information regarding copyright
5# ownership. You may not use this file except in compliance with the License.
6#
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied. See the License for the
15# specific language governing permissions and limitations
16# under the License.
17#
18
19#
20# Copyright (C) 2018 Scylladb, Ltd.
21#
22
9f95a23c
TL
23#
24# Variables:
25#
26# StdFilesystem_CXX_DIALECT
27#
28
11fdf7f2
TL
29include (CheckCXXSourceCompiles)
30file (READ ${CMAKE_CURRENT_LIST_DIR}/code_tests/StdFilesystem_test.cc _stdfilesystem_test_code)
31
9f95a23c
TL
32if (StdFilesystem_CXX_DIALECT)
33 set (_stdfilesystem_cxx_dialect_args "-std=${StdFilesystem_CXX_DIALECT}")
34else ()
35 set (_stdfilesystem_cxx_dialect_args "")
36endif ()
37
11fdf7f2
TL
38macro (_stdfilesystem_check_compiles var)
39 set (libraries ${ARGN})
40 set (CMAKE_REQUIRED_LIBRARIES ${libraries})
9f95a23c 41 set (CMAKE_REQUIRED_FLAGS ${_stdfilesystem_cxx_dialect_args})
11fdf7f2
TL
42 check_cxx_source_compiles ("${_stdfilesystem_test_code}" ${var})
43endmacro ()
44
45# Try to compile without the library first.
46_stdfilesystem_check_compiles (StdFilesystem_NO_EXPLICIT_LINK)
47
48if (StdFilesystem_NO_EXPLICIT_LINK)
49 set (StdFilesystem_FOUND yes)
50else ()
51 _stdfilesystem_check_compiles (StdFilesystem_STDCXXFS_LIBRARY
52 stdc++fs)
53
54 if (StdFilesystem_STDCXXFS_LIBRARY)
55 set (StdFilesystem_LIBRARY_NAME stdc++fs)
56 else ()
57 # Try libc++.
58 _stdfilesystem_check_compiles (StdFilesystem_CXXEXPERIMENTAL_LIBRARY
59 libc++experimental)
60
61 if (StdFilesystem_CXXEXPERIMENTAL_LIBRARY)
62 set (StdFilesystem_LIBRARY_NAME c++experimental)
63 endif ()
64 endif ()
65
66 if (StdFilesystem_LIBRARY_NAME)
67 set (StdFilesystem_LIBRARIES -l${StdFilesystem_LIBRARY_NAME})
68 endif ()
69
70 include (FindPackageHandleStandardArgs)
71
72 find_package_handle_standard_args (StdFilesystem
73 REQUIRED_VARS StdFilesystem_LIBRARY_NAME)
74endif ()
75
76if (StdFilesystem_FOUND AND NOT (TARGET StdFilesystem::filesystem))
77 add_library (StdFilesystem::filesystem INTERFACE IMPORTED)
78
79 set_target_properties (StdFilesystem::filesystem
80 PROPERTIES
9f95a23c 81 INTERFACE_LINK_LIBRARIES "${StdFilesystem_LIBRARIES}")
11fdf7f2 82endif ()