make compile on linux gcc 7.2

This commit is contained in:
Ryan Tharp 2018-07-26 08:52:27 +00:00
parent af17ad2300
commit 2fcd885030
4 changed files with 36 additions and 25 deletions

View File

@ -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.") message(ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 or C++17 support. Please use a different C++ compiler.")
endif() 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") set(THREAD_LIB "-pthread")
if(STATIC_LINK) if(STATIC_LINK)
@ -313,18 +317,18 @@ else()
if(WITH_STATIC) if(WITH_STATIC)
add_library(${STATIC_LIB} STATIC ${LIB_SRC}) 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}) 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}) add_library(llarpplatform-static STATIC ${LIB_PLATFORM_SRC})
target_link_libraries(llarpplatform-static ${THREAD_LIB}) 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) target_link_libraries(${STATIC_LIB} ${LIBS} backport-static llarpplatform-static)
else() else()
target_link_libraries(${STATIC_LIB} ${LIBS} llarpplatform-static) 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(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(${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(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} backport-static llarpplatform-static)
target_link_libraries(rcutil ${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(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} llarpplatform-static ws2_32)
target_link_libraries(rcutil ${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(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) if (MINGW)
target_link_libraries(dns ${STATIC_LIB} llarpplatform-static pthread ws2_32 stdc++fs) target_link_libraries(dns ${STATIC_LIB} llarpplatform-static pthread ws2_32 stdc++fs)
elseif(WIN32) elseif(WIN32)
@ -362,11 +366,11 @@ else()
if(WITH_SHARED) if(WITH_SHARED)
add_library(${SHARED_LIB} SHARED ${LIB_SRC}) 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}) 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}) 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) target_link_libraries(${SHARED_LIB} ${LIBS} backport llarpplatform)
if (MINGW) if (MINGW)
target_link_libraries(${SHARED_LIB} ${LIBS} backport llarpplatform ws2_32 stdc++fs) target_link_libraries(${SHARED_LIB} ${LIBS} backport llarpplatform ws2_32 stdc++fs)
@ -380,9 +384,9 @@ else()
elseif(WIN32) elseif(WIN32)
target_link_libraries(${SHARED_LIB} ${LIBS} llarpplatform ws2_32) target_link_libraries(${SHARED_LIB} ${LIBS} llarpplatform ws2_32)
endif(MINGW) 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(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(${EXE} ${SHARED_LIB} backport llarpplatform)
target_link_libraries(${CLIENT_EXE} ${SHARED_LIB} backport llarpplatform) target_link_libraries(${CLIENT_EXE} ${SHARED_LIB} backport llarpplatform)
target_link_libraries(rcutil ${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(${EXE} ${SHARED_LIB} llarpplatform)
target_link_libraries(${CLIENT_EXE} ${SHARED_LIB} llarpplatform) target_link_libraries(${CLIENT_EXE} ${SHARED_LIB} llarpplatform)
target_link_libraries(rcutil ${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) target_link_libraries(dns ${SHARED_LIB} llarpplatform pthread)
endif(NOT WITH_STATIC) endif(NOT WITH_STATIC)
endif(WITH_SHARED) endif(WITH_SHARED)

View File

@ -8,14 +8,15 @@
#endif #endif
#include "filesystem.h" #include "filesystem.h"
#if !defined(CPP17) || defined(__OpenBSD__)
namespace fs = cpp17::filesystem;
#else
#ifndef __MINGW32__
namespace fs = std::filesystem;
#else
namespace fs = std::experimental::filesystem;
#endif
#endif
#endif // mingw32 in the only one that doesn't use cpp17::filesystem
#if defined(__MINGW32__)
namespace fs = std::experimental::filesystem;
#else
// not CPP17 needs this
// openbsd needs this
// linux gcc 7.2 needs this
namespace fs = cpp17::filesystem;
#endif // end mingw32
#endif // end LLARP_FS_HPP

View File

@ -182,7 +182,7 @@ struct llarp_nodedb
{ {
ssize_t sz = 0; ssize_t sz = 0;
fs::directory_iterator i(dir); fs::directory_iterator i(dir);
#if defined(CPP17) && !defined(__OpenBSD__) #if __has_include(<filesystem>) && !defined(__OpenBSD__)
auto itr = fs::begin(i); auto itr = fs::begin(i);
while(itr != fs::end(i)) while(itr != fs::end(i))
#else #else

View File

@ -32,13 +32,19 @@
#include "version.h" #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(<filesystem>)
#if defined(__MINGW32__) #if defined(__MINGW32__)
// mingw32 needs experimental
#include <experimental/filesystem> #include <experimental/filesystem>
#else #else
#include <filesystem> #include <filesystem>
#endif #endif
#else #else
// OpenBSD needs this
// MacOS llvm 3.8 needs this
#include "fs/absolute.h" #include "fs/absolute.h"
#include "fs/basename.h" #include "fs/basename.h"
#include "fs/cleanpath.h" #include "fs/cleanpath.h"
@ -55,6 +61,6 @@
#include "fs/remove.h" #include "fs/remove.h"
#include "fs/rename.h" #include "fs/rename.h"
#include "fs/tempdir.h" #include "fs/tempdir.h"
#endif #endif // if not cpp17 and not openbsd
#endif // PBL_CPP_FILESYSTEM_H #endif // PBL_CPP_FILESYSTEM_H