clean up win32 build rules

pull/18/head
despair86 6 years ago
parent 0f7c7c871f
commit 7c5d98ca31

@ -81,11 +81,11 @@ add_cxxflags("-Wall")
endif()
if (MSVC)
set(OPTIMIZE_FLAGS "-Od")
set(DEBUG_FLAGS "-ZI")
set(OPTIMIZE_FLAGS "-O2")
set(DEBUG_FLAGS "-Od -ZI")
else()
set(OPTIMIZE_FLAGS "-O0")
set(DEBUG_FLAGS "-g")
set(OPTIMIZE_FLAGS "-O3")
set(DEBUG_FLAGS "-O0 -g")
endif()
if(ASAN)
@ -112,6 +112,12 @@ if(SHADOW)
include_directories(${SHADOW_ROOT}/include)
endif()
if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
set(OPTIMIZE_FLAGS "")
add_cflags("${DEBUG_FLAGS}")
add_cxxflags("${DEBUG_FLAGS}")
endif()
if (MSVC)
add_cflags("-wd4996 -wd4244 -MP ${OPTIMIZE_FLAGS}")
add_cxxflags("-wd4996 -wd4244 -MP ${OPTIMIZE_FLAGS}")
@ -120,11 +126,6 @@ add_cflags("-Wall -Wno-deprecated-declarations ${OPTIMIZE_FLAGS}")
add_cxxflags("-Wall -Wno-deprecated-declarations ${OPTIMIZE_FLAGS}")
endif()
if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
add_cflags("${DEBUG_FLAGS}")
add_cxxflags("${DEBUG_FLAGS}")
endif()
if(SHADOW)
add_cflags("-fPIC")
add_cxxflags("-fPIC")
@ -156,12 +157,17 @@ else()
)
endif()
# HeapAlloc(2) on Windows was significantly revamped in 2009
# but the old algorithm isn't too bad either
# this is _the_ system allocator on BSD UNIX
# openbsd replaced it with a secure/randomised malloc not too
# long ago
if(JEMALLOC)
set(MALLOC_LIB jemalloc)
endif()
set(LIBS ${SODIUM_LIB} ${THREAD_LIB} ${MALLOC_LIB})
if(HAVE_CXX17_FILESYSTEM)
if(HAVE_CXX17_FILESYSTEM AND NOT MSVC)
set(LIBS ${LIBS} stdc++fs)
endif()
@ -215,11 +221,6 @@ if (UNIX)
${LIBTUNTAP_SRC_BASE})
endif()
#if(BACKPORT)
#else()
#set(CPP_BACKPORT_SRC "")
#endif()
set(CPP_BACKPORT_SRC
vendor/cppbackport-master/lib/fs/rename.cpp
vendor/cppbackport-master/lib/fs/filestatus.cpp
@ -248,7 +249,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(ISOLATE_PROC_SRC llarp/linux/netns.cpp)
endif()
set(LIB_PLATFORM_SRC
# for outpug
llarp/logger.cpp
@ -270,7 +270,7 @@ set(LIB_PLATFORM_SRC
${ISOLATE_PROC_SRC}
# tun
${LIBTUNTAP_SRC}
# win32 inline procs
# win32 inline procs and getopt(3) for MS C
llarp/win32_inet.c
llarp/win32_intrnl.c
contrib/msc/getopt.c
@ -332,7 +332,6 @@ set(UTP_SRC
libutp/utp_hash.cpp
)
if(WIN32)
set(UTP_SRC ${UTP_SRC} libutp/libutp_inet_ntop.cpp)
endif()
@ -477,13 +476,11 @@ add_subdirectory(${GTEST_DIR})
include_directories(${GTEST_DIR}/include ${GTEST_DIR})
add_executable(${TEST_EXE} ${TEST_SRC})
if (MSVC)
if (WIN32)
target_link_libraries(${TEST_EXE} ${STATIC_LINK_LIBS} gtest_main ${STATIC_LIB} ws2_32 iphlpapi)
elseif (MINGW)
target_link_libraries(${TEST_EXE} ${STATIC_LINK_LIBS} gtest_main ${STATIC_LIB} stdc++fs iphlpapi ws2_32)
else()
target_link_libraries(${TEST_EXE} ${STATIC_LINK_LIBS} gtest_main ${STATIC_LIB})
endif(MSVC)
endif(WIN32)
if(WITH_STATIC)
add_library(${STATIC_LIB} STATIC ${LIB_SRC})
@ -505,34 +502,24 @@ if(WITH_STATIC)
target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${BACKPORT_LIB} ${PLATFORM_LIB})
target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${BACKPORT_LIB} ${PLATFORM_LIB})
target_link_libraries(${RC_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${BACKPORT_LIB} ${PLATFORM_LIB})
if (MINGW)
target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${BACKPORT_LIB} ${PLATFORM_LIB} ws2_32 stdc++fs iphlpapi)
target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${BACKPORT_LIB} ${PLATFORM_LIB} ws2_32 stdc++fs iphlpapi)
target_link_libraries(${RC_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${BACKPORT_LIB} ${PLATFORM_LIB} ws2_32 stdc++fs iphlpapi)
elseif(MSVC)
if (WIN32)
target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${BACKPORT_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${BACKPORT_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
target_link_libraries(${RC_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${BACKPORT_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
endif(MINGW)
endif(WIN32)
else()
target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB})
target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB})
target_link_libraries(${RC_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB})
if (MINGW)
target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 stdc++fs iphlpapi)
target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 stdc++fs iphlpapi)
target_link_libraries(${RC_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 stdc++fs iphlpapi)
elseif(MSVC)
if (WIN32)
target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
target_link_libraries(${RC_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
endif(MINGW)
endif(WIN32)
endif(NOT HAVE_CXX17_FILESYSTEM)
if (MINGW)
target_link_libraries(${DNS_EXE} ${STATIC_LIB} ${PLATFORM_LIB} ${THREAD_LIB} ws2_32 stdc++fs iphlpapi)
elseif(WIN32)
if (WIN32)
target_link_libraries(${DNS_EXE} ${STATIC_LIB} ${PLATFORM_LIB} ${THREAD_LIB} ws2_32 iphlpapi)
endif(MINGW)
endif(WIN32)
target_link_libraries(${DNS_EXE} ${STATIC_LIB} ${PLATFORM_LIB} ${THREAD_LIB})
endif(NOT WITH_SHARED)
endif(WITH_STATIC)
@ -546,11 +533,9 @@ if(WITH_STATIC)
set(LIB_SRC ${LIB_SRC} ${CPP_BACKPORT_SRC})
endif(HAVE_CXX17_FILESYSTEM)
add_library(${SHARED_LIB} SHARED ${LIB_SRC} ${LIB_PLATFORM_SRC})
if (MINGW)
set(${LIBS} ${LIBS} ws2_32 stdc++fs iphlpapi)
elseif(MSVC)
if (WIN32)
set(${LIBS} ${LIBS} ws2_32 iphlpapi)
endif(MINGW)
endif(WIN32)
target_link_libraries(${SHARED_LIB} ${LIBS} ${THREAD_LIB})
target_link_libraries(${EXE} ${SHARED_LIB})
target_link_libraries(${RC_EXE} ${SHARED_LIB})

@ -1,6 +1,7 @@
#ifndef LLARP_FS_HPP
#define LLARP_FS_HPP
#include <functional>
#if defined(WIN32) || defined(_WIN32)
#define PATH_SEP "\\"
#else
@ -8,21 +9,13 @@
#endif
#include "filesystem.h"
#if defined(CPP17) && defined(USE_CXX17_FILESYSTEM)
// win32 is the only one that doesn't use cpp17::filesystem
// because cpp17::filesystem is unimplemented for Windows
// -despair86
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__sun)
namespace fs = std::experimental::filesystem;
#else
namespace fs = std::experimental::filesystem;
#endif // end win32
#else
// not CPP17 needs this
// openbsd needs this
// linux gcc 7.2 needs this
namespace fs = cpp17::filesystem;
#endif
#include <dirent.h>
namespace llarp

@ -118,7 +118,9 @@ _llarp_nt_heap_free(void* mem)
int
llarp_nt_sockaddr_pton(const char* src, struct sockaddr* dst)
{
struct addrinfo hints = {0}, *result = nullptr;
struct addrinfo hints;
struct addrinfo* result = nullptr;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_TCP;

@ -30,7 +30,7 @@
#ifndef PBL_CPP_FILESYSTEM_H
#define PBL_CPP_FILESYSTEM_H
#if _MSC_VER >= 1910
#if _MSC_VER >= 1900
#define CPP17
#define CPP11
#define CPP14
@ -39,13 +39,8 @@
#include "version.h"
#if defined(CPP17) && defined(USE_CXX17_FILESYSTEM)
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__sun)
// win32 needs experimental
#include <experimental/filesystem>
#else
#include <experimental/filesystem>
#endif
#else
// OpenBSD needs this
// MacOS llvm 3.8 needs this
#include "fs/absolute.h"

@ -127,7 +127,97 @@ std::string basename_posix(const std::string& s)
return s.substr(range.first, range.second);
}
#ifdef WIN32
// A surprisingly portable basename(3) and dirname(3)
std::string basename_win32(const std::string& path)
{
static char bname[MAX_PATH];
size_t len;
const char *endp, *startp;
char tmp[MAX_PATH];
strncpy(tmp, path.c_str(), MAX_PATH);
/* Empty or NULL string gets treated as "." */
if (path.empty()) {
bname[0] = '.';
bname[1] = '\0';
return std::string(bname);
}
/* Strip any trailing slashes */
endp = tmp + strlen(tmp) - 1;
while (endp > tmp && *endp == '/')
endp--;
/* All slashes becomes "/" */
if (endp == tmp && *endp == '/') {
bname[0] = '/';
bname[1] = '\0';
return std::string(bname);
}
/* Find the start of the base */
startp = endp;
while (startp > tmp && *(startp - 1) != '/')
startp--;
len = endp - startp + 1;
if (len >= sizeof(bname)) {
errno = ENAMETOOLONG;
return std::string(nullptr);
}
memcpy(bname, startp, len);
bname[len] = '\0';
return std::string(bname);
}
std::string dirname_win32(const std::string& path)
{
static char dname[MAX_PATH];
size_t len;
const char *endp;
char tmp[MAX_PATH];
strncpy(tmp, path.c_str(), MAX_PATH);
/* Empty or NULL string gets treated as "." */
if (tmp == NULL || tmp[0] == '\0') {
dname[0] = '.';
dname[1] = '\0';
return std::string(dname);
}
/* Strip any trailing slashes */
endp = tmp + strlen(tmp) - 1;
while (endp > tmp && *endp == '/')
endp--;
/* Find the start of the dir */
while (endp > tmp && *endp != '/')
endp--;
/* Either the dir is "/" or there are no slashes */
if (endp == tmp) {
dname[0] = *endp == '/' ? '/' : '.';
dname[1] = '\0';
return std::string(dname);
} else {
/* Move forward past the separating slashes */
do {
endp--;
} while (endp > tmp && *endp == '/');
}
len = endp - tmp + 1;
if (len >= sizeof(dname)) {
errno = ENAMETOOLONG;
return std::string(nullptr);
}
memcpy(dname, tmp, len);
dname[len] = '\0';
return std::string(dname);
}
#endif
std::string dirname_posix(const std::string& s)
{
const std::pair< std::size_t, std::size_t > range = locate_last_path_component(s);
@ -171,11 +261,9 @@ namespace filesystem
std::string basename(const std::string& s)
{
#ifdef OS_POSIX
return basename_posix(s);
#else
#error "No implementation of basename is available for this platform"
return basename_win32(s);
#endif
}

Loading…
Cancel
Save