2 cmake_minimum_required( VERSION 2.6 )
4 # Set some random things default to not being visible in the GUI
5 mark_as_advanced(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH)
6 mark_as_advanced(SQLITE3_INCLUDE_DIR SQLITE3_LIBRARY)
7 mark_as_advanced(JSON_INCLUDE_DIR JSON_LIBRARY)
9 option(ENABLE_CURL "Enable cURL support for fetching media" 1)
12 mark_as_advanced(CLEAR CURL_LIBRARY CURL_INCLUDE_DIR)
13 endif(NOT ENABLE_CURL)
19 if (CURL_FOUND AND ENABLE_CURL)
20 message(STATUS "cURL support enabled")
22 endif(CURL_FOUND AND ENABLE_CURL)
24 # user-visible option to enable/disable gettext usage
25 OPTION(ENABLE_GETTEXT "Use GetText for internationalization" 0)
27 # this is only set to 1 if gettext is enabled _and_ available
31 find_package(GettextLib)
33 MARK_AS_ADVANCED(GETTEXT_ICONV_DLL GETTEXT_INCLUDE_DIR GETTEXT_LIBRARY GETTEXT_MSGFMT)
36 if(GETTEXT_FOUND AND ENABLE_GETTEXT)
37 message(STATUS "gettext include path: ${GETTEXT_INCLUDE_DIR}")
38 message(STATUS "gettext msgfmt path: ${GETTEXT_MSGFMT}")
40 message(STATUS "gettext library: ${GETTEXT_LIBRARY}")
41 message(STATUS "gettext dll: ${GETTEXT_DLL}")
42 message(STATUS "gettext iconv dll: ${GETTEXT_ICONV_DLL}")
45 message(STATUS "GetText enabled; locales found: ${GETTEXT_AVAILABLE_LOCALES}")
46 elseif(GETTEXT_FOUND AND NOT ENABLE_GETTEXT)
47 MESSAGE(STATUS "GetText found but disabled;")
48 else(GETTEXT_FOUND AND ENABLE_GETTEXT)
49 message(STATUS "GetText disabled")
50 endif(GETTEXT_FOUND AND ENABLE_GETTEXT)
52 # user visible option to enable/disable sound
53 OPTION(ENABLE_SOUND "Enable sound" ON)
55 # this is only set to 1 if sound is enabled _and_ available
59 if(ENABLE_SOUND AND BUILD_CLIENT)
64 message(STATUS "Sound enabled, but OpenAL not found!")
66 MARK_AS_ADVANCED(CLEAR OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
69 message(STATUS "Sound enabled, but Vorbis libraries not found!")
71 MARK_AS_ADVANCED(CLEAR OGG_INCLUDE_DIR VORBIS_INCLUDE_DIR OGG_LIBRARY VORBIS_LIBRARY VORBISFILE_LIBRARY)
73 if(OPENAL_FOUND AND VORBIS_FOUND)
75 message(STATUS "Sound enabled")
77 endif(ENABLE_SOUND AND BUILD_CLIENT)
80 message(FATAL_ERROR "Sound enabled, but cannot be used.\n"
81 "To continue, either fill in the required paths or disable sound. (-DENABLE_SOUND=0)")
84 set(sound_SRCS sound_openal.cpp)
85 set(SOUND_INCLUDE_DIRS
96 option(ENABLE_FREETYPE "Enable freetype2 (truetype fonts and basic unicode support)" OFF)
100 endif(ENABLE_FREETYPE)
103 set(USE_GPROF 0 CACHE BOOL "Use -pg flag for g++")
107 add_definitions ( -DUSE_CMAKE_CONFIG_H )
111 if(MSVC) # MSVC Specifics
112 # Surpress some useless warnings
113 add_definitions ( /D "_CRT_SECURE_NO_DEPRECATE" /W1 )
114 else() # Probably MinGW = GCC
115 set(PLATFORM_LIBS ws2_32.lib)
118 set(ZLIB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/../../zlib/zlib-1.2.5"
119 CACHE PATH "Zlib include directory")
120 set(ZLIB_LIBRARIES "${PROJECT_SOURCE_DIR}/../../zlib125dll/dll32/zlibwapi.lib"
121 CACHE FILEPATH "Path to zlibwapi.lib")
122 set(ZLIB_DLL "${PROJECT_SOURCE_DIR}/../../zlib125dll/dll32/zlibwapi.dll"
123 CACHE FILEPATH "Path to zlibwapi.dll (for installation)")
124 set(IRRLICHT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../irrlicht-1.7.2"
125 CACHE PATH "irrlicht dir")
127 set(FREETYPE_INCLUDE_DIR_ft2build "${PROJECT_SOURCE_DIR}/../../freetype2/include/"
128 CACHE PATH "freetype include dir")
129 set(FREETYPE_INCLUDE_DIR_freetype2 "${PROJECT_SOURCE_DIR}/../../freetype2/include/freetype"
130 CACHE PATH "freetype include dir")
131 set(FREETYPE_LIBRARY "${PROJECT_SOURCE_DIR}/../../freetype2/objs/win32/vc2005/freetype247.lib"
132 CACHE FILEPATH "Path to freetype247.lib")
135 CACHE FILEPATH "Path to mingwm10.dll (for installation)")
137 set(OPENAL_DLL "" CACHE FILEPATH "Path to OpenAL32.dll for installation (optional)")
138 set(OGG_DLL "" CACHE FILEPATH "Path to libogg.dll for installation (optional)")
139 set(VORBIS_DLL "" CACHE FILEPATH "Path to libvorbis.dll for installation (optional)")
140 set(VORBISFILE_DLL "" CACHE FILEPATH "Path to libvorbisfile.dll for installation (optional)")
145 find_package(X11 REQUIRED)
146 find_package(OpenGL REQUIRED)
147 find_package(JPEG REQUIRED)
148 find_package(BZip2 REQUIRED)
149 find_package(PNG REQUIRED)
151 FIND_LIBRARY(CARBON_LIB Carbon)
152 FIND_LIBRARY(COCOA_LIB Cocoa)
153 FIND_LIBRARY(IOKIT_LIB IOKit)
159 SET(CLIENT_PLATFORM_LIBS ${CLIENT_PLATFORM_LIBS} ${CARBON_LIB} ${COCOA_LIB} ${IOKIT_LIB})
162 find_package(ZLIB REQUIRED)
163 set(PLATFORM_LIBS -lpthread -lrt ${CMAKE_DL_LIBS})
164 #set(CLIENT_PLATFORM_LIBS -lXxf86vm)
165 # This way Xxf86vm is found on OpenBSD too
166 find_library(XXF86VM_LIBRARY Xxf86vm)
167 mark_as_advanced(XXF86VM_LIBRARY)
168 set(CLIENT_PLATFORM_LIBS ${CLIENT_PLATFORM_LIBS} ${XXF86VM_LIBRARY})
171 find_package(Sqlite3 REQUIRED)
172 find_package(Json REQUIRED)
173 find_package(OpenGLES2)
176 find_package(Freetype REQUIRED)
177 set(CGUITTFONT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cguittfont")
178 set(CGUITTFONT_LIBRARY cguittfont)
182 find_library(LUA_LIBRARY luajit
184 find_path(LUA_INCLUDE_DIR luajit.h
186 PATH_SUFFIXES luajit-2.0)
187 message (STATUS "LuaJIT library: ${LUA_LIBRARY}")
188 message (STATUS "LuaJIT headers: ${LUA_INCLUDE_DIR}")
191 if(LUA_LIBRARY AND LUA_INCLUDE_DIR)
192 message (STATUS "LuaJIT found.")
194 else(LUA_LIBRARY AND LUA_INCLUDE_DIR)
195 message (STATUS "LuaJIT not found, using bundled Lua.")
196 set(LUA_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lua/src")
197 set(LUA_LIBRARY "lua")
198 add_subdirectory(lua)
199 endif(LUA_LIBRARY AND LUA_INCLUDE_DIR)
201 mark_as_advanced(LUA_LIBRARY)
202 mark_as_advanced(LUA_INCLUDE_DIR)
206 OPTION(ENABLE_LEVELDB "Enable LevelDB backend")
209 find_library(LEVELDB_LIBRARY leveldb)
210 find_path(LEVELDB_INCLUDE_DIR db.h PATH_SUFFIXES leveldb)
211 message (STATUS "LevelDB library: ${LEVELDB_LIBRARY}")
212 message (STATUS "LevelDB headers: ${LEVELDB_INCLUDE_DIR}")
213 if(LEVELDB_LIBRARY AND LEVELDB_INCLUDE_DIR)
215 message(STATUS "LevelDB backend enabled")
216 include_directories(${LEVELDB_INCLUDE_DIR})
217 else(LEVELDB_LIBRARY AND LEVELDB_INCLUDE_DIR)
219 message(STATUS "LevelDB not found!")
220 endif(LEVELDB_LIBRARY AND LEVELDB_INCLUDE_DIR)
221 endif(ENABLE_LEVELDB)
224 "${PROJECT_SOURCE_DIR}/cmake_config.h.in"
225 "${PROJECT_BINARY_DIR}/cmake_config.h"
228 # Add a target that always rebuilds cmake_config_githash.h
229 add_custom_target(GenerateVersion
230 COMMAND ${CMAKE_COMMAND}
231 -D "GENERATE_VERSION_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
232 -D "GENERATE_VERSION_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
233 -D "VERSION_STRING=${VERSION_STRING}"
234 -D "VERSION_EXTRA=${VERSION_EXTRA}"
235 -P "${CMAKE_SOURCE_DIR}/cmake/Modules/GenerateVersion.cmake"
236 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
238 add_subdirectory(jthread)
239 add_subdirectory(script)
240 add_subdirectory(util)
244 rollback_interface.cpp
258 object_properties.cpp
266 mapgen_singlenode.cpp
312 ${common_SCRIPT_SRCS}
316 # This gives us the icon
318 set(WINRESOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../misc/winresource.rc)
320 if(NOT CMAKE_RC_COMPILER)
321 set(CMAKE_RC_COMPILER "windres.exe")
323 ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o
324 COMMAND ${CMAKE_RC_COMPILER} -I${CMAKE_CURRENT_SOURCE_DIR}
325 -i${WINRESOURCE_FILE}
326 -o ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o
327 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
328 SET(common_SRCS ${common_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o)
329 else(MINGW) # Probably MSVC
330 set(common_SRCS ${common_SRCS} ${WINRESOURCE_FILE})
358 guiPasswordChange.cpp
370 guiFileSelectMenu.cpp
372 ${minetest_SCRIPT_SRCS}
382 list(SORT minetest_SRCS)
385 set(minetestserver_SRCS
389 list(SORT minetestserver_SRCS)
392 ${PROJECT_BINARY_DIR}
393 ${PROJECT_SOURCE_DIR}
394 ${IRRLICHT_INCLUDE_DIR}
398 ${GETTEXT_INCLUDE_DIR}
399 ${SOUND_INCLUDE_DIRS}
400 ${SQLITE3_INCLUDE_DIR}
403 ${PROJECT_SOURCE_DIR}/script
408 ${FREETYPE_INCLUDE_DIRS}
409 ${CGUITTFONT_INCLUDE_DIR}
419 set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
422 add_executable(${PROJECT_NAME} ${minetest_SRCS})
423 add_dependencies(${PROJECT_NAME} GenerateVersion)
424 target_link_libraries(
438 ${OPENGLES2_LIBRARIES}
440 ${CLIENT_PLATFORM_LIBS}
443 target_link_libraries(
449 target_link_libraries(
452 ${CGUITTFONT_LIBRARY}
456 target_link_libraries(${PROJECT_NAME} ${LEVELDB_LIBRARY})
461 add_executable(${PROJECT_NAME}server ${minetestserver_SRCS})
462 add_dependencies(${PROJECT_NAME}server GenerateVersion)
463 target_link_libraries(
464 ${PROJECT_NAME}server
473 target_link_libraries(${PROJECT_NAME}server ${LEVELDB_LIBRARY})
476 target_link_libraries(
477 ${PROJECT_NAME}server
485 # Set some optimizations and tweaks
488 include(CheckCXXCompilerFlag)
493 # EHa enables SEH exceptions (used for catching segfaults)
494 set(CMAKE_CXX_FLAGS_RELEASE "/EHa /O2 /Ob2 /Oi /Ot /Oy /GL /FD /MT /GS- /arch:SSE /fp:fast /D NDEBUG /D _HAS_ITERATOR_DEBUGGING=0 /TP")
495 #set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /NODEFAULTLIB:\"libcmtd.lib\" /NODEFAULTLIB:\"libcmt.lib\"")
496 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG")
498 # Debug build doesn't catch exceptions by itself
499 # Add some optimizations because otherwise it's VERY slow
500 set(CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1")
502 # Flags for C files (sqlite)
503 # /MT = Link statically with standard library stuff
504 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT")
507 set_target_properties(${PROJECT_NAME}server PROPERTIES
508 COMPILE_DEFINITIONS "SERVER")
515 set(RELEASE_WARNING_FLAGS "-Wall")
517 set(RELEASE_WARNING_FLAGS "")
520 if(NOT APPLE AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
521 CHECK_CXX_COMPILER_FLAG("-Wno-unused-but-set-variable" HAS_UNUSED_BUT_SET_VARIABLE_WARNING)
522 if(HAS_UNUSED_BUT_SET_VARIABLE_WARNING)
523 set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-unused-but-set-variable")
524 endif(HAS_UNUSED_BUT_SET_VARIABLE_WARNING)
528 set(OTHER_FLAGS "-mthreads -fexceptions")
532 set(CMAKE_OSX_ARCHITECTURES i386 CACHE STRING "do not build for 64-bit" FORCE)
536 set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops")
537 set(CMAKE_CXX_FLAGS_DEBUG "-g -O1 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS}")
540 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
544 set_target_properties(${PROJECT_NAME}server PROPERTIES
545 COMPILE_DEFINITIONS "SERVER")
550 #MESSAGE(STATUS "CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}")
551 #MESSAGE(STATUS "CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
558 install(FILES ${MINGWM10_DLL} DESTINATION ${BINDIR})
561 install(FILES ${ZLIB_DLL} DESTINATION ${BINDIR})
565 install(FILES ${OPENAL_DLL} DESTINATION ${BINDIR})
568 install(FILES ${OGG_DLL} DESTINATION ${BINDIR})
571 install(FILES ${VORBIS_DLL} DESTINATION ${BINDIR})
574 install(FILES ${VORBISFILE_DLL} DESTINATION ${BINDIR})
577 install(FILES ${CURL_DLL} DESTINATION ${BINDIR})
583 install(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR})
586 foreach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
587 set_mo_paths(MO_BUILD_PATH MO_DEST_PATH ${LOCALE})
588 set(MO_BUILD_PATH "${MO_BUILD_PATH}/${PROJECT_NAME}.mo")
589 install(FILES ${MO_BUILD_PATH} DESTINATION ${MO_DEST_PATH})
590 endforeach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
594 if(DEFINED IRRLICHT_DLL)
595 install(FILES ${IRRLICHT_DLL} DESTINATION ${BINDIR})
598 if(DEFINED GETTEXT_DLL)
599 install(FILES ${GETTEXT_DLL} DESTINATION ${BINDIR})
601 if(DEFINED GETTEXT_ICONV_DLL)
602 install(FILES ${GETTEXT_ICONV_DLL} DESTINATION ${BINDIR})
609 install(TARGETS ${PROJECT_NAME}server DESTINATION ${BINDIR})
615 foreach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
616 set(PO_FILE_PATH "${GETTEXT_PO_PATH}/${LOCALE}/minetest.po")
617 set_mo_paths(MO_BUILD_PATH MO_DEST_PATH ${LOCALE})
618 set(MO_FILE_PATH "${MO_BUILD_PATH}/${PROJECT_NAME}.mo")
620 add_custom_command(OUTPUT ${MO_BUILD_PATH}
621 COMMAND ${CMAKE_COMMAND} -E make_directory ${MO_BUILD_PATH}
622 COMMENT "mo-update [${LOCALE}]: Creating locale directory.")
625 OUTPUT ${MO_FILE_PATH}
626 COMMAND ${GETTEXT_MSGFMT} -o ${MO_FILE_PATH} ${PO_FILE_PATH}
627 DEPENDS ${MO_BUILD_PATH} ${PO_FILE_PATH}
628 WORKING_DIRECTORY "${GETTEXT_PO_PATH}/${LOCALE}"
629 COMMENT "mo-update [${LOCALE}]: Creating mo file."
632 set(MO_FILES ${MO_FILES} ${MO_FILE_PATH})
633 endforeach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
635 add_custom_target(translations ALL COMMENT "mo update" DEPENDS ${MO_FILES})
642 add_subdirectory(sqlite)
643 endif (SQLITE3_FOUND)
645 if (BUILD_CLIENT AND USE_FREETYPE)
646 add_subdirectory(cguittfont)
647 endif (BUILD_CLIENT AND USE_FREETYPE)
651 add_subdirectory(json)