2
0

CMakeLists.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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 6)
  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. # Included stuff
  50. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  51. set(IRRLICHTMT_BUILD_DIR "" CACHE PATH "Path to IrrlichtMt build directory.")
  52. if(NOT "${IRRLICHTMT_BUILD_DIR}" STREQUAL "")
  53. find_package(IrrlichtMt QUIET
  54. PATHS "${IRRLICHTMT_BUILD_DIR}"
  55. NO_DEFAULT_PATH
  56. )
  57. if(NOT TARGET IrrlichtMt::IrrlichtMt)
  58. # find_package() searches certain subdirectories. ${PATH}/cmake is not
  59. # the only one, but it is the one where IrrlichtMt is supposed to export
  60. # IrrlichtMtConfig.cmake
  61. message(FATAL_ERROR "Could not find IrrlichtMtConfig.cmake in ${IRRLICHTMT_BUILD_DIR}/cmake.")
  62. endif()
  63. elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt")
  64. message(STATUS "Using user-provided IrrlichtMt at subdirectory 'lib/irrlichtmt'")
  65. if(BUILD_CLIENT)
  66. # tell IrrlichtMt to create a static library
  67. set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared library" FORCE)
  68. add_subdirectory(lib/irrlichtmt EXCLUDE_FROM_ALL)
  69. unset(BUILD_SHARED_LIBS CACHE)
  70. if(NOT TARGET IrrlichtMt)
  71. message(FATAL_ERROR "IrrlichtMt project is missing a CMake target?!")
  72. endif()
  73. else()
  74. add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
  75. set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
  76. INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt/include")
  77. endif()
  78. else()
  79. find_package(IrrlichtMt QUIET)
  80. if(NOT TARGET IrrlichtMt::IrrlichtMt)
  81. string(CONCAT explanation_msg
  82. "The Minetest team has forked Irrlicht to make their own customizations. "
  83. "It can be found here: https://github.com/minetest/irrlicht\n"
  84. "For example use: git clone --depth=1 https://github.com/minetest/irrlicht lib/irrlichtmt\n")
  85. if(BUILD_CLIENT)
  86. message(FATAL_ERROR "IrrlichtMt is required to build the client, but it was not found.\n${explanation_msg}")
  87. endif()
  88. include(MinetestFindIrrlichtHeaders)
  89. if(NOT IRRLICHT_INCLUDE_DIR)
  90. message(FATAL_ERROR "IrrlichtMt headers are required to build the server, but none found.\n${explanation_msg}")
  91. endif()
  92. message(STATUS "Found IrrlichtMt headers: ${IRRLICHT_INCLUDE_DIR}")
  93. add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
  94. # Note that we can't use target_include_directories() since that doesn't work for IMPORTED targets before CMake 3.11
  95. set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
  96. INTERFACE_INCLUDE_DIRECTORIES "${IRRLICHT_INCLUDE_DIR}")
  97. endif()
  98. endif()
  99. if(BUILD_CLIENT AND TARGET IrrlichtMt::IrrlichtMt)
  100. # retrieve version somehow
  101. if(NOT IrrlichtMt_VERSION)
  102. get_target_property(IrrlichtMt_VERSION IrrlichtMt VERSION)
  103. endif()
  104. message(STATUS "Found IrrlichtMt ${IrrlichtMt_VERSION}")
  105. set(TARGET_VER_S 1.9.0mt7)
  106. string(REPLACE "mt" "." TARGET_VER ${TARGET_VER_S})
  107. if(IrrlichtMt_VERSION VERSION_LESS ${TARGET_VER})
  108. message(FATAL_ERROR "At least IrrlichtMt ${TARGET_VER_S} is required to build")
  109. elseif(NOT DEVELOPMENT_BUILD AND IrrlichtMt_VERSION VERSION_GREATER ${TARGET_VER})
  110. message(FATAL_ERROR "IrrlichtMt ${TARGET_VER_S} is required to build")
  111. endif()
  112. endif()
  113. # Installation
  114. if(WIN32)
  115. set(SHAREDIR ".")
  116. set(BINDIR "bin")
  117. set(DOCDIR "doc")
  118. set(EXAMPLE_CONF_DIR ".")
  119. set(LOCALEDIR "locale")
  120. elseif(APPLE)
  121. set(BUNDLE_NAME ${PROJECT_NAME}.app)
  122. set(BUNDLE_PATH "${BUNDLE_NAME}")
  123. set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
  124. set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
  125. set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
  126. set(EXAMPLE_CONF_DIR ${DOCDIR})
  127. set(LOCALEDIR "${SHAREDIR}/locale")
  128. elseif(UNIX) # Linux, BSD etc
  129. if(RUN_IN_PLACE)
  130. set(SHAREDIR ".")
  131. set(BINDIR "bin")
  132. set(DOCDIR "doc")
  133. set(EXAMPLE_CONF_DIR ".")
  134. set(MANDIR "unix/man")
  135. set(XDG_APPS_DIR "unix/applications")
  136. set(APPDATADIR "unix/metainfo")
  137. set(ICONDIR "unix/icons")
  138. set(LOCALEDIR "locale")
  139. else()
  140. include(GNUInstallDirs)
  141. set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
  142. set(BINDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  143. set(DOCDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}")
  144. set(MANDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}")
  145. set(EXAMPLE_CONF_DIR ${DOCDIR})
  146. set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/applications")
  147. set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/metainfo")
  148. set(ICONDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/icons")
  149. set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")
  150. endif()
  151. endif()
  152. set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
  153. if(NOT CUSTOM_SHAREDIR STREQUAL "")
  154. set(SHAREDIR "${CUSTOM_SHAREDIR}")
  155. message(STATUS "Using SHAREDIR=${SHAREDIR}")
  156. endif()
  157. set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into")
  158. if(NOT CUSTOM_BINDIR STREQUAL "")
  159. set(BINDIR "${CUSTOM_BINDIR}")
  160. message(STATUS "Using BINDIR=${BINDIR}")
  161. endif()
  162. set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
  163. if(NOT CUSTOM_DOCDIR STREQUAL "")
  164. set(DOCDIR "${CUSTOM_DOCDIR}")
  165. if(NOT RUN_IN_PLACE)
  166. set(EXAMPLE_CONF_DIR ${DOCDIR})
  167. endif()
  168. message(STATUS "Using DOCDIR=${DOCDIR}")
  169. endif()
  170. set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
  171. if(NOT CUSTOM_MANDIR STREQUAL "")
  172. set(MANDIR "${CUSTOM_MANDIR}")
  173. message(STATUS "Using MANDIR=${MANDIR}")
  174. endif()
  175. set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
  176. if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
  177. set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
  178. message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
  179. endif()
  180. set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
  181. if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
  182. set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
  183. message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
  184. endif()
  185. set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
  186. if(NOT CUSTOM_ICONDIR STREQUAL "")
  187. set(ICONDIR "${CUSTOM_ICONDIR}")
  188. message(STATUS "Using ICONDIR=${ICONDIR}")
  189. endif()
  190. set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
  191. if(NOT CUSTOM_LOCALEDIR STREQUAL "")
  192. set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
  193. message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
  194. endif()
  195. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
  196. if(RUN_IN_PLACE)
  197. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
  198. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
  199. endif()
  200. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game" DESTINATION "${SHAREDIR}/games/"
  201. COMPONENT "SUBGAME_MINETEST_GAME" OPTIONAL PATTERN ".git*" EXCLUDE )
  202. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
  203. COMPONENT "SUBGAME_MINIMAL" OPTIONAL PATTERN ".git*" EXCLUDE )
  204. if(BUILD_CLIENT)
  205. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
  206. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
  207. if(RUN_IN_PLACE)
  208. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
  209. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
  210. endif()
  211. endif()
  212. install(FILES "README.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  213. install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  214. install(FILES "doc/client_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  215. install(FILES "doc/menu_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  216. install(FILES "doc/texture_packs.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  217. install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  218. install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
  219. if(UNIX AND NOT APPLE)
  220. install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
  221. install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
  222. install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}")
  223. install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
  224. install(FILES "misc/minetest-xorg-icon-128.png"
  225. DESTINATION "${ICONDIR}/hicolor/128x128/apps"
  226. RENAME "minetest.png")
  227. endif()
  228. if(APPLE)
  229. install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
  230. install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
  231. endif()
  232. # Library pack
  233. find_package(GMP REQUIRED)
  234. find_package(Json REQUIRED)
  235. find_package(Lua REQUIRED)
  236. if(NOT USE_LUAJIT)
  237. set(LUA_BIT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/bitop)
  238. set(LUA_BIT_LIBRARY bitop)
  239. add_subdirectory(lib/bitop)
  240. endif()
  241. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  242. if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
  243. message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  244. "Version ${GCC_MINIMUM_VERSION} or higher is required.")
  245. endif()
  246. elseif(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang")
  247. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
  248. message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  249. "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
  250. endif()
  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()