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