2
0

CMakeLists.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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(WARN_ALL TRUE CACHE BOOL "Enable -Wall for Release build")
  44. if(NOT CMAKE_BUILD_TYPE)
  45. # Default to release
  46. set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
  47. endif()
  48. # Included stuff
  49. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  50. set(IRRLICHTMT_BUILD_DIR "" CACHE PATH "Path to IrrlichtMt build directory.")
  51. if(NOT "${IRRLICHTMT_BUILD_DIR}" STREQUAL "")
  52. find_package(IrrlichtMt QUIET
  53. PATHS "${IRRLICHTMT_BUILD_DIR}"
  54. NO_DEFAULT_PATH
  55. )
  56. if(NOT TARGET IrrlichtMt::IrrlichtMt)
  57. # find_package() searches certain subdirectories. ${PATH}/cmake is not
  58. # the only one, but it is the one where IrrlichtMt is supposed to export
  59. # IrrlichtMtConfig.cmake
  60. message(FATAL_ERROR "Could not find IrrlichtMtConfig.cmake in ${IRRLICHTMT_BUILD_DIR}/cmake.")
  61. endif()
  62. # This is done here so that relative search paths are more reasonable
  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 "Irrlicht or IrrlichtMt headers are required to build the server, but none found.\n${explanation_msg}")
  91. endif()
  92. message(STATUS "Found Irrlicht 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(TARGET IrrlichtMt::IrrlichtMt)
  100. message(STATUS "Found IrrlichtMt ${IrrlichtMt_VERSION}")
  101. endif()
  102. # Installation
  103. if(WIN32)
  104. set(SHAREDIR ".")
  105. set(BINDIR "bin")
  106. set(DOCDIR "doc")
  107. set(EXAMPLE_CONF_DIR ".")
  108. set(LOCALEDIR "locale")
  109. elseif(APPLE)
  110. set(BUNDLE_NAME ${PROJECT_NAME}.app)
  111. set(BUNDLE_PATH "${BUNDLE_NAME}")
  112. set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
  113. set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
  114. set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
  115. set(EXAMPLE_CONF_DIR ${DOCDIR})
  116. set(LOCALEDIR "${SHAREDIR}/locale")
  117. elseif(UNIX) # Linux, BSD etc
  118. if(RUN_IN_PLACE)
  119. set(SHAREDIR ".")
  120. set(BINDIR "bin")
  121. set(DOCDIR "doc")
  122. set(EXAMPLE_CONF_DIR ".")
  123. set(MANDIR "unix/man")
  124. set(XDG_APPS_DIR "unix/applications")
  125. set(APPDATADIR "unix/metainfo")
  126. set(ICONDIR "unix/icons")
  127. set(LOCALEDIR "locale")
  128. else()
  129. include(GNUInstallDirs)
  130. set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
  131. set(BINDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  132. set(DOCDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}")
  133. set(MANDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}")
  134. set(EXAMPLE_CONF_DIR ${DOCDIR})
  135. set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/applications")
  136. set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/metainfo")
  137. set(ICONDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/icons")
  138. set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")
  139. endif()
  140. endif()
  141. set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
  142. if(NOT CUSTOM_SHAREDIR STREQUAL "")
  143. set(SHAREDIR "${CUSTOM_SHAREDIR}")
  144. message(STATUS "Using SHAREDIR=${SHAREDIR}")
  145. endif()
  146. set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into")
  147. if(NOT CUSTOM_BINDIR STREQUAL "")
  148. set(BINDIR "${CUSTOM_BINDIR}")
  149. message(STATUS "Using BINDIR=${BINDIR}")
  150. endif()
  151. set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
  152. if(NOT CUSTOM_DOCDIR STREQUAL "")
  153. set(DOCDIR "${CUSTOM_DOCDIR}")
  154. if(NOT RUN_IN_PLACE)
  155. set(EXAMPLE_CONF_DIR ${DOCDIR})
  156. endif()
  157. message(STATUS "Using DOCDIR=${DOCDIR}")
  158. endif()
  159. set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
  160. if(NOT CUSTOM_MANDIR STREQUAL "")
  161. set(MANDIR "${CUSTOM_MANDIR}")
  162. message(STATUS "Using MANDIR=${MANDIR}")
  163. endif()
  164. set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
  165. if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
  166. set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
  167. message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
  168. endif()
  169. set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
  170. if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
  171. set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
  172. message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
  173. endif()
  174. set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
  175. if(NOT CUSTOM_ICONDIR STREQUAL "")
  176. set(ICONDIR "${CUSTOM_ICONDIR}")
  177. message(STATUS "Using ICONDIR=${ICONDIR}")
  178. endif()
  179. set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
  180. if(NOT CUSTOM_LOCALEDIR STREQUAL "")
  181. set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
  182. message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
  183. endif()
  184. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
  185. if(RUN_IN_PLACE)
  186. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
  187. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
  188. endif()
  189. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game" DESTINATION "${SHAREDIR}/games/"
  190. COMPONENT "SUBGAME_MINETEST_GAME" OPTIONAL PATTERN ".git*" EXCLUDE )
  191. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
  192. COMPONENT "SUBGAME_MINIMAL" OPTIONAL PATTERN ".git*" EXCLUDE )
  193. if(BUILD_CLIENT)
  194. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
  195. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
  196. if(RUN_IN_PLACE)
  197. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
  198. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
  199. endif()
  200. endif()
  201. install(FILES "README.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  202. install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  203. install(FILES "doc/client_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  204. install(FILES "doc/menu_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  205. install(FILES "doc/texture_packs.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  206. install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  207. install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
  208. if(UNIX AND NOT APPLE)
  209. install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
  210. install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
  211. install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}")
  212. install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
  213. install(FILES "misc/minetest-xorg-icon-128.png"
  214. DESTINATION "${ICONDIR}/hicolor/128x128/apps"
  215. RENAME "minetest.png")
  216. endif()
  217. if(APPLE)
  218. install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
  219. install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
  220. endif()
  221. # Library pack
  222. find_package(GMP REQUIRED)
  223. find_package(Json REQUIRED)
  224. find_package(Lua REQUIRED)
  225. if(NOT USE_LUAJIT)
  226. set(LUA_BIT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/bitop)
  227. set(LUA_BIT_LIBRARY bitop)
  228. add_subdirectory(lib/bitop)
  229. endif()
  230. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  231. if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
  232. message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  233. "Version ${GCC_MINIMUM_VERSION} or higher is required.")
  234. endif()
  235. elseif(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang")
  236. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
  237. message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  238. "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
  239. endif()
  240. endif()
  241. # Subdirectories
  242. # Be sure to add all relevant definitions above this
  243. add_subdirectory(src)
  244. # CPack
  245. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A free open-source voxel game engine with easy modding and game creation.")
  246. set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
  247. set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
  248. set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
  249. set(CPACK_PACKAGE_VENDOR "celeron55")
  250. set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
  251. include(CPackComponent)
  252. cpack_add_component(Docs
  253. DISPLAY_NAME "Documentation"
  254. DESCRIPTION "Documentation about Minetest and Minetest modding"
  255. )
  256. cpack_add_component(SUBGAME_MINETEST_GAME
  257. DISPLAY_NAME "Minetest Game"
  258. DESCRIPTION "The default game bundled in the Minetest engine. Mainly used as a modding base."
  259. GROUP "Games"
  260. )
  261. cpack_add_component(SUBGAME_MINIMAL
  262. DISPLAY_NAME "Development Test"
  263. DESCRIPTION "A basic testing environment used for engine development and sometimes for testing mods."
  264. DISABLED #DISABLED does not mean it is disabled, and is just not selected by default.
  265. GROUP "Games"
  266. )
  267. cpack_add_component_group(Subgames
  268. DESCRIPTION "Games for the Minetest engine."
  269. )
  270. if(WIN32)
  271. # Include all dynamically linked runtime libaries such as MSVCRxxx.dll
  272. include(InstallRequiredSystemLibraries)
  273. if(RUN_IN_PLACE)
  274. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  275. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
  276. else()
  277. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
  278. endif()
  279. set(CPACK_GENERATOR ZIP)
  280. else()
  281. set(CPACK_GENERATOR WIX)
  282. set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
  283. set(CPACK_PACKAGE_INSTALL_DIRECTORY ".")
  284. set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
  285. set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
  286. set(CPACK_PACKAGING_INSTALL_PREFIX "/${PROJECT_NAME_CAPITALIZED}")
  287. set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/misc/minetest-icon.ico")
  288. # Supported languages can be found at
  289. # http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
  290. #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")
  291. set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_BANNER.BMP")
  292. set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_DIALOG.BMP")
  293. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/lgpl-2.1.txt")
  294. # The correct way would be to include both x32 and x64 into one installer
  295. # and install the appropriate one.
  296. # CMake does not support that, so there are two separate GUID's
  297. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  298. set(CPACK_WIX_UPGRADE_GUID "745A0FB3-5552-44CA-A587-A91C397CCC56")
  299. else()
  300. set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
  301. endif()
  302. endif()
  303. elseif(APPLE)
  304. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  305. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
  306. set(CPACK_GENERATOR ZIP)
  307. else()
  308. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
  309. set(CPACK_GENERATOR TGZ)
  310. set(CPACK_SOURCE_GENERATOR TGZ)
  311. endif()
  312. include(CPack)
  313. # Add a target to generate API documentation with Doxygen
  314. find_package(Doxygen)
  315. if(DOXYGEN_FOUND)
  316. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
  317. ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
  318. add_custom_target(doc
  319. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
  320. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
  321. COMMENT "Generating API documentation with Doxygen" VERBATIM
  322. )
  323. endif()