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(JTHREAD_INCLUDE_DIR JTHREAD_LIBRARY)
7 mark_as_advanced(SQLITE3_INCLUDE_DIR SQLITE3_LIBRARY)
8 mark_as_advanced(JSON_INCLUDE_DIR JSON_LIBRARY)
10 option(ENABLE_CURL "Enable cURL support for fetching media" 1)
13 mark_as_advanced(CLEAR CURL_LIBRARY CURL_INCLUDE_DIR)
14 endif(NOT ENABLE_CURL)
20 if (CURL_FOUND AND ENABLE_CURL)
21 message(STATUS "cURL support enabled")
23 endif(CURL_FOUND AND ENABLE_CURL)
25 # user-visible option to enable/disable gettext usage
26 OPTION(ENABLE_GETTEXT "Use GetText for internationalization" 0)
28 # this is only set to 1 if gettext is enabled _and_ available
32 find_package(GettextLib)
34 MARK_AS_ADVANCED(GETTEXT_ICONV_DLL GETTEXT_INCLUDE_DIR GETTEXT_LIBRARY GETTEXT_MSGFMT)
37 if(GETTEXT_FOUND AND ENABLE_GETTEXT)
38 message(STATUS "gettext include path: ${GETTEXT_INCLUDE_DIR}")
39 message(STATUS "gettext msgfmt path: ${GETTEXT_MSGFMT}")
41 message(STATUS "gettext library: ${GETTEXT_LIBRARY}")
42 message(STATUS "gettext dll: ${GETTEXT_DLL}")
43 message(STATUS "gettext iconv dll: ${GETTEXT_ICONV_DLL}")
46 message(STATUS "GetText enabled; locales found: ${GETTEXT_AVAILABLE_LOCALES}")
47 elseif(GETTEXT_FOUND AND NOT ENABLE_GETTEXT)
48 MESSAGE(STATUS "GetText found but disabled;")
49 else(GETTEXT_FOUND AND ENABLE_GETTEXT)
50 message(STATUS "GetText disabled")
51 endif(GETTEXT_FOUND AND ENABLE_GETTEXT)
53 # user visible option to enable/disable sound
54 OPTION(ENABLE_SOUND "Enable sound" ON)
56 # this is only set to 1 if sound is enabled _and_ available
60 if(ENABLE_SOUND AND BUILD_CLIENT)
65 message(STATUS "Sound enabled, but OpenAL not found!")
67 MARK_AS_ADVANCED(CLEAR OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
70 message(STATUS "Sound enabled, but Vorbis libraries not found!")
72 MARK_AS_ADVANCED(CLEAR OGG_INCLUDE_DIR VORBIS_INCLUDE_DIR OGG_LIBRARY VORBIS_LIBRARY VORBISFILE_LIBRARY)
74 if(OPENAL_FOUND AND VORBIS_FOUND)
76 message(STATUS "Sound enabled")
78 endif(ENABLE_SOUND AND BUILD_CLIENT)
81 message(FATAL_ERROR "Sound enabled, but cannot be used.\n"
82 "To continue, either fill in the required paths or disable sound. (-DENABLE_SOUND=0)")
85 set(sound_SRCS sound_openal.cpp)
86 set(SOUND_INCLUDE_DIRS
97 option(ENABLE_FREETYPE "Enable freetype2 (truetype fonts and basic unicode support)" OFF)
101 endif(ENABLE_FREETYPE)
104 set(USE_GPROF 0 CACHE BOOL "Use -pg flag for g++")
108 add_definitions ( -DUSE_CMAKE_CONFIG_H )
112 if(MSVC) # MSVC Specifics
113 # Surpress some useless warnings
114 add_definitions ( /D "_CRT_SECURE_NO_DEPRECATE" /W1 )
115 else() # Probably MinGW = GCC
116 set(PLATFORM_LIBS ws2_32.lib)
119 set(ZLIB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/../../zlib/zlib-1.2.5"
120 CACHE PATH "Zlib include directory")
121 set(ZLIB_LIBRARIES "${PROJECT_SOURCE_DIR}/../../zlib125dll/dll32/zlibwapi.lib"
122 CACHE FILEPATH "Path to zlibwapi.lib")
123 set(ZLIB_DLL "${PROJECT_SOURCE_DIR}/../../zlib125dll/dll32/zlibwapi.dll"
124 CACHE FILEPATH "Path to zlibwapi.dll (for installation)")
125 set(IRRLICHT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../irrlicht-1.7.2"
126 CACHE PATH "irrlicht dir")
128 set(FREETYPE_INCLUDE_DIR_ft2build "${PROJECT_SOURCE_DIR}/../../freetype2/include/"
129 CACHE PATH "freetype include dir")
130 set(FREETYPE_INCLUDE_DIR_freetype2 "${PROJECT_SOURCE_DIR}/../../freetype2/include/freetype"
131 CACHE PATH "freetype include dir")
132 set(FREETYPE_LIBRARY "${PROJECT_SOURCE_DIR}/../../freetype2/objs/win32/vc2005/freetype247.lib"
133 CACHE FILEPATH "Path to freetype247.lib")
136 CACHE FILEPATH "Path to mingwm10.dll (for installation)")
138 set(OPENAL_DLL "" CACHE FILEPATH "Path to OpenAL32.dll for installation (optional)")
139 set(OGG_DLL "" CACHE FILEPATH "Path to libogg.dll for installation (optional)")
140 set(VORBIS_DLL "" CACHE FILEPATH "Path to libvorbis.dll for installation (optional)")
141 set(VORBISFILE_DLL "" CACHE FILEPATH "Path to libvorbisfile.dll for installation (optional)")
146 find_package(X11 REQUIRED)
147 find_package(OpenGL REQUIRED)
148 find_package(JPEG REQUIRED)
149 find_package(BZip2 REQUIRED)
150 find_package(PNG REQUIRED)
152 FIND_LIBRARY(CARBON_LIB Carbon)
153 FIND_LIBRARY(COCOA_LIB Cocoa)
154 FIND_LIBRARY(IOKIT_LIB IOKit)
160 SET(CLIENT_PLATFORM_LIBS ${CLIENT_PLATFORM_LIBS} ${CARBON_LIB} ${COCOA_LIB} ${IOKIT_LIB})
163 find_package(ZLIB REQUIRED)
164 set(PLATFORM_LIBS -lpthread -lrt ${CMAKE_DL_LIBS})
165 #set(CLIENT_PLATFORM_LIBS -lXxf86vm)
166 # This way Xxf86vm is found on OpenBSD too
167 find_library(XXF86VM_LIBRARY Xxf86vm)
168 mark_as_advanced(XXF86VM_LIBRARY)
169 set(CLIENT_PLATFORM_LIBS ${CLIENT_PLATFORM_LIBS} ${XXF86VM_LIBRARY})
172 find_package(Jthread REQUIRED)
173 find_package(Sqlite3 REQUIRED)
174 find_package(Json REQUIRED)
175 find_package(OpenGLES2)
178 find_package(Freetype REQUIRED)
179 set(CGUITTFONT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cguittfont")
180 set(CGUITTFONT_LIBRARY cguittfont)
184 find_library(LUA_LIBRARY luajit
186 find_path(LUA_INCLUDE_DIR luajit.h
188 PATH_SUFFIXES luajit-2.0)
189 message (STATUS "LuaJIT library: ${LUA_LIBRARY}")
190 message (STATUS "LuaJIT headers: ${LUA_INCLUDE_DIR}")
192 if(LUA_LIBRARY AND LUA_INCLUDE_DIR)
193 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)
205 "${PROJECT_SOURCE_DIR}/cmake_config.h.in"
206 "${PROJECT_BINARY_DIR}/cmake_config.h"
210 rollback_interface.cpp
224 object_properties.cpp
227 scriptapi_content.cpp
232 scriptapi_nodetimer.cpp
236 scriptapi_nodemeta.cpp
237 scriptapi_inventory.cpp
238 scriptapi_particles.cpp
248 mapgen_singlenode.cpp
287 util/directiontables.cpp
289 util/pointedthing.cpp
294 # This gives us the icon
296 set(WINRESOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../misc/winresource.rc)
298 if(NOT CMAKE_RC_COMPILER)
299 set(CMAKE_RC_COMPILER "windres.exe")
301 ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o
302 COMMAND ${CMAKE_RC_COMPILER} -I${CMAKE_CURRENT_SOURCE_DIR}
303 -i${WINRESOURCE_FILE}
304 -o ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o
305 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
306 SET(common_SRCS ${common_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o)
307 else(MINGW) # Probably MSVC
308 set(common_SRCS ${common_SRCS} ${WINRESOURCE_FILE})
338 guiPasswordChange.cpp
343 guiConfigureWorld.cpp
361 set(minetestserver_SRCS
367 ${PROJECT_BINARY_DIR}
368 ${IRRLICHT_INCLUDE_DIR}
372 ${GETTEXT_INCLUDE_DIR}
373 ${SOUND_INCLUDE_DIRS}
374 ${JTHREAD_INCLUDE_DIR}
375 ${SQLITE3_INCLUDE_DIR}
382 ${FREETYPE_INCLUDE_DIRS}
383 ${CGUITTFONT_INCLUDE_DIR}
393 set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
396 add_executable(${PROJECT_NAME} ${minetest_SRCS})
397 target_link_libraries(
412 ${OPENGLES2_LIBRARIES}
414 ${CLIENT_PLATFORM_LIBS}
417 target_link_libraries(
423 target_link_libraries(
426 ${CGUITTFONT_LIBRARY}
432 add_executable(${PROJECT_NAME}server ${minetestserver_SRCS})
433 target_link_libraries(
434 ${PROJECT_NAME}server
444 target_link_libraries(
445 ${PROJECT_NAME}server
453 # Set some optimizations and tweaks
456 include(CheckCXXCompilerFlag)
461 # EHa enables SEH exceptions (used for catching segfaults)
462 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")
463 #set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /NODEFAULTLIB:\"libcmtd.lib\" /NODEFAULTLIB:\"libcmt.lib\"")
464 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG")
466 # Debug build doesn't catch exceptions by itself
467 # Add some optimizations because otherwise it's VERY slow
468 set(CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1")
470 # Flags for C files (sqlite)
471 # /MT = Link statically with standard library stuff
472 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT")
475 set_target_properties(${PROJECT_NAME}server PROPERTIES
476 COMPILE_DEFINITIONS "SERVER")
483 set(RELEASE_WARNING_FLAGS "-Wall")
485 set(RELEASE_WARNING_FLAGS "")
488 if(NOT APPLE AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
489 CHECK_CXX_COMPILER_FLAG("-Wno-unused-but-set-variable" HAS_UNUSED_BUT_SET_VARIABLE_WARNING)
490 if(HAS_UNUSED_BUT_SET_VARIABLE_WARNING)
491 set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-unused-but-set-variable")
492 endif(HAS_UNUSED_BUT_SET_VARIABLE_WARNING)
496 set(OTHER_FLAGS "-mthreads -fexceptions")
500 set(CMAKE_OSX_ARCHITECTURES i386 CACHE STRING "do not build for 64-bit" FORCE)
504 set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops")
505 set(CMAKE_CXX_FLAGS_DEBUG "-g -O1 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS}")
508 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
512 set_target_properties(${PROJECT_NAME}server PROPERTIES
513 COMPILE_DEFINITIONS "SERVER")
518 #MESSAGE(STATUS "CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}")
519 #MESSAGE(STATUS "CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
526 install(FILES ${MINGWM10_DLL} DESTINATION ${BINDIR})
529 install(FILES ${ZLIB_DLL} DESTINATION ${BINDIR})
533 install(FILES ${OPENAL_DLL} DESTINATION ${BINDIR})
536 install(FILES ${OGG_DLL} DESTINATION ${BINDIR})
539 install(FILES ${VORBIS_DLL} DESTINATION ${BINDIR})
542 install(FILES ${VORBISFILE_DLL} DESTINATION ${BINDIR})
545 install(FILES ${CURL_DLL} DESTINATION ${BINDIR})
551 install(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR})
554 foreach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
555 set_mo_paths(MO_BUILD_PATH MO_DEST_PATH ${LOCALE})
556 set(MO_BUILD_PATH "${MO_BUILD_PATH}/${PROJECT_NAME}.mo")
557 install(FILES ${MO_BUILD_PATH} DESTINATION ${MO_DEST_PATH})
558 endforeach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
562 if(DEFINED IRRLICHT_DLL)
563 install(FILES ${IRRLICHT_DLL} DESTINATION ${BINDIR})
566 if(DEFINED GETTEXT_DLL)
567 install(FILES ${GETTEXT_DLL} DESTINATION ${BINDIR})
569 if(DEFINED GETTEXT_ICONV_DLL)
570 install(FILES ${GETTEXT_ICONV_DLL} DESTINATION ${BINDIR})
577 install(TARGETS ${PROJECT_NAME}server DESTINATION ${BINDIR})
583 foreach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
584 set(PO_FILE_PATH "${GETTEXT_PO_PATH}/${LOCALE}/minetest.po")
585 set_mo_paths(MO_BUILD_PATH MO_DEST_PATH ${LOCALE})
586 set(MO_FILE_PATH "${MO_BUILD_PATH}/${PROJECT_NAME}.mo")
588 add_custom_command(OUTPUT ${MO_BUILD_PATH}
589 COMMAND ${CMAKE_COMMAND} -E make_directory ${MO_BUILD_PATH}
590 COMMENT "mo-update [${LOCALE}]: Creating locale directory.")
593 OUTPUT ${MO_FILE_PATH}
594 COMMAND ${GETTEXT_MSGFMT} -o ${MO_FILE_PATH} ${PO_FILE_PATH}
595 DEPENDS ${MO_BUILD_PATH} ${PO_FILE_PATH}
596 WORKING_DIRECTORY "${GETTEXT_PO_PATH}/${LOCALE}"
597 COMMENT "mo-update [${LOCALE}]: Creating mo file."
600 set(MO_FILES ${MO_FILES} ${MO_FILE_PATH})
601 endforeach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
603 add_custom_target(translations ALL COMMENT "mo update" DEPENDS ${MO_FILES})
610 add_subdirectory(jthread)
611 endif (JTHREAD_FOUND)
615 add_subdirectory(sqlite)
616 endif (SQLITE3_FOUND)
618 if (BUILD_CLIENT AND USE_FREETYPE)
619 add_subdirectory(cguittfont)
620 endif (BUILD_CLIENT AND USE_FREETYPE)
624 add_subdirectory(json)