mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Move all CGO flags into CMakeLists.txt so they can inherit all our system detection and stuff.
This commit is contained in:
parent
f0fc4713d8
commit
3c6448a717
2 changed files with 30 additions and 8 deletions
|
@ -23,7 +23,6 @@ else(NOT GO)
|
||||||
message(STATUS "Found Golang at ${GO}")
|
message(STATUS "Found Golang at ${GO}")
|
||||||
endif(NOT GO)
|
endif(NOT GO)
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(default_build_type "Release")
|
set(default_build_type "Release")
|
||||||
|
|
||||||
|
@ -68,10 +67,13 @@ set(GOFLAGS
|
||||||
)
|
)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
|
||||||
message("++ Setting Windows Compiler Flags ${CMAKE_BUILD_TYPE}")
|
message("++ Setting Windows Compiler Flags ${CMAKE_BUILD_TYPE}")
|
||||||
add_definitions(-DNOMINMAX)
|
add_definitions(-DNOMINMAX)
|
||||||
|
|
||||||
else(WIN32)
|
else(WIN32)
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
|
|
||||||
message("++ Setting MacOS Compiler Flags ${CMAKE_BUILD_TYPE}")
|
message("++ Setting MacOS Compiler Flags ${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
add_compile_options(
|
add_compile_options(
|
||||||
|
@ -85,15 +87,24 @@ else(WIN32)
|
||||||
$<$<CONFIG:RELEASE>:-ffast-math>
|
$<$<CONFIG:RELEASE>:-ffast-math>
|
||||||
$<$<CONFIG:RELEASE>:-fPIE>
|
$<$<CONFIG:RELEASE>:-fPIE>
|
||||||
$<$<CONFIG:RELEASE>:-flto>
|
$<$<CONFIG:RELEASE>:-flto>
|
||||||
$<$<CONFIG:RELWITHDEBINFO>:-Ofast>
|
$<$<CONFIG:RELWITHDEBINFO>:-O1>
|
||||||
$<$<CONFIG:RELWITHDEBINFO>:-fPIE>
|
$<$<CONFIG:RELWITHDEBINFO>:-fPIE>
|
||||||
$<$<CONFIG:RELWITHDEBINFO>:-g>
|
$<$<CONFIG:RELWITHDEBINFO>:-g>
|
||||||
)
|
)
|
||||||
|
|
||||||
add_link_options(
|
add_link_options(
|
||||||
-mmacosx-version-min=10.12
|
-mmacosx-version-min=10.12
|
||||||
$<$<CONFIG:RELEASE>:-flto>
|
$<$<CONFIG:RELEASE>:-flto>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(GOFLAGS
|
||||||
|
${GOFLAGS}
|
||||||
|
-a
|
||||||
|
-ldflags '-w -extldflags \"-Wl,-undefined -Wl,dynamic_lookup\"'
|
||||||
|
)
|
||||||
|
|
||||||
else(APPLE)
|
else(APPLE)
|
||||||
|
|
||||||
message("++ Setting Linux/BSD/Posix Compiler Flags (${CMAKE_BUILD_TYPE})")
|
message("++ Setting Linux/BSD/Posix Compiler Flags (${CMAKE_BUILD_TYPE})")
|
||||||
add_compile_options(
|
add_compile_options(
|
||||||
-Wall
|
-Wall
|
||||||
|
@ -109,8 +120,10 @@ else(WIN32)
|
||||||
$<$<CONFIG:RELWITHDEBINFO>:-fPIE>
|
$<$<CONFIG:RELWITHDEBINFO>:-fPIE>
|
||||||
$<$<CONFIG:RELWITHDEBINFO>:-g>
|
$<$<CONFIG:RELWITHDEBINFO>:-g>
|
||||||
)
|
)
|
||||||
|
|
||||||
option(BUILD_32BIT "Force building as 32-bit binary" OFF)
|
option(BUILD_32BIT "Force building as 32-bit binary" OFF)
|
||||||
option(BUILD_STATIC "Build statically linked executable" OFF)
|
option(BUILD_STATIC "Build statically linked executable" OFF)
|
||||||
|
|
||||||
if(BUILD_32BIT)
|
if(BUILD_32BIT)
|
||||||
set(CMAKE_SYSTEM_PROCESSOR "x86" CACHE STRING "system processor")
|
set(CMAKE_SYSTEM_PROCESSOR "x86" CACHE STRING "system processor")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags")
|
||||||
|
@ -120,6 +133,7 @@ else(WIN32)
|
||||||
-m32
|
-m32
|
||||||
)
|
)
|
||||||
endif(BUILD_32BIT)
|
endif(BUILD_32BIT)
|
||||||
|
|
||||||
if(BUILD_STATIC)
|
if(BUILD_STATIC)
|
||||||
add_link_options(
|
add_link_options(
|
||||||
-static
|
-static
|
||||||
|
@ -129,8 +143,17 @@ else(WIN32)
|
||||||
${GOFLAGS}
|
${GOFLAGS}
|
||||||
-a
|
-a
|
||||||
-tags netgo
|
-tags netgo
|
||||||
-ldflags '-w -extldflags \"-static\"')
|
-ldflags '-w -extldflags \"-static -Wl,-unresolved-symbols=ignore-all\"'
|
||||||
|
)
|
||||||
|
else(BUILD_STATIC)
|
||||||
|
set(GOFLAGS
|
||||||
|
${GOFLAGS}
|
||||||
|
-a
|
||||||
|
-tags netgo
|
||||||
|
-ldflags '-w -extldflags \"-Wl,-unresolved-symbols=ignore-all\"'
|
||||||
|
)
|
||||||
endif(BUILD_STATIC)
|
endif(BUILD_STATIC)
|
||||||
|
|
||||||
endif(APPLE)
|
endif(APPLE)
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
|
@ -144,6 +167,7 @@ if (
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(GO_BUILD_TAGS)
|
set(GO_BUILD_TAGS)
|
||||||
|
|
||||||
if(BUILD_CENTRAL_CONTROLLER)
|
if(BUILD_CENTRAL_CONTROLLER)
|
||||||
add_definitions(-DZT_CONTROLLER_USE_LIBPQ=1)
|
add_definitions(-DZT_CONTROLLER_USE_LIBPQ=1)
|
||||||
set(GO_BUILD_TAGS -tags central)
|
set(GO_BUILD_TAGS -tags central)
|
||||||
|
@ -163,7 +187,7 @@ add_custom_target(
|
||||||
zerotier ALL
|
zerotier ALL
|
||||||
BYPRODUCTS ${CMAKE_BINARY_DIR}/zerotier
|
BYPRODUCTS ${CMAKE_BINARY_DIR}/zerotier
|
||||||
SOURCES ${go_src}
|
SOURCES ${go_src}
|
||||||
COMMAND ${GOARCH} CGO_ENABLED=1 CGO_LDFLAGS=\"$<TARGET_FILE:zt_osdep> $<TARGET_FILE:zt_core> $<TARGET_FILE:zt_controller> $<TARGET_FILE:zt_service_io_core>\" ${GO} build ${GOFLAGS} -o ${CMAKE_BINARY_DIR}/zerotier ${CMAKE_SOURCE_DIR}/cmd/zerotier/zerotier.go
|
COMMAND ${GOARCH} CGO_ENABLED=1 CGO_CFLAGS=\"${CMAKE_C_FLAGS}\" CGO_LDFLAGS=\"$<TARGET_FILE:zt_osdep> $<TARGET_FILE:zt_core> $<TARGET_FILE:zt_controller> $<TARGET_FILE:zt_service_io_core> -l${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}\" ${GO} build ${GOFLAGS} -o ${CMAKE_BINARY_DIR}/zerotier ${CMAKE_SOURCE_DIR}/cmd/zerotier/zerotier.go
|
||||||
COMMENT "Compiling Go Code..."
|
COMMENT "Compiling Go Code..."
|
||||||
)
|
)
|
||||||
add_dependencies(zerotier zt_osdep zt_core zt_controller zt_service_io_core)
|
add_dependencies(zerotier zt_osdep zt_core zt_controller zt_service_io_core)
|
||||||
|
|
|
@ -13,9 +13,7 @@
|
||||||
|
|
||||||
package zerotier
|
package zerotier
|
||||||
|
|
||||||
// #cgo CFLAGS: -O3 -I${SRCDIR}/../../build/core
|
// #cgo CFLAGS: -I${SRCDIR}/../../build/core
|
||||||
// #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup -lc++
|
|
||||||
// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all -lstdc++
|
|
||||||
// #include "../../serviceiocore/GoGlue.h"
|
// #include "../../serviceiocore/GoGlue.h"
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue