From f50b180a1f83c623858265b224a35ad09527bf1d Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Tue, 25 Oct 2022 20:09:23 +0100 Subject: [PATCH] core, build: Fix filesystem library support detection --- .../ns3-compiler-workarounds.cmake | 18 +++++++++++------- src/core/model/system-path.cc | 8 ++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/build-support/custom-modules/ns3-compiler-workarounds.cmake b/build-support/custom-modules/ns3-compiler-workarounds.cmake index 8b64ab8db..42e8d9dbe 100644 --- a/build-support/custom-modules/ns3-compiler-workarounds.cmake +++ b/build-support/custom-modules/ns3-compiler-workarounds.cmake @@ -55,17 +55,21 @@ endif() # link it manually. https://en.cppreference.com/w/cpp/filesystem check_cxx_source_compiles( " - # ifdef __cpp_lib_filesystem - #include - namespace fs = std::filesystem; - #else - #include - namespace fs = std::experimental::filesystem; + #ifdef __has_include + #if __has_include() + #include + namespace fs = std::filesystem; + #elif __has_include() + #include + namespace fs = std::experimental::filesystem; + #else + #error \"No support for filesystem library\" + #endif #endif int main() { std::string path = \"/\"; - return !fs::exists (path); + return !fs::exists(path); } " FILESYSTEM_LIBRARY_IS_LINKED diff --git a/src/core/model/system-path.cc b/src/core/model/system-path.cc index 81c628cb4..ccf53ea3f 100644 --- a/src/core/model/system-path.cc +++ b/src/core/model/system-path.cc @@ -39,12 +39,16 @@ // version or require a more up-to-date GCC. // we use the "fs" namespace to prevent collisions // with musl libc. -#ifdef __cpp_lib_filesystem +#ifdef __has_include +#if __has_include() #include namespace fs = std::filesystem; -#else +#elif __has_include() #include namespace fs = std::experimental::filesystem; +#else +#error "No support for filesystem library" +#endif #endif #ifdef __APPLE__