From 1a38dfdbde66c8ef55eef3b52a144b8a2d0ee18f Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Mon, 15 Jun 2020 13:51:24 -0700 Subject: [PATCH] back to go main --- CMakeLists.txt | 41 ++++++++++---------------------- cmd/zerotier/zerotier.go | 4 ---- main.cpp | 51 ---------------------------------------- 3 files changed, 12 insertions(+), 84 deletions(-) delete mode 100644 main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5048dd1ad..66c5cad89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,11 @@ 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) @@ -121,6 +126,7 @@ else(WIN32) ) set(CMAKE_EXE_LINKER_FLAGS "-static ${CMAKE_EXE_LINKER_FLAGS}") set(GOFLAGS + ${GOFLAGS} -a -tags netgo -ldflags '-w -extldflags \"-static\"') @@ -152,34 +158,11 @@ file(GLOB go_src ${CMAKE_SOURCE_DIR}/cmd/cmd/*.go ${CMAKE_SOURCE_DIR}/pkg/zerotier/*.go) -add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/zerotier_cgo.h ${CMAKE_BINARY_DIR}/zerotier_cgo.a - COMMAND ${GOARCH} CGO_ENABLED=1 ${GO} build -buildmode=c-archive ${GOFLAGS} -o ${CMAKE_BINARY_DIR}/zerotier_cgo.a ${CMAKE_SOURCE_DIR}/cmd/zerotier/zerotier.go - IMPLICIT_DEPENDS ${go_src} +add_custom_target( + zerotier ALL + BYPRODUCTS ${CMAKE_BINARY_DIR}/zerotier + SOURCES ${go_src} + COMMAND ${GOARCH} CGO_ENABLED=1 CGO_LDFLAGS=\"$ $ $ $\" ${GO} build ${GOFLAGS} -o ${CMAKE_BINARY_DIR}/zerotier ${CMAKE_SOURCE_DIR}/cmd/zerotier/zerotier.go COMMENT "Compiling Go Code..." ) -add_custom_target( - zerotier_cgo_target - DEPENDS ${CMAKE_BINARY_DIR}/zerotier_cgo.a - SOURCES ${go_src} -) -add_library(zerotier_cgo STATIC IMPORTED GLOBAL) -add_dependencies(zerotier_cgo zerotier_cgo_target) -set_target_properties( - zerotier_cgo - PROPERTIES - IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/zerotier_cgo.a - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR} -) - -add_executable(zerotier main.cpp) -target_include_directories(zerotier PUBLIC ${CMAKE_BINARY_DIR}) -add_dependencies(zerotier zerotier_cgo zt_osdep zt_core zt_controller zt_service_io_core) -target_link_libraries(zerotier zerotier_cgo zt_service_io_core zt_core zt_osdep zt_controller ) -if (APPLE) - target_link_libraries(zerotier "-framework CoreFoundation" "-framework Security") -else(APPLE) - if ("${CMAKE_SYSTEM}" MATCHES "Linux") - target_link_libraries(zerotier "-lpthread" "-lm") - endif ("${CMAKE_SYSTEM}" MATCHES "Linux") -endif (APPLE) +add_dependencies(zerotier zt_osdep zt_core zt_controller zt_service_io_core) diff --git a/cmd/zerotier/zerotier.go b/cmd/zerotier/zerotier.go index d43fe97a3..2c8a855ce 100644 --- a/cmd/zerotier/zerotier.go +++ b/cmd/zerotier/zerotier.go @@ -52,10 +52,6 @@ func authTokenRequired(authToken string) { } func main() { -} - -//export ZeroTierMain -func ZeroTierMain() { // Reduce Go's thread and memory footprint. This would slow things down if the Go code // were doing a lot, but it's not. It just manages the core and is not directly involved // in pushing a lot of packets around. If that ever changes this should be adjusted. diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 18856e290..000000000 --- a/main.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c)2013-2020 ZeroTier, Inc. - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file in the project's root directory. - * - * Change Date: 2024-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2.0 of the Apache License. - */ -/****/ - -#if !defined(_WIN32) && !defined(_WIN64) -#include -#include -#include -#include -#endif - -#include "zerotier_cgo.h" - -int main(int argc,char **argv) -{ - // Fork into background if run with 'service -d'. This is best done prior - // to launching the Go code, since Go likes to start thread pools and stuff - // that don't play nice with fork. This is obviously unsupported on Windows. -#if !defined(_WIN32) && !defined(_WIN64) - for(int i=1;i 0) { - return 0; - } - break; - } - } - break; - } - } -#endif - - ZeroTierMain(); - - return 0; -}