CMakeLists.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. cmake_minimum_required(VERSION 3.12)
  2. # This can be read from ${PROJECT_NAME} after project() is called
  3. project(minetest)
  4. set(PROJECT_NAME_CAPITALIZED "Minetest")
  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 9)
  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(DEFAULT_RUN_IN_PLACE FALSE)
  51. if(WIN32)
  52. set(DEFAULT_RUN_IN_PLACE TRUE)
  53. endif()
  54. set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL
  55. "Run directly in source directory structure")
  56. message(STATUS "*** Will build version ${VERSION_STRING} ***")
  57. message(STATUS "BUILD_CLIENT: " ${BUILD_CLIENT})
  58. message(STATUS "BUILD_SERVER: " ${BUILD_SERVER})
  59. message(STATUS "BUILD_UNITTESTS: " ${BUILD_UNITTESTS})
  60. message(STATUS "BUILD_BENCHMARKS: " ${BUILD_BENCHMARKS})
  61. message(STATUS "BUILD_DOCUMENTATION: " ${BUILD_DOCUMENTATION})
  62. message(STATUS "RUN_IN_PLACE: " ${RUN_IN_PLACE})
  63. set(WARN_ALL TRUE CACHE BOOL "Enable -Wall for Release build")
  64. if(NOT CMAKE_BUILD_TYPE)
  65. # Default to release
  66. set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
  67. endif()
  68. set(ENABLE_UPDATE_CHECKER (NOT ${DEVELOPMENT_BUILD}) CACHE BOOL
  69. "Whether to enable update checks by default")
  70. # Included stuff
  71. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  72. # Load default options for Android
  73. if(ANDROID)
  74. cmake_minimum_required(VERSION 3.20)
  75. include(MinetestAndroidLibs)
  76. endif()
  77. if(TRUE)
  78. message(STATUS "Using imported IrrlichtMt at subdirectory 'irr'")
  79. if(BUILD_CLIENT)
  80. add_subdirectory(irr EXCLUDE_FROM_ALL)
  81. if(NOT TARGET IrrlichtMt)
  82. message(FATAL_ERROR "IrrlichtMt project is missing a CMake target?!")
  83. endif()
  84. else()
  85. add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
  86. set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
  87. INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/irr/include")
  88. endif()
  89. endif()
  90. if (ENABLE_LTO OR CMAKE_INTERPROCEDURAL_OPTIMIZATION)
  91. include(CheckIPOSupported)
  92. check_ipo_supported(RESULT lto_supported OUTPUT lto_output)
  93. if(lto_supported)
  94. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
  95. message(STATUS "LTO/IPO is enabled")
  96. else()
  97. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
  98. message(STATUS "LTO/IPO was requested but is not supported by the compiler: ${lto_output}")
  99. endif()
  100. else()
  101. message(STATUS "LTO/IPO is not enabled")
  102. endif()
  103. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  104. if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
  105. message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  106. "Version ${GCC_MINIMUM_VERSION} or higher is required.")
  107. endif()
  108. elseif(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang")
  109. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
  110. message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  111. "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
  112. endif()
  113. endif()
  114. # Installation
  115. if(WIN32)
  116. set(SHAREDIR ".")
  117. set(BINDIR "bin")
  118. set(DOCDIR "doc")
  119. set(EXAMPLE_CONF_DIR ".")
  120. set(LOCALEDIR "locale")
  121. elseif(APPLE)
  122. set(BUNDLE_NAME ${PROJECT_NAME}.app)
  123. set(BUNDLE_PATH "${BUNDLE_NAME}")
  124. set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
  125. set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
  126. set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
  127. set(EXAMPLE_CONF_DIR ${DOCDIR})
  128. set(LOCALEDIR "${SHAREDIR}/locale")
  129. elseif(UNIX) # Linux, BSD etc
  130. if(RUN_IN_PLACE)
  131. set(SHAREDIR ".")
  132. set(BINDIR "bin")
  133. set(DOCDIR "doc")
  134. set(EXAMPLE_CONF_DIR ".")
  135. set(MANDIR "unix/man")
  136. set(XDG_APPS_DIR "unix/applications")
  137. set(APPDATADIR "unix/metainfo")
  138. set(ICONDIR "unix/icons")
  139. set(LOCALEDIR "locale")
  140. else()
  141. include(GNUInstallDirs)
  142. set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
  143. set(BINDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  144. set(DOCDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}")
  145. set(MANDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}")
  146. set(EXAMPLE_CONF_DIR ${DOCDIR})
  147. set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/applications")
  148. set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/metainfo")
  149. set(ICONDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/icons")
  150. set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")
  151. endif()
  152. endif()
  153. set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
  154. if(NOT CUSTOM_SHAREDIR STREQUAL "")
  155. set(SHAREDIR "${CUSTOM_SHAREDIR}")
  156. message(STATUS "Using SHAREDIR=${SHAREDIR}")
  157. endif()
  158. set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into")
  159. if(NOT CUSTOM_BINDIR STREQUAL "")
  160. set(BINDIR "${CUSTOM_BINDIR}")
  161. message(STATUS "Using BINDIR=${BINDIR}")
  162. endif()
  163. set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
  164. if(NOT CUSTOM_DOCDIR STREQUAL "")
  165. set(DOCDIR "${CUSTOM_DOCDIR}")
  166. if(NOT RUN_IN_PLACE)
  167. set(EXAMPLE_CONF_DIR ${DOCDIR})
  168. endif()
  169. message(STATUS "Using DOCDIR=${DOCDIR}")
  170. endif()
  171. set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
  172. if(NOT CUSTOM_MANDIR STREQUAL "")
  173. set(MANDIR "${CUSTOM_MANDIR}")
  174. message(STATUS "Using MANDIR=${MANDIR}")
  175. endif()
  176. set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
  177. if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
  178. set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
  179. message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
  180. endif()
  181. set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
  182. if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
  183. set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
  184. message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
  185. endif()
  186. set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
  187. if(NOT CUSTOM_ICONDIR STREQUAL "")
  188. set(ICONDIR "${CUSTOM_ICONDIR}")
  189. message(STATUS "Using ICONDIR=${ICONDIR}")
  190. endif()
  191. set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
  192. if(NOT CUSTOM_LOCALEDIR STREQUAL "")
  193. set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
  194. message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
  195. endif()
  196. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
  197. if(RUN_IN_PLACE)
  198. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
  199. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
  200. endif()
  201. set(INSTALL_DEVTEST FALSE CACHE BOOL "Install Development Test")
  202. if(INSTALL_DEVTEST)
  203. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
  204. PATTERN ".git*" EXCLUDE )
  205. endif()
  206. if(BUILD_CLIENT)
  207. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
  208. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
  209. if(RUN_IN_PLACE)
  210. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
  211. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
  212. endif()
  213. endif()
  214. install(FILES "README.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  215. install(FILES "doc/lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  216. install(FILES "doc/client_lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  217. install(FILES "doc/menu_lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  218. install(FILES "doc/texture_packs.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  219. install(FILES "doc/world_format.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  220. install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
  221. if(UNIX AND NOT APPLE)
  222. install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
  223. install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
  224. install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}")
  225. install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
  226. install(FILES "misc/minetest-xorg-icon-128.png"
  227. DESTINATION "${ICONDIR}/hicolor/128x128/apps"
  228. RENAME "minetest.png")
  229. endif()
  230. if(APPLE)
  231. install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
  232. install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
  233. endif()
  234. # Library pack
  235. find_package(GMP REQUIRED)
  236. find_package(Json REQUIRED)
  237. find_package(Lua REQUIRED)
  238. if(NOT USE_LUAJIT)
  239. add_subdirectory(lib/bitop)
  240. endif()
  241. add_subdirectory(lib/sha256)
  242. if(BUILD_UNITTESTS OR BUILD_BENCHMARKS)
  243. add_subdirectory(lib/catch2)
  244. endif()
  245. # Subdirectories
  246. # Be sure to add all relevant definitions above this
  247. add_subdirectory(src)
  248. # CPack
  249. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A free open-source voxel game engine with easy modding and game creation.")
  250. set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
  251. set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
  252. set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
  253. set(CPACK_PACKAGE_VENDOR "celeron55")
  254. set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
  255. include(CPackComponent)
  256. cpack_add_component(Docs
  257. DISPLAY_NAME "Documentation"
  258. DESCRIPTION "Documentation about Minetest and Minetest modding"
  259. )
  260. if(WIN32)
  261. # Include all dynamically linked runtime libraries such as MSVCRxxx.dll
  262. include(InstallRequiredSystemLibraries)
  263. if(RUN_IN_PLACE)
  264. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  265. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
  266. else()
  267. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
  268. endif()
  269. set(CPACK_GENERATOR ZIP)
  270. else()
  271. set(CPACK_GENERATOR WIX)
  272. set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
  273. set(CPACK_PACKAGE_INSTALL_DIRECTORY ".")
  274. set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
  275. set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
  276. set(CPACK_PACKAGING_INSTALL_PREFIX "/${PROJECT_NAME_CAPITALIZED}")
  277. set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/misc/minetest-icon.ico")
  278. # Supported languages can be found at
  279. # http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
  280. #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")
  281. set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_BANNER.BMP")
  282. set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_DIALOG.BMP")
  283. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/lgpl-2.1.txt")
  284. # The correct way would be to include both x32 and x64 into one installer
  285. # and install the appropriate one.
  286. # CMake does not support that, so there are two separate GUID's
  287. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  288. set(CPACK_WIX_UPGRADE_GUID "745A0FB3-5552-44CA-A587-A91C397CCC56")
  289. else()
  290. set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
  291. endif()
  292. endif()
  293. elseif(APPLE)
  294. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  295. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
  296. set(CPACK_GENERATOR ZIP)
  297. else()
  298. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
  299. set(CPACK_GENERATOR TGZ)
  300. set(CPACK_SOURCE_GENERATOR TGZ)
  301. endif()
  302. include(CPack)
  303. # Add a target to generate API documentation with Doxygen
  304. if(BUILD_DOCUMENTATION)
  305. find_package(Doxygen)
  306. if(DOXYGEN_FOUND)
  307. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
  308. ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
  309. add_custom_target(doc
  310. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
  311. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
  312. COMMENT "Generating API documentation with Doxygen" VERBATIM
  313. )
  314. endif()
  315. endif()