1 cmake_minimum_required(VERSION 3.5)
3 # Set policies up to 3.9 since we want to enable the IPO option
4 if(${CMAKE_VERSION} VERSION_LESS 3.9)
5 cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
7 cmake_policy(VERSION 3.9)
10 # This can be read from ${PROJECT_NAME} after project() is called
12 set(PROJECT_NAME_CAPITALIZED "Minetest")
14 set(CMAKE_CXX_STANDARD 14)
15 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
16 set(GCC_MINIMUM_VERSION "5.1")
17 set(CLANG_MINIMUM_VERSION "3.5")
19 # Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing
23 set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
25 # Change to false for releases
26 set(DEVELOPMENT_BUILD TRUE)
28 set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
30 set(VERSION_STRING "${VERSION_STRING}-${VERSION_EXTRA}")
31 elseif(DEVELOPMENT_BUILD)
32 set(VERSION_STRING "${VERSION_STRING}-dev")
35 if (CMAKE_BUILD_TYPE STREQUAL Debug)
36 # Append "-debug" to version string
37 set(VERSION_STRING "${VERSION_STRING}-debug")
40 message(STATUS "*** Will build version ${VERSION_STRING} ***")
43 # Configuration options
44 set(DEFAULT_RUN_IN_PLACE FALSE)
46 set(DEFAULT_RUN_IN_PLACE TRUE)
48 set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL
49 "Run directly in source directory structure")
52 set(BUILD_CLIENT TRUE CACHE BOOL "Build client")
53 set(BUILD_SERVER FALSE CACHE BOOL "Build server")
54 set(BUILD_UNITTESTS TRUE CACHE BOOL "Build unittests")
55 set(BUILD_BENCHMARKS FALSE CACHE BOOL "Build benchmarks")
57 set(WARN_ALL TRUE CACHE BOOL "Enable -Wall for Release build")
59 if(NOT CMAKE_BUILD_TYPE)
61 set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
65 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
68 set(IRRLICHTMT_BUILD_DIR "" CACHE PATH "Path to IrrlichtMt build directory.")
69 if(NOT "${IRRLICHTMT_BUILD_DIR}" STREQUAL "")
70 find_package(IrrlichtMt QUIET
71 PATHS "${IRRLICHTMT_BUILD_DIR}"
75 if(NOT TARGET IrrlichtMt::IrrlichtMt)
76 # find_package() searches certain subdirectories. ${PATH}/cmake is not
77 # the only one, but it is the one where IrrlichtMt is supposed to export
78 # IrrlichtMtConfig.cmake
79 message(FATAL_ERROR "Could not find IrrlichtMtConfig.cmake in ${IRRLICHTMT_BUILD_DIR}/cmake.")
81 # This is done here so that relative search paths are more reasonable
82 elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt")
83 message(STATUS "Using user-provided IrrlichtMt at subdirectory 'lib/irrlichtmt'")
85 # tell IrrlichtMt to create a static library
86 set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared library" FORCE)
87 add_subdirectory(lib/irrlichtmt EXCLUDE_FROM_ALL)
88 unset(BUILD_SHARED_LIBS CACHE)
90 if(NOT TARGET IrrlichtMt)
91 message(FATAL_ERROR "IrrlichtMt project is missing a CMake target?!")
94 add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
95 set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
96 INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt/include")
99 find_package(IrrlichtMt QUIET)
100 if(NOT TARGET IrrlichtMt::IrrlichtMt)
101 string(CONCAT explanation_msg
102 "The Minetest team has forked Irrlicht to make their own customizations. "
103 "It can be found here: https://github.com/minetest/irrlicht\n"
104 "For example use: git clone --depth=1 https://github.com/minetest/irrlicht lib/irrlichtmt\n")
106 message(FATAL_ERROR "IrrlichtMt is required to build the client, but it was not found.\n${explanation_msg}")
109 include(MinetestFindIrrlichtHeaders)
110 if(NOT IRRLICHT_INCLUDE_DIR)
111 message(FATAL_ERROR "Irrlicht or IrrlichtMt headers are required to build the server, but none found.\n${explanation_msg}")
113 message(STATUS "Found Irrlicht headers: ${IRRLICHT_INCLUDE_DIR}")
114 add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
115 # Note that we can't use target_include_directories() since that doesn't work for IMPORTED targets before CMake 3.11
116 set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
117 INTERFACE_INCLUDE_DIRECTORIES "${IRRLICHT_INCLUDE_DIR}")
121 if(TARGET IrrlichtMt::IrrlichtMt)
122 message(STATUS "Found IrrlichtMt ${IrrlichtMt_VERSION}")
132 set(EXAMPLE_CONF_DIR ".")
133 set(LOCALEDIR "locale")
135 set(BUNDLE_NAME ${PROJECT_NAME}.app)
136 set(BUNDLE_PATH "${BUNDLE_NAME}")
137 set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
138 set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
139 set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
140 set(EXAMPLE_CONF_DIR ${DOCDIR})
141 set(LOCALEDIR "${SHAREDIR}/locale")
142 elseif(UNIX) # Linux, BSD etc
147 set(EXAMPLE_CONF_DIR ".")
148 set(MANDIR "unix/man")
149 set(XDG_APPS_DIR "unix/applications")
150 set(APPDATADIR "unix/metainfo")
151 set(ICONDIR "unix/icons")
152 set(LOCALEDIR "locale")
154 include(GNUInstallDirs)
155 set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
156 set(BINDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
157 set(DOCDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}")
158 set(MANDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}")
159 set(EXAMPLE_CONF_DIR ${DOCDIR})
160 set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/applications")
161 set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/metainfo")
162 set(ICONDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/icons")
163 set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")
167 set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
168 if(NOT CUSTOM_SHAREDIR STREQUAL "")
169 set(SHAREDIR "${CUSTOM_SHAREDIR}")
170 message(STATUS "Using SHAREDIR=${SHAREDIR}")
173 set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into")
174 if(NOT CUSTOM_BINDIR STREQUAL "")
175 set(BINDIR "${CUSTOM_BINDIR}")
176 message(STATUS "Using BINDIR=${BINDIR}")
179 set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
180 if(NOT CUSTOM_DOCDIR STREQUAL "")
181 set(DOCDIR "${CUSTOM_DOCDIR}")
183 set(EXAMPLE_CONF_DIR ${DOCDIR})
185 message(STATUS "Using DOCDIR=${DOCDIR}")
188 set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
189 if(NOT CUSTOM_MANDIR STREQUAL "")
190 set(MANDIR "${CUSTOM_MANDIR}")
191 message(STATUS "Using MANDIR=${MANDIR}")
194 set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
195 if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
196 set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
197 message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
200 set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
201 if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
202 set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
203 message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
206 set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
207 if(NOT CUSTOM_ICONDIR STREQUAL "")
208 set(ICONDIR "${CUSTOM_ICONDIR}")
209 message(STATUS "Using ICONDIR=${ICONDIR}")
212 set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
213 if(NOT CUSTOM_LOCALEDIR STREQUAL "")
214 set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
215 message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
219 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
221 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
222 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
225 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game" DESTINATION "${SHAREDIR}/games/"
226 COMPONENT "SUBGAME_MINETEST_GAME" OPTIONAL PATTERN ".git*" EXCLUDE )
227 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
228 COMPONENT "SUBGAME_MINIMAL" OPTIONAL PATTERN ".git*" EXCLUDE )
231 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
232 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
234 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
235 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
239 install(FILES "README.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
240 install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
241 install(FILES "doc/client_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
242 install(FILES "doc/menu_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
243 install(FILES "doc/texture_packs.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
244 install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
245 install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
247 if(UNIX AND NOT APPLE)
248 install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
249 install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
250 install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}")
251 install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
252 install(FILES "misc/minetest-xorg-icon-128.png"
253 DESTINATION "${ICONDIR}/hicolor/128x128/apps"
254 RENAME "minetest.png")
258 install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
259 install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
263 find_package(GMP REQUIRED)
264 find_package(Json REQUIRED)
265 find_package(Lua REQUIRED)
267 set(LUA_BIT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/bitop)
268 set(LUA_BIT_LIBRARY bitop)
269 add_subdirectory(lib/bitop)
272 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
273 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
274 message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
275 "Version ${GCC_MINIMUM_VERSION} or higher is required.")
277 elseif(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang")
278 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
279 message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
280 "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
285 add_subdirectory(lib/catch2)
289 # Be sure to add all relevant definitions above this
290 add_subdirectory(src)
295 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A free open-source voxel game engine with easy modding and game creation.")
296 set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
297 set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
298 set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
299 set(CPACK_PACKAGE_VENDOR "celeron55")
300 set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
302 include(CPackComponent)
304 cpack_add_component(Docs
305 DISPLAY_NAME "Documentation"
306 DESCRIPTION "Documentation about Minetest and Minetest modding"
309 cpack_add_component(SUBGAME_MINETEST_GAME
310 DISPLAY_NAME "Minetest Game"
311 DESCRIPTION "The default game bundled in the Minetest engine. Mainly used as a modding base."
315 cpack_add_component(SUBGAME_MINIMAL
316 DISPLAY_NAME "Development Test"
317 DESCRIPTION "A basic testing environment used for engine development and sometimes for testing mods."
318 DISABLED #DISABLED does not mean it is disabled, and is just not selected by default.
322 cpack_add_component_group(Subgames
323 DESCRIPTION "Games for the Minetest engine."
327 # Include all dynamically linked runtime libaries such as MSVCRxxx.dll
328 include(InstallRequiredSystemLibraries)
331 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
332 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
334 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
337 set(CPACK_GENERATOR ZIP)
340 set(CPACK_GENERATOR WIX)
341 set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
342 set(CPACK_PACKAGE_INSTALL_DIRECTORY ".")
343 set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
344 set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
345 set(CPACK_PACKAGING_INSTALL_PREFIX "/${PROJECT_NAME_CAPITALIZED}")
347 set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/misc/minetest-icon.ico")
348 # Supported languages can be found at
349 # http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
350 #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")
351 set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_BANNER.BMP")
352 set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_DIALOG.BMP")
354 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/lgpl-2.1.txt")
356 # The correct way would be to include both x32 and x64 into one installer
357 # and install the appropriate one.
358 # CMake does not support that, so there are two separate GUID's
359 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
360 set(CPACK_WIX_UPGRADE_GUID "745A0FB3-5552-44CA-A587-A91C397CCC56")
362 set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
366 set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
367 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
368 set(CPACK_GENERATOR ZIP)
370 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
371 set(CPACK_GENERATOR TGZ)
372 set(CPACK_SOURCE_GENERATOR TGZ)
378 # Add a target to generate API documentation with Doxygen
379 find_package(Doxygen)
381 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
382 ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
383 add_custom_target(doc
384 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
385 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
386 COMMENT "Generating API documentation with Doxygen" VERBATIM