clientobject: add null checks
[waspsaliva.git] / src / CMakeLists.txt
blobb8ce69f1d71880fc1d74fccd426afd861093d070
1 cmake_minimum_required(VERSION 2.6)
3 project(minetest)
5 INCLUDE(CheckIncludeFiles)
6 INCLUDE(CheckLibraryExists)
8 # Add custom SemiDebug build mode
9 set(CMAKE_CXX_FLAGS_SEMIDEBUG "-O1 -g -Wall" CACHE STRING
10         "Flags used by the C++ compiler during semidebug builds."
11         FORCE
13 set(CMAKE_C_FLAGS_SEMIDEBUG "-O1 -g -Wall -pedantic" CACHE STRING
14         "Flags used by the C compiler during semidebug builds."
15         FORCE
17 mark_as_advanced(
18         CMAKE_CXX_FLAGS_SEMIDEBUG
19         CMAKE_C_FLAGS_SEMIDEBUG
21 set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
22         "Choose the type of build. Options are: None Debug SemiDebug RelWithDebInfo MinSizeRel."
23         FORCE
27 # Set some random things default to not being visible in the GUI
28 mark_as_advanced(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH)
31 if(NOT (BUILD_CLIENT OR BUILD_SERVER))
32         message(WARNING "Neither BUILD_CLIENT nor BUILD_SERVER is set! Setting BUILD_SERVER=true")
33         set(BUILD_SERVER TRUE)
34 endif()
37 option(ENABLE_CURL "Enable cURL support for fetching media" TRUE)
38 set(USE_CURL FALSE)
40 if(ENABLE_CURL)
41         find_package(CURL)
42         if (CURL_FOUND)
43                 message(STATUS "cURL support enabled.")
44                 set(USE_CURL TRUE)
45         endif()
46 else()
47         mark_as_advanced(CLEAR CURL_LIBRARY CURL_INCLUDE_DIR)
48 endif()
50 if(NOT USE_CURL)
51         if(BUILD_CLIENT)
52                 message(WARNING "cURL is required to load the server list")
53         endif()
54         if(BUILD_SERVER)
55                 message(WARNING "cURL is required to announce to the server list")
56         endif()
57 endif()
60 option(ENABLE_GETTEXT "Use GetText for internationalization" TRUE)
61 set(USE_GETTEXT FALSE)
63 if(ENABLE_GETTEXT)
64         find_package(GettextLib)
65         if(GETTEXTLIB_FOUND)
66                 if(WIN32)
67                         message(STATUS "GetText library: ${GETTEXT_LIBRARY}")
68                         message(STATUS "GetText DLL: ${GETTEXT_DLL}")
69                         message(STATUS "GetText iconv DLL: ${GETTEXT_ICONV_DLL}")
70                 endif()
71                 set(USE_GETTEXT TRUE)
72                 message(STATUS "GetText enabled; locales found: ${GETTEXT_AVAILABLE_LOCALES}")
73         endif(GETTEXTLIB_FOUND)
74 else()
75         mark_as_advanced(GETTEXT_ICONV_DLL GETTEXT_INCLUDE_DIR GETTEXT_LIBRARY GETTEXT_MSGFMT)
76         message(STATUS "GetText disabled.")
77 endif()
80 option(ENABLE_SOUND "Enable sound" TRUE)
81 set(USE_SOUND FALSE)
83 if(BUILD_CLIENT AND ENABLE_SOUND)
84         # Sound libraries
85         find_package(OpenAL)
86         find_package(Vorbis)
87         if(NOT OPENAL_FOUND)
88                 message(STATUS "Sound enabled, but OpenAL not found!")
89                 mark_as_advanced(CLEAR OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
90         endif()
91         if(NOT VORBIS_FOUND)
92                 message(STATUS "Sound enabled, but Vorbis libraries not found!")
93                 mark_as_advanced(CLEAR OGG_INCLUDE_DIR VORBIS_INCLUDE_DIR OGG_LIBRARY VORBIS_LIBRARY VORBISFILE_LIBRARY)
94         endif()
95         if(OPENAL_FOUND AND VORBIS_FOUND)
96                 set(USE_SOUND TRUE)
97                 message(STATUS "Sound enabled.")
98         else()
99                 message(FATAL_ERROR "Sound enabled, but cannot be used.\n"
100                         "To continue, either fill in the required paths or disable sound. (-DENABLE_SOUND=0)")
101         endif()
102 endif()
105 option(ENABLE_GLES "Use OpenGL ES instead of OpenGL" FALSE)
106 mark_as_advanced(ENABLE_GLES)
107 if(BUILD_CLIENT)
108         if(ENABLE_GLES)
109                 find_package(OpenGLES2 REQUIRED)
110         else()
111                 # transitive dependency from Irrlicht (see longer explanation below)
112                 if(NOT WIN32)
113                         set(OPENGL_GL_PREFERENCE "LEGACY" CACHE STRING
114                                 "See CMake Policy CMP0072 for reference. GLVND is broken on some nvidia setups")
115                         set(OpenGL_GL_PREFERENCE ${OPENGL_GL_PREFERENCE})
117                         find_package(OpenGL REQUIRED)
118                 endif()
119         endif()
120 endif()
123 option(ENABLE_FREETYPE "Enable FreeType2 (TrueType fonts and basic unicode support)" TRUE)
124 set(USE_FREETYPE FALSE)
126 if(ENABLE_FREETYPE)
128 ## Note: FindFreetype.cmake seems to have been fixed in recent versions of
129 ## CMake. If issues persist, re-enable this workaround specificially for the
130 ## failing platforms.
132 #       if(UNIX)
133 #               include(FindPkgConfig)
134 #               if(PKG_CONFIG_FOUND)
135 #                       pkg_check_modules(FREETYPE QUIET freetype2)
136 #                       if(FREETYPE_FOUND)
137 #                               SET(FREETYPE_PKGCONFIG_FOUND TRUE)
138 #                               SET(FREETYPE_LIBRARY ${FREETYPE_LIBRARIES})
139 #                               # Because CMake is idiotic
140 #                               string(REPLACE ";" " " FREETYPE_CFLAGS_STR ${FREETYPE_CFLAGS})
141 #                               string(REPLACE ";" " " FREETYPE_LDFLAGS_STR ${FREETYPE_LDFLAGS})
142 #                       endif(FREETYPE_FOUND)
143 #               endif(PKG_CONFIG_FOUND)
144 #       endif(UNIX)
145 #       if(NOT FREETYPE_FOUND)
146 #               find_package(Freetype)
147 #       endif()
148         find_package(Freetype)
149         if(FREETYPE_FOUND)
150                 message(STATUS "Freetype enabled.")
151                 set(USE_FREETYPE TRUE)
152         endif()
153 endif(ENABLE_FREETYPE)
155 option(ENABLE_CURSES "Enable ncurses console" TRUE)
156 set(USE_CURSES FALSE)
158 if(ENABLE_CURSES)
159         find_package(Ncursesw)
160         if(CURSES_FOUND)
161                 set(USE_CURSES TRUE)
162                 message(STATUS "ncurses console enabled.")
163                 include_directories(${CURSES_INCLUDE_DIRS})
164         else()
165                 message(STATUS "ncurses not found!")
166         endif()
167 endif(ENABLE_CURSES)
169 option(ENABLE_POSTGRESQL "Enable PostgreSQL backend" TRUE)
170 set(USE_POSTGRESQL FALSE)
172 if(ENABLE_POSTGRESQL)
173         find_package("PostgreSQL")
175         if(PostgreSQL_FOUND)
176                 set(USE_POSTGRESQL TRUE)
177                 message(STATUS "PostgreSQL backend enabled")
178                 # This variable is case sensitive, don't try to change it to POSTGRESQL_INCLUDE_DIR
179                 message(STATUS "PostgreSQL includes: ${PostgreSQL_INCLUDE_DIRS}")
180                 include_directories(${PostgreSQL_INCLUDE_DIRS})
181         else()
182                 message(STATUS "PostgreSQL not found!")
183         endif()
184 endif(ENABLE_POSTGRESQL)
186 option(ENABLE_LEVELDB "Enable LevelDB backend" TRUE)
187 set(USE_LEVELDB FALSE)
189 if(ENABLE_LEVELDB)
190         find_library(LEVELDB_LIBRARY NAMES leveldb libleveldb)
191         find_path(LEVELDB_INCLUDE_DIR db.h PATH_SUFFIXES leveldb)
192         if(LEVELDB_LIBRARY AND LEVELDB_INCLUDE_DIR)
193                 set(USE_LEVELDB TRUE)
194                 message(STATUS "LevelDB backend enabled.")
195                 include_directories(${LEVELDB_INCLUDE_DIR})
196         else()
197                 message(STATUS "LevelDB not found!")
198         endif()
199 endif(ENABLE_LEVELDB)
202 OPTION(ENABLE_REDIS "Enable Redis backend" TRUE)
203 set(USE_REDIS FALSE)
205 if(ENABLE_REDIS)
206         find_library(REDIS_LIBRARY hiredis)
207         find_path(REDIS_INCLUDE_DIR hiredis.h PATH_SUFFIXES hiredis)
208         if(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
209                 set(USE_REDIS TRUE)
210                 message(STATUS "Redis backend enabled.")
211                 include_directories(${REDIS_INCLUDE_DIR})
212         else(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
213                 message(STATUS "Redis not found!")
214         endif(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
215 endif(ENABLE_REDIS)
218 find_package(SQLite3 REQUIRED)
220 OPTION(ENABLE_PROMETHEUS "Enable prometheus client support" FALSE)
221 set(USE_PROMETHEUS FALSE)
223 if(ENABLE_PROMETHEUS)
224         find_path(PROMETHEUS_CPP_INCLUDE_DIR NAMES prometheus/counter.h)
225         find_library(PROMETHEUS_PULL_LIBRARY NAMES prometheus-cpp-pull)
226         find_library(PROMETHEUS_CORE_LIBRARY NAMES prometheus-cpp-core)
227         if(PROMETHEUS_CPP_INCLUDE_DIR AND PROMETHEUS_PULL_LIBRARY AND PROMETHEUS_CORE_LIBRARY)
228                 set(PROMETHEUS_LIBRARIES ${PROMETHEUS_PULL_LIBRARY} ${PROMETHEUS_CORE_LIBRARY})
229                 set(USE_PROMETHEUS TRUE)
230                 include_directories(${PROMETHEUS_CPP_INCLUDE_DIR})
231         endif(PROMETHEUS_CPP_INCLUDE_DIR AND PROMETHEUS_PULL_LIBRARY AND PROMETHEUS_CORE_LIBRARY)
232 endif(ENABLE_PROMETHEUS)
234 if(USE_PROMETHEUS)
235         message(STATUS "Prometheus client enabled.")
236 else(USE_PROMETHEUS)
237         message(STATUS "Prometheus client disabled.")
238 endif(USE_PROMETHEUS)
240 OPTION(ENABLE_SPATIAL "Enable SpatialIndex AreaStore backend" TRUE)
241 set(USE_SPATIAL FALSE)
243 if(ENABLE_SPATIAL)
244         find_library(SPATIAL_LIBRARY spatialindex)
245         find_path(SPATIAL_INCLUDE_DIR spatialindex/SpatialIndex.h)
246         if(SPATIAL_LIBRARY AND SPATIAL_INCLUDE_DIR)
247                 set(USE_SPATIAL TRUE)
248                 message(STATUS "SpatialIndex AreaStore backend enabled.")
249                 include_directories(${SPATIAL_INCLUDE_DIR})
250         else(SPATIAL_LIBRARY AND SPATIAL_INCLUDE_DIR)
251                 message(STATUS "SpatialIndex not found!")
252         endif(SPATIAL_LIBRARY AND SPATIAL_INCLUDE_DIR)
253 endif(ENABLE_SPATIAL)
256 if(NOT MSVC)
257         set(USE_GPROF FALSE CACHE BOOL "Use -pg flag for g++")
258 endif()
260 # Haiku endian support
261 if(HAIKU)
262         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE")
263         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_BSD_SOURCE")
264 endif()
266 # Use cmake_config.h
267 add_definitions(-DUSE_CMAKE_CONFIG_H)
269 if(WIN32)
270         # Windows
271         if(MSVC) # MSVC Specifics
272                 set(PLATFORM_LIBS dbghelp.lib ${PLATFORM_LIBS})
273                 # Surpress some useless warnings
274                 add_definitions ( /D "_CRT_SECURE_NO_DEPRECATE" /W1 )
275                 # Get M_PI to work
276                 add_definitions(/D "_USE_MATH_DEFINES")
277                 # Dont define min/max macros in minwindef.h
278                 add_definitions(/D "NOMINMAX")
279         else() # Probably MinGW = GCC
280                 set(PLATFORM_LIBS "")
281         endif()
282         set(PLATFORM_LIBS ws2_32.lib version.lib shlwapi.lib ${PLATFORM_LIBS})
284         # Zlib stuff
285         find_path(ZLIB_INCLUDE_DIR "zlib.h" DOC "Zlib include directory")
286         find_library(ZLIB_LIBRARIES "zlib" DOC "Path to zlib library")
288         # Dll's are automatically copied to the output directory by vcpkg when VCPKG_APPLOCAL_DEPS=ON
289         if(NOT VCPKG_APPLOCAL_DEPS)
290                 find_file(ZLIB_DLL NAMES "zlib.dll" "zlib1.dll" DOC "Path to zlib.dll for installation (optional)")
291                 if(ENABLE_SOUND)
292                         set(OPENAL_DLL "" CACHE FILEPATH "Path to OpenAL32.dll for installation (optional)")
293                         set(OGG_DLL "" CACHE FILEPATH "Path to libogg.dll for installation (optional)")
294                         set(VORBIS_DLL "" CACHE FILEPATH "Path to libvorbis.dll for installation (optional)")
295                         set(VORBISFILE_DLL "" CACHE FILEPATH "Path to libvorbisfile.dll for installation (optional)")
296                 endif()
297                 if(USE_LUAJIT)
298                         set(LUA_DLL "" CACHE FILEPATH "Path to luajit-5.1.dll for installation (optional)")
299                 endif()
300         endif()
302 else()
303         # Unix probably
304         if(BUILD_CLIENT)
305                 if(NOT HAIKU AND NOT APPLE)
306                         find_package(X11 REQUIRED)
307                 endif(NOT HAIKU AND NOT APPLE)
309                 ##
310                 # The following dependencies are transitive dependencies from Irrlicht.
311                 # Minetest itself does not use them, but we link them so that statically
312                 # linking Irrlicht works.
313                 if(NOT HAIKU AND NOT APPLE)
314                         # This way Xxf86vm is found on OpenBSD too
315                         find_library(XXF86VM_LIBRARY Xxf86vm)
316                         mark_as_advanced(XXF86VM_LIBRARY)
317                         set(CLIENT_PLATFORM_LIBS ${CLIENT_PLATFORM_LIBS} ${XXF86VM_LIBRARY})
318                 endif(NOT HAIKU AND NOT APPLE)
320                 find_package(JPEG REQUIRED)
321                 find_package(BZip2 REQUIRED)
322                 find_package(PNG REQUIRED)
323                 if(APPLE)
324                         find_library(CARBON_LIB Carbon REQUIRED)
325                         find_library(COCOA_LIB Cocoa REQUIRED)
326                         find_library(IOKIT_LIB IOKit REQUIRED)
327                         mark_as_advanced(
328                                 CARBON_LIB
329                                 COCOA_LIB
330                                 IOKIT_LIB
331                         )
332                         SET(CLIENT_PLATFORM_LIBS ${CLIENT_PLATFORM_LIBS} ${CARBON_LIB} ${COCOA_LIB} ${IOKIT_LIB})
333                 endif(APPLE)
334                 ##
335         endif(BUILD_CLIENT)
337         find_package(ZLIB REQUIRED)
338         set(PLATFORM_LIBS -lpthread ${CMAKE_DL_LIBS})
339         if(APPLE)
340                 set(PLATFORM_LIBS "-framework CoreFoundation" ${PLATFORM_LIBS})
341         else()
342                 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
343                 if (HAVE_LIBRT)
344                         set(PLATFORM_LIBS -lrt ${PLATFORM_LIBS})
345                 endif(HAVE_LIBRT)
346         endif(APPLE)
348         # Prefer local iconv if installed
349         find_library(ICONV_LIBRARY iconv)
350         mark_as_advanced(ICONV_LIBRARY)
351         if (ICONV_LIBRARY)
352                 set(PLATFORM_LIBS ${PLATFORM_LIBS} ${ICONV_LIBRARY})
353         endif()
354         if (HAIKU)
355                 set(PLATFORM_LIBS ${PLATFORM_LIBS} intl network)
356         endif()
358 endif()
360 check_include_files(endian.h HAVE_ENDIAN_H)
362 configure_file(
363         "${PROJECT_SOURCE_DIR}/cmake_config.h.in"
364         "${PROJECT_BINARY_DIR}/cmake_config.h"
368 # Add a target that always rebuilds cmake_config_githash.h
369 add_custom_target(GenerateVersion
370         COMMAND ${CMAKE_COMMAND}
371         -D "GENERATE_VERSION_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
372         -D "GENERATE_VERSION_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
373         -D "VERSION_STRING=${VERSION_STRING}"
374         -D "DEVELOPMENT_BUILD=${DEVELOPMENT_BUILD}"
375         -P "${CMAKE_SOURCE_DIR}/cmake/Modules/GenerateVersion.cmake"
376         WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
379 add_subdirectory(threading)
380 add_subdirectory(content)
381 add_subdirectory(database)
382 add_subdirectory(gui)
383 add_subdirectory(mapgen)
384 add_subdirectory(network)
385 add_subdirectory(script)
386 add_subdirectory(unittest)
387 add_subdirectory(util)
388 add_subdirectory(irrlicht_changes)
389 add_subdirectory(server)
391 set(common_SRCS
392         ${database_SRCS}
393         ${mapgen_SRCS}
394         ${server_SRCS}
395         ${content_SRCS}
396         ban.cpp
397         chat.cpp
398         clientiface.cpp
399         collision.cpp
400         content_mapnode.cpp
401         content_nodemeta.cpp
402         convert_json.cpp
403         craftdef.cpp
404         debug.cpp
405         defaultsettings.cpp
406         emerge.cpp
407         environment.cpp
408         face_position_cache.cpp
409         filesys.cpp
410         gettext.cpp
411         httpfetch.cpp
412         hud.cpp
413         inventory.cpp
414         inventorymanager.cpp
415         itemdef.cpp
416         itemstackmetadata.cpp
417         light.cpp
418         log.cpp
419         main.cpp
420         map.cpp
421         map_settings_manager.cpp
422         mapblock.cpp
423         mapnode.cpp
424         mapsector.cpp
425         metadata.cpp
426         modchannels.cpp
427         nameidmapping.cpp
428         nodedef.cpp
429         nodemetadata.cpp
430         nodetimer.cpp
431         noise.cpp
432         objdef.cpp
433         object_properties.cpp
434         particles.cpp
435         pathfinder.cpp
436         player.cpp
437         porting.cpp
438         profiler.cpp
439         raycast.cpp
440         reflowscan.cpp
441         remoteplayer.cpp
442         rollback.cpp
443         rollback_interface.cpp
444         serialization.cpp
445         server.cpp
446         serverenvironment.cpp
447         serverlist.cpp
448         settings.cpp
449         staticobject.cpp
450         terminal_chat_console.cpp
451         texture_override.cpp
452         tileanimation.cpp
453         tool.cpp
454         translation.cpp
455         version.cpp
456         voxel.cpp
457         voxelalgorithms.cpp
458         hud.cpp
459         ${common_network_SRCS}
460         ${JTHREAD_SRCS}
461         ${common_SCRIPT_SRCS}
462         ${UTIL_SRCS}
465 if(BUILD_UNITTESTS)
466         set(common_SRCS ${common_SRCS} ${UNITTEST_SRCS})
467 endif()
470 # This gives us the icon and file version information
471 if(WIN32)
472         set(WINRESOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../misc/winresource.rc")
473         set(MINETEST_EXE_MANIFEST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../misc/minetest.exe.manifest")
474         if(MINGW)
475                 if(NOT CMAKE_RC_COMPILER)
476                         set(CMAKE_RC_COMPILER "windres.exe")
477                 endif()
478                 ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o
479                         COMMAND ${CMAKE_RC_COMPILER} -I${CMAKE_CURRENT_SOURCE_DIR} -I${CMAKE_CURRENT_BINARY_DIR}
480                         -i${WINRESOURCE_FILE}
481                         -o ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o
482                         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
483                         DEPENDS ${WINRESOURCE_FILE} ${MINETEST_EXE_MANIFEST_FILE})
484                 SET(extra_windows_SRCS ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o)
485         else(MINGW) # Probably MSVC
486                 set(extra_windows_SRCS ${WINRESOURCE_FILE} ${MINETEST_EXE_MANIFEST_FILE})
487         endif(MINGW)
488 endif()
491 # Client sources
492 if (BUILD_CLIENT)
493         add_subdirectory(client)
494 endif(BUILD_CLIENT)
496 set(client_SRCS
497         ${client_SRCS}
498         ${common_SRCS}
499         ${gui_SRCS}
500         ${client_network_SRCS}
501         ${client_irrlicht_changes_SRCS}
502         ${client_SCRIPT_SRCS}
505 if(BUILD_UNITTESTS)
506         set(client_SRCS ${client_SRCS} ${UNITTEST_CLIENT_SRCS})
507 endif()
509 list(SORT client_SRCS)
511 # Server sources
512 set(server_SRCS
513         ${common_SRCS}
515 list(SORT server_SRCS)
517 # Avoid source_group on broken CMake version.
518 # see issue #7074 #7075
519 if (CMAKE_VERSION VERSION_GREATER 3.8.1)
520         source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "Source Files" FILES ${client_SRCS})
521         source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "Source Files" FILES ${server_SRCS})
522 endif()
524 include_directories(
525         ${PROJECT_BINARY_DIR}
526         ${PROJECT_SOURCE_DIR}
527         ${IRRLICHT_INCLUDE_DIR}
528         ${ZLIB_INCLUDE_DIR}
529         ${PNG_INCLUDE_DIR}
530         ${SOUND_INCLUDE_DIRS}
531         ${SQLITE3_INCLUDE_DIR}
532         ${LUA_INCLUDE_DIR}
533         ${GMP_INCLUDE_DIR}
534         ${JSON_INCLUDE_DIR}
535         ${X11_INCLUDE_DIR}
536         ${PROJECT_SOURCE_DIR}/script
539 if(USE_GETTEXT)
540         include_directories(${GETTEXT_INCLUDE_DIR})
541 endif()
543 if(USE_FREETYPE)
544         include_directories(${FREETYPE_INCLUDE_DIRS})
545 endif()
547 if(USE_CURL)
548         include_directories(${CURL_INCLUDE_DIR})
549 endif()
552 set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
555 if(BUILD_CLIENT)
556         add_executable(${PROJECT_NAME} ${client_SRCS} ${extra_windows_SRCS})
557         add_dependencies(${PROJECT_NAME} GenerateVersion)
558         set(client_LIBS
559                 ${PROJECT_NAME}
560                 ${ZLIB_LIBRARIES}
561                 ${IRRLICHT_LIBRARY}
562                 ${JPEG_LIBRARIES}
563                 ${BZIP2_LIBRARIES}
564                 ${PNG_LIBRARIES}
565                 ${X11_LIBRARIES}
566                 ${SOUND_LIBRARIES}
567                 ${SQLITE3_LIBRARY}
568                 ${LUA_LIBRARY}
569                 ${GMP_LIBRARY}
570                 ${JSON_LIBRARY}
571                 ${PLATFORM_LIBS}
572                 ${CLIENT_PLATFORM_LIBS}
573         )
574         target_link_libraries(
575                 ${client_LIBS}
576         )
577         if(ENABLE_GLES)
578                 target_link_libraries(
579                         ${PROJECT_NAME}
580                         ${OPENGLES2_LIBRARIES}
581                         ${EGL_LIBRARIES}
582                 )
583         else()
584                 target_link_libraries(
585                         ${PROJECT_NAME}
586                         ${OPENGL_LIBRARIES}
587                 )
588         endif()
589         if(USE_GETTEXT)
590                 target_link_libraries(
591                         ${PROJECT_NAME}
592                         ${GETTEXT_LIBRARY}
593                 )
594         endif()
595         if(USE_CURL)
596                 target_link_libraries(
597                         ${PROJECT_NAME}
598                         ${CURL_LIBRARY}
599                 )
600         endif()
601         if(USE_FREETYPE)
602                 if(FREETYPE_PKGCONFIG_FOUND)
603                         set_target_properties(${PROJECT_NAME}
604                                 PROPERTIES
605                                 COMPILE_FLAGS "${FREETYPE_CFLAGS_STR}"
606                         )
607                 endif()
608                 target_link_libraries(
609                         ${PROJECT_NAME}
610                         ${FREETYPE_LIBRARY}
611                 )
612         endif()
613         if (USE_CURSES)
614                 target_link_libraries(${PROJECT_NAME} ${CURSES_LIBRARIES})
615         endif()
616         if (USE_POSTGRESQL)
617                 target_link_libraries(${PROJECT_NAME} ${PostgreSQL_LIBRARIES})
618         endif()
619         if (USE_LEVELDB)
620                 target_link_libraries(${PROJECT_NAME} ${LEVELDB_LIBRARY})
621         endif()
622         if (USE_REDIS)
623                 target_link_libraries(${PROJECT_NAME} ${REDIS_LIBRARY})
624         endif()
625         if (USE_PROMETHEUS)
626                 target_link_libraries(${PROJECT_NAME} ${PROMETHEUS_LIBRARIES})
627         endif()
628         if (USE_SPATIAL)
629                 target_link_libraries(${PROJECT_NAME} ${SPATIAL_LIBRARY})
630         endif()
631 endif(BUILD_CLIENT)
634 if(BUILD_SERVER)
635         add_executable(${PROJECT_NAME}server ${server_SRCS} ${extra_windows_SRCS})
636         add_dependencies(${PROJECT_NAME}server GenerateVersion)
637         target_link_libraries(
638                 ${PROJECT_NAME}server
639                 ${ZLIB_LIBRARIES}
640                 ${SQLITE3_LIBRARY}
641                 ${JSON_LIBRARY}
642                 ${LUA_LIBRARY}
643                 ${GMP_LIBRARY}
644                 ${PLATFORM_LIBS}
645         )
646         set_target_properties(${PROJECT_NAME}server PROPERTIES
647                         COMPILE_DEFINITIONS "SERVER")
648         if (USE_GETTEXT)
649                 target_link_libraries(${PROJECT_NAME}server ${GETTEXT_LIBRARY})
650         endif()
651         if (USE_CURSES)
652                 target_link_libraries(${PROJECT_NAME}server ${CURSES_LIBRARIES})
653         endif()
654         if (USE_POSTGRESQL)
655                 target_link_libraries(${PROJECT_NAME}server ${PostgreSQL_LIBRARIES})
656         endif()
657         if (USE_LEVELDB)
658                 target_link_libraries(${PROJECT_NAME}server ${LEVELDB_LIBRARY})
659         endif()
660         if (USE_REDIS)
661                 target_link_libraries(${PROJECT_NAME}server ${REDIS_LIBRARY})
662         endif()
663         if (USE_PROMETHEUS)
664                 target_link_libraries(${PROJECT_NAME}server ${PROMETHEUS_LIBRARIES})
665         endif()
666         if (USE_SPATIAL)
667                 target_link_libraries(${PROJECT_NAME}server ${SPATIAL_LIBRARY})
668         endif()
669         if(USE_CURL)
670                 target_link_libraries(
671                         ${PROJECT_NAME}server
672                         ${CURL_LIBRARY}
673                 )
674         endif()
675 endif(BUILD_SERVER)
677 # Blacklisted locales that don't work.
678 # see issue #4638
679 set(GETTEXT_BLACKLISTED_LOCALES
680         ar
681         he
682         ky
683         ms_Arab
684         th
687 option(APPLY_LOCALE_BLACKLIST "Use a blacklist to avoid broken locales" TRUE)
689 if (GETTEXTLIB_FOUND AND APPLY_LOCALE_BLACKLIST)
690         set(GETTEXT_USED_LOCALES "")
691         foreach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
692                 if (NOT ";${GETTEXT_BLACKLISTED_LOCALES};" MATCHES ";${LOCALE};")
693                         list(APPEND GETTEXT_USED_LOCALES ${LOCALE})
694                 endif()
695         endforeach()
696         message(STATUS "Locale blacklist applied; Locales used: ${GETTEXT_USED_LOCALES}")
697 endif()
699 # Set some optimizations and tweaks
701 include(CheckCSourceCompiles)
703 if(MSVC)
704         # Visual Studio
705         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D WIN32_LEAN_AND_MEAN")
706         # EHa enables SEH exceptions (used for catching segfaults)
707         set(CMAKE_CXX_FLAGS_RELEASE "/EHa /Ox /MD /GS- /Zi /fp:fast /D NDEBUG /D _HAS_ITERATOR_DEBUGGING=0")
708         if(CMAKE_SIZEOF_VOID_P EQUAL 4)
709                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:SSE")
710         endif()
712         set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
714         set(CMAKE_CXX_FLAGS_SEMIDEBUG "/MDd /Zi /Ob0 /O1 /RTC1")
716         # Debug build doesn't catch exceptions by itself
717         # Add some optimizations because otherwise it's VERY slow
718         set(CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1")
720         # Flags for C files (sqlite)
721         # /MD = dynamically link to MSVCRxxx.dll
722         set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MD")
724         # Flags that cannot be shared between cl and clang-cl
725         # https://clang.llvm.org/docs/UsersManual.html#clang-cl
726         if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
727                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=lld")
729                 # Disable pragma-pack warning
730                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-pragma-pack")
731         else()
732                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
733                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /TP /FD /GL")
734                 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
735         endif()
736 else()
737         # GCC or compatible compilers such as Clang
738         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
739         if(WARN_ALL)
740                 set(RELEASE_WARNING_FLAGS "-Wall")
741         else()
742                 set(RELEASE_WARNING_FLAGS "")
743         endif()
744         if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
745                 set(WARNING_FLAGS "${WARNING_FLAGS} -Wsign-compare")
746         endif()
748         if(APPLE AND USE_LUAJIT)
749                 # required per http://luajit.org/install.html
750                 SET(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -pagezero_size 10000 -image_base 100000000")
751         elseif(UNIX AND USE_LUAJIT)
752                 check_c_source_compiles("#ifndef __aarch64__\n#error\n#endif\nint main(){}" IS_AARCH64)
753                 if(IS_AARCH64)
754                         # Move text segment below LuaJIT's 47-bit limit (see issue #9367)
755                         SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Ttext-segment=0x200000000")
756                 endif()
757         endif()
759         if(MINGW)
760                 set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions")
761                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_LEAN_AND_MEAN")
762         endif()
764         # Use a safe subset of flags to speed up math calculations:
765         # - we don't need errno or math exceptions
766         # - we don't deal with Inf/NaN or signed zero
767         set(MATH_FLAGS "-fno-math-errno -fno-trapping-math -ffinite-math-only -fno-signed-zeros")
769         set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -Wall -pipe -funroll-loops")
770         if(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)")
771                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os")
772         else()
773                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -fomit-frame-pointer")
774                 if(CMAKE_SYSTEM_NAME STREQUAL "Linux"
775                                 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
776                                 AND CMAKE_CXX_COMPILER_VERSION MATCHES "^9\\.")
777                         # Clang 9 has broken -ffast-math on glibc
778                 else()
779                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MATH_FLAGS}")
780                 endif()
781         endif(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)")
782         set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS}")
783         set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS}")
785         if(USE_GPROF)
786                 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
787         endif()
789         if(MINGW)
790                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mwindows")
791         endif()
792 endif()
795 # Installation
797 if(WIN32)
798         if(VCPKG_APPLOCAL_DEPS)
799                 # Collect the dll's from the output path
800                 install(DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/Release/
801                                 DESTINATION ${BINDIR}
802                                 CONFIGURATIONS Release
803                                 FILES_MATCHING PATTERN "*.dll")
804                 install(DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/Debug/
805                                 DESTINATION ${BINDIR}
806                                 CONFIGURATIONS Debug
807                                 FILES_MATCHING PATTERN "*.dll")
808                 install(DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/RelWithDebInfo/
809                                 DESTINATION ${BINDIR}
810                                 CONFIGURATIONS RelWithDebInfo
811                                 FILES_MATCHING PATTERN "*.dll")
812                 install(DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/MinSizeRel/
813                                 DESTINATION ${BINDIR}
814                                 CONFIGURATIONS MinSizeRel
815                                 FILES_MATCHING PATTERN "*.dll")
816         else()
817                 # Use the old-style way to install dll's
818                 if(USE_SOUND)
819                         if(OPENAL_DLL)
820                                 install(FILES ${OPENAL_DLL} DESTINATION ${BINDIR})
821                         endif()
822                         if(OGG_DLL)
823                                 install(FILES ${OGG_DLL} DESTINATION ${BINDIR})
824                         endif()
825                         if(VORBIS_DLL)
826                                 install(FILES ${VORBIS_DLL} DESTINATION ${BINDIR})
827                         endif()
828                         if(VORBISFILE_DLL)
829                                 install(FILES ${VORBISFILE_DLL} DESTINATION ${BINDIR})
830                         endif()
831                 endif()
832                 if(CURL_DLL)
833                         install(FILES ${CURL_DLL} DESTINATION ${BINDIR})
834                 endif()
835                 if(ZLIB_DLL)
836                         install(FILES ${ZLIB_DLL} DESTINATION ${BINDIR})
837                 endif()
838                 if(FREETYPE_DLL)
839                         install(FILES ${FREETYPE_DLL} DESTINATION ${BINDIR})
840                 endif()
841                 if(SQLITE3_DLL)
842                         install(FILES ${SQLITE3_DLL} DESTINATION ${BINDIR})
843                 endif()
844                 if(LEVELDB_DLL)
845                         install(FILES ${LEVELDB_DLL} DESTINATION ${BINDIR})
846                 endif()
847                 if(LUA_DLL)
848                         install(FILES ${LUA_DLL} DESTINATION ${BINDIR})
849                 endif()
850         endif()
851 endif()
853 if(BUILD_CLIENT)
854         install(TARGETS ${PROJECT_NAME}
855                 RUNTIME DESTINATION ${BINDIR}
856                 LIBRARY DESTINATION ${BINDIR}
857                 ARCHIVE DESTINATION ${BINDIR}
858                 BUNDLE DESTINATION .
859         )
861         if(APPLE)
862                 install(CODE "
863                         set(BU_CHMOD_BUNDLE_ITEMS ON)
864                         include(BundleUtilities)
865                         fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${BUNDLE_PATH}\" \"\" \"\${CMAKE_INSTALL_PREFIX}/${BINDIR}\")
866                 " COMPONENT Runtime)
867         endif()
869         if(USE_GETTEXT)
870                 foreach(LOCALE ${GETTEXT_USED_LOCALES})
871                         set_mo_paths(MO_BUILD_PATH MO_DEST_PATH ${LOCALE})
872                         set(MO_BUILD_PATH "${MO_BUILD_PATH}/${PROJECT_NAME}.mo")
873                         install(FILES ${MO_BUILD_PATH} DESTINATION ${MO_DEST_PATH})
874                 endforeach()
875         endif()
877         if(USE_FREETYPE)
878                 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../fonts" DESTINATION "${SHAREDIR}"
879                                 FILES_MATCHING PATTERN "*.ttf" PATTERN "*.txt")
880         else()
881                 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../fonts" DESTINATION "${SHAREDIR}"
882                                 FILES_MATCHING PATTERN "*.png" PATTERN "*.xml")
883         endif()
885         if(WIN32)
886                 if(NOT VCPKG_APPLOCAL_DEPS)
887                         if(DEFINED IRRLICHT_DLL)
888                                 install(FILES ${IRRLICHT_DLL} DESTINATION ${BINDIR})
889                         endif()
890                         if(USE_GETTEXT)
891                                 if(DEFINED GETTEXT_DLL)
892                                         install(FILES ${GETTEXT_DLL} DESTINATION ${BINDIR})
893                                 endif()
894                                 if(DEFINED GETTEXT_ICONV_DLL)
895                                         install(FILES ${GETTEXT_ICONV_DLL} DESTINATION ${BINDIR})
896                                 endif()
897                         endif()
898                 endif()
899         endif()
900 endif(BUILD_CLIENT)
902 if(BUILD_SERVER)
903         install(TARGETS ${PROJECT_NAME}server DESTINATION ${BINDIR})
904 endif()
906 if (USE_GETTEXT)
907         set(MO_FILES)
909         foreach(LOCALE ${GETTEXT_USED_LOCALES})
910                 set(PO_FILE_PATH "${GETTEXT_PO_PATH}/${LOCALE}/${PROJECT_NAME}.po")
911                 set_mo_paths(MO_BUILD_PATH MO_DEST_PATH ${LOCALE})
912                 set(MO_FILE_PATH "${MO_BUILD_PATH}/${PROJECT_NAME}.mo")
914                 add_custom_command(OUTPUT ${MO_BUILD_PATH}
915                         COMMAND ${CMAKE_COMMAND} -E make_directory ${MO_BUILD_PATH}
916                         COMMENT "mo-update [${LOCALE}]: Creating locale directory.")
918                 add_custom_command(
919                         OUTPUT ${MO_FILE_PATH}
920                         COMMAND ${GETTEXT_MSGFMT} -o ${MO_FILE_PATH} ${PO_FILE_PATH}
921                         DEPENDS ${MO_BUILD_PATH} ${PO_FILE_PATH}
922                         WORKING_DIRECTORY "${GETTEXT_PO_PATH}/${LOCALE}"
923                         COMMENT "mo-update [${LOCALE}]: Creating mo file."
924                         )
926                 set(MO_FILES ${MO_FILES} ${MO_FILE_PATH})
927         endforeach()
929         add_custom_target(translations ALL COMMENT "mo update" DEPENDS ${MO_FILES})
930 endif()