enable -DPACKAGE_STATIC=1 builds

Only configures the project for packaging of the statically built binary placed in build/
This commit is contained in:
Grant Limberg 2020-06-22 13:50:35 -07:00
parent 7c6f5e2c37
commit 09a8b66d3b
No known key found for this signature in database
GPG key ID: 2BA62CCABBB4095A

View file

@ -17,41 +17,41 @@ project(zerotier
DESCRIPTION "ZeroTier Network Hypervisor" DESCRIPTION "ZeroTier Network Hypervisor"
LANGUAGES CXX C) LANGUAGES CXX C)
if(${CMAKE_VERSION} VERSION_LESS 3.15) if(${CMAKE_VERSION} VERSION_LESS 3.15)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else() else()
cmake_policy(VERSION 3.15) cmake_policy(VERSION 3.15)
endif() endif()
find_program( if(NOT PACKAGE_STATIC)
find_program(
GO go GO go
HINTS "/usr/local/go/bin" "C:/go/bin" HINTS "/usr/local/go/bin" "C:/go/bin"
) )
if(NOT GO) if(NOT GO)
message(FATAL_ERROR "Golang not found") message(FATAL_ERROR "Golang not found")
else(NOT GO) 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")
if(WIN32) if(WIN32)
set(CMAKE_SYSTEM_VERSION "7" CACHE STRING INTERNAL FORCE) set(CMAKE_SYSTEM_VERSION "7" CACHE STRING INTERNAL FORCE)
endif(WIN32) endif(WIN32)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X Deployment Version") set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X Deployment Version")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.") message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif() endif()
option(BUILD_CENTRAL_CONTROLLER "Build ZeroTier Central Controller" OFF) option(BUILD_CENTRAL_CONTROLLER "Build ZeroTier Central Controller" OFF)
if(BUILD_CENTRAL_CONTROLLER) if(BUILD_CENTRAL_CONTROLLER)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
if(APPLE) if(APPLE)
set(CMAKE_PREFIX_PATH set(CMAKE_PREFIX_PATH
@ -67,13 +67,13 @@ if(BUILD_CENTRAL_CONTROLLER)
add_subdirectory(controller/thirdparty/redis-plus-plus-1.1.1) add_subdirectory(controller/thirdparty/redis-plus-plus-1.1.1)
set(redispp_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/controller/thirdparty/redis-plus-plus-1.1.1/src/sw) set(redispp_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/controller/thirdparty/redis-plus-plus-1.1.1/src/sw)
set(redispp_STATIC_LIB redispp_static) set(redispp_STATIC_LIB redispp_static)
endif(BUILD_CENTRAL_CONTROLLER) endif(BUILD_CENTRAL_CONTROLLER)
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DZT_DEBUG) add_definitions(-DZT_DEBUG)
endif(CMAKE_BUILD_TYPE STREQUAL "Debug") endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
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)
@ -96,7 +96,7 @@ if(WIN32)
-m32 -m32
) )
endif(BUILD_32BIT) endif(BUILD_32BIT)
else(WIN32) else(WIN32)
set(GOFLAGS set(GOFLAGS
-trimpath -trimpath
@ -186,56 +186,64 @@ else(WIN32)
endif(BUILD_STATIC) endif(BUILD_STATIC)
endif(APPLE) endif(APPLE)
endif(WIN32) endif(WIN32)
if ( if (
CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR
CMAKE_SYSTEM_PROCESSOR MATCHES "amd64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "amd64" OR
CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64" CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64"
) )
message("++ Adding flags for processor ${CMAKE_SYSTEM_PROCESSOR}") message("++ Adding flags for processor ${CMAKE_SYSTEM_PROCESSOR}")
add_compile_options(-maes -mrdrnd -mpclmul -msse -msse2 -mssse3) add_compile_options(-maes -mrdrnd -mpclmul -msse -msse2 -mssse3)
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)
endif(BUILD_CENTRAL_CONTROLLER) endif(BUILD_CENTRAL_CONTROLLER)
add_subdirectory(core) add_subdirectory(core)
add_subdirectory(controller) add_subdirectory(controller)
add_subdirectory(osdep) add_subdirectory(osdep)
add_subdirectory(serviceiocore) add_subdirectory(serviceiocore)
file(GLOB go_src file(GLOB go_src
${CMAKE_SOURCE_DIR}/cmd/*.go ${CMAKE_SOURCE_DIR}/cmd/*.go
${CMAKE_SOURCE_DIR}/cmd/cmd/*.go ${CMAKE_SOURCE_DIR}/cmd/cmd/*.go
${CMAKE_SOURCE_DIR}/pkg/zerotier/*.go) ${CMAKE_SOURCE_DIR}/pkg/zerotier/*.go)
if(WIN32) if(WIN32)
set(GO_EXE_NAME "zerotier.exe") set(GO_EXE_NAME "zerotier.exe")
set(GO_EXTRA_LIBRARIES "-lstdc++ -lwsock32 -lws2_32 -liphlpapi -lole32 -loleaut32 -lrpcrt4 -luuid") set(GO_EXTRA_LIBRARIES "-lstdc++ -lwsock32 -lws2_32 -liphlpapi -lole32 -loleaut32 -lrpcrt4 -luuid")
else(WIN32) else(WIN32)
set(GO_EXE_NAME "zerotier") set(GO_EXE_NAME "zerotier")
if(CMAKE_SYSTEM_NAME MATCHES "Linux") if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(GO_EXTRA_LIBRARIES "-lstdc++") set(GO_EXTRA_LIBRARIES "-lstdc++")
else() else()
set(GO_EXTRA_LIBRARIES "-lc++") set(GO_EXTRA_LIBRARIES "-lc++")
endif() endif()
endif(WIN32) endif(WIN32)
add_custom_target( add_custom_target(
zerotier ALL zerotier ALL
BYPRODUCTS ${CMAKE_BINARY_DIR}/zerotier BYPRODUCTS ${CMAKE_BINARY_DIR}/zerotier
SOURCES ${go_src} SOURCES ${go_src}
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 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..." 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)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/zerotier DESTINATION bin)
else(NOT PACKAGE_STATIC)
set(STATIC_BINARY ${CMAKE_BINARY_DIR}/zerotier)
set(IMPORTED_LOCATION ${CMAKE_BINARY_DIR})
add_executable(zerotier IMPORTED GLOBAL)
install(PROGRAMS ${STATIC_BINARY} DESTINATION bin)
endif(NOT PACKAGE_STATIC)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/zerotier DESTINATION bin)
if("${CMAKE_SYSTEM_NAME}" EQUAL "Linux") if("${CMAKE_SYSTEM_NAME}" EQUAL "Linux")
if(IS_DIRECTORY /lib/systemd/system) if(IS_DIRECTORY /lib/systemd/system)
install( install(