2
0

CMakeLists.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. cmake_minimum_required(VERSION 3.12)
  2. # This can be read from ${PROJECT_NAME} after project() is called
  3. project(luanti)
  4. set(PROJECT_NAME_CAPITALIZED "Luanti")
  5. set(CMAKE_CXX_STANDARD 17)
  6. set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
  7. set(GCC_MINIMUM_VERSION "7.5")
  8. set(CLANG_MINIMUM_VERSION "7.0.1")
  9. # You should not need to edit these manually, use util/bump_version.sh
  10. set(VERSION_MAJOR 5)
  11. set(VERSION_MINOR 11)
  12. set(VERSION_PATCH 0)
  13. set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
  14. # Change to false for releases
  15. set(DEVELOPMENT_BUILD TRUE)
  16. set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
  17. if(VERSION_EXTRA)
  18. set(VERSION_STRING "${VERSION_STRING}-${VERSION_EXTRA}")
  19. elseif(DEVELOPMENT_BUILD)
  20. set(VERSION_STRING "${VERSION_STRING}-dev")
  21. endif()
  22. if (CMAKE_BUILD_TYPE STREQUAL Debug)
  23. # Append "-debug" to version string
  24. set(VERSION_STRING "${VERSION_STRING}-debug")
  25. endif()
  26. # Configuration options
  27. set(BUILD_CLIENT TRUE CACHE BOOL "Build client")
  28. set(BUILD_SERVER FALSE CACHE BOOL "Build server")
  29. set(BUILD_UNITTESTS TRUE CACHE BOOL "Build unittests")
  30. set(BUILD_BENCHMARKS FALSE CACHE BOOL "Build benchmarks")
  31. set(BUILD_DOCUMENTATION TRUE CACHE BOOL "Build documentation")
  32. set(DEFAULT_ENABLE_LTO TRUE)
  33. # by default don't enable on Debug builds to get faster builds
  34. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  35. set(DEFAULT_ENABLE_LTO FALSE)
  36. endif()
  37. #### LTO testing list ####
  38. # - Linux: seems to work always
  39. # - win32/msvc: works
  40. # - win32/gcc: fails to link
  41. # - win32/clang: works
  42. # - macOS on x86: seems to be fine
  43. # - macOS on ARM: crashes, see <https://github.com/minetest/minetest/issues/14397>
  44. # Note: since CMake has no easy architecture detection disabling for Mac entirely
  45. #### ####
  46. if((WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR APPLE)
  47. set(DEFAULT_ENABLE_LTO FALSE)
  48. endif()
  49. set(ENABLE_LTO ${DEFAULT_ENABLE_LTO} CACHE BOOL "Use Link Time Optimization")
  50. set(BUILD_WITH_TRACY FALSE CACHE BOOL
  51. "Fetch and build with the Tracy profiler client")
  52. set(FETCH_TRACY_GIT_TAG "master" CACHE STRING
  53. "Git tag for fetching Tracy client. Match with your server (gui) version")
  54. set(DEFAULT_RUN_IN_PLACE FALSE)
  55. if(WIN32)
  56. set(DEFAULT_RUN_IN_PLACE TRUE)
  57. endif()
  58. set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL
  59. "Run directly in source directory structure")
  60. message(STATUS "*** Will build version ${VERSION_STRING} ***")
  61. message(STATUS "BUILD_CLIENT: " ${BUILD_CLIENT})
  62. message(STATUS "BUILD_SERVER: " ${BUILD_SERVER})
  63. message(STATUS "BUILD_UNITTESTS: " ${BUILD_UNITTESTS})
  64. message(STATUS "BUILD_BENCHMARKS: " ${BUILD_BENCHMARKS})
  65. message(STATUS "BUILD_DOCUMENTATION: " ${BUILD_DOCUMENTATION})
  66. message(STATUS "RUN_IN_PLACE: " ${RUN_IN_PLACE})
  67. set(WARN_ALL TRUE CACHE BOOL "Enable -Wall for Release build")
  68. if(NOT CMAKE_BUILD_TYPE)
  69. # Default to release
  70. set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
  71. endif()
  72. set(ENABLE_UPDATE_CHECKER (NOT ${DEVELOPMENT_BUILD}) CACHE BOOL
  73. "Whether to enable update checks by default")
  74. # Included stuff
  75. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  76. # Load default options for Android
  77. if(ANDROID)
  78. cmake_minimum_required(VERSION 3.20)
  79. include(AndroidLibs)
  80. endif()
  81. if(TRUE)
  82. message(STATUS "Using imported IrrlichtMt at subdirectory 'irr'")
  83. if(BUILD_CLIENT)
  84. add_subdirectory(irr EXCLUDE_FROM_ALL)
  85. if(NOT TARGET IrrlichtMt)
  86. message(FATAL_ERROR "IrrlichtMt project is missing a CMake target?!")
  87. endif()
  88. else()
  89. add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
  90. set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
  91. INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/irr/include")
  92. endif()
  93. endif()
  94. if (ENABLE_LTO OR CMAKE_INTERPROCEDURAL_OPTIMIZATION)
  95. include(CheckIPOSupported)
  96. check_ipo_supported(RESULT lto_supported OUTPUT lto_output)
  97. if(lto_supported)
  98. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
  99. message(STATUS "LTO/IPO is enabled")
  100. else()
  101. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
  102. message(STATUS "LTO/IPO was requested but is not supported by the compiler: ${lto_output}")
  103. endif()
  104. else()
  105. message(STATUS "LTO/IPO is not enabled")
  106. endif()
  107. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  108. if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
  109. message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  110. "Version ${GCC_MINIMUM_VERSION} or higher is required.")
  111. endif()
  112. elseif(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang")
  113. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
  114. message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  115. "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
  116. endif()
  117. endif()
  118. # Installation
  119. if(WIN32)
  120. set(SHAREDIR ".")
  121. set(BINDIR "bin")
  122. set(DOCDIR "doc")
  123. set(EXAMPLE_CONF_DIR ".")
  124. set(LOCALEDIR "locale")
  125. elseif(APPLE)
  126. set(BUNDLE_NAME ${PROJECT_NAME}.app)
  127. set(BUNDLE_PATH "${BUNDLE_NAME}")
  128. set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
  129. set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
  130. set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
  131. set(EXAMPLE_CONF_DIR ${DOCDIR})
  132. set(LOCALEDIR "${SHAREDIR}/locale")
  133. elseif(UNIX) # Linux, BSD etc
  134. if(RUN_IN_PLACE)
  135. set(SHAREDIR ".")
  136. set(BINDIR "bin")
  137. set(DOCDIR "doc")
  138. set(EXAMPLE_CONF_DIR ".")
  139. set(MANDIR "unix/man")
  140. set(XDG_APPS_DIR "unix/applications")
  141. set(METAINFODIR "unix/metainfo")
  142. set(ICONDIR "unix/icons")
  143. set(LOCALEDIR "locale")
  144. else()
  145. include(GNUInstallDirs)
  146. set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
  147. set(BINDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  148. set(DOCDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}")
  149. set(MANDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}")
  150. set(EXAMPLE_CONF_DIR ${DOCDIR})
  151. set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/applications")
  152. set(METAINFODIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/metainfo")
  153. set(ICONDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/icons")
  154. set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")
  155. endif()
  156. endif()
  157. set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
  158. if(NOT CUSTOM_SHAREDIR STREQUAL "")
  159. set(SHAREDIR "${CUSTOM_SHAREDIR}")
  160. message(STATUS "Using SHAREDIR=${SHAREDIR}")
  161. endif()
  162. set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into")
  163. if(NOT CUSTOM_BINDIR STREQUAL "")
  164. set(BINDIR "${CUSTOM_BINDIR}")
  165. message(STATUS "Using BINDIR=${BINDIR}")
  166. endif()
  167. set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
  168. if(NOT CUSTOM_DOCDIR STREQUAL "")
  169. set(DOCDIR "${CUSTOM_DOCDIR}")
  170. if(NOT RUN_IN_PLACE)
  171. set(EXAMPLE_CONF_DIR ${DOCDIR})
  172. endif()
  173. message(STATUS "Using DOCDIR=${DOCDIR}")
  174. endif()
  175. set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
  176. if(NOT CUSTOM_MANDIR STREQUAL "")
  177. set(MANDIR "${CUSTOM_MANDIR}")
  178. message(STATUS "Using MANDIR=${MANDIR}")
  179. endif()
  180. set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
  181. if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
  182. set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
  183. message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
  184. endif()
  185. set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
  186. if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
  187. set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
  188. message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
  189. endif()
  190. set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
  191. if(NOT CUSTOM_ICONDIR STREQUAL "")
  192. set(ICONDIR "${CUSTOM_ICONDIR}")
  193. message(STATUS "Using ICONDIR=${ICONDIR}")
  194. endif()
  195. set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
  196. if(NOT CUSTOM_LOCALEDIR STREQUAL "")
  197. set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
  198. message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
  199. endif()
  200. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
  201. if(RUN_IN_PLACE)
  202. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
  203. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
  204. endif()
  205. set(INSTALL_DEVTEST FALSE CACHE BOOL "Install Development Test")
  206. if(INSTALL_DEVTEST)
  207. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
  208. PATTERN ".git*" EXCLUDE )
  209. endif()
  210. if(BUILD_CLIENT)
  211. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
  212. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
  213. if(RUN_IN_PLACE)
  214. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
  215. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
  216. endif()
  217. endif()
  218. install(FILES "README.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  219. install(FILES "doc/lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  220. install(FILES "doc/client_lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  221. install(FILES "doc/menu_lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  222. install(FILES "doc/texture_packs.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  223. install(FILES "doc/world_format.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  224. install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
  225. if(UNIX AND NOT APPLE)
  226. install(FILES "doc/luanti.6" "doc/luantiserver.6" DESTINATION "${MANDIR}/man6")
  227. install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
  228. install(FILES "misc/net.minetest.minetest.metainfo.xml" DESTINATION "${METAINFODIR}")
  229. install(FILES "misc/luanti.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
  230. install(FILES "misc/luanti-xorg-icon-128.png"
  231. DESTINATION "${ICONDIR}/hicolor/128x128/apps"
  232. RENAME "luanti.png")
  233. endif()
  234. if(APPLE)
  235. install(FILES "misc/luanti-icon.icns" DESTINATION "${SHAREDIR}")
  236. install(FILES "${CMAKE_BINARY_DIR}/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
  237. endif()
  238. if(CMAKE_GENERATOR STREQUAL "Xcode")
  239. set(client_RESOURCES "${CMAKE_SOURCE_DIR}/misc/luanti-icon.icns")
  240. endif()
  241. # Library pack
  242. find_package(GMP REQUIRED)
  243. find_package(Json 1.0.0 REQUIRED)
  244. find_package(Lua REQUIRED)
  245. if(NOT USE_LUAJIT)
  246. add_subdirectory(lib/bitop)
  247. endif()
  248. add_subdirectory(lib/sha256)
  249. if(BUILD_UNITTESTS OR BUILD_BENCHMARKS)
  250. add_subdirectory(lib/catch2)
  251. endif()
  252. add_subdirectory(lib/tiniergltf)
  253. # Subdirectories
  254. # Be sure to add all relevant definitions above this
  255. add_subdirectory(src)
  256. # CPack
  257. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A free open-source voxel game engine with easy modding and game creation.")
  258. set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
  259. set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
  260. set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
  261. set(CPACK_PACKAGE_VENDOR "celeron55")
  262. set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
  263. include(CPackComponent)
  264. cpack_add_component(Docs
  265. DISPLAY_NAME "Documentation"
  266. DESCRIPTION "Documentation about ${PROJECT_NAME_CAPITALIZED} and ${PROJECT_NAME_CAPITALIZED} modding"
  267. )
  268. if(WIN32)
  269. # Include all dynamically linked runtime libraries such as MSVCRxxx.dll
  270. include(InstallRequiredSystemLibraries)
  271. if(RUN_IN_PLACE)
  272. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  273. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
  274. else()
  275. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
  276. endif()
  277. set(CPACK_GENERATOR ZIP)
  278. else()
  279. set(CPACK_GENERATOR WIX)
  280. set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
  281. set(CPACK_PACKAGE_INSTALL_DIRECTORY ".")
  282. set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
  283. set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
  284. set(CPACK_PACKAGING_INSTALL_PREFIX "/${PROJECT_NAME_CAPITALIZED}")
  285. set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/misc/luanti-icon.ico")
  286. # Supported languages can be found at
  287. # http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
  288. #set(CPACK_WIX_CULTURES "ar-SA,bg-BG,ca-ES,hr-HR,cs-CZ,da-DK,nl-NL,en-US,et-EE,fi-FI,fr-FR,de-DE")
  289. set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_BANNER.BMP")
  290. set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_DIALOG.BMP")
  291. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/lgpl-2.1.txt")
  292. # The correct way would be to include both x32 and x64 into one installer
  293. # and install the appropriate one.
  294. # CMake does not support that, so there are two separate GUID's
  295. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  296. set(CPACK_WIX_UPGRADE_GUID "745A0FB3-5552-44CA-A587-A91C397CCC56")
  297. else()
  298. set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
  299. endif()
  300. endif()
  301. elseif(APPLE)
  302. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  303. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
  304. set(CPACK_GENERATOR ZIP)
  305. else()
  306. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
  307. set(CPACK_GENERATOR TGZ)
  308. set(CPACK_SOURCE_GENERATOR TGZ)
  309. endif()
  310. include(CPack)
  311. # Add a target to generate API documentation with Doxygen
  312. if(BUILD_DOCUMENTATION)
  313. find_package(Doxygen)
  314. if(DOXYGEN_FOUND)
  315. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
  316. ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
  317. add_custom_target(doc
  318. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
  319. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
  320. COMMENT "Generating API documentation with Doxygen" VERBATIM
  321. )
  322. endif()
  323. endif()
  324. # Fetch Tracy
  325. if(BUILD_WITH_TRACY)
  326. include(FetchContent)
  327. message(STATUS "Fetching Tracy (${FETCH_TRACY_GIT_TAG})...")
  328. FetchContent_Declare(
  329. tracy
  330. GIT_REPOSITORY https://github.com/wolfpld/tracy.git
  331. GIT_TAG ${FETCH_TRACY_GIT_TAG}
  332. GIT_SHALLOW TRUE
  333. GIT_PROGRESS TRUE
  334. )
  335. FetchContent_MakeAvailable(tracy)
  336. message(STATUS "Fetching Tracy - done")
  337. endif()