Disable SDL2 for 5.11.0 (#15704)
[minetest.git] / CMakeLists.txt
blobd942bb3aa139a71549159b6db1f1100f48d5cb12
1 cmake_minimum_required(VERSION 3.12)
3 # This can be read from ${PROJECT_NAME} after project() is called
4 project(luanti)
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
13 set(VERSION_MAJOR 5)
14 set(VERSION_MINOR 11)
15 set(VERSION_PATCH 0)
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}")
22 if(VERSION_EXTRA)
23         set(VERSION_STRING "${VERSION_STRING}-${VERSION_EXTRA}")
24 elseif(DEVELOPMENT_BUILD)
25         set(VERSION_STRING "${VERSION_STRING}-dev")
26 endif()
28 if (CMAKE_BUILD_TYPE STREQUAL Debug)
29         # Append "-debug" to version string
30         set(VERSION_STRING "${VERSION_STRING}-debug")
31 endif()
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)
44 endif()
45 #### LTO testing list ####
46 # - Linux: seems to work always
47 # - win32/msvc: works
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
53 #### ####
54 if((WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR APPLE)
55         set(DEFAULT_ENABLE_LTO FALSE)
56 endif()
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)
65 if(WIN32)
66         set(DEFAULT_RUN_IN_PLACE TRUE)
67 endif()
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)
82         # Default to release
83         set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
84 endif()
86 set(ENABLE_UPDATE_CHECKER (NOT ${DEVELOPMENT_BUILD}) CACHE BOOL
87         "Whether to enable update checks by default")
89 # Included stuff
90 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
92 # Load default options for Android
93 if(ANDROID)
94         cmake_minimum_required(VERSION 3.20)
95         include(AndroidLibs)
96 endif()
99 if(TRUE)
100         message(STATUS "Using imported IrrlichtMt at subdirectory 'irr'")
101         if(BUILD_CLIENT)
102                 add_subdirectory(irr EXCLUDE_FROM_ALL)
104                 if(NOT TARGET IrrlichtMt)
105                         message(FATAL_ERROR "IrrlichtMt project is missing a CMake target?!")
106                 endif()
107         else()
108                 add_library(IrrlichtMt::IrrlichtMt INTERFACE IMPORTED)
109                 set_target_properties(IrrlichtMt::IrrlichtMt PROPERTIES
110                         INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/irr/include")
111         endif()
112 endif()
114 if (ENABLE_LTO OR CMAKE_INTERPROCEDURAL_OPTIMIZATION)
115         include(CheckIPOSupported)
116         check_ipo_supported(RESULT lto_supported OUTPUT lto_output)
117         if(lto_supported)
118                 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
119                 message(STATUS "LTO/IPO is enabled")
120         else()
121                 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
122                 message(STATUS "LTO/IPO was requested but is not supported by the compiler: ${lto_output}")
123         endif()
124 else()
125         message(STATUS "LTO/IPO is not enabled")
126 endif()
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.")
132         endif()
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.")
137         endif()
138 endif()
140 # Installation
142 if(WIN32)
143         set(SHAREDIR ".")
144         set(BINDIR "bin")
145         set(DOCDIR "doc")
146         set(EXAMPLE_CONF_DIR ".")
147         set(LOCALEDIR "locale")
148 elseif(APPLE)
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
157         if(RUN_IN_PLACE)
158                 set(SHAREDIR ".")
159                 set(BINDIR "bin")
160                 set(DOCDIR "doc")
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")
167         else()
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}")
178         endif()
179 endif()
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}")
185 endif()
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}")
191 endif()
193 set(CUSTOM_DOCDIR "" CACHE STRING "Directory to install documentation into")
194 if(NOT CUSTOM_DOCDIR STREQUAL "")
195         set(DOCDIR "${CUSTOM_DOCDIR}")
196         if(NOT RUN_IN_PLACE)
197                 set(EXAMPLE_CONF_DIR ${DOCDIR})
198         endif()
199         message(STATUS "Using DOCDIR=${DOCDIR}")
200 endif()
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}")
206 endif()
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}")
212 endif()
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}")
218 endif()
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}")
224 endif()
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}")
230 endif()
233 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builtin" DESTINATION "${SHAREDIR}")
234 if(RUN_IN_PLACE)
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")
237 endif()
239 set(INSTALL_DEVTEST FALSE CACHE BOOL "Install Development Test")
241 if(INSTALL_DEVTEST)
242         install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/"
243                 PATTERN ".git*" EXCLUDE )
244 endif()
246 if(BUILD_CLIENT)
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")
249         if(RUN_IN_PLACE)
250                 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/clientmods" DESTINATION "${SHAREDIR}")
251                 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/client/serverlist" DESTINATION "${SHAREDIR}/client")
252         endif()
253 endif()
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"
270                 RENAME "luanti.png")
271 endif()
273 if(APPLE)
274         install(FILES "misc/luanti-icon.icns" DESTINATION "${SHAREDIR}")
275         install(FILES "${CMAKE_BINARY_DIR}/Info.plist" DESTINATION "${BUNDLE_PATH}/Contents")
276 endif()
278 if(CMAKE_GENERATOR STREQUAL "Xcode")
279         set(client_RESOURCES "${CMAKE_SOURCE_DIR}/misc/luanti-icon.icns")
280 endif()
282 # Library pack
283 find_package(GMP REQUIRED)
284 find_package(Json 1.0.0 REQUIRED)
285 find_package(Lua REQUIRED)
286 if(NOT USE_LUAJIT)
287         add_subdirectory(lib/bitop)
288 endif()
289 add_subdirectory(lib/sha256)
291 if(BUILD_UNITTESTS OR BUILD_BENCHMARKS)
292         add_subdirectory(lib/catch2)
293 endif()
295 add_subdirectory(lib/tiniergltf)
297 # Subdirectories
298 # Be sure to add all relevant definitions above this
299 add_subdirectory(src)
301 # CPack
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"
317 if(WIN32)
318         # Include all dynamically linked runtime libraries such as MSVCRxxx.dll
319         include(InstallRequiredSystemLibraries)
321         if(RUN_IN_PLACE)
322                 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
323                         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
324                 else()
325                         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
326                 endif()
328                 set(CPACK_GENERATOR ZIP)
330         else()
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")
352                 else()
353                         set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
354                 endif()
355         endif()
356 elseif(APPLE)
357         set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
358         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx")
359         set(CPACK_GENERATOR ZIP)
360 else()
361         set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
362         set(CPACK_GENERATOR TGZ)
363         set(CPACK_SOURCE_GENERATOR TGZ)
364 endif()
366 include(CPack)
369 # Add a target to generate API documentation with Doxygen
370 if(BUILD_DOCUMENTATION)
371         find_package(Doxygen)
372         if(DOXYGEN_FOUND)
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
379                 )
380         endif()
381 endif()
383 # Fetch Tracy
384 if(BUILD_WITH_TRACY)
385         include(FetchContent)
387         message(STATUS "Fetching Tracy (${FETCH_TRACY_GIT_TAG})...")
388         FetchContent_Declare(
389                 tracy
390                 GIT_REPOSITORY https://github.com/wolfpld/tracy.git
391                 GIT_TAG ${FETCH_TRACY_GIT_TAG}
392                 GIT_SHALLOW TRUE
393                 GIT_PROGRESS TRUE
394         )
395         FetchContent_MakeAvailable(tracy)
396         message(STATUS "Fetching Tracy - done")
397 endif()