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 # You should not need to edit these manually, use util/bump_version.sh
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)
64 set(ENABLE_UPDATE_CHECKER (NOT ${DEVELOPMENT_BUILD}) CACHE BOOL
65 "Whether to enable update checks by default")
68 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
71 set(IRRLICHTMT_BUILD_DIR "" CACHE PATH "Path to IrrlichtMt build directory.")
72 if(NOT "${IRRLICHTMT_BUILD_DIR}" STREQUAL "")
73 find_package(IrrlichtMt QUIET
74 PATHS "${IRRLICHTMT_BUILD_DIR}"
78 if(NOT TARGET IrrlichtMt::IrrlichtMt)
79 # find_package() searches certain subdirectories. ${PATH}/cmake is not
80 # the only one, but it is the one where IrrlichtMt is supposed to export
81 # IrrlichtMtConfig.cmake
82 message(FATAL_ERROR "Could not find IrrlichtMtConfig.cmake in ${IRRLICHTMT_BUILD_DIR}/cmake.")
84 elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt")
85 message(STATUS "Using user-provided IrrlichtMt at subdirectory 'lib/irrlichtmt'")
87 # tell IrrlichtMt to create a static library
88 set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared library" FORCE)
89 add_subdirectory(lib/irrlichtmt EXCLUDE_FROM_ALL)
90 unset(BUILD_SHARED_LIBS CACHE)
92 if(NOT TARGET IrrlichtMt)
93 message(FATAL_ERROR "IrrlichtMt project is missing a CMake target?!")
96 add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
97 set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
98 INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/irrlichtmt/include")
101 find_package(IrrlichtMt QUIET)
102 if(NOT TARGET IrrlichtMt::IrrlichtMt)
103 string(CONCAT explanation_msg
104 "The Minetest team has forked Irrlicht to make their own customizations. "
105 "It can be found here: https://github.com/minetest/irrlicht\n"
106 "For example use: git clone --depth=1 https://github.com/minetest/irrlicht lib/irrlichtmt\n")
108 message(FATAL_ERROR "IrrlichtMt is required to build the client, but it was not found.\n${explanation_msg}")
111 include(MinetestFindIrrlichtHeaders)
112 if(NOT IRRLICHT_INCLUDE_DIR)
113 message(FATAL_ERROR "IrrlichtMt headers are required to build the server, but none found.\n${explanation_msg}")
115 message(STATUS "Found IrrlichtMt headers: ${IRRLICHT_INCLUDE_DIR}")
116 add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
117 # Note that we can't use target_include_directories() since that doesn't work for IMPORTED targets before CMake 3.11
118 set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
119 INTERFACE_INCLUDE_DIRECTORIES "${IRRLICHT_INCLUDE_DIR}")
123 if(BUILD_CLIENT AND TARGET IrrlichtMt::IrrlichtMt)
124 # retrieve version somehow
125 if(NOT IrrlichtMt_VERSION)
126 get_target_property(IrrlichtMt_VERSION IrrlichtMt VERSION)
128 message(STATUS "Found IrrlichtMt ${IrrlichtMt_VERSION}")
130 set(TARGET_VER_S 1.9.0mt8)
131 string(REPLACE "mt" "." TARGET_VER ${TARGET_VER_S})
132 if(IrrlichtMt_VERSION VERSION_LESS ${TARGET_VER})
133 message(FATAL_ERROR "At least IrrlichtMt ${TARGET_VER_S} is required to build")
134 elseif(NOT DEVELOPMENT_BUILD AND IrrlichtMt_VERSION VERSION_GREATER ${TARGET_VER})
135 message(FATAL_ERROR "IrrlichtMt ${TARGET_VER_S} is required to build")
139 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
140 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
141 message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
142 "Version ${GCC_MINIMUM_VERSION} or higher is required.")
144 elseif(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang")
145 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
146 message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
147 "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
157 set(EXAMPLE_CONF_DIR ".")
158 set(LOCALEDIR "locale")
160 set(BUNDLE_NAME ${PROJECT_NAME}.app)
161 set(BUNDLE_PATH "${BUNDLE_NAME}")
162 set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
163 set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
164 set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
165 set(EXAMPLE_CONF_DIR ${DOCDIR})
166 set(LOCALEDIR "${SHAREDIR}/locale")
167 elseif(UNIX) # Linux, BSD etc
172 set(EXAMPLE_CONF_DIR ".")
173 set(MANDIR "unix/man")
174 set(XDG_APPS_DIR "unix/applications")
175 set(APPDATADIR "unix/metainfo")
176 set(ICONDIR "unix/icons")
177 set(LOCALEDIR "locale")
179 include(GNUInstallDirs)
180 set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
181 set(BINDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
182 set(DOCDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}")
183 set(MANDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}")
184 set(EXAMPLE_CONF_DIR ${DOCDIR})
185 set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/applications")
186 set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/metainfo")
187 set(ICONDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/icons")
188 set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")
192 set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
193 if(NOT CUSTOM_SHAREDIR STREQUAL "")
194 set(SHAREDIR "${CUSTOM_SHAREDIR}")
195 message(STATUS "Using SHAREDIR=${SHAREDIR}")
198 set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into")
199 if(NOT CUSTOM_BINDIR STREQUAL "")
200 set(BINDIR "${CUSTOM_BINDIR}")
201 message(STATUS "Using BINDIR=${BINDIR}")
204 set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
205 if(NOT CUSTOM_DOCDIR STREQUAL "")
206 set(DOCDIR "${CUSTOM_DOCDIR}")
208 set(EXAMPLE_CONF_DIR ${DOCDIR})
210 message(STATUS "Using DOCDIR=${DOCDIR}")
213 set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
214 if(NOT CUSTOM_MANDIR STREQUAL "")
215 set(MANDIR "${CUSTOM_MANDIR}")
216 message(STATUS "Using MANDIR=${MANDIR}")
219 set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
220 if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
221 set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
222 message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
225 set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
226 if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
227 set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
228 message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
231 set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
232 if(NOT CUSTOM_ICONDIR STREQUAL "")
233 set(ICONDIR "${CUSTOM_ICONDIR}")
234 message(STATUS "Using ICONDIR=${ICONDIR}")
237 set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
238 if(NOT CUSTOM_LOCALEDIR STREQUAL "")
239 set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
240 message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
244 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
246 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
247 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
250 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game" DESTINATION "${SHAREDIR}/games/"
251 COMPONENT "SUBGAME_MINETEST_GAME" OPTIONAL PATTERN ".git*" EXCLUDE )
252 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
253 COMPONENT "SUBGAME_MINIMAL" OPTIONAL PATTERN ".git*" EXCLUDE )
256 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
257 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
259 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
260 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
264 install(FILES "README.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
265 install(FILES "doc/lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
266 install(FILES "doc/client_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
267 install(FILES "doc/menu_lua_api.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
268 install(FILES "doc/texture_packs.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
269 install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs")
270 install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
272 if(UNIX AND NOT APPLE)
273 install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
274 install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
275 install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}")
276 install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
277 install(FILES "misc/minetest-xorg-icon-128.png"
278 DESTINATION "${ICONDIR}/hicolor/128x128/apps"
279 RENAME "minetest.png")
283 install(FILES "misc/minetest-icon.icns" DESTINATION "${SHAREDIR}")
284 install(FILES "misc/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
288 find_package(GMP REQUIRED)
289 find_package(Json REQUIRED)
290 find_package(Lua REQUIRED)
292 add_subdirectory(lib/bitop)
296 add_subdirectory(lib/catch2)
300 # Be sure to add all relevant definitions above this
301 add_subdirectory(src)
305 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A free open-source voxel game engine with easy modding and game creation.")
306 set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
307 set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
308 set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
309 set(CPACK_PACKAGE_VENDOR "celeron55")
310 set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
312 include(CPackComponent)
314 cpack_add_component(Docs
315 DISPLAY_NAME "Documentation"
316 DESCRIPTION "Documentation about Minetest and Minetest modding"
319 cpack_add_component(SUBGAME_MINETEST_GAME
320 DISPLAY_NAME "Minetest Game"
321 DESCRIPTION "The default game bundled in the Minetest engine. Mainly used as a modding base."
325 cpack_add_component(SUBGAME_MINIMAL
326 DISPLAY_NAME "Development Test"
327 DESCRIPTION "A basic testing environment used for engine development and sometimes for testing mods."
328 DISABLED #DISABLED does not mean it is disabled, and is just not selected by default.
332 cpack_add_component_group(Subgames
333 DESCRIPTION "Games for the Minetest engine."
337 # Include all dynamically linked runtime libaries such as MSVCRxxx.dll
338 include(InstallRequiredSystemLibraries)
341 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
342 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
344 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
347 set(CPACK_GENERATOR ZIP)
350 set(CPACK_GENERATOR WIX)
351 set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
352 set(CPACK_PACKAGE_INSTALL_DIRECTORY ".")
353 set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
354 set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
355 set(CPACK_PACKAGING_INSTALL_PREFIX "/${PROJECT_NAME_CAPITALIZED}")
357 set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/misc/minetest-icon.ico")
358 # Supported languages can be found at
359 # http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
360 #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")
361 set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_BANNER.BMP")
362 set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_DIALOG.BMP")
364 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/lgpl-2.1.txt")
366 # The correct way would be to include both x32 and x64 into one installer
367 # and install the appropriate one.
368 # CMake does not support that, so there are two separate GUID's
369 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
370 set(CPACK_WIX_UPGRADE_GUID "745A0FB3-5552-44CA-A587-A91C397CCC56")
372 set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
376 set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
377 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
378 set(CPACK_GENERATOR ZIP)
380 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
381 set(CPACK_GENERATOR TGZ)
382 set(CPACK_SOURCE_GENERATOR TGZ)
388 # Add a target to generate API documentation with Doxygen
389 find_package(Doxygen)
391 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
392 ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
393 add_custom_target(doc
394 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
395 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
396 COMMENT "Generating API documentation with Doxygen" VERBATIM