CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. cmake_minimum_required(VERSION 2.6)
  2. if(${CMAKE_VERSION} STREQUAL "2.8.2")
  3. # Bug http://vtk.org/Bug/view.php?id=11020
  4. message(WARNING "CMake/CPack version 2.8.2 will not create working .deb packages!")
  5. endif()
  6. # This can be read from ${PROJECT_NAME} after project() is called
  7. project(minetest)
  8. set(PROJECT_NAME_CAPITALIZED "Minetest")
  9. # Works only for cmake 3.1 and greater
  10. set(CMAKE_CXX_STANDARD 11)
  11. set(GCC_MINIMUM_VERSION "4.8")
  12. set(CLANG_MINIMUM_VERSION "3.4")
  13. # Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing
  14. set(VERSION_MAJOR 5)
  15. set(VERSION_MINOR 3)
  16. set(VERSION_PATCH 0)
  17. set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
  18. # Change to false for releases
  19. set(DEVELOPMENT_BUILD TRUE)
  20. set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
  21. if(VERSION_EXTRA)
  22. set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA})
  23. elseif(DEVELOPMENT_BUILD)
  24. set(VERSION_STRING "${VERSION_STRING}-dev")
  25. endif()
  26. if (CMAKE_BUILD_TYPE STREQUAL Debug)
  27. # Append "-debug" to version string
  28. set(VERSION_STRING "${VERSION_STRING}-debug")
  29. endif()
  30. message(STATUS "*** Will build version ${VERSION_STRING} ***")
  31. # Configuration options
  32. set(DEFAULT_RUN_IN_PLACE FALSE)
  33. if(WIN32)
  34. set(DEFAULT_RUN_IN_PLACE TRUE)
  35. endif()
  36. set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL
  37. "Run directly in source directory structure")
  38. set(BUILD_CLIENT TRUE CACHE BOOL "Build client")
  39. set(BUILD_SERVER FALSE CACHE BOOL "Build server")
  40. set(BUILD_UNITTESTS TRUE CACHE BOOL "Build unittests")
  41. set(WARN_ALL TRUE CACHE BOOL "Enable -Wall for Release build")
  42. if(NOT CMAKE_BUILD_TYPE)
  43. # Default to release
  44. set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
  45. endif()
  46. # Included stuff
  47. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  48. # This is done here so that relative search paths are more reasonable
  49. find_package(Irrlicht)
  50. # Installation
  51. if(WIN32)
  52. set(SHAREDIR ".")
  53. set(BINDIR "bin")
  54. set(DOCDIR "doc")
  55. set(EXAMPLE_CONF_DIR ".")
  56. set(LOCALEDIR "locale")
  57. elseif(APPLE)
  58. set(BUNDLE_NAME ${PROJECT_NAME}.app)
  59. set(BUNDLE_PATH "${BUNDLE_NAME}")
  60. set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
  61. set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
  62. set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
  63. set(EXAMPLE_CONF_DIR ${DOCDIR})
  64. set(LOCALEDIR "${SHAREDIR}/locale")
  65. elseif(UNIX) # Linux, BSD etc
  66. if(RUN_IN_PLACE)
  67. set(SHAREDIR ".")
  68. set(BINDIR "bin")
  69. set(DOCDIR "doc")
  70. set(EXAMPLE_CONF_DIR ".")
  71. set(MANDIR "unix/man")
  72. set(XDG_APPS_DIR "unix/applications")
  73. set(APPDATADIR "unix/metainfo")
  74. set(ICONDIR "unix/icons")
  75. set(LOCALEDIR "locale")
  76. else()
  77. set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
  78. set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  79. set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}")
  80. set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
  81. set(EXAMPLE_CONF_DIR ${DOCDIR})
  82. set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/share/applications")
  83. set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/metainfo")
  84. set(ICONDIR "${CMAKE_INSTALL_PREFIX}/share/icons")
  85. set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/locale")
  86. endif()
  87. endif()
  88. set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
  89. if(NOT CUSTOM_SHAREDIR STREQUAL "")
  90. set(SHAREDIR "${CUSTOM_SHAREDIR}")
  91. message(STATUS "Using SHAREDIR=${SHAREDIR}")
  92. endif()
  93. set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into")
  94. if(NOT CUSTOM_BINDIR STREQUAL "")
  95. set(BINDIR "${CUSTOM_BINDIR}")
  96. message(STATUS "Using BINDIR=${BINDIR}")
  97. endif()
  98. set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
  99. if(NOT CUSTOM_DOCDIR STREQUAL "")
  100. set(DOCDIR "${CUSTOM_DOCDIR}")
  101. if(NOT RUN_IN_PLACE)
  102. set(EXAMPLE_CONF_DIR ${DOCDIR})
  103. endif()
  104. message(STATUS "Using DOCDIR=${DOCDIR}")
  105. endif()
  106. set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
  107. if(NOT CUSTOM_MANDIR STREQUAL "")
  108. set(MANDIR "${CUSTOM_MANDIR}")
  109. message(STATUS "Using MANDIR=${MANDIR}")
  110. endif()
  111. set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
  112. if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
  113. set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
  114. message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
  115. endif()
  116. set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
  117. if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
  118. set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
  119. message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
  120. endif()
  121. set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
  122. if(NOT CUSTOM_ICONDIR STREQUAL "")
  123. set(ICONDIR "${CUSTOM_ICONDIR}")
  124. message(STATUS "Using ICONDIR=${ICONDIR}")
  125. endif()
  126. set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
  127. if(NOT CUSTOM_LOCALEDIR STREQUAL "")
  128. set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
  129. message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
  130. endif()
  131. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
  132. if(RUN_IN_PLACE)
  133. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
  134. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
  135. endif()
  136. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game" DESTINATION "${SHAREDIR}/games/"
  137. COMPONENT "SUBGAME_MINETEST_GAME" OPTIONAL PATTERN ".git*" EXCLUDE )
  138. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
  139. COMPONENT "SUBGAME_MINIMAL" OPTIONAL PATTERN ".git*" EXCLUDE )
  140. if(BUILD_CLIENT)
  141. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
  142. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
  143. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fonts" DESTINATION "${SHAREDIR}")
  144. if(RUN_IN_PLACE)
  145. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
  146. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
  147. endif()
  148. endif()
  149. install(FILES "README.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  150. install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  151. install(FILES "doc/client_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  152. install(FILES "doc/menu_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  153. install(FILES "doc/texture_packs.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  154. install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
  155. install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
  156. if(UNIX AND NOT APPLE)
  157. install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
  158. install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
  159. install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}")
  160. install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
  161. install(FILES "misc/minetest-xorg-icon-128.png"
  162. DESTINATION "${ICONDIR}/hicolor/128x128/apps"
  163. RENAME "minetest.png")
  164. endif()
  165. if(APPLE)
  166. install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
  167. install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
  168. endif()
  169. # Library pack
  170. find_package(GMP REQUIRED)
  171. find_package(Json REQUIRED)
  172. find_package(Lua REQUIRED)
  173. # JsonCPP doesn't compile well on GCC 4.8
  174. if(NOT ENABLE_SYSTEM_JSONCPP)
  175. set(GCC_MINIMUM_VERSION "4.9")
  176. endif()
  177. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  178. if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
  179. message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  180. "Version ${GCC_MINIMUM_VERSION} or higher is required.")
  181. endif()
  182. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  183. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
  184. message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  185. "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
  186. endif()
  187. endif()
  188. # Subdirectories
  189. # Be sure to add all relevant definitions above this
  190. add_subdirectory(src)
  191. # CPack
  192. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A free open-source voxel game engine with easy modding and game creation.")
  193. set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
  194. set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
  195. set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
  196. set(CPACK_PACKAGE_VENDOR "celeron55")
  197. set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
  198. include(CPackComponent)
  199. cpack_add_component(Docs
  200. DISPLAY_NAME "Documentation"
  201. DESCRIPTION "Documentation about Minetest and Minetest modding"
  202. )
  203. cpack_add_component(SUBGAME_MINETEST_GAME
  204. DISPLAY_NAME "Minetest Game"
  205. DESCRIPTION "The official subgame for the Minetest engine, that can easily extended by mods."
  206. GROUP "Subgames"
  207. )
  208. cpack_add_component(SUBGAME_MINIMAL
  209. DISPLAY_NAME "Development Test"
  210. DESCRIPTION "A minimal test game helping to develop the engine."
  211. DISABLED #DISABLED does not mean it is disabled, and is just not selected by default.
  212. GROUP "Subgames"
  213. )
  214. cpack_add_component_group(Subgames
  215. DESCRIPTION "Games for the Minetest engine."
  216. )
  217. if(WIN32)
  218. # Include all dynamically linked runtime libaries such as MSVCRxxx.dll
  219. include(InstallRequiredSystemLibraries)
  220. if(RUN_IN_PLACE)
  221. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  222. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
  223. else()
  224. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
  225. endif()
  226. set(CPACK_GENERATOR ZIP)
  227. else()
  228. set(CPACK_GENERATOR WIX ZIP)
  229. set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
  230. set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME_CAPITALIZED}")
  231. set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
  232. set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
  233. set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/misc/minetest-icon.ico")
  234. # Supported languages can be found at
  235. # http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
  236. #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")
  237. set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_BANNER.BMP")
  238. set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_DIALOG.BMP")
  239. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/lgpl-2.1.txt")
  240. # The correct way would be to include both x32 and x64 into one installer
  241. # and install the appropriate one.
  242. # CMake does not support that, so there are two separate GUID's
  243. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  244. set(CPACK_WIX_UPGRADE_GUID "745A0FB3-5552-44CA-A587-A91C397CCC56")
  245. else()
  246. set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
  247. endif()
  248. endif()
  249. elseif(APPLE)
  250. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  251. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
  252. set(CPACK_GENERATOR ZIP)
  253. else()
  254. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
  255. set(CPACK_GENERATOR TGZ)
  256. set(CPACK_SOURCE_GENERATOR TGZ)
  257. endif()
  258. include(CPack)
  259. # Add a target to generate API documentation with Doxygen
  260. find_package(Doxygen)
  261. if(DOXYGEN_FOUND)
  262. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
  263. ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
  264. add_custom_target(doc
  265. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
  266. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
  267. COMMENT "Generating API documentation with Doxygen" VERBATIM
  268. )
  269. endif()