From 2fcd88503011e5587aafeeeeb1659e3a0ed77964 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Thu, 26 Jul 2018 08:52:27 +0000 Subject: [PATCH] make compile on linux gcc 7.2 --- CMakeLists.txt | 28 ++++++++++++---------- llarp/fs.hpp | 19 ++++++++------- llarp/nodedb.cpp | 2 +- vendor/cppbackport-master/lib/filesystem.h | 10 ++++++-- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4fd056ac..54dfc8f79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,10 @@ else() message(ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 or C++17 support. Please use a different C++ compiler.") endif() +# attempting to fix linux gcc 7.2 which COMPILER_SUPPORTS_CXX17 but doesn't have filesystem.h +include(CheckIncludeFileCXX) +CHECK_INCLUDE_FILE_CXX(filesystem.h HAVE_STD_FS) + set(THREAD_LIB "-pthread") if(STATIC_LINK) @@ -313,18 +317,18 @@ else() if(WITH_STATIC) add_library(${STATIC_LIB} STATIC ${LIB_SRC}) - if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) add_library(backport-static STATIC ${CPP_BACKPORT_SRC}) - endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) add_library(llarpplatform-static STATIC ${LIB_PLATFORM_SRC}) target_link_libraries(llarpplatform-static ${THREAD_LIB}) - if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) target_link_libraries(${STATIC_LIB} ${LIBS} backport-static llarpplatform-static) else() target_link_libraries(${STATIC_LIB} ${LIBS} llarpplatform-static) - endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) if(NOT WITH_SHARED) - if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} backport-static llarpplatform-static) target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} backport-static llarpplatform-static) target_link_libraries(rcutil ${STATIC_LINK_LIBS} ${STATIC_LIB} backport-static llarpplatform-static) @@ -350,7 +354,7 @@ else() target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} llarpplatform-static ws2_32) target_link_libraries(rcutil ${STATIC_LINK_LIBS} ${STATIC_LIB} llarpplatform-static ws2_32) endif(MINGW) - endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) if (MINGW) target_link_libraries(dns ${STATIC_LIB} llarpplatform-static pthread ws2_32 stdc++fs) elseif(WIN32) @@ -362,11 +366,11 @@ else() if(WITH_SHARED) add_library(${SHARED_LIB} SHARED ${LIB_SRC}) - if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) add_library(backport SHARED ${CPP_BACKPORT_SRC}) - endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) add_library(llarpplatform SHARED ${LIB_PLATFORM_SRC}) - if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) target_link_libraries(${SHARED_LIB} ${LIBS} backport llarpplatform) if (MINGW) target_link_libraries(${SHARED_LIB} ${LIBS} backport llarpplatform ws2_32 stdc++fs) @@ -380,9 +384,9 @@ else() elseif(WIN32) target_link_libraries(${SHARED_LIB} ${LIBS} llarpplatform ws2_32) endif(MINGW) - endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) if(NOT WITH_STATIC) - if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) target_link_libraries(${EXE} ${SHARED_LIB} backport llarpplatform) target_link_libraries(${CLIENT_EXE} ${SHARED_LIB} backport llarpplatform) target_link_libraries(rcutil ${SHARED_LIB} backport llarpplatform) @@ -390,7 +394,7 @@ else() target_link_libraries(${EXE} ${SHARED_LIB} llarpplatform) target_link_libraries(${CLIENT_EXE} ${SHARED_LIB} llarpplatform) target_link_libraries(rcutil ${SHARED_LIB} llarpplatform) - endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" OR NOT HAVE_STD_FS) target_link_libraries(dns ${SHARED_LIB} llarpplatform pthread) endif(NOT WITH_STATIC) endif(WITH_SHARED) diff --git a/llarp/fs.hpp b/llarp/fs.hpp index bb79f61a1..96fb5c30c 100644 --- a/llarp/fs.hpp +++ b/llarp/fs.hpp @@ -8,14 +8,15 @@ #endif #include "filesystem.h" -#if !defined(CPP17) || defined(__OpenBSD__) -namespace fs = cpp17::filesystem; -#else -#ifndef __MINGW32__ -namespace fs = std::filesystem; -#else + +// mingw32 in the only one that doesn't use cpp17::filesystem +#if defined(__MINGW32__) namespace fs = std::experimental::filesystem; -#endif -#endif +#else +// not CPP17 needs this +// openbsd needs this +// linux gcc 7.2 needs this +namespace fs = cpp17::filesystem; +#endif // end mingw32 -#endif +#endif // end LLARP_FS_HPP diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index dd4f96cd5..8e17522fc 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -182,7 +182,7 @@ struct llarp_nodedb { ssize_t sz = 0; fs::directory_iterator i(dir); -#if defined(CPP17) && !defined(__OpenBSD__) +#if __has_include() && !defined(__OpenBSD__) auto itr = fs::begin(i); while(itr != fs::end(i)) #else diff --git a/vendor/cppbackport-master/lib/filesystem.h b/vendor/cppbackport-master/lib/filesystem.h index cbaa9f0d7..8b96f9a09 100644 --- a/vendor/cppbackport-master/lib/filesystem.h +++ b/vendor/cppbackport-master/lib/filesystem.h @@ -32,13 +32,19 @@ #include "version.h" -#if defined(CPP17) && !defined(__OpenBSD__) +// linux gcc 7.2 has CPP17 but doesn't have filesystem.h +#if defined(CPP17) && !defined(__OpenBSD__) && __has_include() + #if defined(__MINGW32__) +// mingw32 needs experimental #include #else #include #endif + #else +// OpenBSD needs this +// MacOS llvm 3.8 needs this #include "fs/absolute.h" #include "fs/basename.h" #include "fs/cleanpath.h" @@ -55,6 +61,6 @@ #include "fs/remove.h" #include "fs/rename.h" #include "fs/tempdir.h" -#endif +#endif // if not cpp17 and not openbsd #endif // PBL_CPP_FILESYSTEM_H