CMakeLists.txt 7.9 KB

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