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