Add Freetype support
[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 4-d1)
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(MINETEST_GAME_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game")
137 if(EXISTS ${MINETEST_GAME_SOURCE} AND IS_DIRECTORY ${MINETEST_GAME_SOURCE})
138         install(FILES ${MINETEST_GAME_SOURCE}/game.conf DESTINATION "${SHAREDIR}/games/minetest_game/")
139         install(FILES ${MINETEST_GAME_SOURCE}/README.txt DESTINATION "${SHAREDIR}/games/minetest_game/")
140         install(DIRECTORY ${MINETEST_GAME_SOURCE}/mods DESTINATION "${SHAREDIR}/games/minetest_game")
141 endif()
142 if(BUILD_CLIENT)
143         #install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/sounds/base/pack" DESTINATION "${SHAREDIR}/sounds/base")
144         install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
145 endif()
146 if(RUN_IN_PLACE)
147         install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/minetest/mods_here.txt" DESTINATION "${SHAREDIR}/mods/minetest")
148         install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/all/textures_here.txt" DESTINATION "${SHAREDIR}/textures/all")
149 endif()
150
151 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fonts" DESTINATION "${SHAREDIR}")
152
153 install(FILES "README.txt" DESTINATION "${DOCDIR}")
154 install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}")
155 install(FILES "doc/mapformat.txt" DESTINATION "${DOCDIR}")
156 install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
157
158 if(UNIX)
159         install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
160         install(FILES "misc/minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
161         install(FILES "misc/minetest-icon.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
162 endif()
163
164 #
165 # Subdirectories
166 # Be sure to add all relevant definitions above this
167 #
168
169 add_subdirectory(src)
170
171 # CPack
172
173 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An InfiniMiner/Minecraft inspired game")
174 set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
175 set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
176 set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
177 set(CPACK_PACKAGE_VENDOR "celeron55")
178 set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
179
180 if(WIN32)
181         # For some reason these aren't copied otherwise
182         # NOTE: For some reason now it seems to work without these
183         #if(BUILD_CLIENT)
184         #       install(FILES bin/minetest.exe DESTINATION bin)
185         #endif()
186         #if(BUILD_SERVER)
187         #       install(FILES bin/minetestserver.exe DESTINATION bin)
188         #endif()
189
190         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
191
192         set(CPACK_GENERATOR ZIP)
193
194         # This might be needed for some installer
195         #set(CPACK_PACKAGE_EXECUTABLES bin/minetest.exe "Minetest" bin/minetestserver.exe "Minetest Server")
196 elseif(APPLE)
197         # TODO
198         # see http://cmake.org/Wiki/CMake:CPackPackageGenerators#Bundle_.28OSX_only.29
199         #
200         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
201         set(CPACK_PACKAGE_ICON "")
202         set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
203         set(CPACK_BUNDLE_ICON "")
204         set(CPACK_BUNDLE_PLIST "")
205         set(CPACK_BUNDLE_STARTUP_COMMAND "Contents/MacOS/${PROJECT_NAME}")
206         set(CPACK_GENERATOR "Bundle")
207 else()
208         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
209         set(CPACK_GENERATOR TGZ)
210         set(CPACK_SOURCE_GENERATOR TGZ)
211 endif()
212
213 include(CPack)
214