CMakeLists.txt 14 KB

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