CMakeLists.txt 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 0)
  15. set(VERSION_MINOR 5)
  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" DESTINATION "${SHAREDIR}" PATTERN ".git*" EXCLUDE)
  136. if(BUILD_CLIENT)
  137. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
  138. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
  139. if(RUN_IN_PLACE)
  140. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
  141. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
  142. endif()
  143. endif()
  144. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fonts" DESTINATION "${SHAREDIR}")
  145. install(FILES "README.md" DESTINATION "${DOCDIR}")
  146. install(FILES "LICENSE.txt" DESTINATION "${DOCDIR}")
  147. install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}")
  148. install(FILES "doc/menu_lua_api.txt" DESTINATION "${DOCDIR}")
  149. install(FILES "doc/texture_packs.txt" DESTINATION "${DOCDIR}")
  150. install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}")
  151. install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
  152. if(UNIX AND NOT APPLE)
  153. install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
  154. install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
  155. install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}")
  156. install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
  157. install(FILES "misc/minetest-xorg-icon-128.png"
  158. DESTINATION "${ICONDIR}/hicolor/128x128/apps"
  159. RENAME "minetest.png")
  160. endif()
  161. if(APPLE)
  162. install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
  163. install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
  164. endif()
  165. # Library pack
  166. find_package(GMP REQUIRED)
  167. find_package(Json REQUIRED)
  168. find_package(Lua REQUIRED)
  169. # JsonCPP doesn't compile well on GCC 4.8
  170. if(NOT ENABLE_SYSTEM_JSONCPP)
  171. set(GCC_MINIMUM_VERSION "4.9")
  172. endif()
  173. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  174. if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
  175. message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  176. "Version ${GCC_MINIMUM_VERSION} or higher is required.")
  177. endif()
  178. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  179. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
  180. message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
  181. "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
  182. endif()
  183. endif()
  184. # Subdirectories
  185. # Be sure to add all relevant definitions above this
  186. add_subdirectory(src)
  187. # CPack
  188. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An InfiniMiner/Minecraft inspired game")
  189. set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
  190. set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
  191. set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
  192. set(CPACK_PACKAGE_VENDOR "celeron55")
  193. set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
  194. if(WIN32)
  195. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  196. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
  197. else()
  198. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
  199. endif()
  200. set(CPACK_GENERATOR ZIP)
  201. elseif(APPLE)
  202. set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
  203. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
  204. set(CPACK_GENERATOR ZIP)
  205. else()
  206. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
  207. set(CPACK_GENERATOR TGZ)
  208. set(CPACK_SOURCE_GENERATOR TGZ)
  209. endif()
  210. include(CPack)
  211. # Add a target to generate API documentation with Doxygen
  212. find_package(Doxygen)
  213. if(DOXYGEN_FOUND)
  214. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
  215. ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
  216. add_custom_target(doc
  217. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
  218. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
  219. COMMENT "Generating API documentation with Doxygen" VERBATIM
  220. )
  221. endif()