mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-07-24 19:22:51 +02:00
236 lines
6.2 KiB
CMake
236 lines
6.2 KiB
CMake
cmake_minimum_required (VERSION 3.8)
|
|
|
|
cmake_policy(SET CMP0048 NEW)
|
|
|
|
if(${CMAKE_VERSION} VERSION_LESS 3.15)
|
|
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
|
else()
|
|
cmake_policy(VERSION 3.15)
|
|
endif()
|
|
|
|
set(ZEROTIER_VERSION_MAJOR 1 CACHE INTERNAL "")
|
|
set(ZEROTIER_VERSION_MINOR 9 CACHE INTERNAL "")
|
|
set(ZEROTIER_VERSION_REVISION 0 CACHE INTERNAL "")
|
|
set(ZEROTIER_VERSION_BUILD 0 CACHE INTERNAL "")
|
|
|
|
project(zerotier
|
|
VERSION ${ZEROTIER_VERSION_MAJOR}.${ZEROTIER_VERSION_MINOR}.${ZEROTIER_VERSION_REVISION}.${ZEROTIER_VERSION_BUILD}
|
|
DESCRIPTION "ZeroTier Network Hypervisor"
|
|
LANGUAGES CXX C)
|
|
|
|
if(NOT PACKAGE_STATIC)
|
|
|
|
set(default_build_type "Release")
|
|
|
|
if(WIN32)
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_SYSTEM_VERSION "7" CACHE STRING INTERNAL FORCE)
|
|
else(WIN32)
|
|
if(APPLE)
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
else(APPLE)
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
endif(APPLE)
|
|
endif(WIN32)
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
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_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
|
endif()
|
|
|
|
option(BUILD_CENTRAL_CONTROLLER "Build ZeroTier Central Controller" OFF)
|
|
if(BUILD_CENTRAL_CONTROLLER)
|
|
find_package(PkgConfig REQUIRED)
|
|
if(APPLE)
|
|
set(CMAKE_PREFIX_PATH
|
|
${CMAKE_PREFIX_PATH}
|
|
/usr/local/opt/libpq
|
|
/usr/local/lib
|
|
)
|
|
endif(APPLE)
|
|
find_package(PostgreSQL REQUIRED)
|
|
|
|
pkg_check_modules(hiredis REQUIRED IMPORTED_TARGET hiredis)
|
|
|
|
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_STATIC_LIB redispp_static)
|
|
endif(BUILD_CENTRAL_CONTROLLER)
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
add_definitions(-DZT_DEBUG)
|
|
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
if(WIN32)
|
|
|
|
message("++ Setting Windows Compiler Flags ${CMAKE_BUILD_TYPE}")
|
|
|
|
add_definitions(-DNOMINMAX)
|
|
add_compile_options(
|
|
-Wall
|
|
-Wno-deprecated
|
|
-Wno-unused-function
|
|
-Wno-format
|
|
-Wno-attributes
|
|
$<$<CONFIG:DEBUG>:-g>
|
|
$<$<CONFIG:DEBUG>:-O0>
|
|
$<$<CONFIG:RELEASE>:-O3>
|
|
$<$<CONFIG:RELEASE>:-ffast-math>
|
|
$<$<CONFIG:RELWITHDEBINFO>:-O3>
|
|
$<$<CONFIG:RELWITHDEBINFO>:-g>
|
|
)
|
|
|
|
#set(GOFLAGS
|
|
# -a
|
|
# -trimpath
|
|
#)
|
|
|
|
if(BUILD_32BIT)
|
|
set(CMAKE_SYSTEM_PROCESSOR "x86" CACHE STRING "system processor")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags")
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags")
|
|
set(GOARCH "GOARCH=386" CACHE STRING "go architecture")
|
|
add_compile_options(
|
|
-m32
|
|
)
|
|
add_link_options(
|
|
-m32
|
|
)
|
|
endif(BUILD_32BIT)
|
|
|
|
else(WIN32)
|
|
|
|
if(APPLE)
|
|
|
|
message("++ Setting MacOS Compiler Flags ${CMAKE_BUILD_TYPE}")
|
|
|
|
set(MACOS_VERSION_MIN "10.14")
|
|
|
|
add_compile_options(
|
|
-Wall
|
|
-Wno-deprecated
|
|
-Wno-unused-function
|
|
-Wno-attributes
|
|
-mmacosx-version-min=${MACOS_VERSION_MIN}
|
|
$<$<CONFIG:DEBUG>:-g>
|
|
$<$<CONFIG:DEBUG>:-O0>
|
|
$<$<CONFIG:RELEASE>:-Ofast>
|
|
$<$<CONFIG:RELEASE>:-ffast-math>
|
|
$<$<CONFIG:RELEASE>:-fPIE>
|
|
$<$<CONFIG:RELEASE>:-flto>
|
|
$<$<CONFIG:RELWITHDEBINFO>:-O1>
|
|
$<$<CONFIG:RELWITHDEBINFO>:-fPIE>
|
|
$<$<CONFIG:RELWITHDEBINFO>:-g>
|
|
)
|
|
|
|
add_link_options(
|
|
-mmacosx-version-min=${MACOS_VERSION_MIN}
|
|
$<$<CONFIG:RELEASE>:-flto>
|
|
)
|
|
|
|
else(APPLE)
|
|
|
|
message("++ Setting Linux/BSD/Posix Compiler Flags (${CMAKE_BUILD_TYPE})")
|
|
|
|
add_compile_options(
|
|
-Wall
|
|
-Wno-deprecated
|
|
-Wno-unused-function
|
|
-Wno-format
|
|
-Wno-attributes
|
|
$<$<CONFIG:DEBUG>:-g>
|
|
$<$<CONFIG:DEBUG>:-O0>
|
|
$<$<CONFIG:RELEASE>:-O3>
|
|
$<$<CONFIG:RELEASE>:-ffast-math>
|
|
$<$<CONFIG:RELEASE>:-fPIE>
|
|
$<$<CONFIG:RELWITHDEBINFO>:-O3>
|
|
$<$<CONFIG:RELWITHDEBINFO>:-fPIE>
|
|
$<$<CONFIG:RELWITHDEBINFO>:-g>
|
|
)
|
|
|
|
option(BUILD_32BIT "Force building as 32-bit binary" OFF)
|
|
option(BUILD_STATIC "Build statically linked executable" OFF)
|
|
|
|
if(BUILD_32BIT)
|
|
set(CMAKE_SYSTEM_PROCESSOR "x86" CACHE STRING "system processor")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags")
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags")
|
|
add_compile_options(
|
|
-m32
|
|
)
|
|
endif(BUILD_32BIT)
|
|
|
|
if(BUILD_STATIC)
|
|
add_link_options(
|
|
-static
|
|
)
|
|
set(CMAKE_EXE_LINKER_FLAGS "-static ${CMAKE_EXE_LINKER_FLAGS}")
|
|
endif(BUILD_STATIC)
|
|
|
|
endif(APPLE)
|
|
endif(WIN32)
|
|
|
|
if (
|
|
CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR
|
|
CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" OR
|
|
CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64" OR
|
|
CMAKE_SYSTEM_PROCESSOR MATCHES "AARCH64"
|
|
)
|
|
message("++ Adding flags for processor ${CMAKE_SYSTEM_PROCESSOR}")
|
|
add_compile_options(-march=armv8-a+aes+crypto -mtune=generic -mstrict-align)
|
|
endif()
|
|
|
|
if(BUILD_CENTRAL_CONTROLLER)
|
|
add_definitions(-DZT_CONTROLLER_USE_LIBPQ=1)
|
|
endif(BUILD_CENTRAL_CONTROLLER)
|
|
|
|
add_subdirectory(core)
|
|
# add_subdirectory(controller)
|
|
add_subdirectory(osdep)
|
|
|
|
else(NOT PACKAGE_STATIC)
|
|
|
|
if(BUILD_32BIT)
|
|
set(CMAKE_SYSTEM_PROCESSOR "x86" CACHE STRING "system processor")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags")
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags")
|
|
add_compile_options(
|
|
-m32
|
|
)
|
|
endif(BUILD_32BIT)
|
|
|
|
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)
|
|
|
|
# Linux packaging
|
|
|
|
if("${CMAKE_SYSTEM_NAME}" EQUAL "Linux")
|
|
if(IS_DIRECTORY /lib/systemd/system)
|
|
install(
|
|
FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/debian/zerotier.service
|
|
DESTINATION /lib/systemd/system
|
|
)
|
|
elseif(IS_DIRECTORY /usr/lib/systemd/system)
|
|
install(
|
|
FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/debian/zerotier.service
|
|
DESTINATION /usr/lib/systemd/system
|
|
)
|
|
else()
|
|
install(
|
|
FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/debian/zerotier.init
|
|
DESTINATION /etc/init.d
|
|
)
|
|
endif()
|
|
endif()
|
|
|
|
if("${ZT_PACKAGE_FORMAT}" MATCHES "DEB")
|
|
include(packaging/debian.cmake)
|
|
elseif("${ZT_PACKAGE_FORMAT}" MATCHES "RPM")
|
|
include(packaging/rpm.cmake)
|
|
else()
|
|
endif()
|