wasplib: add some placement helpers
[waspsaliva.git] / CMakeLists.txt
blob283460fffbcbeb3cb6a4cf7eacf95d93d4298487
1 cmake_minimum_required(VERSION 2.6)
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()
8 # This can be read from ${PROJECT_NAME} after project() is called
9 project(minetest)
10 set(PROJECT_NAME_CAPITALIZED "waspsaliva")
12 # Works only for cmake 3.1 and greater
13 set(CMAKE_CXX_STANDARD 11)
14 set(GCC_MINIMUM_VERSION "4.8")
15 set(CLANG_MINIMUM_VERSION "3.4")
17 # Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing
18 set(VERSION_MAJOR 5)
19 set(VERSION_MINOR 4)
20 set(VERSION_PATCH 0)
21 set(VERSION_EXTRA "-dragonfire" CACHE STRING "Stuff to append to version string") ##set dragonfire to make hackclient detection easier for servers
23 # Change to false for releases
24 set(DEVELOPMENT_BUILD FALSE)
26 set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
27 if(VERSION_EXTRA)
28         set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA})
29 elseif(DEVELOPMENT_BUILD)
30         set(VERSION_STRING "${VERSION_STRING}-dev")
31 endif()
33 if (CMAKE_BUILD_TYPE STREQUAL Debug)
34         # Append "-debug" to version string
35         set(VERSION_STRING "${VERSION_STRING}-debug")
36 endif()
38 message(STATUS "*** Will build version ${VERSION_STRING} ***")
41 # Configuration options
42 set(DEFAULT_RUN_IN_PLACE FALSE)
43 if(WIN32)
44         set(DEFAULT_RUN_IN_PLACE TRUE)
45 endif()
46 set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL
47         "Run directly in source directory structure")
50 set(BUILD_CLIENT TRUE CACHE BOOL "Build client")
51 set(BUILD_SERVER FALSE CACHE BOOL "Build server")
52 set(BUILD_UNITTESTS TRUE CACHE BOOL "Build unittests")
55 set(WARN_ALL TRUE CACHE BOOL "Enable -Wall for Release build")
57 if(NOT CMAKE_BUILD_TYPE)
58         # Default to release
59         set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
60 endif()
62 # Included stuff
63 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
66 # This is done here so that relative search paths are more reasonable
67 find_package(Irrlicht)
70 # Installation
72 if(WIN32)
73         set(SHAREDIR ".")
74         set(BINDIR "bin")
75         set(DOCDIR "doc")
76         set(EXAMPLE_CONF_DIR ".")
77         set(LOCALEDIR "locale")
78 elseif(APPLE)
79         set(BUNDLE_NAME ${PROJECT_NAME}.app)
80         set(BUNDLE_PATH "${BUNDLE_NAME}")
81         set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
82         set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
83         set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
84         set(EXAMPLE_CONF_DIR ${DOCDIR})
85         set(LOCALEDIR "${SHAREDIR}/locale")
86 elseif(UNIX) # Linux, BSD etc
87         if(RUN_IN_PLACE)
88                 set(SHAREDIR ".")
89                 set(BINDIR "bin")
90                 set(DOCDIR "doc")
91                 set(EXAMPLE_CONF_DIR ".")
92                 set(MANDIR "unix/man")
93                 set(XDG_APPS_DIR "unix/applications")
94                 set(APPDATADIR "unix/metainfo")
95                 set(ICONDIR "unix/icons")
96                 set(LOCALEDIR "locale")
97         else()
98                 set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
99                 set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
100                 set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}")
101                 set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
102                 set(EXAMPLE_CONF_DIR ${DOCDIR})
103                 set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/share/applications")
104                 set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/metainfo")
105                 set(ICONDIR "${CMAKE_INSTALL_PREFIX}/share/icons")
106                 set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/locale")
107         endif()
108 endif()
110 set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
111 if(NOT CUSTOM_SHAREDIR STREQUAL "")
112         set(SHAREDIR "${CUSTOM_SHAREDIR}")
113         message(STATUS "Using SHAREDIR=${SHAREDIR}")
114 endif()
116 set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into")
117 if(NOT CUSTOM_BINDIR STREQUAL "")
118         set(BINDIR "${CUSTOM_BINDIR}")
119         message(STATUS "Using BINDIR=${BINDIR}")
120 endif()
122 set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
123 if(NOT CUSTOM_DOCDIR STREQUAL "")
124         set(DOCDIR "${CUSTOM_DOCDIR}")
125         if(NOT RUN_IN_PLACE)
126                 set(EXAMPLE_CONF_DIR ${DOCDIR})
127         endif()
128         message(STATUS "Using DOCDIR=${DOCDIR}")
129 endif()
131 set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
132 if(NOT CUSTOM_MANDIR STREQUAL "")
133         set(MANDIR "${CUSTOM_MANDIR}")
134         message(STATUS "Using MANDIR=${MANDIR}")
135 endif()
137 set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
138 if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
139         set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
140         message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
141 endif()
143 set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
144 if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
145         set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
146         message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
147 endif()
149 set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
150 if(NOT CUSTOM_ICONDIR STREQUAL "")
151         set(ICONDIR "${CUSTOM_ICONDIR}")
152         message(STATUS "Using ICONDIR=${ICONDIR}")
153 endif()
155 set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
156 if(NOT CUSTOM_LOCALEDIR STREQUAL "")
157         set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
158         message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
159 endif()
162 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
163 if(RUN_IN_PLACE)
164         install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
165         install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
166 endif()
168 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game" DESTINATION "${SHAREDIR}/games/" 
169         COMPONENT "SUBGAME_MINETEST_GAME" OPTIONAL PATTERN ".git*" EXCLUDE )
170 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
171         COMPONENT "SUBGAME_MINIMAL" OPTIONAL PATTERN ".git*" EXCLUDE )
173 if(BUILD_CLIENT)
174         install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
175         install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
176         install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fonts" DESTINATION "${SHAREDIR}")
177         if(RUN_IN_PLACE)
178                 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
179                 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
180         endif()
181 endif()
183 install(FILES "README.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
184 install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
185 install(FILES "doc/client_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
186 install(FILES "doc/menu_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
187 install(FILES "doc/texture_packs.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
188 install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
189 install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
191 if(UNIX AND NOT APPLE)
192         install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
193         install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
194         install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}")
195         install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
196         install(FILES "misc/minetest-xorg-icon-128.png"
197                 DESTINATION "${ICONDIR}/hicolor/128x128/apps"
198                 RENAME "minetest.png")
199 endif()
201 if(APPLE)
202         install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
203         install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
204 endif()
206 # Library pack
207 find_package(GMP REQUIRED)
208 find_package(Json REQUIRED)
209 find_package(Lua REQUIRED)
211 # JsonCPP doesn't compile well on GCC 4.8
212 if(NOT ENABLE_SYSTEM_JSONCPP)
213         set(GCC_MINIMUM_VERSION "4.9")
214 endif()
216 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
217         if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
218                 message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
219                         "Version ${GCC_MINIMUM_VERSION} or higher is required.")
220         endif()
221 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
222         if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
223                 message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
224                         "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
225         endif()
226 endif()
228 # Subdirectories
229 # Be sure to add all relevant definitions above this
231 add_subdirectory(src)
234 # CPack
236 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A free open-source voxel game engine with easy modding and game creation.")
237 set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
238 set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
239 set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
240 set(CPACK_PACKAGE_VENDOR "celeron55")
241 set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
243 include(CPackComponent)
245 cpack_add_component(Docs
246         DISPLAY_NAME "Documentation"
247         DESCRIPTION "Documentation about Minetest and Minetest modding"
250 cpack_add_component(SUBGAME_MINETEST_GAME
251         DISPLAY_NAME "Minetest Game"
252         DESCRIPTION "The default game bundled in the Minetest engine. Mainly used as a modding base."
253         GROUP "Games"
256 cpack_add_component(SUBGAME_MINIMAL
257         DISPLAY_NAME "Development Test"
258         DESCRIPTION "A basic testing environment used for engine development and sometimes for testing mods."
259         DISABLED #DISABLED does not mean it is disabled, and is just not selected by default.
260         GROUP "Games"
263 cpack_add_component_group(Subgames
264         DESCRIPTION "Games for the Minetest engine."
267 if(WIN32)
268         # Include all dynamically linked runtime libaries such as MSVCRxxx.dll
269         include(InstallRequiredSystemLibraries)
271         if(RUN_IN_PLACE)
272                 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
273                         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
274                 else()
275                         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
276                 endif()
278                 set(CPACK_GENERATOR ZIP)
280         else()
281                 set(CPACK_GENERATOR WIX ZIP)
282                 set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
283                 set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME_CAPITALIZED}")
284                 set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
285                 set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
287                 set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/misc/minetest-icon.ico")
288                 # Supported languages can be found at 
289                 # http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
290                 #set(CPACK_WIX_CULTURES "ar-SA,bg-BG,ca-ES,hr-HR,cs-CZ,da-DK,nl-NL,en-US,et-EE,fi-FI,fr-FR,de-DE")
291                 set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_BANNER.BMP")
292                 set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_DIALOG.BMP")
293                 
294                 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/lgpl-2.1.txt")
296                 # The correct way would be to include both x32 and x64 into one installer
297                 # and install the appropriate one.
298                 # CMake does not support that, so there are two separate GUID's
299                 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
300                         set(CPACK_WIX_UPGRADE_GUID "745A0FB3-5552-44CA-A587-A91C397CCC56")
301                 else()
302                         set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
303                 endif()
304         endif()
305 elseif(APPLE)
306         set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
307         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
308         set(CPACK_GENERATOR ZIP)
309 else()
310         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
311         set(CPACK_GENERATOR TGZ)
312         set(CPACK_SOURCE_GENERATOR TGZ)
313 endif()
315 include(CPack)
318 # Add a target to generate API documentation with Doxygen
319 find_package(Doxygen)
320 if(DOXYGEN_FOUND)
321         configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
322                         ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
323         add_custom_target(doc
324                 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
325                 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
326                 COMMENT "Generating API documentation with Doxygen" VERBATIM
327         )
328 endif()