OMG Windows builds!

This commit is contained in:
Adam Ierymenko 2020-06-16 22:26:47 -07:00
parent a472aafb3e
commit 224c468aa3
6 changed files with 32 additions and 19 deletions

View file

@ -61,17 +61,22 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DZT_DEBUG)
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(GOFLAGS
-trimpath
-buildmode=pie
)
if(WIN32)
message("++ Setting Windows Compiler Flags ${CMAKE_BUILD_TYPE}")
add_definitions(-DNOMINMAX)
set(GOFLAGS
-trimpath
)
else(WIN32)
set(GOFLAGS
-trimpath
-buildmode=pie
)
if(APPLE)
message("++ Setting MacOS Compiler Flags ${CMAKE_BUILD_TYPE}")
@ -183,16 +188,23 @@ file(GLOB go_src
${CMAKE_SOURCE_DIR}/cmd/cmd/*.go
${CMAKE_SOURCE_DIR}/pkg/zerotier/*.go)
set(CXX_CORE_LIBRARIES "-lc++")
if(WIN32)
set(GO_EXE_NAME "zerotier.exe")
set(GO_EXTRA_LIBRARIES "-lstdc++ -lwsock32 -lws2_32 -liphlpapi -lole32 -loleaut32 -lrpcrt4 -luuid")
else(WIN32)
set(GO_EXE_NAME "zerotier")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CXX_CORE_LIBRARIES "-lstdc++")
endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(GO_EXTRA_LIBRARIES "-lstdc++")
else()
set(GO_EXTRA_LIBRARIES "-lc++")
endif()
endif(WIN32)
add_custom_target(
zerotier ALL
BYPRODUCTS ${CMAKE_BINARY_DIR}/zerotier
SOURCES ${go_src}
COMMAND ${GOARCH} CGO_ENABLED=1 CGO_CFLAGS=\"-O3\" CGO_LDFLAGS=\"$<TARGET_FILE:zt_core> $<TARGET_FILE:zt_controller> $<TARGET_FILE:zt_service_io_core> $<TARGET_FILE:zt_osdep> ${CXX_CORE_LIBRARIES}\" ${GO} build ${GOFLAGS} -o ${CMAKE_BINARY_DIR}/zerotier ${CMAKE_SOURCE_DIR}/cmd/zerotier/zerotier.go
COMMAND ${CMAKE_COMMAND} -E env "${GOARCH} CGO_ENABLED=1 CGO_CFLAGS=\"-O3\" CGO_LDFLAGS=\"$<TARGET_FILE:zt_core> $<TARGET_FILE:zt_controller> $<TARGET_FILE:zt_service_io_core> $<TARGET_FILE:zt_osdep> ${GO_EXTRA_LIBRARIES}\"" ${GO} build ${GOFLAGS} -o ${CMAKE_BINARY_DIR}/${GO_EXE_NAME} ${CMAKE_SOURCE_DIR}/cmd/zerotier/zerotier.go
COMMENT "Compiling Go Code..."
)
add_dependencies(zerotier zt_osdep zt_core zt_controller zt_service_io_core)

View file

@ -2,3 +2,4 @@ echo off
mkdir build
cd build
cmake .. -G "MinGW Makefiles"
make -j4

View file

@ -39,8 +39,7 @@ func Service(basePath, authToken string, args []string) {
fmt.Println("FATAL: error initializing node: " + err.Error())
} else {
osSignalChannel := make(chan os.Signal, 2)
signal.Notify(osSignalChannel, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGSTOP)
signal.Ignore(syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGPIPE, syscall.SIGHUP)
signal.Notify(osSignalChannel, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT)
<-osSignalChannel
node.Close()
}

View file

@ -14,9 +14,6 @@
#include "EthernetTap.hpp"
#include "OSUtils.hpp"
#include <cstdlib>
#include <cstring>
#ifdef ZT_SDK
#include "../controller/EmbeddedNetworkController.hpp"

View file

@ -829,7 +829,8 @@ void WindowsEthernetTap::setFriendlyName(const char *dn)
if (hr != S_OK) return;
INetSharingManager *nsm;
hr = CoCreateInstance(__uuidof(NetSharingManager), NULL, CLSCTX_ALL, __uuidof(INetSharingManager), (void**)&nsm);
//hr = CoCreateInstance(__uuidof(NetSharingManager), NULL, CLSCTX_ALL, __uuidof(INetSharingManager), (void**)&nsm);
hr = CoCreateInstance(CLSID_NetSharingManager, NULL, CLSCTX_ALL, IID_INetSharingManager, (void**)&nsm);
if (hr != S_OK) return;
bool found = false;
@ -844,7 +845,8 @@ void WindowsEthernetTap::setFriendlyName(const char *dn)
IUnknown *unk = nullptr;
hr = nsecc->get__NewEnum(&unk);
if (unk) {
hr = unk->QueryInterface(__uuidof(IEnumVARIANT), (void**)&ev);
//hr = unk->QueryInterface(__uuidof(IEnumVARIANT), (void**)&ev);
hr = unk->QueryInterface(IID_IEnumVARIANT, (void**)&ev);
unk->Release();
}
if (ev) {
@ -854,7 +856,8 @@ void WindowsEthernetTap::setFriendlyName(const char *dn)
while ((S_OK == ev->Next(1, &v, NULL)) && found == FALSE) {
if (V_VT(&v) == VT_UNKNOWN) {
INetConnection *nc = nullptr;
V_UNKNOWN(&v)->QueryInterface(__uuidof(INetConnection), (void**)&nc);
//V_UNKNOWN(&v)->QueryInterface(__uuidof(INetConnection), (void**)&nc);
V_UNKNOWN(&v)->QueryInterface(IID_INetConnection, (void**)&nc);
if (nc) {
NETCON_PROPERTIES *ncp = nullptr;
nc->GetProperties(&ncp);

View file

@ -17,6 +17,7 @@ package zerotier
import (
"net"
"net/http"
winio "github.com/Microsoft/go-winio"
)
@ -24,7 +25,7 @@ import (
const windowsAPISocketPathPrefix = "\\\\.\\pipe\\zerotier_"
func createNamedSocketListener(basePath, name string) (net.Listener, error) {
winio.ListenPipe(windowsAPISocketPathPrefix+name, nil)
return winio.ListenPipe(windowsAPISocketPathPrefix+name, nil)
}
func createNamedSocketHTTPClient(basePath, name string) (*http.Client, error) {