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.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
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
20 # Copyright (C) 2018 Scylladb, Ltd.
26 # StdFilesystem_CXX_DIALECT
29 include (CheckCXXSourceCompiles)
30 file (READ ${CMAKE_CURRENT_LIST_DIR}/code_tests/StdFilesystem_test.cc _stdfilesystem_test_code)
32 if (StdFilesystem_CXX_DIALECT)
33 set (_stdfilesystem_cxx_dialect_args "-std=${StdFilesystem_CXX_DIALECT}")
35 set (_stdfilesystem_cxx_dialect_args "")
38 macro (_stdfilesystem_check_compiles var)
39 set (libraries ${ARGN})
40 set (CMAKE_REQUIRED_LIBRARIES ${libraries})
41 set (CMAKE_REQUIRED_FLAGS ${_stdfilesystem_cxx_dialect_args})
42 check_cxx_source_compiles ("${_stdfilesystem_test_code}" ${var})
45 # Try to compile without the library first.
46 _stdfilesystem_check_compiles (StdFilesystem_NO_EXPLICIT_LINK)
48 if (StdFilesystem_NO_EXPLICIT_LINK)
49 set (StdFilesystem_FOUND yes)
51 _stdfilesystem_check_compiles (StdFilesystem_STDCXXFS_LIBRARY
54 if (StdFilesystem_STDCXXFS_LIBRARY)
55 set (StdFilesystem_LIBRARY_NAME stdc++fs)
58 _stdfilesystem_check_compiles (StdFilesystem_CXXEXPERIMENTAL_LIBRARY
61 if (StdFilesystem_CXXEXPERIMENTAL_LIBRARY)
62 set (StdFilesystem_LIBRARY_NAME c++experimental)
66 if (StdFilesystem_LIBRARY_NAME)
67 set (StdFilesystem_LIBRARIES -l${StdFilesystem_LIBRARY_NAME})
70 include (FindPackageHandleStandardArgs)
72 find_package_handle_standard_args (StdFilesystem
73 REQUIRED_VARS StdFilesystem_LIBRARY_NAME)
76 if (StdFilesystem_FOUND AND NOT (TARGET StdFilesystem::filesystem))
77 add_library (StdFilesystem::filesystem INTERFACE IMPORTED)
79 set_target_properties (StdFilesystem::filesystem
81 INTERFACE_LINK_LIBRARIES "${StdFilesystem_LIBRARIES}")