CMakeLists.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. cmake_minimum_required(VERSION 3.5)
  2. # Set policies up to 3.9 since we want to enable the IPO option
  3. if(${CMAKE_VERSION} VERSION_LESS 3.9)
  4. cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
  5. else()
  6. cmake_policy(VERSION 3.9)
  7. endif()
  8. # This can be read from ${PROJECT_NAME} after project() is called
  9. project(minetest)
  10. set(PROJECT_NAME_CAPITALIZED "Minetest")
  11. set(CMAKE_CXX_STANDARD 14)
  12. set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
  13. set(GCC_MINIMUM_VERSION "5.1")
  14. set(CLANG_MINIMUM_VERSION "3.5")
  15. # You should not need to edit these manually, use util/bump_version.sh
  16. set(VERSION_MAJOR 5)
  17. set(VERSION_MINOR 8)
  18. set(VERSION_PATCH 0)
  19. set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
  20. # Change to false for releases
  21. set(DEVELOPMENT_BUILD TRUE)
  22. set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
  23. if(VERSION_EXTRA)
  24. set(VERSION_STRING "${VERSION_STRING}-${VERSION_EXTRA}")
  25. elseif(DEVELOPMENT_BUILD)
  26. set(VERSION_STRING "${VERSION_STRING}-dev")
  27. endif()
  28. if (CMAKE_BUILD_TYPE STREQUAL Debug)
  29. # Append "-debug" to version string
  30. set(VERSION_STRING "${VERSION_STRING}-debug")
  31. endif()
  32. message(STATUS "*** Will build version ${VERSION_STRING} ***")
  33. # Configuration options
  34. set(DEFAULT_RUN_IN_PLACE FALSE)
  35. if(WIN32)
  36. set(DEFAULT_RUN_IN_PLACE TRUE)
  37. endif()
  38. set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL
  39. "Run directly in source directory structure")
  40. set(BUILD_CLIENT TRUE CACHE BOOL "Build client")
  41. set(BUILD_SERVER FALSE CACHE BOOL "Build server")
  42. set(BUILD_UNITTESTS TRUE CACHE BOOL "Build unittests")
  43. set(BUILD_BENCHMARKS FALSE CACHE BOOL "Build benchmarks")
  44. set(WARN_ALL TRUE CACHE BOOL "Enable -Wall for Release build")
  45. if(NOT CMAKE_BUILD_TYPE)
  46. # Default to release
  47. set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
  48. endif()
  49. set(ENABLE_UPDATE_CHECKER (NOT ${DEVELOPMENT_BUILD}) CACHE BOOL
  50. "Whether to enable update checks by default")
  51. # Included stuff
  52. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  53. # Load default options for Android
  54. if(ANDROID)
  55. cmake_minimum_required(VERSION 3.20)
  56. include(MinetestAndroidLibs)
  57. endif()
  58. set(IRRLICHTMT_BUILD_DIR "" CACHE PATH "Path to IrrlichtMt build directory.")
  59. if(ANDROID)
  60. # currently manually provided
  61. elseif(NOT "${IRRLICHTMT_BUILD_DIR}" STREQUAL "")
  62. find_package(IrrlichtMt QUIET
  63. PATHS "${IRRLICHTMT_BUILD_DIR}"
  64. NO_DEFAULT_PATH
  65. )
  66. if(NOT TARGET IrrlichtMt::IrrlichtMt)
  67. # find_package() searches certain subdirectories. ${PATH}/cmake is not
  68. # the only one, but it is the one where IrrlichtMt is supposed to export
  69. # IrrlichtMtConfig.cmake
  70. message(FATAL_ERROR "Could not find IrrlichtMtConfig.cmake in ${IRRLICHTMT_BUILD_DIR}/cmake.")
  71. endif()
  72. elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt")
  73. message(STATUS "Using user-provided IrrlichtMt at subdirectory 'lib/irrlichtmt'")
  74. if(BUILD_CLIENT)
  75. # tell IrrlichtMt to create a static library
  76. set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared library" FORCE)
  77. add_subdirectory(lib/irrlichtmt EXCLUDE_FROM_ALL)
  78. unset(BUILD_SHARED_LIBS CACHE)
  79. if(NOT TARGET IrrlichtMt)
  80. message(FATAL_ERROR "IrrlichtMt project is missing a CMake target?!")
  81. endif()
  82. else()
  83. add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
  84. set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
  85. INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt/include")
  86. endif()
  87. else()
  88. find_package(IrrlichtMt QUIET)
  89. if(NOT TARGET IrrlichtMt::IrrlichtMt)
  90. string(CONCAT explanation_msg
  91. "The Minetest team has forked Irrlicht to make their own customizations. "
  92. "It can be found here: https://github.com/minetest/irrlicht\n"
  93. "For example use: git clone --depth=1 https://github.com/minetest/irrlicht lib/irrlichtmt\n")
  94. if(BUILD_CLIENT)
  95. message(FATAL_ERROR "IrrlichtMt is required to build the client, but it was not found.\n${explanation_msg}")
  96. endif()
  97. include(MinetestFindIrrlichtHeaders)
  98. if(NOT IRRLICHT_INCLUDE_DIR)
  99. message(FATAL_ERROR "IrrlichtMt headers are required to build the server, but none found.\n${explanation_msg}")
  100. endif()
  101. message(STATUS "Found IrrlichtMt headers: ${IRRLICHT_INCLUDE_DIR}")
  102. add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
  103. # Note that we can't use target_include_directories() since that doesn't work for IMPORTED targets before CMake 3.11
  104. set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
  105. INTERFACE_INCLUDE_DIRECTORIES "${IRRLICHT_INCLUDE_DIR}")
  106. endif()
  107. endif()
  108. if(ANDROID)
  109. # skipped for now
  110. elseif(BUILD_CLIENT AND TARGET IrrlichtMt::IrrlichtMt)
  111. # retrieve version somehow
  112. if(NOT IrrlichtMt_VERSION)
  113. get_target_property(IrrlichtMt_VERSION IrrlichtMt VERSION)
  114. endif()
  115. message(STATUS "Found IrrlichtMt ${IrrlichtMt_VERSION}")
  116. set(TARGET_VER_S 1.9.0mt11)
  117. string(REPLACE "mt" "." TARGET_VER ${TARGET_VER_S})
  118. if(IrrlichtMt_VERSION VERSION_LESS ${TARGET_VER})
  119. message(FATAL_ERROR "At least IrrlichtMt ${TARGET_VER_S} is required to build")
  120. elseif(NOT DEVELOPMENT_BUILD AND IrrlichtMt_VERSION VERSION_GREATER ${TARGET_VER})
  121. message(FATAL_ERROR "IrrlichtMt ${TARGET_VER_S} is required to build")
  122. endif()
  123. endif()
  124. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  125. if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
  126. message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  127. "Version ${GCC_MINIMUM_VERSION} or higher is required.")
  128. endif()
  129. elseif(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang")
  130. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
  131. message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  132. "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
  133. endif()
  134. endif()
  135. # Installation
  136. if(WIN32)
  137. set(SHAREDIR ".")
  138. set(BINDIR "bin")
  139. set(DOCDIR "doc")
  140. set(EXAMPLE_CONF_DIR ".")
  141. set(LOCALEDIR "locale")
  142. elseif(APPLE)
  143. set(BUNDLE_NAME ${PROJECT_NAME}.app)
  144. set(BUNDLE_PATH "${BUNDLE_NAME}")
  145. set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
  146. set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
  147. set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
  148. set(EXAMPLE_CONF_DIR ${DOCDIR})
  149. set(LOCALEDIR "${SHAREDIR}/locale")
  150. elseif(UNIX) # Linux, BSD etc
  151. if(RUN_IN_PLACE)
  152. set(SHAREDIR ".")
  153. set(BINDIR "bin")
  154. set(DOCDIR "doc")
  155. set(EXAMPLE_CONF_DIR ".")
  156. set(MANDIR "unix/man")
  157. set(XDG_APPS_DIR "unix/applications")
  158. set(APPDATADIR "unix/metainfo")
  159. set(ICONDIR "unix/icons")
  160. set(LOCALEDIR "locale")
  161. else()
  162. include(GNUInstallDirs)
  163. set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
  164. set(BINDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  165. set(DOCDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}")
  166. set(MANDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}")
  167. set(EXAMPLE_CONF_DIR ${DOCDIR})
  168. set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/applications")
  169. set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/metainfo")
  170. set(ICONDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/icons")
  171. set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")
  172. endif()
  173. endif()
  174. set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
  175. if(NOT CUSTOM_SHAREDIR STREQUAL "")
  176. set(SHAREDIR "${CUSTOM_SHAREDIR}")
  177. message(STATUS "Using SHAREDIR=${SHAREDIR}")
  178. endif()
  179. set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into")
  180. if(NOT CUSTOM_BINDIR STREQUAL "")
  181. set(BINDIR "${CUSTOM_BINDIR}")
  182. message(STATUS "Using BINDIR=${BINDIR}")
  183. endif()
  184. set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
  185. if(NOT CUSTOM_DOCDIR STREQUAL "")
  186. set(DOCDIR "${CUSTOM_DOCDIR}")
  187. if(NOT RUN_IN_PLACE)
  188. set(EXAMPLE_CONF_DIR ${DOCDIR})
  189. endif()
  190. message(STATUS "Using DOCDIR=${DOCDIR}")
  191. endif()
  192. set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
  193. if(NOT CUSTOM_MANDIR STREQUAL "")
  194. set(MANDIR "${CUSTOM_MANDIR}")
  195. message(STATUS "Using MANDIR=${MANDIR}")
  196. endif()
  197. set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
  198. if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
  199. set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
  200. message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
  201. endif()
  202. set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
  203. if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
  204. set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
  205. message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
  206. endif()
  207. set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
  208. if(NOT CUSTOM_ICONDIR STREQUAL "")
  209. set(ICONDIR "${CUSTOM_ICONDIR}")
  210. message(STATUS "Using ICONDIR=${ICONDIR}")
  211. endif()
  212. set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
  213. if(NOT CUSTOM_LOCALEDIR STREQUAL "")
  214. set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
  215. message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
  216. endif()
  217. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
  218. if(RUN_IN_PLACE)
  219. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
  220. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
  221. endif()
  222. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game" DESTINATION "${SHAREDIR}/games/"
  223. COMPONENT "SUBGAME_MINETEST_GAME" OPTIONAL PATTERN ".git*" EXCLUDE )
  224. set(INSTALL_DEVTEST FALSE CACHE BOOL "Install Development Test")
  225. if(INSTALL_DEVTEST)
  226. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
  227. PATTERN ".git*" EXCLUDE )
  228. endif()
  229. if(BUILD_CLIENT)
  230. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
  231. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
  232. if(RUN_IN_PLACE)
  233. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
  234. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
  235. endif()
  236. endif()
  237. install(FILES "README.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  238. install(FILES "doc/lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  239. install(FILES "doc/client_lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  240. install(FILES "doc/menu_lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  241. install(FILES "doc/texture_packs.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  242. install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  243. install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
  244. if(UNIX AND NOT APPLE)
  245. install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
  246. install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
  247. install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}")
  248. install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
  249. install(FILES "misc/minetest-xorg-icon-128.png"
  250. DESTINATION "${ICONDIR}/hicolor/128x128/apps"
  251. RENAME "minetest.png")
  252. endif()
  253. if(APPLE)
  254. install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
  255. install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
  256. endif()
  257. # Library pack
  258. find_package(GMP REQUIRED)
  259. find_package(Json REQUIRED)
  260. find_package(Lua REQUIRED)
  261. if(NOT USE_LUAJIT)
  262. add_subdirectory(lib/bitop)
  263. endif()
  264. if(BUILD_BENCHMARKS)
  265. add_subdirectory(lib/catch2)
  266. endif()
  267. # Subdirectories
  268. # Be sure to add all relevant definitions above this
  269. add_subdirectory(src)
  270. # CPack
  271. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A free open-source voxel game engine with easy modding and game creation.")
  272. set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
  273. set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
  274. set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
  275. set(CPACK_PACKAGE_VENDOR "celeron55")
  276. set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
  277. include(CPackComponent)
  278. cpack_add_component(Docs
  279. DISPLAY_NAME "Documentation"
  280. DESCRIPTION "Documentation about Minetest and Minetest modding"
  281. )
  282. cpack_add_component(SUBGAME_MINETEST_GAME
  283. DISPLAY_NAME "Minetest Game"
  284. DESCRIPTION "The default game bundled in the Minetest engine. Mainly used as a modding base."
  285. GROUP "Games"
  286. )
  287. cpack_add_component_group(Subgames
  288. DESCRIPTION "Games for the Minetest engine."
  289. )
  290. if(WIN32)
  291. # Include all dynamically linked runtime libraries such as MSVCRxxx.dll
  292. include(InstallRequiredSystemLibraries)
  293. if(RUN_IN_PLACE)
  294. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  295. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
  296. else()
  297. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
  298. endif()
  299. set(CPACK_GENERATOR ZIP)
  300. else()
  301. set(CPACK_GENERATOR WIX)
  302. set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
  303. set(CPACK_PACKAGE_INSTALL_DIRECTORY ".")
  304. set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
  305. set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
  306. set(CPACK_PACKAGING_INSTALL_PREFIX "/${PROJECT_NAME_CAPITALIZED}")
  307. set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/misc/minetest-icon.ico")
  308. # Supported languages can be found at
  309. # http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
  310. #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")
  311. set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_BANNER.BMP")
  312. set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_DIALOG.BMP")
  313. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/lgpl-2.1.txt")
  314. # The correct way would be to include both x32 and x64 into one installer
  315. # and install the appropriate one.
  316. # CMake does not support that, so there are two separate GUID's
  317. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  318. set(CPACK_WIX_UPGRADE_GUID "745A0FB3-5552-44CA-A587-A91C397CCC56")
  319. else()
  320. set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
  321. endif()
  322. endif()
  323. elseif(APPLE)
  324. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  325. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
  326. set(CPACK_GENERATOR ZIP)
  327. else()
  328. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
  329. set(CPACK_GENERATOR TGZ)
  330. set(CPACK_SOURCE_GENERATOR TGZ)
  331. endif()
  332. include(CPack)
  333. # Add a target to generate API documentation with Doxygen
  334. find_package(Doxygen)
  335. if(DOXYGEN_FOUND)
  336. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
  337. ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
  338. add_custom_target(doc
  339. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
  340. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
  341. COMMENT "Generating API documentation with Doxygen" VERBATIM
  342. )
  343. endif()