-
Notifications
You must be signed in to change notification settings - Fork 35.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add support for std::filesystem
Add a macro to check if linking with -lstdc++fs or -lc++fs is required.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
dnl Copyright (c) 2022 The Bitcoin Core developers | ||
dnl Distributed under the MIT software license, see the accompanying | ||
dnl file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
# GCC 8.1 and earlier requires -lstdc++fs | ||
# Clang 8.0.0 (libc++) and earlier requires -lc++fs | ||
|
||
m4_define([_CHECK_FILESYSTEM_testbody], [[ | ||
#include <filesystem> | ||
namespace fs = std::filesystem; | ||
int main() { | ||
(void)fs::current_path().root_name(); | ||
return 0; | ||
} | ||
]]) | ||
|
||
AC_DEFUN([CHECK_FILESYSTEM], [ | ||
AC_LANG_PUSH(C++) | ||
AC_MSG_CHECKING([whether std::filesystem can be used without link library]) | ||
AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_FILESYSTEM_testbody])],[ | ||
AC_MSG_RESULT([yes]) | ||
],[ | ||
AC_MSG_RESULT([no]) | ||
SAVED_LIBS="$LIBS" | ||
LIBS="$SAVED_LIBS -lstdc++fs" | ||
AC_MSG_CHECKING([whether std::filesystem needs -lstdc++fs]) | ||
AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_FILESYSTEM_testbody])],[ | ||
AC_MSG_RESULT([yes]) | ||
],[ | ||
AC_MSG_RESULT([no]) | ||
AC_MSG_CHECKING([whether std::filesystem needs -lc++fs]) | ||
LIBS="$SAVED_LIBS -lc++fs" | ||
AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_FILESYSTEM_testbody])],[ | ||
AC_MSG_RESULT([yes]) | ||
],[ | ||
AC_MSG_FAILURE([cannot figure out how to use std::filesystem]) | ||
]) | ||
]) | ||
]) | ||
AC_LANG_POP | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters