diff --git a/.gitignore b/.gitignore index 9fff4b757..29402446b 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,5 @@ shadow.config.xml testnet_tmp -*.pid \ No newline at end of file +*.pid +vsproject/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ff02b8bd4..b4fd056ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,10 +13,13 @@ endmacro(add_cxxflags) include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) -if(COMPILER_SUPPORTS_CXX11) +CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17) +if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") add_cxxflags("-std=c++11") +elseif(COMPILER_SUPPORTS_CXX17) + add_cxxflags("-std=c++17") else() - message(ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 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() set(THREAD_LIB "-pthread") @@ -97,9 +100,9 @@ if(SODIUM_LIBRARIES) set(SODIUM_LIB ${SODIUM_LIBRARIES}) else() find_library ( - SODIUM_LIB - NAMES sodium libsodium - HINTS "/usr/local/lib" + SODIUM_LIB + NAMES sodium libsodium + HINTS "/usr/local/lib" ) endif() @@ -310,29 +313,85 @@ else() if(WITH_STATIC) add_library(${STATIC_LIB} STATIC ${LIB_SRC}) - add_library(libbackport-static STATIC ${CPP_BACKPORT_SRC}) - add_library(libllarpplatform-static STATIC ${LIB_PLATFORM_SRC}) - target_link_libraries(libllarpplatform-static ${THREAD_LIB}) - target_link_libraries(${STATIC_LIB} ${LIBS} libbackport-static libllarpplatform-static) + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + add_library(backport-static STATIC ${CPP_BACKPORT_SRC}) + endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + 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") + 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") if(NOT WITH_SHARED) - target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} libbackport-static libllarpplatform-static) - target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} libbackport-static libllarpplatform-static) - target_link_libraries(rcutil ${STATIC_LINK_LIBS} ${STATIC_LIB} libbackport-static libllarpplatform-static) - target_link_libraries(dns libllarpplatform-static pthread) - endif() - endif() + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + 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) + if (MINGW) + target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} backport-static llarpplatform-static ws2_32 stdc++fs) + target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} backport-static llarpplatform-static ws2_32 stdc++fs) + target_link_libraries(rcutil ${STATIC_LINK_LIBS} ${STATIC_LIB} backport-static llarpplatform-static ws2_32 stdc++fs) + elseif(WIN32) + target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} backport-static llarpplatform-static ws2_32) + target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} backport-static llarpplatform-static ws2_32) + target_link_libraries(rcutil ${STATIC_LINK_LIBS} ${STATIC_LIB} backport-static llarpplatform-static ws2_32) + endif(MINGW) + else() + target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} llarpplatform-static) + target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} llarpplatform-static) + target_link_libraries(rcutil ${STATIC_LINK_LIBS} ${STATIC_LIB} llarpplatform-static) + if (MINGW) + target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} llarpplatform-static ws2_32 stdc++fs) + target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} llarpplatform-static ws2_32 stdc++fs) + target_link_libraries(rcutil ${STATIC_LINK_LIBS} ${STATIC_LIB} llarpplatform-static ws2_32 stdc++fs) + elseif(WIN32) + target_link_libraries(${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) + endif(MINGW) + endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + if (MINGW) + target_link_libraries(dns ${STATIC_LIB} llarpplatform-static pthread ws2_32 stdc++fs) + elseif(WIN32) + target_link_libraries(dns ${STATIC_LIB} llarpplatform-static pthread ws2_32) + endif(MINGW) + target_link_libraries(dns ${STATIC_LIB} llarpplatform-static pthread) + endif(NOT WITH_SHARED) + endif(WITH_STATIC) if(WITH_SHARED) add_library(${SHARED_LIB} SHARED ${LIB_SRC}) - add_library(libbackport SHARED ${CPP_BACKPORT_SRC}) - add_library(libllarpplatform SHARED ${LIB_PLATFORM_SRC}) - target_link_libraries(${SHARED_LIB} ${LIBS} libbackport libllarpplatform) + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + add_library(backport SHARED ${CPP_BACKPORT_SRC}) + endif(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + add_library(llarpplatform SHARED ${LIB_PLATFORM_SRC}) + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + target_link_libraries(${SHARED_LIB} ${LIBS} backport llarpplatform) + if (MINGW) + target_link_libraries(${SHARED_LIB} ${LIBS} backport llarpplatform ws2_32 stdc++fs) + elseif(WIN32) + target_link_libraries(${SHARED_LIB} ${LIBS} backport llarpplatform ws2_32) + endif(MINGW) + else() + target_link_libraries(${SHARED_LIB} ${LIBS} llarpplatform) + if (MINGW) + target_link_libraries(${SHARED_LIB} ${LIBS} llarpplatform ws2_32 stdc++fs) + 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") if(NOT WITH_STATIC) - target_link_libraries(${EXE} ${SHARED_LIB} libbackport libllarpplatform) - target_link_libraries(${CLIENT_EXE} ${SHARED_LIB} libbackport libllarpplatform) - target_link_libraries(rcutil ${SHARED_LIB} libbackport libllarpplatform) - target_link_libraries(dns libllarpplatform pthread) - endif() - endif() - -endif() + if(COMPILER_SUPPORTS_CXX11 AND NOT COMPILER_SUPPORTS_CXX17 OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + 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) + 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") + target_link_libraries(dns ${SHARED_LIB} llarpplatform pthread) + endif(NOT WITH_STATIC) + endif(WITH_SHARED) +endif(SHADOW) diff --git a/daemon/dns.cpp b/daemon/dns.cpp index 14e350db5..47721a212 100644 --- a/daemon/dns.cpp +++ b/daemon/dns.cpp @@ -12,6 +12,10 @@ #include // for multithreaded version #include +#if(__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) +#include +#endif + bool done = false; void @@ -29,7 +33,7 @@ hookChecker(std::string name) } // FIXME: make configurable -#define SERVER "8.8.8.8" +#define SERVER "1.1.1.1" #define PORT 53 int @@ -85,7 +89,7 @@ main(int argc, char *argv[]) netio_threads.emplace_back([netio]() { llarp_ev_loop_run(netio); }); #if(__APPLE__ && __MACH__) -#elif(__FreeBSD__) +#elif(__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) pthread_set_name_np(netio_threads.back().native_handle(), "llarp-netio"); #else diff --git a/llarp/context.cpp b/llarp/context.cpp index 77d6879ba..3bbf7a997 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -6,7 +6,7 @@ #include "math.h" #include "router.hpp" -#if(__FreeBSD__) +#if(__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) #include #endif @@ -191,7 +191,7 @@ namespace llarp netio_threads.emplace_back([netio]() { llarp_ev_loop_run(netio); }); #if(__APPLE__ && __MACH__) -#elif(__FreeBSD__) +#elif(__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) pthread_set_name_np(netio_threads.back().native_handle(), "llarp-" "netio"); diff --git a/llarp/ev.cpp b/llarp/ev.cpp index 929c3e766..19049b179 100644 --- a/llarp/ev.cpp +++ b/llarp/ev.cpp @@ -8,7 +8,7 @@ #if(__APPLE__ && __MACH__) #include "ev_kqueue.hpp" #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #include "ev_kqueue.hpp" #endif @@ -21,7 +21,7 @@ llarp_ev_loop_alloc(struct llarp_ev_loop **ev) #if(__APPLE__ && __MACH__) *ev = new llarp_kqueue_loop; #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) *ev = new llarp_kqueue_loop; #endif (*ev)->init(); diff --git a/llarp/ev_kqueue.hpp b/llarp/ev_kqueue.hpp index 39c501d6f..0b8a091d2 100644 --- a/llarp/ev_kqueue.hpp +++ b/llarp/ev_kqueue.hpp @@ -3,7 +3,7 @@ #include #include -#if __FreeBSD__ +#if __FreeBSD__ || __OpenBSD__ || __NetBSD__ // kqueue / kevent #include #include diff --git a/llarp/fs.hpp b/llarp/fs.hpp index ecaa7d417..bb79f61a1 100644 --- a/llarp/fs.hpp +++ b/llarp/fs.hpp @@ -8,6 +8,14 @@ #endif #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 diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index 62c957b45..dd4f96cd5 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -182,8 +182,13 @@ struct llarp_nodedb { ssize_t sz = 0; fs::directory_iterator i(dir); +#if defined(CPP17) && !defined(__OpenBSD__) + auto itr = fs::begin(i); + while(itr != fs::end(i)) +#else auto itr = i.begin(); while(itr != itr.end()) +#endif { if(fs::is_regular_file(itr->symlink_status()) && loadfile(*itr)) sz++; diff --git a/llarp/threadpool.cpp b/llarp/threadpool.cpp index 4f3617718..3abba5210 100644 --- a/llarp/threadpool.cpp +++ b/llarp/threadpool.cpp @@ -7,7 +7,7 @@ #include "logger.hpp" -#if(__FreeBSD__) +#if(__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) #include #endif @@ -25,7 +25,7 @@ namespace llarp { #if(__APPLE__ && __MACH__) pthread_setname_np(name); -#elif(__FreeBSD__) +#elif(__FreeBSD__) || (__OpenBSD__) || (__NetBSD__) pthread_set_name_np(pthread_self(), name); #else pthread_setname_np(pthread_self(), name); diff --git a/vendor/cppbackport-master/lib/filesystem.h b/vendor/cppbackport-master/lib/filesystem.h index 3ce451356..cbaa9f0d7 100644 --- a/vendor/cppbackport-master/lib/filesystem.h +++ b/vendor/cppbackport-master/lib/filesystem.h @@ -32,8 +32,12 @@ #include "version.h" -#if defined(CPP17) +#if defined(CPP17) && !defined(__OpenBSD__) +#if defined(__MINGW32__) +#include +#else #include +#endif #else #include "fs/absolute.h" #include "fs/basename.h"