You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

889 lines
23 KiB

  1. cmake_minimum_required(VERSION 2.6)
  2. project(minetest)
  3. INCLUDE(CheckIncludeFiles)
  4. INCLUDE(CheckLibraryExists)
  5. # Add custom SemiDebug build mode
  6. set(CMAKE_CXX_FLAGS_SEMIDEBUG "-O1 -g -Wall -Wabi" CACHE STRING
  7. "Flags used by the C++ compiler during semidebug builds."
  8. FORCE
  9. )
  10. set(CMAKE_C_FLAGS_SEMIDEBUG "-O1 -g -Wall -pedantic" CACHE STRING
  11. "Flags used by the C compiler during semidebug builds."
  12. FORCE
  13. )
  14. mark_as_advanced(
  15. CMAKE_CXX_FLAGS_SEMIDEBUG
  16. CMAKE_C_FLAGS_SEMIDEBUG
  17. )
  18. set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
  19. "Choose the type of build. Options are: None Debug SemiDebug RelWithDebInfo MinSizeRel."
  20. FORCE
  21. )
  22. # Set some random things default to not being visible in the GUI
  23. mark_as_advanced(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH)
  24. if(NOT (BUILD_CLIENT OR BUILD_SERVER))
  25. message(WARNING "Neither BUILD_CLIENT nor BUILD_SERVER is set! Setting BUILD_SERVER=true")
  26. set(BUILD_SERVER TRUE)
  27. endif()
  28. option(ENABLE_CURL "Enable cURL support for fetching media" TRUE)
  29. set(USE_CURL FALSE)
  30. if(ENABLE_CURL)
  31. find_package(CURL)
  32. if (CURL_FOUND)
  33. message(STATUS "cURL support enabled.")
  34. set(USE_CURL TRUE)
  35. endif()
  36. else()
  37. mark_as_advanced(CLEAR CURL_LIBRARY CURL_INCLUDE_DIR)
  38. endif()
  39. if(NOT USE_CURL)
  40. if(BUILD_CLIENT)
  41. message(WARNING "cURL is required to load the server list")
  42. endif()
  43. if(BUILD_SERVER)
  44. message(WARNING "cURL is required to announce to the server list")
  45. endif()
  46. endif()
  47. option(ENABLE_GETTEXT "Use GetText for internationalization" FALSE)
  48. set(USE_GETTEXT FALSE)
  49. if(ENABLE_GETTEXT)
  50. find_package(GettextLib)
  51. if(GETTEXT_FOUND)
  52. if(WIN32)
  53. message(STATUS "GetText library: ${GETTEXT_LIBRARY}")
  54. message(STATUS "GetText DLL: ${GETTEXT_DLL}")
  55. message(STATUS "GetText iconv DLL: ${GETTEXT_ICONV_DLL}")
  56. endif()
  57. set(USE_GETTEXT TRUE)
  58. message(STATUS "GetText enabled; locales found: ${GETTEXT_AVAILABLE_LOCALES}")
  59. endif(GETTEXT_FOUND)
  60. else()
  61. mark_as_advanced(GETTEXT_ICONV_DLL GETTEXT_INCLUDE_DIR GETTEXT_LIBRARY GETTEXT_MSGFMT)
  62. message(STATUS "GetText disabled.")
  63. endif()
  64. option(ENABLE_SOUND "Enable sound" TRUE)
  65. set(USE_SOUND FALSE)
  66. if(BUILD_CLIENT AND ENABLE_SOUND)
  67. # Sound libraries
  68. find_package(OpenAL)
  69. find_package(Vorbis)
  70. if(NOT OPENAL_FOUND)
  71. message(STATUS "Sound enabled, but OpenAL not found!")
  72. mark_as_advanced(CLEAR OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
  73. endif()
  74. if(NOT VORBIS_FOUND)
  75. message(STATUS "Sound enabled, but Vorbis libraries not found!")
  76. mark_as_advanced(CLEAR OGG_INCLUDE_DIR VORBIS_INCLUDE_DIR OGG_LIBRARY VORBIS_LIBRARY VORBISFILE_LIBRARY)
  77. endif()
  78. if(OPENAL_FOUND AND VORBIS_FOUND)
  79. set(USE_SOUND TRUE)
  80. message(STATUS "Sound enabled.")
  81. else()
  82. message(FATAL_ERROR "Sound enabled, but cannot be used.\n"
  83. "To continue, either fill in the required paths or disable sound. (-DENABLE_SOUND=0)")
  84. endif()
  85. endif()
  86. if(USE_SOUND)
  87. set(sound_SRCS sound_openal.cpp)
  88. set(SOUND_INCLUDE_DIRS
  89. ${OPENAL_INCLUDE_DIR}
  90. ${VORBIS_INCLUDE_DIR}
  91. ${OGG_INCLUDE_DIR}
  92. )
  93. set(SOUND_LIBRARIES
  94. ${OPENAL_LIBRARY}
  95. ${VORBIS_LIBRARIES}
  96. )
  97. endif()
  98. option(ENABLE_GLES "Enable OpenGL ES support" FALSE)
  99. mark_as_advanced(ENABLE_GLES)
  100. if(ENABLE_GLES)
  101. find_package(OpenGLES2)
  102. endif()
  103. option(ENABLE_FREETYPE "Enable FreeType2 (TrueType fonts and basic unicode support)" TRUE)
  104. set(USE_FREETYPE FALSE)
  105. if(ENABLE_FREETYPE)
  106. ##
  107. ## Note: FindFreetype.cmake seems to have been fixed in recent versions of
  108. ## CMake. If issues persist, re-enable this workaround specificially for the
  109. ## failing platforms.
  110. ##
  111. # if(UNIX)
  112. # include(FindPkgConfig)
  113. # if(PKG_CONFIG_FOUND)
  114. # pkg_check_modules(FREETYPE QUIET freetype2)
  115. # if(FREETYPE_FOUND)
  116. # SET(FREETYPE_PKGCONFIG_FOUND TRUE)
  117. # SET(FREETYPE_LIBRARY ${FREETYPE_LIBRARIES})
  118. # # Because CMake is idiotic
  119. # string(REPLACE ";" " " FREETYPE_CFLAGS_STR ${FREETYPE_CFLAGS})
  120. # string(REPLACE ";" " " FREETYPE_LDFLAGS_STR ${FREETYPE_LDFLAGS})
  121. # endif(FREETYPE_FOUND)
  122. # endif(PKG_CONFIG_FOUND)
  123. # endif(UNIX)
  124. # if(NOT FREETYPE_FOUND)
  125. # find_package(Freetype)
  126. # endif()
  127. find_package(Freetype)
  128. if(FREETYPE_FOUND)
  129. message(STATUS "Freetype enabled.")
  130. set(USE_FREETYPE TRUE)
  131. set(CGUITTFONT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cguittfont")
  132. set(CGUITTFONT_LIBRARY cguittfont)
  133. endif()
  134. endif(ENABLE_FREETYPE)
  135. option(ENABLE_CURSES "Enable ncurses console" TRUE)
  136. set(USE_CURSES FALSE)
  137. if(ENABLE_CURSES)
  138. find_package(Ncursesw)
  139. if(CURSES_FOUND)
  140. set(USE_CURSES TRUE)
  141. message(STATUS "ncurses console enabled.")
  142. include_directories(${CURSES_INCLUDE_DIRS})
  143. else()
  144. message(STATUS "ncurses not found!")
  145. endif()
  146. endif(ENABLE_CURSES)
  147. option(ENABLE_POSTGRESQL "Enable PostgreSQL backend" TRUE)
  148. set(USE_POSTGRESQL FALSE)
  149. if(ENABLE_POSTGRESQL)
  150. find_program(POSTGRESQL_CONFIG_EXECUTABLE pg_config DOC "pg_config")
  151. find_library(POSTGRESQL_LIBRARY pq)
  152. if(POSTGRESQL_CONFIG_EXECUTABLE)
  153. execute_process(COMMAND ${POSTGRESQL_CONFIG_EXECUTABLE} --includedir-server
  154. OUTPUT_VARIABLE POSTGRESQL_SERVER_INCLUDE_DIRS
  155. OUTPUT_STRIP_TRAILING_WHITESPACE)
  156. execute_process(COMMAND ${POSTGRESQL_CONFIG_EXECUTABLE}
  157. OUTPUT_VARIABLE POSTGRESQL_CLIENT_INCLUDE_DIRS
  158. OUTPUT_STRIP_TRAILING_WHITESPACE)
  159. # This variable is case sensitive for the cmake PostgreSQL module
  160. set(PostgreSQL_ADDITIONAL_SEARCH_PATHS ${POSTGRESQL_SERVER_INCLUDE_DIRS} ${POSTGRESQL_CLIENT_INCLUDE_DIRS})
  161. endif()
  162. find_package("PostgreSQL")
  163. if(POSTGRESQL_FOUND)
  164. set(USE_POSTGRESQL TRUE)
  165. message(STATUS "PostgreSQL backend enabled")
  166. # This variable is case sensitive, don't try to change it to POSTGRESQL_INCLUDE_DIR
  167. message(STATUS "PostgreSQL includes: ${PostgreSQL_INCLUDE_DIR}")
  168. include_directories(${PostgreSQL_INCLUDE_DIR})
  169. else()
  170. message(STATUS "PostgreSQL not found!")
  171. endif()
  172. endif(ENABLE_POSTGRESQL)
  173. option(ENABLE_LEVELDB "Enable LevelDB backend" TRUE)
  174. set(USE_LEVELDB FALSE)
  175. if(ENABLE_LEVELDB)
  176. find_library(LEVELDB_LIBRARY leveldb)
  177. find_path(LEVELDB_INCLUDE_DIR db.h PATH_SUFFIXES leveldb)
  178. if(LEVELDB_LIBRARY AND LEVELDB_INCLUDE_DIR)
  179. set(USE_LEVELDB TRUE)
  180. message(STATUS "LevelDB backend enabled.")
  181. include_directories(${LEVELDB_INCLUDE_DIR})
  182. else()
  183. message(STATUS "LevelDB not found!")
  184. endif()
  185. endif(ENABLE_LEVELDB)
  186. OPTION(ENABLE_REDIS "Enable Redis backend" TRUE)
  187. set(USE_REDIS FALSE)
  188. if(ENABLE_REDIS)
  189. find_library(REDIS_LIBRARY hiredis)
  190. find_path(REDIS_INCLUDE_DIR hiredis.h PATH_SUFFIXES hiredis)
  191. if(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
  192. set(USE_REDIS TRUE)
  193. message(STATUS "Redis backend enabled.")
  194. include_directories(${REDIS_INCLUDE_DIR})
  195. else(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
  196. message(STATUS "Redis not found!")
  197. endif(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
  198. endif(ENABLE_REDIS)
  199. find_package(SQLite3 REQUIRED)
  200. OPTION(ENABLE_SPATIAL "Enable SpatialIndex AreaStore backend" TRUE)
  201. set(USE_SPATIAL FALSE)
  202. if(ENABLE_SPATIAL)
  203. find_library(SPATIAL_LIBRARY spatialindex)
  204. find_path(SPATIAL_INCLUDE_DIR spatialindex/SpatialIndex.h)
  205. if(SPATIAL_LIBRARY AND SPATIAL_INCLUDE_DIR)
  206. set(USE_SPATIAL TRUE)
  207. message(STATUS "SpatialIndex AreaStore backend enabled.")
  208. include_directories(${SPATIAL_INCLUDE_DIR})
  209. else(SPATIAL_LIBRARY AND SPATIAL_INCLUDE_DIR)
  210. message(STATUS "SpatialIndex not found!")
  211. endif(SPATIAL_LIBRARY AND SPATIAL_INCLUDE_DIR)
  212. endif(ENABLE_SPATIAL)
  213. if(NOT MSVC)
  214. set(USE_GPROF FALSE CACHE BOOL "Use -pg flag for g++")
  215. endif()
  216. # Use cmake_config.h
  217. add_definitions(-DUSE_CMAKE_CONFIG_H)
  218. if(WIN32)
  219. # Windows
  220. if(MSVC) # MSVC Specifics
  221. set(PLATFORM_LIBS dbghelp.lib ${PLATFORM_LIBS})
  222. # Surpress some useless warnings
  223. add_definitions ( /D "_CRT_SECURE_NO_DEPRECATE" /W1 )
  224. # Get M_PI to work
  225. add_definitions(/D "_USE_MATH_DEFINES")
  226. else() # Probably MinGW = GCC
  227. set(PLATFORM_LIBS "")
  228. endif()
  229. set(PLATFORM_LIBS ws2_32.lib shlwapi.lib ${PLATFORM_LIBS})
  230. # Zlib stuff
  231. set(ZLIB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/../../zlib/zlib-1.2.5"
  232. CACHE PATH "Zlib include directory")
  233. set(ZLIB_LIBRARIES "${PROJECT_SOURCE_DIR}/../../zlib125dll/dll32/zlibwapi.lib"
  234. CACHE FILEPATH "Path to zlib library (usually zlibwapi.lib)")
  235. set(ZLIB_DLL "${PROJECT_SOURCE_DIR}/../../zlib125dll/dll32/zlibwapi.dll"
  236. CACHE FILEPATH "Path to zlib DLL (for installation)")
  237. set(ZLIBWAPI_DLL "" CACHE FILEPATH "Path to zlibwapi DLL")
  238. set(IRRLICHT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../irrlicht-1.7.2"
  239. CACHE PATH "irrlicht dir")
  240. if(USE_FREETYPE)
  241. set(FREETYPE_INCLUDE_DIR_ft2build "${PROJECT_SOURCE_DIR}/../../freetype2/include/"
  242. CACHE PATH "freetype include dir")
  243. set(FREETYPE_INCLUDE_DIR_freetype2 "${PROJECT_SOURCE_DIR}/../../freetype2/include/freetype"
  244. CACHE PATH "freetype include dir")
  245. set(FREETYPE_LIBRARY "${PROJECT_SOURCE_DIR}/../../freetype2/objs/win32/vc2005/freetype247.lib"
  246. CACHE FILEPATH "Path to freetype247.lib")
  247. endif()
  248. if(ENABLE_SOUND)
  249. set(OPENAL_DLL "" CACHE FILEPATH "Path to OpenAL32.dll for installation (optional)")
  250. set(OGG_DLL "" CACHE FILEPATH "Path to libogg.dll for installation (optional)")
  251. set(VORBIS_DLL "" CACHE FILEPATH "Path to libvorbis.dll for installation (optional)")
  252. set(VORBISFILE_DLL "" CACHE FILEPATH "Path to libvorbisfile.dll for installation (optional)")
  253. endif()
  254. else()
  255. # Unix probably
  256. if(BUILD_CLIENT)
  257. find_package(X11 REQUIRED)
  258. find_package(OpenGL REQUIRED)
  259. find_package(JPEG REQUIRED)
  260. find_package(BZip2 REQUIRED)
  261. find_package(PNG REQUIRED)
  262. if(APPLE)
  263. find_library(CARBON_LIB Carbon)
  264. find_library(COCOA_LIB Cocoa)
  265. find_library(IOKIT_LIB IOKit)
  266. mark_as_advanced(
  267. CARBON_LIB
  268. COCOA_LIB
  269. IOKIT_LIB
  270. )
  271. SET(CLIENT_PLATFORM_LIBS ${CLIENT_PLATFORM_LIBS} ${CARBON_LIB} ${COCOA_LIB} ${IOKIT_LIB})
  272. endif(APPLE)
  273. endif(BUILD_CLIENT)
  274. find_package(ZLIB REQUIRED)
  275. set(PLATFORM_LIBS -lpthread ${CMAKE_DL_LIBS})
  276. if(APPLE)
  277. set(PLATFORM_LIBS "-framework CoreFoundation" ${PLATFORM_LIBS})
  278. else()
  279. check_library_exists(rt clock_gettime "" HAVE_LIBRT)
  280. if (HAVE_LIBRT)
  281. set(PLATFORM_LIBS -lrt ${PLATFORM_LIBS})
  282. endif(HAVE_LIBRT)
  283. endif(APPLE)
  284. # This way Xxf86vm is found on OpenBSD too
  285. find_library(XXF86VM_LIBRARY Xxf86vm)
  286. mark_as_advanced(XXF86VM_LIBRARY)
  287. set(CLIENT_PLATFORM_LIBS ${CLIENT_PLATFORM_LIBS} ${XXF86VM_LIBRARY})
  288. # Prefer local iconv if installed
  289. find_library(ICONV_LIBRARY iconv)
  290. mark_as_advanced(ICONV_LIBRARY)
  291. if (ICONV_LIBRARY)
  292. set(PLATFORM_LIBS ${PLATFORM_LIBS} ${ICONV_LIBRARY})
  293. endif()
  294. endif()
  295. check_include_files(endian.h HAVE_ENDIAN_H)
  296. configure_file(
  297. "${PROJECT_SOURCE_DIR}/cmake_config.h.in"
  298. "${PROJECT_BINARY_DIR}/cmake_config.h"
  299. )
  300. # Add a target that always rebuilds cmake_config_githash.h
  301. add_custom_target(GenerateVersion
  302. COMMAND ${CMAKE_COMMAND}
  303. -D "GENERATE_VERSION_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
  304. -D "GENERATE_VERSION_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
  305. -D "VERSION_STRING=${VERSION_STRING}"
  306. -D "DEVELOPMENT_BUILD=${DEVELOPMENT_BUILD}"
  307. -P "${CMAKE_SOURCE_DIR}/cmake/Modules/GenerateVersion.cmake"
  308. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
  309. add_subdirectory(threading)
  310. add_subdirectory(network)
  311. add_subdirectory(script)
  312. add_subdirectory(unittest)
  313. add_subdirectory(util)
  314. add_subdirectory(irrlicht_changes)
  315. set(common_SRCS
  316. ban.cpp
  317. cavegen.cpp
  318. chat.cpp
  319. clientiface.cpp
  320. collision.cpp
  321. content_abm.cpp
  322. content_mapnode.cpp
  323. content_nodemeta.cpp
  324. content_sao.cpp
  325. convert_json.cpp
  326. craftdef.cpp
  327. database-dummy.cpp
  328. database-files.cpp
  329. database-leveldb.cpp
  330. database-postgresql.cpp
  331. database-redis.cpp
  332. database-sqlite3.cpp
  333. database.cpp
  334. debug.cpp
  335. defaultsettings.cpp
  336. dungeongen.cpp
  337. emerge.cpp
  338. environment.cpp
  339. face_position_cache.cpp
  340. filesys.cpp
  341. genericobject.cpp
  342. gettext.cpp
  343. httpfetch.cpp
  344. inventory.cpp
  345. inventorymanager.cpp
  346. itemdef.cpp
  347. itemstackmetadata.cpp
  348. light.cpp
  349. log.cpp
  350. map.cpp
  351. map_settings_manager.cpp
  352. mapblock.cpp
  353. mapgen.cpp
  354. mapgen_flat.cpp
  355. mapgen_fractal.cpp
  356. mapgen_singlenode.cpp
  357. mapgen_v5.cpp
  358. mapgen_v6.cpp
  359. mapgen_v7.cpp
  360. mapgen_valleys.cpp
  361. mapnode.cpp
  362. mapsector.cpp
  363. metadata.cpp
  364. mg_biome.cpp
  365. mg_decoration.cpp
  366. mg_ore.cpp
  367. mg_schematic.cpp
  368. mods.cpp
  369. nameidmapping.cpp
  370. nodedef.cpp
  371. nodemetadata.cpp
  372. nodetimer.cpp
  373. noise.cpp
  374. objdef.cpp
  375. object_properties.cpp
  376. pathfinder.cpp
  377. player.cpp
  378. porting.cpp
  379. profiler.cpp
  380. quicktune.cpp
  381. reflowscan.cpp
  382. remoteplayer.cpp
  383. raycast.cpp
  384. rollback.cpp
  385. rollback_interface.cpp
  386. serialization.cpp
  387. server.cpp
  388. serverenvironment.cpp
  389. serverlist.cpp
  390. serverobject.cpp
  391. settings.cpp
  392. socket.cpp
  393. sound.cpp
  394. staticobject.cpp
  395. subgame.cpp
  396. terminal_chat_console.cpp
  397. tileanimation.cpp
  398. tool.cpp
  399. treegen.cpp
  400. version.cpp
  401. voxel.cpp
  402. voxelalgorithms.cpp
  403. ${common_network_SRCS}
  404. ${JTHREAD_SRCS}
  405. ${common_SCRIPT_SRCS}
  406. ${UTIL_SRCS}
  407. ${UNITTEST_SRCS}
  408. )
  409. # This gives us the icon and file version information
  410. if(WIN32)
  411. set(WINRESOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../misc/winresource.rc")
  412. set(MINETEST_EXE_MANIFEST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../misc/minetest.exe.manifest")
  413. if(MINGW)
  414. if(NOT CMAKE_RC_COMPILER)
  415. set(CMAKE_RC_COMPILER "windres.exe")
  416. endif()
  417. ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o
  418. COMMAND ${CMAKE_RC_COMPILER} -I${CMAKE_CURRENT_SOURCE_DIR} -I${CMAKE_CURRENT_BINARY_DIR}
  419. -i${WINRESOURCE_FILE}
  420. -o ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o
  421. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  422. DEPENDS ${WINRESOURCE_FILE})
  423. SET(common_SRCS ${common_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o)
  424. else(MINGW) # Probably MSVC
  425. set(common_SRCS ${common_SRCS} ${WINRESOURCE_FILE} ${MINETEST_EXE_MANIFEST_FILE})
  426. endif(MINGW)
  427. endif()
  428. # Client sources
  429. if (BUILD_CLIENT)
  430. add_subdirectory(client)
  431. endif(BUILD_CLIENT)
  432. set(client_SRCS
  433. ${client_SRCS}
  434. ${common_SRCS}
  435. ${sound_SRCS}
  436. ${client_network_SRCS}
  437. ${client_irrlicht_changes_SRCS}
  438. camera.cpp
  439. client.cpp
  440. clientenvironment.cpp
  441. clientmap.cpp
  442. clientmedia.cpp
  443. clientobject.cpp
  444. clouds.cpp
  445. content_cao.cpp
  446. content_cso.cpp
  447. content_mapblock.cpp
  448. convert_json.cpp
  449. drawscene.cpp
  450. filecache.cpp
  451. fontengine.cpp
  452. game.cpp
  453. guiChatConsole.cpp
  454. guiEngine.cpp
  455. guiFileSelectMenu.cpp
  456. guiFormSpecMenu.cpp
  457. guiKeyChangeMenu.cpp
  458. guiPasswordChange.cpp
  459. guiscalingfilter.cpp
  460. guiTable.cpp
  461. guiVolumeChange.cpp
  462. hud.cpp
  463. imagefilters.cpp
  464. intlGUIEditBox.cpp
  465. keycode.cpp
  466. localplayer.cpp
  467. main.cpp
  468. mapblock_mesh.cpp
  469. mesh.cpp
  470. mesh_generator_thread.cpp
  471. minimap.cpp
  472. particles.cpp
  473. shader.cpp
  474. sky.cpp
  475. wieldmesh.cpp
  476. ${client_SCRIPT_SRCS}
  477. ${UNITTEST_CLIENT_SRCS}
  478. )
  479. list(SORT client_SRCS)
  480. # Server sources
  481. set(server_SRCS
  482. ${common_SRCS}
  483. main.cpp
  484. )
  485. list(SORT server_SRCS)
  486. include_directories(
  487. ${PROJECT_BINARY_DIR}
  488. ${PROJECT_SOURCE_DIR}
  489. ${IRRLICHT_INCLUDE_DIR}
  490. ${ZLIB_INCLUDE_DIR}
  491. ${CMAKE_BUILD_TYPE}
  492. ${PNG_INCLUDE_DIR}
  493. ${GETTEXT_INCLUDE_DIR}
  494. ${SOUND_INCLUDE_DIRS}
  495. ${SQLITE3_INCLUDE_DIR}
  496. ${LUA_INCLUDE_DIR}
  497. ${GMP_INCLUDE_DIR}
  498. ${JSON_INCLUDE_DIR}
  499. ${X11_INCLUDE_DIR}
  500. ${PROJECT_SOURCE_DIR}/script
  501. )
  502. if(USE_FREETYPE)
  503. include_directories(${FREETYPE_INCLUDE_DIRS} ${CGUITTFONT_INCLUDE_DIR})
  504. endif()
  505. if(USE_CURL)
  506. include_directories(${CURL_INCLUDE_DIR})
  507. endif()
  508. set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
  509. if(BUILD_CLIENT)
  510. add_executable(${PROJECT_NAME} ${client_SRCS})
  511. add_dependencies(${PROJECT_NAME} GenerateVersion)
  512. set(client_LIBS
  513. ${PROJECT_NAME}
  514. ${ZLIB_LIBRARIES}
  515. ${IRRLICHT_LIBRARY}
  516. ${OPENGL_LIBRARIES}
  517. ${JPEG_LIBRARIES}
  518. ${BZIP2_LIBRARIES}
  519. ${PNG_LIBRARIES}
  520. ${X11_LIBRARIES}
  521. ${GETTEXT_LIBRARY}
  522. ${SOUND_LIBRARIES}
  523. ${SQLITE3_LIBRARY}
  524. ${LUA_LIBRARY}
  525. ${GMP_LIBRARY}
  526. ${JSON_LIBRARY}
  527. ${OPENGLES2_LIBRARIES}
  528. ${PLATFORM_LIBS}
  529. ${CLIENT_PLATFORM_LIBS}
  530. )
  531. if(APPLE)
  532. target_link_libraries(
  533. ${client_LIBS}
  534. ${ICONV_LIBRARY}
  535. )
  536. else()
  537. target_link_libraries(
  538. ${client_LIBS}
  539. )
  540. endif()
  541. if(USE_CURL)
  542. target_link_libraries(
  543. ${PROJECT_NAME}
  544. ${CURL_LIBRARY}
  545. )
  546. endif()
  547. if(USE_FREETYPE)
  548. if(FREETYPE_PKGCONFIG_FOUND)
  549. set_target_properties(${PROJECT_NAME}
  550. PROPERTIES
  551. COMPILE_FLAGS "${FREETYPE_CFLAGS_STR}"
  552. )
  553. endif()
  554. target_link_libraries(
  555. ${PROJECT_NAME}
  556. ${FREETYPE_LIBRARY}
  557. ${CGUITTFONT_LIBRARY}
  558. )
  559. endif()
  560. if (USE_CURSES)
  561. target_link_libraries(${PROJECT_NAME} ${CURSES_LIBRARIES})
  562. endif()
  563. if (USE_POSTGRESQL)
  564. target_link_libraries(${PROJECT_NAME} ${POSTGRESQL_LIBRARY})
  565. endif()
  566. if (USE_LEVELDB)
  567. target_link_libraries(${PROJECT_NAME} ${LEVELDB_LIBRARY})
  568. endif()
  569. if (USE_REDIS)
  570. target_link_libraries(${PROJECT_NAME} ${REDIS_LIBRARY})
  571. endif()
  572. if (USE_SPATIAL)
  573. target_link_libraries(${PROJECT_NAME} ${SPATIAL_LIBRARY})
  574. endif()
  575. endif(BUILD_CLIENT)
  576. if(BUILD_SERVER)
  577. add_executable(${PROJECT_NAME}server ${server_SRCS})
  578. add_dependencies(${PROJECT_NAME}server GenerateVersion)
  579. target_link_libraries(
  580. ${PROJECT_NAME}server
  581. ${ZLIB_LIBRARIES}
  582. ${SQLITE3_LIBRARY}
  583. ${JSON_LIBRARY}
  584. ${GETTEXT_LIBRARY}
  585. ${LUA_LIBRARY}
  586. ${GMP_LIBRARY}
  587. ${PLATFORM_LIBS}
  588. )
  589. set_target_properties(${PROJECT_NAME}server PROPERTIES
  590. COMPILE_DEFINITIONS "SERVER")
  591. if (USE_CURSES)
  592. target_link_libraries(${PROJECT_NAME}server ${CURSES_LIBRARIES})
  593. endif()
  594. if (USE_POSTGRESQL)
  595. target_link_libraries(${PROJECT_NAME}server ${POSTGRESQL_LIBRARY})
  596. endif()
  597. if (USE_LEVELDB)
  598. target_link_libraries(${PROJECT_NAME}server ${LEVELDB_LIBRARY})
  599. endif()
  600. if (USE_REDIS)
  601. target_link_libraries(${PROJECT_NAME}server ${REDIS_LIBRARY})
  602. endif()
  603. if (USE_SPATIAL)
  604. target_link_libraries(${PROJECT_NAME}server ${SPATIAL_LIBRARY})
  605. endif()
  606. if(USE_CURL)
  607. target_link_libraries(
  608. ${PROJECT_NAME}server
  609. ${CURL_LIBRARY}
  610. )
  611. endif()
  612. endif(BUILD_SERVER)
  613. # Blacklisted locales that don't work.
  614. # see issue #4638
  615. set(GETTEXT_BLACKLISTED_LOCALES
  616. be
  617. he
  618. ko
  619. ky
  620. zh_CN
  621. zh_TW
  622. )
  623. option(APPLY_LOCALE_BLACKLIST "Use a blacklist to avoid broken locales" TRUE)
  624. if (GETTEXT_FOUND AND APPLY_LOCALE_BLACKLIST)
  625. set(GETTEXT_USED_LOCALES "")
  626. foreach(LOCALE ${GETTEXT_AVAILABLE_LOCALES})
  627. if (NOT ";${GETTEXT_BLACKLISTED_LOCALES};" MATCHES ";${LOCALE};")
  628. list(APPEND GETTEXT_USED_LOCALES ${LOCALE})
  629. endif()
  630. endforeach()
  631. message(STATUS "Locale blacklist applied; Locales used: ${GETTEXT_USED_LOCALES}")
  632. endif()
  633. # Set some optimizations and tweaks
  634. include(CheckCXXCompilerFlag)
  635. if(MSVC)
  636. # Visual Studio
  637. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++11")
  638. # EHa enables SEH exceptions (used for catching segfaults)
  639. set(CMAKE_CXX_FLAGS_RELEASE "/EHa /Ox /GL /FD /MT /GS- /Zi /arch:SSE /fp:fast /D NDEBUG /D _HAS_ITERATOR_DEBUGGING=0 /TP")
  640. #set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /NODEFAULTLIB:\"libcmtd.lib\" /NODEFAULTLIB:\"libcmt.lib\"")
  641. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF")
  642. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
  643. set(CMAKE_CXX_FLAGS_SEMIDEBUG "/MDd /Zi /Ob0 /O1 /RTC1")
  644. # Debug build doesn't catch exceptions by itself
  645. # Add some optimizations because otherwise it's VERY slow
  646. set(CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od /RTC1")
  647. # Flags for C files (sqlite)
  648. # /MT = Link statically with standard library stuff
  649. set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT")
  650. else()
  651. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  652. # Probably GCC
  653. if(APPLE)
  654. SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pagezero_size 10000 -image_base 100000000" )
  655. endif()
  656. if(WARN_ALL)
  657. set(RELEASE_WARNING_FLAGS "-Wall")
  658. else()
  659. set(RELEASE_WARNING_FLAGS "")
  660. endif()
  661. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  662. # clang does not understand __extern_always_inline but libc headers use it
  663. set(OTHER_FLAGS "${OTHER_FLAGS} \"-D__extern_always_inline=extern __always_inline\"")
  664. set(OTHER_FLAGS "${OTHER_FLAGS} -Wsign-compare")
  665. endif()
  666. if(WIN32 AND NOT ZLIBWAPI_DLL AND CMAKE_SIZEOF_VOID_P EQUAL 4)
  667. set(OTHER_FLAGS "${OTHER_FLAGS} -DWIN32_NO_ZLIB_WINAPI")
  668. message(WARNING "Defaulting to cdecl for zlib on win32 because ZLIBWAPI_DLL"
  669. " isn't set, ensure that ZLIBWAPI_DLL is set if you want stdcall.")
  670. endif()
  671. if(MINGW)
  672. set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions")
  673. endif()
  674. set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -Wall -pipe -funroll-loops")
  675. if(CMAKE_SYSTEM_NAME MATCHES "(Darwin|FreeBSD)")
  676. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os")
  677. else()
  678. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -ffast-math -fomit-frame-pointer")
  679. endif(CMAKE_SYSTEM_NAME MATCHES "(Darwin|FreeBSD)")
  680. set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 -Wall -Wabi ${WARNING_FLAGS} ${OTHER_FLAGS}")
  681. set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wabi ${WARNING_FLAGS} ${OTHER_FLAGS}")
  682. if(USE_GPROF)
  683. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
  684. endif()
  685. if(MINGW)
  686. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mwindows")
  687. endif()
  688. endif()
  689. # Installation
  690. if(WIN32)
  691. if(USE_SOUND)
  692. if(OPENAL_DLL)
  693. install(FILES ${OPENAL_DLL} DESTINATION ${BINDIR})
  694. endif()
  695. if(OGG_DLL)
  696. install(FILES ${OGG_DLL} DESTINATION ${BINDIR})
  697. endif()
  698. if(VORBIS_DLL)
  699. install(FILES ${VORBIS_DLL} DESTINATION ${BINDIR})
  700. endif()
  701. if(VORBISFILE_DLL)
  702. install(FILES ${VORBISFILE_DLL} DESTINATION ${BINDIR})
  703. endif()
  704. endif()
  705. if(CURL_DLL)
  706. install(FILES ${CURL_DLL} DESTINATION ${BINDIR})
  707. endif()
  708. if(ZLIB_DLL)
  709. install(FILES ${ZLIB_DLL} DESTINATION ${BINDIR})
  710. endif()
  711. if(ZLIBWAPI_DLL)
  712. install(FILES ${ZLIBWAPI_DLL} DESTINATION ${BINDIR})
  713. endif()
  714. if(FREETYPE_DLL)
  715. install(FILES ${FREETYPE_DLL} DESTINATION ${BINDIR})
  716. endif()
  717. if(SQLITE3_DLL)
  718. install(FILES ${SQLITE3_DLL} DESTINATION ${BINDIR})
  719. endif()
  720. if(LEVELDB_DLL)
  721. install(FILES ${LEVELDB_DLL} DESTINATION ${BINDIR})
  722. endif()
  723. endif()
  724. if(BUILD_CLIENT)
  725. install(TARGETS ${PROJECT_NAME}
  726. RUNTIME DESTINATION ${BINDIR}
  727. LIBRARY DESTINATION ${BINDIR}
  728. ARCHIVE DESTINATION ${BINDIR}
  729. BUNDLE DESTINATION .
  730. )
  731. if(APPLE)
  732. install(CODE "
  733. set(BU_CHMOD_BUNDLE_ITEMS ON)
  734. include(BundleUtilities)
  735. fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${BUNDLE_PATH}\" \"\" \"\${CMAKE_INSTALL_PREFIX}/${BINDIR}\")
  736. " COMPONENT Runtime)
  737. endif()
  738. if(USE_GETTEXT)
  739. foreach(LOCALE ${GETTEXT_USED_LOCALES})
  740. set_mo_paths(MO_BUILD_PATH MO_DEST_PATH ${LOCALE})
  741. set(MO_BUILD_PATH "${MO_BUILD_PATH}/${PROJECT_NAME}.mo")
  742. install(FILES ${MO_BUILD_PATH} DESTINATION ${MO_DEST_PATH})
  743. endforeach()
  744. endif()
  745. if(WIN32)
  746. if(DEFINED IRRLICHT_DLL)
  747. install(FILES ${IRRLICHT_DLL} DESTINATION ${BINDIR})
  748. endif()
  749. if(USE_GETTEXT)
  750. if(DEFINED GETTEXT_DLL)
  751. install(FILES ${GETTEXT_DLL} DESTINATION ${BINDIR})
  752. endif()
  753. if(DEFINED GETTEXT_ICONV_DLL)
  754. install(FILES ${GETTEXT_ICONV_DLL} DESTINATION ${BINDIR})
  755. endif()
  756. endif()
  757. endif()
  758. endif(BUILD_CLIENT)
  759. if(BUILD_SERVER)
  760. install(TARGETS ${PROJECT_NAME}server DESTINATION ${BINDIR})
  761. endif()
  762. if (USE_GETTEXT)
  763. set(MO_FILES)
  764. foreach(LOCALE ${GETTEXT_USED_LOCALES})
  765. set(PO_FILE_PATH "${GETTEXT_PO_PATH}/${LOCALE}/${PROJECT_NAME}.po")
  766. set_mo_paths(MO_BUILD_PATH MO_DEST_PATH ${LOCALE})
  767. set(MO_FILE_PATH "${MO_BUILD_PATH}/${PROJECT_NAME}.mo")
  768. add_custom_command(OUTPUT ${MO_BUILD_PATH}
  769. COMMAND ${CMAKE_COMMAND} -E make_directory ${MO_BUILD_PATH}
  770. COMMENT "mo-update [${LOCALE}]: Creating locale directory.")
  771. add_custom_command(
  772. OUTPUT ${MO_FILE_PATH}
  773. COMMAND ${GETTEXT_MSGFMT} -o ${MO_FILE_PATH} ${PO_FILE_PATH}
  774. DEPENDS ${MO_BUILD_PATH} ${PO_FILE_PATH}
  775. WORKING_DIRECTORY "${GETTEXT_PO_PATH}/${LOCALE}"
  776. COMMENT "mo-update [${LOCALE}]: Creating mo file."
  777. )
  778. set(MO_FILES ${MO_FILES} ${MO_FILE_PATH})
  779. endforeach()
  780. add_custom_target(translations ALL COMMENT "mo update" DEPENDS ${MO_FILES})
  781. endif()
  782. # Subdirectories
  783. if (BUILD_CLIENT AND USE_FREETYPE)
  784. add_subdirectory(cguittfont)
  785. endif()