base: Update <experimental/filesystem> include

This change addresses an error in the compiler tests:
https://jenkins.gem5.org/job/compiler-checks/573/

For clang versions 6 through 10, as well as GCC 7,
in order to use the "filesystem" module, you must
include the experimental namespace.  In all newer
versions, you can use the "filesystem" module as is.

Because of this, include guards to handle this. They include
"<experimental/filesystem>" for the older clang versions and
the "<filesystem>" for all other versions.

As opposed to checking by version, we now check if the
filesystem library has been defined before using it.

Change-Id: I8fb8d4eaa33f3edc29b7626f44b82ee66ffe72be
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/69778
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
This commit is contained in:
Melissa Jost
2023-04-13 11:45:17 -07:00
committed by Melissa Jost
parent 912795afd3
commit 74072cdc80
2 changed files with 17 additions and 10 deletions

View File

@@ -40,13 +40,16 @@
#include <cerrno>
#if (defined(__GNUC__) && (__GNUC__ >= 8)) || defined(__clang__)
// check if filesystem library is available
#if defined(__cpp_lib_filesystem) || __has_include(<filesystem>)
#include <filesystem>
#else
// This is only reachable if we're using GCC 7 (note: gem5 does not support
// GCC versions older than GCC 7 as they do not support the C++17
// standard).
// If we're using GCC 7, we need to use <experimental/filesystem>.
// This is only reachable if we're using GCC 7 or clang versions 6
// through 10 (note: gem5 does not support GCC versions older than
// GCC 7 or clang versions older than clang 6.0 as they do not
// support the C++17 standard).
// If we're using GCC 7 or clang versions 6 through 10, we need to use
// <experimental/filesystem>.
#include <experimental/filesystem>
namespace std {
namespace filesystem = experimental::filesystem;

View File

@@ -39,13 +39,17 @@
#include <algorithm>
#include <cerrno>
#include <cstring>
#if (defined(__GNUC__) && (__GNUC__ >= 8)) || defined(__clang__)
// check if filesystem library is available
#if defined(__cpp_lib_filesystem) || __has_include(<filesystem>)
#include <filesystem>
#else
// This is only reachable if we're using GCC 7 (note: gem5 does not support
// GCC versions older than GCC 7 as they do not support the C++17
// standard).
// If we're using GCC 7, we need to use <experimental/filesystem>.
// This is only reachable if we're using GCC 7 or clang versions 6
// through 10 (note: gem5 does not support GCC versions older than
// GCC 7 or clang versions older than clang 6.0 as they do not
// support the C++17 standard).
// If we're using GCC 7 or clang versions 6 through 10, we need to use
// <experimental/filesystem>.
#include <experimental/filesystem>
namespace std {
namespace filesystem = experimental::filesystem;