Skip to content

Commit a06290e

Browse files
committed
cmake: Add CheckStdFilesystem module
1 parent 6317164 commit a06290e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ include(cmake/introspection.cmake)
101101
include(cmake/crc32c.cmake)
102102
include(cmake/leveldb.cmake)
103103

104+
include(CheckStdFilesystem)
105+
check_std_filesystem()
106+
104107
add_subdirectory(src)
105108

106109
message("\n")

cmake/module/CheckStdFilesystem.cmake

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) 2023 The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
# GCC 8.x (libstdc++) requires -lstdc++fs
6+
# Clang 8.x (libc++) requires -lc++fs
7+
8+
function(check_std_filesystem)
9+
set(source "
10+
#include <filesystem>
11+
12+
int main()
13+
{
14+
(void)std::filesystem::current_path().root_name();
15+
}
16+
")
17+
18+
include(CheckCXXSourceCompiles)
19+
check_cxx_source_links("${source}" STD_FILESYSTEM_NO_EXTRA_LIBS_NEEDED)
20+
if(STD_FILESYSTEM_NO_EXTRA_LIBS_NEEDED)
21+
return()
22+
endif()
23+
24+
add_library(std_filesystem INTERFACE)
25+
check_cxx_source_links_with_libs(stdc++fs "${source}" STD_FILESYSTEM_NEEDS_LINK_TO_LIBSTDCXXFS)
26+
if(STD_FILESYSTEM_NEEDS_LINK_TO_LIBSTDCXXFS)
27+
target_link_libraries(std_filesystem INTERFACE stdc++fs)
28+
return()
29+
endif()
30+
check_cxx_source_links_with_libs(c++fs "${source}" STD_FILESYSTEM_NEEDS_LINK_TO_LIBCXXFS)
31+
if(STD_FILESYSTEM_NEEDS_LINK_TO_LIBCXXFS)
32+
target_link_libraries(std_filesystem INTERFACE c++fs)
33+
return()
34+
endif()
35+
message(FATAL_ERROR "Cannot figure out how to use std::filesystem.")
36+
endfunction()

0 commit comments

Comments
 (0)