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