CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # CMake build script for ZeroTier One
  2. cmake_minimum_required (VERSION 3.8)
  3. if(${CMAKE_VERSION} VERSION_LESS 3.15)
  4. cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
  5. else()
  6. cmake_policy(VERSION 3.15)
  7. endif()
  8. if(WIN32)
  9. # If building on Windows, set minimum target to Windows 7
  10. set(CMAKE_SYSTEM_VERSION "7" CACHE STRING INTERNAL FORCE)
  11. endif(WIN32)
  12. #
  13. # ZeroTier One Version Config
  14. #
  15. set(ZEROTIER_ONE_VERSION_MAJOR 1 CACHE INTERNAL "")
  16. set(ZEROTIER_ONE_VERSION_MINOR 9 CACHE INTERNAL "")
  17. set(ZEROTIER_ONE_VERSION_REVISION 0 CACHE INTERNAL "")
  18. set(ZEROTIER_ONE_VERSION_BUILD 0 CACHE INTERNAL "")
  19. #
  20. # Set a default build type if none was specified
  21. #
  22. set(default_build_type "Release")
  23. if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
  24. set(default_build_type "Debug")
  25. endif()
  26. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  27. message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
  28. set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
  29. STRING "Choose the type of build." FORCE)
  30. # Set the possible values of build type for cmake-gui
  31. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  32. "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
  33. endif()
  34. option(BUILD_CENTRAL_CONTROLLER "Build ZeroTier Central Controller" OFF)
  35. option(ZT_TRACE "Trace Messages" OFF)
  36. option(ZT_DEBUG_TRACE "Debug Trace Messages" OFF)
  37. if (BUILD_CENTRAL_CONTROLLER)
  38. find_package(PostgreSQL REQUIRED)
  39. set(ENABLE_SSL_SUPPORT OFF)
  40. set(BUILD_SHARED_LIBS OFF)
  41. set(BUILD_EXAMPLES OFF)
  42. set(BUILD_TOOLS OFF)
  43. set(BUILD_TESTS OFF)
  44. set(BUILD_API_DOCS OFF)
  45. add_subdirectory("ext/librabbitmq")
  46. endif(BUILD_CENTRAL_CONTROLLER)
  47. set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X Deployment Version")
  48. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  49. add_definitions(-DZT_TRACE)
  50. endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
  51. project(zerotier-one
  52. DESCRIPTION "ZeroTier One"
  53. LANGUAGES CXX C)
  54. if(WIN32)
  55. add_definitions(-DNOMINMAX)
  56. else(WIN32)
  57. if(APPLE)
  58. message("Setting macOS Compiler Flags ${CMAKE_BUILD_TYPE}")
  59. add_compile_options(
  60. -Wall
  61. -Wno-deprecated
  62. -maes
  63. -mpclmul
  64. -msse
  65. -msse2
  66. -msse3
  67. -msse4.1
  68. $<$<CONFIG:Debug>:-g>
  69. $<$<CONFIG:DEBUG>:-O0>
  70. $<$<CONFIG:RELEASE>:-Ofast>
  71. $<$<CONFIG:RELEASE>:-fstack-protector-strong>
  72. $<$<CONFIG:RELEASE>:-fPIE>
  73. $<$<CONFIG:RELWITHDEBINFO>:-Ofast>
  74. $<$<CONFIG:RELWITHDEBINFO>:-fstack-protector-strong>
  75. $<$<CONFIG:RELWITHDEBINFO>:-fPIE>
  76. $<$<CONFIG:RELWITHDEBINFO>:-g>
  77. )
  78. elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
  79. message("Setting Linux Compiler Flags ${CMAKE_BUILD_TYPE}")
  80. add_compile_options(
  81. -Wall
  82. -Wno-deprecated
  83. -maes
  84. -mpclmul
  85. -msse
  86. -msse2
  87. -msse3
  88. -msse4.1
  89. $<$<CONFIG:Debug>:-g>
  90. $<$<CONFIG:DEBUG>:-O0>
  91. $<$<CONFIG:RELEASE>:-O3>
  92. $<$<CONFIG:RELEASE>:-fstack-protector>
  93. $<$<CONFIG:RELEASE>:-fPIE>
  94. $<$<CONFIG:RELWITHDEBINFO>:-O3>
  95. $<$<CONFIG:RELWITHDEBINFO>:-fstack-protector>
  96. $<$<CONFIG:RELWITHDEBINFO>:-fPIE>
  97. $<$<CONFIG:RELWITHDEBINFO>:-g>
  98. )
  99. endif(APPLE)
  100. endif(WIN32)
  101. if(ZT_TRACE)
  102. add_definitions(-DZT_TRACE)
  103. endif()
  104. if(ZT_DEBUG_TRACE)
  105. add_definitions(-DZT_DEBUG_TRACE)
  106. endif()
  107. add_subdirectory(node)
  108. add_subdirectory(controller)
  109. add_subdirectory(osdep)
  110. add_subdirectory(service)
  111. if(WIN32)
  112. add_subdirectory("windows/WinUI")
  113. add_subdirectory("windows/copyutil")
  114. add_definitions(-DNOMINMAX)
  115. endif(WIN32)
  116. set(libs
  117. zt_service
  118. zt_osdep
  119. zt_core
  120. zt_controller
  121. )
  122. configure_file(
  123. ${CMAKE_SOURCE_DIR}/version.h.in
  124. ${CMAKE_BINARY_DIR}/version.h
  125. )
  126. set(src
  127. one.cpp
  128. "ext/http-parser/http_parser.c"
  129. )
  130. set(headers
  131. "ext/http-parser/http_parser.h"
  132. )
  133. if(WIN32)
  134. set(libs ${libs} wsock32 ws2_32 rpcrt4 iphlpapi)
  135. set(src
  136. ${src}
  137. "windows/ZeroTierOne/ServiceBase.cpp"
  138. "windows/ZeroTierOne/ServiceInstaller.cpp"
  139. "windows/ZeroTierOne/ZeroTierOneService.cpp"
  140. "windows/ZeroTierOne/ZeroTierOne.rc"
  141. )
  142. set(headers
  143. ${headers}
  144. "windows/ZeroTierOne/ServiceBase.h"
  145. "windows/ZeroTierOne/ServiceInstaller.h"
  146. "windows/ZeroTierOne/ZeroTierOneService.h"
  147. )
  148. else(WIN32)
  149. set(libs ${libs} pthread resolv)
  150. endif(WIN32)
  151. if(BUILD_CENTRAL_CONTROLLER)
  152. set(libs ${libs} rabbitmq-static ${PostgreSQL_LIBRARIES})
  153. endif(BUILD_CENTRAL_CONTROLLER)
  154. add_executable(${PROJECT_NAME} ${src} ${headers})
  155. target_link_libraries(${PROJECT_NAME} ${libs})
  156. target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR})
  157. add_executable(zerotier-selftest selftest.cpp)
  158. target_link_libraries(zerotier-selftest ${libs})