1 cmake_minimum_required(VERSION 3.12)
3 # This can be read from ${PROJECT_NAME} after project() is called
5 set(PROJECT_NAME_CAPITALIZED "Luanti")
7 set(CMAKE_CXX_STANDARD 17)
8 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
9 set(GCC_MINIMUM_VERSION "7.5")
10 set(CLANG_MINIMUM_VERSION "7.0.1")
12 # You should not need to edit these manually, use util/bump_version.sh
16 set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
18 # Change to false for releases
19 set(DEVELOPMENT_BUILD TRUE)
21 set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
23 set(VERSION_STRING "${VERSION_STRING}-${VERSION_EXTRA}")
24 elseif(DEVELOPMENT_BUILD)
25 set(VERSION_STRING "${VERSION_STRING}-dev")
28 if (CMAKE_BUILD_TYPE STREQUAL Debug)
29 # Append "-debug" to version string
30 set(VERSION_STRING "${VERSION_STRING}-debug")
33 # Configuration options
34 set(BUILD_CLIENT TRUE CACHE BOOL "Build client")
35 set(BUILD_SERVER FALSE CACHE BOOL "Build server")
36 set(BUILD_UNITTESTS TRUE CACHE BOOL "Build unittests")
37 set(BUILD_BENCHMARKS FALSE CACHE BOOL "Build benchmarks")
38 set(BUILD_DOCUMENTATION TRUE CACHE BOOL "Build documentation")
40 set(DEFAULT_ENABLE_LTO TRUE)
41 # by default don't enable on Debug builds to get faster builds
42 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
43 set(DEFAULT_ENABLE_LTO FALSE)
45 #### LTO testing list ####
46 # - Linux: seems to work always
48 # - win32/gcc: fails to link
49 # - win32/clang: works
50 # - macOS on x86: seems to be fine
51 # - macOS on ARM: crashes, see <https://github.com/luanti-org/luanti/issues/14397>
52 # Note: since CMake has no easy architecture detection disabling for Mac entirely
54 if((WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR APPLE)
55 set(DEFAULT_ENABLE_LTO FALSE)
57 set(ENABLE_LTO ${DEFAULT_ENABLE_LTO} CACHE BOOL "Use Link Time Optimization")
59 set(BUILD_WITH_TRACY FALSE CACHE BOOL
60 "Fetch and build with the Tracy profiler client")
61 set(FETCH_TRACY_GIT_TAG "master" CACHE STRING
62 "Git tag for fetching Tracy client. Match with your server (gui) version")
64 set(DEFAULT_RUN_IN_PLACE FALSE)
66 set(DEFAULT_RUN_IN_PLACE TRUE)
68 set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL
69 "Run directly in source directory structure")
71 message(STATUS "*** Will build version ${VERSION_STRING} ***")
72 message(STATUS "BUILD_CLIENT: " ${BUILD_CLIENT})
73 message(STATUS "BUILD_SERVER: " ${BUILD_SERVER})
74 message(STATUS "BUILD_UNITTESTS: " ${BUILD_UNITTESTS})
75 message(STATUS "BUILD_BENCHMARKS: " ${BUILD_BENCHMARKS})
76 message(STATUS "BUILD_DOCUMENTATION: " ${BUILD_DOCUMENTATION})
77 message(STATUS "RUN_IN_PLACE: " ${RUN_IN_PLACE})
79 set(WARN_ALL TRUE CACHE BOOL "Enable -Wall for Release build")
81 if(NOT CMAKE_BUILD_TYPE)
83 set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
86 set(ENABLE_UPDATE_CHECKER (NOT ${DEVELOPMENT_BUILD}) CACHE BOOL
87 "Whether to enable update checks by default")
90 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
92 # Load default options for Android
94 cmake_minimum_required(VERSION 3.20)
100 message(STATUS "Using imported IrrlichtMt at subdirectory 'irr'")
102 add_subdirectory(irr EXCLUDE_FROM_ALL)
104 if(NOT TARGET IrrlichtMt)
105 message(FATAL_ERROR "IrrlichtMt project is missing a CMake target?!")
108 add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
109 set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
110 INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/irr/include")
114 if (ENABLE_LTO OR CMAKE_INTERPROCEDURAL_OPTIMIZATION)
115 include(CheckIPOSupported)
116 check_ipo_supported(RESULT lto_supported OUTPUT lto_output)
118 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
119 message(STATUS "LTO/IPO is enabled")
121 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
122 message(STATUS "LTO/IPO was requested but is not supported by the compiler: ${lto_output}")
125 message(STATUS "LTO/IPO is not enabled")
128 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
129 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}")
130 message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. "
131 "Version ${GCC_MINIMUM_VERSION} or higher is required.")
133 elseif(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang")
134 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_MINIMUM_VERSION}")
135 message(FATAL_ERROR "Insufficient clang version, found ${CMAKE_CXX_COMPILER_VERSION}. "
136 "Version ${CLANG_MINIMUM_VERSION} or higher is required.")
146 set(EXAMPLE_CONF_DIR ".")
147 set(LOCALEDIR "locale")
149 set(BUNDLE_NAME ${PROJECT_NAME}.app)
150 set(BUNDLE_PATH "${BUNDLE_NAME}")
151 set(BINDIR ${BUNDLE_NAME}/Contents/MacOS)
152 set(SHAREDIR ${BUNDLE_NAME}/Contents/Resources)
153 set(DOCDIR "${SHAREDIR}/${PROJECT_NAME}")
154 set(EXAMPLE_CONF_DIR ${DOCDIR})
155 set(LOCALEDIR "${SHAREDIR}/locale")
156 elseif(UNIX) # Linux, BSD etc
161 set(EXAMPLE_CONF_DIR ".")
162 set(MANDIR "unix/man")
163 set(XDG_APPS_DIR "unix/applications")
164 set(METAINFODIR "unix/metainfo")
165 set(ICONDIR "unix/icons")
166 set(LOCALEDIR "locale")
168 include(GNUInstallDirs)
169 set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
170 set(BINDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
171 set(DOCDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}")
172 set(MANDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}")
173 set(EXAMPLE_CONF_DIR ${DOCDIR})
174 set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/applications")
175 set(METAINFODIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/metainfo")
176 set(ICONDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/icons")
177 set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")
181 set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into")
182 if(NOT CUSTOM_SHAREDIR STREQUAL "")
183 set(SHAREDIR "${CUSTOM_SHAREDIR}")
184 message(STATUS "Using SHAREDIR=${SHAREDIR}")
187 set(CUSTOM_BINDIR "" CACHE STRING "Directory to install binaries into")
188 if(NOT CUSTOM_BINDIR STREQUAL "")
189 set(BINDIR "${CUSTOM_BINDIR}")
190 message(STATUS "Using BINDIR=${BINDIR}")
193 set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
194 if(NOT CUSTOM_DOCDIR STREQUAL "")
195 set(DOCDIR "${CUSTOM_DOCDIR}")
197 set(EXAMPLE_CONF_DIR ${DOCDIR})
199 message(STATUS "Using DOCDIR=${DOCDIR}")
202 set(CUSTOM_MANDIR "" CACHE STRING "Directory to install manpages into")
203 if(NOT CUSTOM_MANDIR STREQUAL "")
204 set(MANDIR "${CUSTOM_MANDIR}")
205 message(STATUS "Using MANDIR=${MANDIR}")
208 set(CUSTOM_EXAMPLE_CONF_DIR "" CACHE STRING "Directory to install example config file into")
209 if(NOT CUSTOM_EXAMPLE_CONF_DIR STREQUAL "")
210 set(EXAMPLE_CONF_DIR "${CUSTOM_EXAMPLE_CONF_DIR}")
211 message(STATUS "Using EXAMPLE_CONF_DIR=${EXAMPLE_CONF_DIR}")
214 set(CUSTOM_XDG_APPS_DIR "" CACHE STRING "Directory to install .desktop files into")
215 if(NOT CUSTOM_XDG_APPS_DIR STREQUAL "")
216 set(XDG_APPS_DIR "${CUSTOM_XDG_APPS_DIR}")
217 message(STATUS "Using XDG_APPS_DIR=${XDG_APPS_DIR}")
220 set(CUSTOM_ICONDIR "" CACHE STRING "Directory to install icons into")
221 if(NOT CUSTOM_ICONDIR STREQUAL "")
222 set(ICONDIR "${CUSTOM_ICONDIR}")
223 message(STATUS "Using ICONDIR=${ICONDIR}")
226 set(CUSTOM_LOCALEDIR "" CACHE STRING "Directory to install l10n files into")
227 if(NOT CUSTOM_LOCALEDIR STREQUAL "")
228 set(LOCALEDIR "${CUSTOM_LOCALEDIR}")
229 message(STATUS "Using LOCALEDIR=${LOCALEDIR}")
233 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
235 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/mods/mods_here.txt" DESTINATION "${SHAREDIR}/mods")
236 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/textures/texture_packs_here.txt" DESTINATION "${SHAREDIR}/textures")
239 set(INSTALL_DEVTEST FALSE CACHE BOOL "Install Development Test")
242 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
243 PATTERN ".git*" EXCLUDE )
247 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/shaders" DESTINATION "${SHAREDIR}/client")
248 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/textures/base/pack" DESTINATION "${SHAREDIR}/textures/base")
250 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
251 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
255 install(FILES "README.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
256 install(FILES "doc/lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
257 install(FILES "doc/client_lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
258 install(FILES "doc/menu_lua_api.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
259 install(FILES "doc/texture_packs.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
260 install(FILES "doc/world_format.md" DESTINATION "${DOCDIR}" COMPONENT "Docs")
261 install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
263 if(UNIX AND NOT APPLE)
264 install(FILES "doc/luanti.6" "doc/luantiserver.6" DESTINATION "${MANDIR}/man6")
265 install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
266 install(FILES "misc/net.minetest.minetest.metainfo.xml" DESTINATION "${METAINFODIR}")
267 install(FILES "misc/luanti.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
268 install(FILES "misc/luanti-xorg-icon-128.png"
269 DESTINATION "${ICONDIR}/hicolor/128x128/apps"
274 install(FILES "misc/luanti-icon.icns" DESTINATION "${SHAREDIR}")
275 install(FILES "${CMAKE_BINARY_DIR}/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
278 if(CMAKE_GENERATOR STREQUAL "Xcode")
279 set(client_RESOURCES "${CMAKE_SOURCE_DIR}/misc/luanti-icon.icns")
283 find_package(GMP REQUIRED)
284 find_package(Json 1.0.0 REQUIRED)
285 find_package(Lua REQUIRED)
287 add_subdirectory(lib/bitop)
289 add_subdirectory(lib/sha256)
291 if(BUILD_UNITTESTS OR BUILD_BENCHMARKS)
292 add_subdirectory(lib/catch2)
295 add_subdirectory(lib/tiniergltf)
298 # Be sure to add all relevant definitions above this
299 add_subdirectory(src)
303 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A free open-source voxel game engine with easy modding and game creation.")
304 set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
305 set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
306 set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
307 set(CPACK_PACKAGE_VENDOR "celeron55")
308 set(CPACK_PACKAGE_CONTACT "Perttu Ahola <celeron55@gmail.com>")
310 include(CPackComponent)
312 cpack_add_component(Docs
313 DISPLAY_NAME "Documentation"
314 DESCRIPTION "Documentation about ${PROJECT_NAME_CAPITALIZED} and ${PROJECT_NAME_CAPITALIZED} modding"
318 # Include all dynamically linked runtime libraries such as MSVCRxxx.dll
319 include(InstallRequiredSystemLibraries)
322 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
323 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
325 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
328 set(CPACK_GENERATOR ZIP)
331 set(CPACK_GENERATOR WIX)
332 set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
333 set(CPACK_PACKAGE_INSTALL_DIRECTORY ".")
334 set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
335 set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
336 set(CPACK_PACKAGING_INSTALL_PREFIX "/${PROJECT_NAME_CAPITALIZED}")
338 set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/misc/luanti-icon.ico")
339 # Supported languages can be found at
340 # http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
341 #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")
342 set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_BANNER.BMP")
343 set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_DIALOG.BMP")
345 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/lgpl-2.1.txt")
347 # The correct way would be to include both x32 and x64 into one installer
348 # and install the appropriate one.
349 # CMake does not support that, so there are two separate GUID's
350 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
351 set(CPACK_WIX_UPGRADE_GUID "745A0FB3-5552-44CA-A587-A91C397CCC56")
353 set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
357 set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
358 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
359 set(CPACK_GENERATOR ZIP)
361 set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
362 set(CPACK_GENERATOR TGZ)
363 set(CPACK_SOURCE_GENERATOR TGZ)
369 # Add a target to generate API documentation with Doxygen
370 if(BUILD_DOCUMENTATION)
371 find_package(Doxygen)
373 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
374 ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
375 add_custom_target(doc
376 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
377 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
378 COMMENT "Generating API documentation with Doxygen" VERBATIM
385 include(FetchContent)
387 message(STATUS "Fetching Tracy (${FETCH_TRACY_GIT_TAG})...")
388 FetchContent_Declare(
390 GIT_REPOSITORY https://github.com/wolfpld/tracy.git
391 GIT_TAG ${FETCH_TRACY_GIT_TAG}
395 FetchContent_MakeAvailable(tracy)
396 message(STATUS "Fetching Tracy - done")