Rename and move basicmacros.h to util/basic_macros.h
[oweals/minetest.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2
3 if(${CMAKE_VERSION} STREQUAL "2.8.2")
4         # Bug http://vtk.org/Bug/view.php?id=11020
5         message(WARNING "CMake/CPack version 2.8.2 will not create working .deb packages!")
6 endif()
7
8 # This can be read from ${PROJECT_NAME} after project() is called
9 project(minetest)
10 set(PROJECT_NAME_CAPITALIZED "Minetest")
11
12
13 # Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing
14 set(VERSION_MAJOR 0)
15 set(VERSION_MINOR 4)
16 set(VERSION_PATCH 13)
17 set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
18
19 # Change to false for releases
20 set(DEVELOPMENT_BUILD TRUE)
21
22 set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
23 if(VERSION_EXTRA)
24         set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA})
25 elseif(DEVELOPMENT_BUILD)
26         set(VERSION_STRING "${VERSION_STRING}-dev")
27 endif()
28
29 message(STATUS "*** Will build version ${VERSION_STRING} ***")
30
31
32 # Configuration options
33 set(DEFAULT_RUN_IN_PLACE FALSE)
34 if(WIN32)
35         set(DEFAULT_RUN_IN_PLACE TRUE)
36 endif()
37 set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL
38         "Run directly in source directory structure")
39
40
41 set(BUILD_CLIENT TRUE CACHE BOOL "Build client")
42 set(BUILD_SERVER FALSE CACHE BOOL "Build server")
43
44
45 set(WARN_ALL TRUE CACHE BOOL "Enable -Wall for Release build")
46
47 if(NOT CMAKE_BUILD_TYPE)
48         # Default to release
49         set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
50 endif()
51
52
53 # Included stuff
54 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
55
56
57 # This is done here so that relative search paths are more reasonable
58 find_package(Irrlicht)
59
60
61 # Installation
62
63 if(WIN32)
64         set(SHAREDIR ".")
65         set(BINDIR "bin")
66         set(DOCDIR "doc")
67         set(EXAMPLE_CONF_DIR ".")
68         set(LOCALEDIR "locale")
69 elseif(APPLE)
70         set(BUNDLE_NAME ${PROJECT_NAME}.app)
71         set(BUNDLE_PATH "${BUNDLE_NAME}")
72         set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
73         set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
74         set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
75         set(EXAMPLE_CONF_DIR ${DOCDIR})
76         set(LOCALEDIR "${SHAREDIR}/locale")
77 elseif(UNIX) # Linux, BSD etc
78         if(RUN_IN_PLACE)
79                 set(SHAREDIR ".")
80                 set(BINDIR "bin")
81                 set(DOCDIR "doc")
82                 set(EXAMPLE_CONF_DIR ".")
83                 set(MANDIR "unix/man")
84                 set(XDG_APPS_DIR "unix/applications")
85                 set(APPDATADIR "unix/appdata")
86                 set(ICONDIR "unix/icons")
87                 set(LOCALEDIR "locale")
88         else()
89                 set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
90                 set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
91                 set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}")
92                 set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
93                 set(EXAMPLE_CONF_DIR ${DOCDIR})
94                 set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/share/applications")
95                 set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/appdata")
96                 set(ICONDIR "${CMAKE_INSTALL_PREFIX}/share/icons")
97                 set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/locale")
98         endif()
99 endif()
100
101 set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
102 if(NOT CUSTOM_SHAREDIR STREQUAL "")
103         set(SHAREDIR "${CUSTOM_SHAREDIR}")
104         message(STATUS "Using SHAREDIR=${SHAREDIR}")
105 endif()
106
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
113 set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
114 if(NOT CUSTOM_DOCDIR STREQUAL "")
115         set(DOCDIR "${CUSTOM_DOCDIR}")
116         message(STATUS "Using DOCDIR=${DOCDIR}")
117 endif()
118
119 set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
120 if(NOT CUSTOM_MANDIR STREQUAL "")
121         set(MANDIR "${CUSTOM_MANDIR}")
122         message(STATUS "Using MANDIR=${MANDIR}")
123 endif()
124
125 set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
126 if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
127         set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
128         message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
129 endif()
130
131 set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
132 if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
133         set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
134         message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
135 endif()
136
137 set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
138 if(NOT CUSTOM_ICONDIR STREQUAL "")
139         set(ICONDIR "${CUSTOM_ICONDIR}")
140         message(STATUS "Using ICONDIR=${ICONDIR}")
141 endif()
142
143 set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
144 if(NOT CUSTOM_LOCALEDIR STREQUAL "")
145         set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
146         message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
147 endif()
148
149
150 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
151 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client" DESTINATION "${SHAREDIR}")
152 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minimal" DESTINATION "${SHAREDIR}/games")
153 set(MINETEST_GAME_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game")
154 if(EXISTS ${MINETEST_GAME_SOURCE} AND IS_DIRECTORY ${MINETEST_GAME_SOURCE})
155         install(FILES ${MINETEST_GAME_SOURCE}/game.conf DESTINATION "${SHAREDIR}/games/minetest_game/")
156         install(FILES ${MINETEST_GAME_SOURCE}/README.txt DESTINATION "${SHAREDIR}/games/minetest_game/")
157         install(DIRECTORY ${MINETEST_GAME_SOURCE}/mods DESTINATION "${SHAREDIR}/games/minetest_game")
158         install(DIRECTORY ${MINETEST_GAME_SOURCE}/menu DESTINATION "${SHAREDIR}/games/minetest_game")
159 endif()
160 if(BUILD_CLIENT)
161         #install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/sounds/base/pack" DESTINATION "${SHAREDIR}/sounds/base")
162         install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
163 endif()
164 if(RUN_IN_PLACE)
165         install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
166         install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
167 endif()
168
169 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fonts" DESTINATION "${SHAREDIR}")
170
171 install(FILES "README.txt" DESTINATION "${DOCDIR}")
172 install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}")
173 install(FILES "doc/menu_lua_api.txt" DESTINATION "${DOCDIR}")
174 install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}")
175 install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
176
177 if(UNIX AND NOT APPLE)
178         install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
179         install(FILES "misc/minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
180         install(FILES "misc/minetest.appdata.xml" DESTINATION "${APPDATADIR}")
181         install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
182 endif()
183
184 if(APPLE)
185         install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
186         install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
187 endif()
188
189
190 # Subdirectories
191 # Be sure to add all relevant definitions above this
192
193 add_subdirectory(src)
194
195
196 # CPack
197
198 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An InfiniMiner/Minecraft inspired game")
199 set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
200 set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
201 set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
202 set(CPACK_PACKAGE_VENDOR "celeron55")
203 set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
204
205 if(WIN32)
206         if(CMAKE_SIZEOF_VOID_P EQUAL 8)
207                 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
208         else()
209                 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
210         endif()
211
212         set(CPACK_GENERATOR ZIP)
213 elseif(APPLE)
214         set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
215         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
216         set(CPACK_GENERATOR ZIP)
217 else()
218         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
219         set(CPACK_GENERATOR TGZ)
220         set(CPACK_SOURCE_GENERATOR TGZ)
221 endif()
222
223 include(CPack)
224
225
226 # Add a target to generate API documentation with Doxygen
227 find_package(Doxygen)
228 if(DOXYGEN_FOUND)
229         configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
230                         ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
231         add_custom_target(doc
232                 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
233                 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
234                 COMMENT "Generating API documentation with Doxygen" VERBATIM
235         )
236 endif()
237