CMakeLists.txt 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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(${CMAKE_VERSION} STREQUAL "2.8.2")
  6. # This can be read from ${PROJECT_NAME} after project() is called
  7. project(minetest)
  8. set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
  9. # Also remember to set PROTOCOL_VERSION in clientserver.h when releasing
  10. set(VERSION_MAJOR 0)
  11. set(VERSION_MINOR 4)
  12. set(VERSION_PATCH 9)
  13. set(VERSION_PATCH_ORIG ${VERSION_PATCH})
  14. if(VERSION_EXTRA)
  15. set(VERSION_PATCH ${VERSION_PATCH}-${VERSION_EXTRA})
  16. else()
  17. # Comment the following line during release
  18. set(VERSION_PATCH ${VERSION_PATCH}-dev)
  19. endif()
  20. set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
  21. MESSAGE(STATUS "*** Will build version ${VERSION_STRING} ***")
  22. # Configuration options
  23. if(WIN32)
  24. set(RUN_IN_PLACE 1 CACHE BOOL "Run directly in source directory structure")
  25. else()
  26. set(RUN_IN_PLACE 0 CACHE BOOL "Run directly in source directory structure")
  27. endif()
  28. # RUN_IN_PLACE is exported as a #define value, ensure it's 1/0 instead of ON/OFF
  29. if(RUN_IN_PLACE)
  30. set(RUN_IN_PLACE 1)
  31. else()
  32. set(RUN_IN_PLACE 0)
  33. endif()
  34. set(BUILD_CLIENT 1 CACHE BOOL "Build client")
  35. if(WIN32)
  36. set(BUILD_SERVER 0 CACHE BOOL "Build server")
  37. else()
  38. set(BUILD_SERVER 1 CACHE BOOL "Build server")
  39. endif()
  40. set(WARN_ALL 1 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. include(${CMAKE_SOURCE_DIR}/cmake/Modules/misc.cmake)
  48. # This is done here so that relative search paths are more reasnable
  49. find_package(Irrlicht)
  50. #
  51. # Installation
  52. #
  53. if(WIN32)
  54. set(SHAREDIR ".")
  55. set(BINDIR "bin")
  56. set(DOCDIR "doc")
  57. set(EXAMPLE_CONF_DIR ".")
  58. set(LOCALEDIR "locale")
  59. elseif(APPLE)
  60. # Random placeholders; this isn't usually used and may not work
  61. # See https://github.com/toabi/minetest-mac/
  62. set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
  63. set(BINDIR "bin")
  64. set(DOCDIR "share/doc/${PROJECT_NAME}")
  65. set(EXAMPLE_CONF_DIR ${DOCDIR})
  66. set(LOCALEDIR "locale")
  67. elseif(UNIX) # Linux, BSD etc
  68. if(RUN_IN_PLACE)
  69. set(SHAREDIR ".")
  70. set(BINDIR "bin")
  71. set(DOCDIR "doc")
  72. set(EXAMPLE_CONF_DIR ".")
  73. set(MANDIR "unix/man")
  74. set(XDG_APPS_DIR "unix/applications")
  75. set(ICONDIR "unix/icons")
  76. set(LOCALEDIR "locale")
  77. else()
  78. set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
  79. set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  80. set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}")
  81. set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
  82. set(EXAMPLE_CONF_DIR ${DOCDIR})
  83. set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/share/applications")
  84. set(ICONDIR "${CMAKE_INSTALL_PREFIX}/share/icons")
  85. set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/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. message(STATUS "Using DOCDIR=${DOCDIR}")
  102. endif()
  103. set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
  104. if(NOT CUSTOM_MANDIR STREQUAL "")
  105. set(MANDIR "${CUSTOM_MANDIR}")
  106. message(STATUS "Using MANDIR=${MANDIR}")
  107. endif()
  108. set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
  109. if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
  110. set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
  111. message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
  112. endif()
  113. set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
  114. if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
  115. set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
  116. message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
  117. endif()
  118. set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
  119. if(NOT CUSTOM_ICONDIR STREQUAL "")
  120. set(ICONDIR "${CUSTOM_ICONDIR}")
  121. message(STATUS "Using ICONDIR=${ICONDIR}")
  122. endif()
  123. set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
  124. if(NOT CUSTOM_LOCALEDIR STREQUAL "")
  125. set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
  126. message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
  127. endif()
  128. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
  129. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client" DESTINATION "${SHAREDIR}")
  130. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minimal" DESTINATION "${SHAREDIR}/games")
  131. set(MINETEST_GAME_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game")
  132. if(EXISTS ${MINETEST_GAME_SOURCE} AND IS_DIRECTORY ${MINETEST_GAME_SOURCE})
  133. install(FILES ${MINETEST_GAME_SOURCE}/game.conf DESTINATION "${SHAREDIR}/games/minetest_game/")
  134. install(FILES ${MINETEST_GAME_SOURCE}/README.txt DESTINATION "${SHAREDIR}/games/minetest_game/")
  135. install(DIRECTORY ${MINETEST_GAME_SOURCE}/mods DESTINATION "${SHAREDIR}/games/minetest_game")
  136. install(DIRECTORY ${MINETEST_GAME_SOURCE}/menu DESTINATION "${SHAREDIR}/games/minetest_game")
  137. endif()
  138. if(BUILD_CLIENT)
  139. #install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/sounds/base/pack" DESTINATION "${SHAREDIR}/sounds/base")
  140. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
  141. endif()
  142. if(RUN_IN_PLACE)
  143. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
  144. install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
  145. endif()
  146. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fonts" DESTINATION "${SHAREDIR}")
  147. install(FILES "README.txt" DESTINATION "${DOCDIR}")
  148. install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}")
  149. install(FILES "doc/menu_lua_api.txt" DESTINATION "${DOCDIR}")
  150. install(FILES "doc/mapformat.txt" DESTINATION "${DOCDIR}")
  151. install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
  152. if(UNIX)
  153. install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
  154. install(FILES "misc/minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
  155. install(FILES "misc/minetest-icon.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
  156. endif()
  157. #
  158. # Subdirectories
  159. # Be sure to add all relevant definitions above this
  160. #
  161. add_subdirectory(src)
  162. # CPack
  163. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An InfiniMiner/Minecraft inspired game")
  164. set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
  165. set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
  166. set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
  167. set(CPACK_PACKAGE_VENDOR "celeron55")
  168. set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
  169. if(WIN32)
  170. # For some reason these aren't copied otherwise
  171. # NOTE: For some reason now it seems to work without these
  172. #if(BUILD_CLIENT)
  173. # install(FILES bin/minetest.exe DESTINATION bin)
  174. #endif()
  175. #if(BUILD_SERVER)
  176. # install(FILES bin/minetestserver.exe DESTINATION bin)
  177. #endif()
  178. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
  179. set(CPACK_GENERATOR ZIP)
  180. # This might be needed for some installer
  181. #set(CPACK_PACKAGE_EXECUTABLES bin/minetest.exe "Minetest" bin/minetestserver.exe "Minetest Server")
  182. elseif(APPLE)
  183. # TODO
  184. # see http://cmake.org/Wiki/CMake:CPackPackageGenerators#Bundle_.28OSX_only.29
  185. #
  186. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
  187. set(CPACK_PACKAGE_ICON "")
  188. set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
  189. set(CPACK_BUNDLE_ICON "")
  190. set(CPACK_BUNDLE_PLIST "")
  191. set(CPACK_BUNDLE_STARTUP_COMMAND "Contents/MacOS/${PROJECT_NAME}")
  192. set(CPACK_GENERATOR "Bundle")
  193. else()
  194. set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
  195. set(CPACK_GENERATOR TGZ)
  196. set(CPACK_SOURCE_GENERATOR TGZ)
  197. endif()
  198. include(CPack)