CMakeLists.txt 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. cmake_minimum_required(VERSION 2.8.4)
  2. # root CMakeLists for the SuperTuxKart project
  3. project(SuperTuxKart)
  4. set(PROJECT_VERSION "git")
  5. add_definitions( -DSUPERTUXKART_VERSION="${PROJECT_VERSION}" )
  6. if(NOT (CMAKE_MAJOR_VERSION VERSION_LESS 3))
  7. cmake_policy(SET CMP0043 OLD)
  8. endif()
  9. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
  10. include(CMakeDependentOption)
  11. include(BuildTypeSTKRelease)
  12. if(NOT CMAKE_BUILD_TYPE)
  13. message(STATUS "No build type selected, default to STKRelease")
  14. set(CMAKE_BUILD_TYPE "STKRelease")
  15. endif()
  16. option(SERVER_ONLY "Create a server only (i.e. no graphics or sound)" OFF)
  17. option(CHECK_ASSETS "Check if assets are installed in ../stk-assets" ON)
  18. option(USE_SYSTEM_ANGELSCRIPT "Use system angelscript instead of built-in angelscript. If you enable this option, make sure to use a compatible version." OFF)
  19. option(USE_SYSTEM_ENET "Use system ENET instead of the built-in version, when available." ON)
  20. option(USE_SYSTEM_GLEW "Use system GLEW instead of the built-in version, when available." ON)
  21. CMAKE_DEPENDENT_OPTION(USE_CRYPTO_OPENSSL "Use OpenSSL instead of Nettle for cryptography in STK." OFF
  22. "NOT APPLE" ON)
  23. CMAKE_DEPENDENT_OPTION(BUILD_RECORDER "Build opengl recorder" ON
  24. "NOT SERVER_ONLY;NOT APPLE" OFF)
  25. CMAKE_DEPENDENT_OPTION(USE_FRIBIDI "Support for right-to-left languages" ON
  26. "NOT SERVER_ONLY" OFF)
  27. CMAKE_DEPENDENT_OPTION(USE_WIIUSE "Support for wiimote input devices" ON
  28. "NOT SERVER_ONLY;NOT MINGW;NOT CYGWIN" OFF)
  29. if(APPLE)
  30. list(APPEND CMAKE_PREFIX_PATH /usr/local/opt)
  31. include_directories(/usr/local/opt/fribidi/include/)
  32. include_directories(/usr/local/opt/openssl@1.1/include/)
  33. include_directories(/usr/local/opt/openssl@1.1/include/openssl/)
  34. include_directories(/usr/local/opt/freetype/include/freetype2/)
  35. endif()
  36. if((UNIX AND NOT APPLE) AND NOT SERVER_ONLY)
  37. option(ENABLE_WAYLAND_DEVICE "Enable Wayland device for linux build" ON)
  38. if((${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") OR
  39. (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
  40. option(USE_GLES2 "Use OpenGL ES2 renderer" ON)
  41. else()
  42. option(USE_GLES2 "Use OpenGL ES2 renderer" OFF)
  43. endif()
  44. endif()
  45. if(UNIX OR MINGW)
  46. option(DEBUG_SYMBOLS "Compile with debug symbols" OFF)
  47. endif()
  48. if(MSVC AND (MSVC_VERSION LESS 1900))
  49. # Normally hide the option to build wiiuse on VS, since it depends
  50. # on the installation of the Windows DDK (Driver Developer Kit),
  51. # which also needs an absolute path :(
  52. option(WIIUSE_BUILD "Build wiiuse lib (only for developers)" OFF)
  53. mark_as_advanced(WIIUSE_BUILD)
  54. else()
  55. set(WIIUSE_BUILD ON)
  56. endif()
  57. if(UNIX AND NOT APPLE)
  58. option(USE_ASAN "Build with Leak/Address sanitizer" OFF)
  59. option(USE_LIBBFD "Use libbfd for crash reporting and leak check" OFF)
  60. endif()
  61. set(STK_SOURCE_DIR "src")
  62. set(STK_DATA_DIR "${PROJECT_SOURCE_DIR}/data")
  63. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
  64. # Define install paths
  65. set(STK_INSTALL_BINARY_DIR "bin" CACHE
  66. STRING "Install executable to this directory, absolute or relative to CMAKE_INSTALL_PREFIX")
  67. set(STK_INSTALL_DATA_DIR "share/supertuxkart" CACHE
  68. STRING "Install data folder to this directory, absolute or relative to CMAKE_INSTALL_PREFIX")
  69. # Define dependencies path
  70. if(MSVC)
  71. set(DEPENDENCIES "dependencies-vs")
  72. elseif(MINGW)
  73. set(DEPENDENCIES "dependencies-mingw")
  74. else()
  75. set(DEPENDENCIES "dependencies")
  76. endif()
  77. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  78. set(DEPENDENCIES "${DEPENDENCIES}-64bit")
  79. endif()
  80. if(WIN32)
  81. if(NOT IS_DIRECTORY "${PROJECT_SOURCE_DIR}/${DEPENDENCIES}")
  82. set(DEPENDENCIES "dependencies")
  83. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  84. set(DEPENDENCIES "${DEPENDENCIES}-64bit")
  85. endif()
  86. endif()
  87. if(NOT IS_DIRECTORY "${PROJECT_SOURCE_DIR}/${DEPENDENCIES}")
  88. message(FATAL_ERROR "Dependencies directory not found.")
  89. endif()
  90. endif()
  91. # These variables enable MSVC to find libraries located in "dependencies"
  92. if(WIN32)
  93. set(ENV{PATH} "$ENV{PATH};${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/include")
  94. set(ENV{LIB} ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib)
  95. set(ENV{OPENALDIR} ${PROJECT_SOURCE_DIR}/${DEPENDENCIES})
  96. add_definitions(-D_IRR_STATIC_LIB_)
  97. add_definitions(-DNO_IRR_COMPILE_WITH_X11_)
  98. include_directories(${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/include)
  99. endif()
  100. if(USE_GLES2)
  101. add_definitions(-DUSE_GLES2)
  102. add_definitions(-D_IRR_COMPILE_WITH_OGLES2_ -DNO_IRR_COMPILE_WITH_OPENGL_)
  103. endif()
  104. if(SERVER_ONLY)
  105. add_definitions(-DSERVER_ONLY)
  106. add_definitions(-DNO_IRR_COMPILE_WITH_X11_ -DNO_IRR_COMPILE_WITH_OPENGL_ -DNO_IRR_COMPILE_WITH_OSX_DEVICE_)
  107. endif()
  108. if(UNIX OR MINGW)
  109. if(DEBUG_SYMBOLS)
  110. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
  111. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
  112. endif()
  113. endif()
  114. if(UNIX AND NOT APPLE)
  115. find_package(PkgConfig REQUIRED)
  116. if(NOT PKGCONFIG_FOUND)
  117. message(FATAL_ERROR "Pkg-config not found.")
  118. endif()
  119. endif()
  120. # Build the Bullet physics library
  121. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/bullet")
  122. include_directories("${PROJECT_SOURCE_DIR}/lib/bullet/src")
  123. # Find system ENet library or build it if missing
  124. if((UNIX AND NOT APPLE) AND USE_SYSTEM_ENET)
  125. pkg_check_modules(ENET libenet>=1.3.4)
  126. endif()
  127. if(ENET_FOUND)
  128. include_directories(${ENET_INCLUDE_DIRS})
  129. else()
  130. # Fallback to built-in version
  131. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/enet")
  132. include_directories("${PROJECT_SOURCE_DIR}/lib/enet/include")
  133. set(ENET_LIBRARIES "enet")
  134. endif()
  135. # Find system GLEW library or build it if missing
  136. if (APPLE)
  137. find_package(glew)
  138. if(GLEW_FOUND)
  139. include_directories(${GLEW_INCLUDE_DIRS})
  140. endif()
  141. elseif(NOT USE_GLES2 AND NOT SERVER_ONLY)
  142. add_definitions(-DGLEW_NO_GLU)
  143. if((UNIX AND NOT APPLE) AND USE_SYSTEM_GLEW)
  144. pkg_check_modules(GLEW glew>=2.1)
  145. endif()
  146. if(GLEW_FOUND)
  147. include_directories(${GLEW_INCLUDE_DIRS})
  148. else()
  149. # Fallback to built-in version silently
  150. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/glew")
  151. include_directories("${PROJECT_SOURCE_DIR}/lib/glew/include")
  152. set(GLEW_LIBRARIES "glew")
  153. endif()
  154. endif()
  155. if(MSVC)
  156. # Build zlib library
  157. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/zlib")
  158. include_directories("${PROJECT_SOURCE_DIR}/lib/zlib")
  159. set(ZLIB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lib/zlib" "${PROJECT_BINARY_DIR}/lib/zlib/")
  160. set(ZLIB_LIBRARY zlibstatic)
  161. endif()
  162. if (NOT SERVER_ONLY)
  163. if(MSVC OR APPLE)
  164. # Build png library
  165. set(SKIP_INSTALL_ALL TRUE)
  166. set(PNG_STATIC TRUE CACHE BOOL "Build static lib")
  167. set(PNG_TESTS FALSE CACHE BOOL "Build libpng tests")
  168. set(PNG_SHARED FALSE CACHE BOOL "Build shared lib")
  169. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/libpng")
  170. include_directories("${PROJECT_SOURCE_DIR}/lib/libpng")
  171. set(PNG_PNG_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lib/libpng/")
  172. set(PNG_LIBRARY png_static)
  173. endif()
  174. # Add jpeg library
  175. if (APPLE)
  176. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/jpeglib")
  177. include_directories("${PROJECT_SOURCE_DIR}/lib/jpeglib")
  178. set(JPEG_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lib/jpeglib/")
  179. set(JPEG_LIBRARY jpeglib)
  180. else()
  181. find_package(JPEG REQUIRED)
  182. include_directories(${JPEG_INCLUDE_DIR})
  183. endif()
  184. endif()
  185. if (BUILD_RECORDER)
  186. find_library(OPENGLRECORDER_LIBRARY NAMES openglrecorder libopenglrecorder PATHS "${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib")
  187. find_path(OPENGLRECORDER_INCLUDEDIR NAMES openglrecorder.h PATHS "${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/include")
  188. if (NOT OPENGLRECORDER_LIBRARY OR NOT OPENGLRECORDER_INCLUDEDIR)
  189. if(PROJECT_VERSION STREQUAL "git")
  190. message(WARNING "libopenglrecorder not found, disabling in-game recorder. "
  191. "To use recorder, install libopenglrecorder.")
  192. set(OPENGLRECORDER_LIBRARY CACHE INTERNAL "")
  193. set(OPENGLRECORDER_INCLUDEDIR CACHE INTERNAL "")
  194. set(BUILD_RECORDER OFF)
  195. else()
  196. message(FATAL_ERROR "libopenglrecorder not found. "
  197. "Either install libopenglrecorder or disable in-game recorder with -DBUILD_RECORDER=0")
  198. endif()
  199. else()
  200. include_directories(${OPENGLRECORDER_INCLUDEDIR})
  201. mark_as_advanced(OPENGLRECORDER_LIBRARY OPENGLRECORDER_INCLUDEDIR)
  202. add_definitions(-DENABLE_RECORDER)
  203. endif()
  204. endif()
  205. if(NOT SERVER_ONLY)
  206. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/graphics_utils")
  207. include_directories("${PROJECT_SOURCE_DIR}/lib/graphics_utils")
  208. endif()
  209. if(NOT SERVER_ONLY)
  210. find_library(SQUISH_LIBRARY NAMES squish libsquish)
  211. find_path(SQUISH_INCLUDEDIR NAMES squish.h PATHS)
  212. if (NOT SQUISH_LIBRARY OR NOT SQUISH_INCLUDEDIR)
  213. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/libsquish")
  214. include_directories("${PROJECT_SOURCE_DIR}/lib/libsquish")
  215. SET(SQUISH_LIBRARY squish)
  216. else()
  217. include_directories("${SQUISH_INCLUDEDIR}")
  218. MESSAGE(STATUS "Use system libsquish: ${SQUISH_LIBRARY}")
  219. endif()
  220. endif()
  221. # Build the irrlicht library
  222. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/irrlicht")
  223. include_directories("${PROJECT_SOURCE_DIR}/lib/irrlicht/include")
  224. # Build the Wiiuse library
  225. # Note: wiiuse MUST be declared after irrlicht, since otherwise
  226. # (at least on VS) irrlicht will find wiiuse io.h file because
  227. # of the added include directory.
  228. if(USE_WIIUSE)
  229. if(WIIUSE_BUILD)
  230. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/wiiuse")
  231. endif()
  232. include_directories("${PROJECT_SOURCE_DIR}/lib/wiiuse")
  233. endif()
  234. # Set include paths
  235. include_directories(${STK_SOURCE_DIR})
  236. if(APPLE)
  237. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64")
  238. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch x86_64 -F/Library/Frameworks")
  239. elseif(MSVC)
  240. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") # Enable multi-processor compilation (faster)
  241. endif()
  242. # Build the angelscript library if not in system
  243. if(USE_SYSTEM_ANGELSCRIPT)
  244. find_package(Angelscript)
  245. if(ANGELSCRIPT_FOUND)
  246. include_directories(${Angelscript_INCLUDE_DIRS})
  247. else()
  248. message(FATAL_ERROR "Angelscript not found. "
  249. "Either install angelscript or use built-in version using "
  250. "-DUSE_SYSTEM_ANGELSCRIPT=0")
  251. endif()
  252. else()
  253. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/angelscript/projects/cmake")
  254. include_directories("${PROJECT_SOURCE_DIR}/lib/angelscript/include")
  255. set(Angelscript_LIBRARIES angelscript)
  256. endif()
  257. if(NOT SERVER_ONLY)
  258. # OpenAL
  259. find_package(OpenAL REQUIRED)
  260. include_directories(${OPENAL_INCLUDE_DIR})
  261. # OggVorbis
  262. find_package(OggVorbis REQUIRED)
  263. include_directories(${OGGVORBIS_INCLUDE_DIRS})
  264. add_definitions(-DENABLE_SOUND)
  265. endif()
  266. # Freetype
  267. if (NOT SERVER_ONLY)
  268. find_package(Freetype)
  269. if(FREETYPE_FOUND)
  270. include_directories(${FREETYPE_INCLUDE_DIRS})
  271. else()
  272. message(FATAL_ERROR "Freetype not found. "
  273. "Freetype is required to display characters in SuperTuxKart. ")
  274. endif()
  275. endif()
  276. # Fribidi
  277. if(USE_FRIBIDI)
  278. find_package(Fribidi)
  279. if(FRIBIDI_FOUND)
  280. include_directories(${FRIBIDI_INCLUDE_DIRS})
  281. else()
  282. message(FATAL_ERROR "Fribidi not found. "
  283. "Either install fribidi or disable bidi support with -DUSE_FRIBIDI=0 "
  284. "(if you don't use a right-to-left language then you don't need this).")
  285. endif()
  286. endif()
  287. # OpenGL
  288. if(NOT USE_GLES2 AND NOT SERVER_ONLY)
  289. find_package(OpenGL REQUIRED)
  290. include_directories(${OPENGL_INCLUDE_DIR})
  291. endif()
  292. if(USE_LIBBFD)
  293. find_package(Libbfd)
  294. if(LIBBFD_FOUND)
  295. add_definitions(-DENABLE_LIBBFD)
  296. include_directories(${LIBBFD_INCLUDE_DIRS})
  297. else()
  298. set(USE_LIBBFD OFF CACHE BOOL "Use libbfd for crash reporting and leak check" FORCE)
  299. message(WARNING "Libbfd not found, disable integrated stack trace.")
  300. endif()
  301. endif()
  302. # Set some compiler options
  303. if(UNIX OR MINGW)
  304. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
  305. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-function")
  306. endif()
  307. if(MINGW AND CMAKE_BUILD_TYPE MATCHES Release)
  308. SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--subsystem,windows")
  309. endif()
  310. if(WIN32)
  311. # By default windows.h has macros defined for min and max that screw up everything
  312. add_definitions(-DNOMINMAX)
  313. # And shut up about unsafe stuff
  314. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  315. # Avoid timespec structure redeclaration on Visual Studio 2015
  316. if (NOT (MSVC_VERSION LESS 1900))
  317. add_definitions(-DHAVE_STRUCT_TIMESPEC)
  318. endif()
  319. endif()
  320. if(MSVC)
  321. # VS will automatically add NDEBUG for release mode, but only _DEBUG in debug mode.
  322. # Since STK uses DEBUG, this is added for debug compilation only:
  323. set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG)
  324. else()
  325. # All non VS generators used create only a single compile mode, so
  326. # compile flags can be simplye be added
  327. if(CMAKE_BUILD_TYPE MATCHES Debug)
  328. add_definitions(-DDEBUG)
  329. else()
  330. add_definitions(-DNDEBUG)
  331. endif()
  332. endif()
  333. if(WIN32)
  334. configure_file("${STK_SOURCE_DIR}/../tools/windows_installer/icon_rc.template" "${PROJECT_BINARY_DIR}/tmp/icon.rc")
  335. endif()
  336. # Provides list of source and header files (STK_SOURCES and STK_HEADERS)
  337. include(sources.cmake)
  338. # Generate source groups useful for MSVC project explorer
  339. include(cmake/SourceGroupFunctions.cmake)
  340. source_group_hierarchy(STK_SOURCES STK_HEADERS)
  341. if(APPLE)
  342. # icon files to copy in the bundle
  343. set(OSX_ICON_FILES ${PROJECT_SOURCE_DIR}/data/supertuxkart.icns)
  344. set_source_files_properties(${OSX_ICON_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  345. set(STK_SOURCES ${STK_SOURCES} ${OSX_ICON_FILES})
  346. # build the executable and create an app bundle
  347. add_executable(supertuxkart MACOSX_BUNDLE ${STK_SOURCES})
  348. find_library(IOKIT_LIBRARY IOKit)
  349. find_library(COCOA_LIBRARY Cocoa)
  350. target_link_libraries(supertuxkart
  351. ${IOKIT_LIBRARY}
  352. ${COCOA_LIBRARY})
  353. # configure CMake to use a custom Info.plist
  354. set_target_properties(supertuxkart PROPERTIES
  355. MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/data/SuperTuxKart-Info.plist)
  356. if(CMAKE_GENERATOR MATCHES "Xcode")
  357. add_custom_command(TARGET supertuxkart POST_BUILD
  358. COMMAND ln -f -s ${PROJECT_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/bin/\${CONFIGURATION}/supertuxkart.app/Contents/Resources)
  359. else()
  360. add_custom_command(TARGET supertuxkart POST_BUILD
  361. COMMAND ln -f -s ${PROJECT_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/bin/supertuxkart.app/Contents/Resources)
  362. endif()
  363. else()
  364. if(MSVC)
  365. set(PTHREAD_NAMES pthreadVC2)
  366. elseif(MINGW)
  367. set(PTHREAD_NAMES "winpthread-1" "libwinpthread-1" "pthreadGC2")
  368. endif()
  369. find_library(PTHREAD_LIBRARY NAMES pthread ${PTHREAD_NAMES} PATHS ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib)
  370. mark_as_advanced(PTHREAD_LIBRARY)
  371. # Set data dir (absolute or relative to CMAKE_INSTALL_PREFIX)
  372. if(NOT STK_INSTALL_DATA_DIR_ABSOLUTE)
  373. get_filename_component(STK_INSTALL_DATA_DIR_ABSOLUTE ${STK_INSTALL_DATA_DIR} ABSOLUTE)
  374. if(${STK_INSTALL_DATA_DIR_ABSOLUTE} STREQUAL ${STK_INSTALL_DATA_DIR})
  375. add_definitions(-DSUPERTUXKART_DATADIR=\"${STK_INSTALL_DATA_DIR_ABSOLUTE}\")
  376. else()
  377. add_definitions(-DSUPERTUXKART_DATADIR=\"${CMAKE_INSTALL_PREFIX}/${STK_INSTALL_DATA_DIR}\")
  378. endif()
  379. else()
  380. add_definitions(-DSUPERTUXKART_DATADIR=\"${STK_INSTALL_DATA_DIR_ABSOLUTE}\")
  381. endif()
  382. # Build the final executable
  383. add_executable(supertuxkart ${STK_SOURCES} ${STK_RESOURCES} ${STK_HEADERS})
  384. target_link_libraries(supertuxkart ${PTHREAD_LIBRARY})
  385. endif()
  386. # CURL and OpenSSL or Nettle
  387. # 1.0.1d for compatible AES GCM handling
  388. SET(OPENSSL_MINIMUM_VERSION "1.0.1d")
  389. if(MSVC)
  390. set(USE_CRYPTO_OPENSSL ON)
  391. target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/libcurl.lib)
  392. target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/libeay32.lib)
  393. elseif(MINGW)
  394. set(USE_CRYPTO_OPENSSL ON)
  395. target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/libcurldll.a)
  396. target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/libeay32.dll)
  397. else()
  398. find_package(CURL REQUIRED)
  399. include_directories(${CURL_INCLUDE_DIRS})
  400. find_path(NETTLE_INCLUDE_DIRS nettle/gcm.h nettle/sha.h nettle/base64.h nettle/version.h nettle/yarrow.h)
  401. find_library(NETTLE_LIBRARY NAMES nettle libnettle)
  402. if (NOT NETTLE_INCLUDE_DIRS OR NOT NETTLE_LIBRARY OR USE_CRYPTO_OPENSSL)
  403. set(USE_CRYPTO_OPENSSL ON)
  404. find_package(OpenSSL REQUIRED)
  405. if(${OPENSSL_VERSION} VERSION_LESS ${OPENSSL_MINIMUM_VERSION} OR
  406. (${OPENSSL_VERSION} VERSION_EQUAL ${OPENSSL_MINIMUM_VERSION} AND ${OPENSSL_VERSION} STRLESS ${OPENSSL_MINIMUM_VERSION}))
  407. message(FATAL_ERROR "OpenSSL version found (${OPENSSL_VERSION}) is less then the minimum required (${OPENSSL_MINIMUM_VERSION}), aborting.")
  408. endif()
  409. include_directories(${OpenSSL_INCLUDE_DIRS})
  410. else()
  411. set(USE_CRYPTO_OPENSSL OFF)
  412. include_directories(${NETTLE_INCLUDE_DIRS})
  413. endif()
  414. endif()
  415. if (USE_CRYPTO_OPENSSL)
  416. message(STATUS "OpenSSL will be used for cryptography in STK.")
  417. add_definitions(-DENABLE_CRYPTO_OPENSSL)
  418. else()
  419. message(STATUS "Nettle will be used for cryptography in STK.")
  420. add_definitions(-DENABLE_CRYPTO_NETTLE)
  421. endif()
  422. # Common library dependencies
  423. target_link_libraries(supertuxkart
  424. bulletdynamics
  425. bulletcollision
  426. bulletmath
  427. ${ENET_LIBRARIES}
  428. stkirrlicht
  429. ${Angelscript_LIBRARIES}
  430. ${CURL_LIBRARIES}
  431. )
  432. if (USE_CRYPTO_OPENSSL)
  433. target_link_libraries(supertuxkart ${OPENSSL_CRYPTO_LIBRARY})
  434. else()
  435. target_link_libraries(supertuxkart ${NETTLE_LIBRARY})
  436. endif()
  437. if(NOT SERVER_ONLY)
  438. if(NOT USE_GLES2)
  439. target_link_libraries(supertuxkart ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARIES})
  440. else()
  441. target_link_libraries(supertuxkart GLESv2)
  442. endif()
  443. target_link_libraries(supertuxkart
  444. ${SQUISH_LIBRARY}
  445. ${FREETYPE_LIBRARIES}
  446. ${JPEG_LIBRARIES}
  447. ${OGGVORBIS_LIBRARIES}
  448. ${OPENAL_LIBRARY}
  449. graphics_utils)
  450. endif()
  451. if(UNIX AND NOT APPLE)
  452. if(USE_LIBBFD)
  453. target_link_libraries(supertuxkart ${LIBBFD_LIBRARIES})
  454. endif()
  455. if(USE_ASAN)
  456. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
  457. target_link_libraries(supertuxkart "-fsanitize=address")
  458. endif()
  459. endif()
  460. if(BUILD_RECORDER)
  461. target_link_libraries(supertuxkart ${OPENGLRECORDER_LIBRARY})
  462. endif()
  463. # FreeBSD does not search in /usr/local/lib, but at least Freetype is installed there :(
  464. if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
  465. SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
  466. endif()
  467. if(USE_FRIBIDI)
  468. target_link_libraries(supertuxkart ${FRIBIDI_LIBRARIES})
  469. add_definitions(-DENABLE_BIDI)
  470. endif()
  471. # Wiiuse
  472. # ------
  473. if(USE_WIIUSE)
  474. if(APPLE)
  475. find_library(BLUETOOTH_LIBRARY NAMES IOBluetooth PATHS /Developer/Library/Frameworks/IOBluetooth.framework)
  476. target_link_libraries(supertuxkart wiiuse ${BLUETOOTH_LIBRARY})
  477. elseif(WIN32)
  478. add_definitions(-DWIIUSE_STATIC)
  479. if(WIIUSE_BUILD)
  480. target_link_libraries(supertuxkart wiiuse)
  481. else()
  482. target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/wiiuse.lib)
  483. endif()
  484. else()
  485. target_link_libraries(supertuxkart wiiuse bluetooth)
  486. endif()
  487. add_definitions(-DENABLE_WIIUSE)
  488. endif()
  489. if(MSVC OR MINGW)
  490. target_link_libraries(supertuxkart iphlpapi.lib)
  491. add_custom_command(TARGET supertuxkart POST_BUILD
  492. COMMAND ${CMAKE_COMMAND} -E copy_directory
  493. "${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/dll"
  494. $<TARGET_FILE_DIR:supertuxkart>)
  495. add_custom_target(stkshaders SOURCES ${STK_SHADERS})
  496. endif()
  497. if(MINGW)
  498. find_library(LIBGCC NAMES "libgcc_s_dw2-1.dll" "libgcc_s_sjlj-1.dll" "libgcc_s_seh-1.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
  499. if(LIBGCC)
  500. file(COPY ${LIBGCC} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
  501. endif()
  502. find_library(LIBSTDCPP NAMES "libstdc++-6.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
  503. if(LIBSTDCPP)
  504. file(COPY ${LIBSTDCPP} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
  505. endif()
  506. find_library(LIBPTHREAD NAMES "winpthread-1.dll" "libwinpthread-1.dll" "pthreadGC2.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
  507. if(LIBPTHREAD)
  508. file(COPY ${LIBPTHREAD} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
  509. endif()
  510. endif()
  511. # ==== Checking if data folder exists ====
  512. if(NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)
  513. message( FATAL_ERROR "${CMAKE_CURRENT_SOURCE_DIR}/data folder doesn't exist" )
  514. endif()
  515. # ==== Checking if stk-assets folder exists ====
  516. if(CHECK_ASSETS)
  517. if((IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/karts) AND
  518. (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/library) AND
  519. (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/music) AND
  520. (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/sfx) AND
  521. (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/textures) AND
  522. (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/tracks))
  523. message(STATUS "Assets found in data directory")
  524. elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../stk-assets)
  525. set(STK_ASSETS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../stk-assets/)
  526. message(STATUS "Assets found")
  527. elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../supertuxkart-assets)
  528. set(STK_ASSETS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../supertuxkart-assets/)
  529. message(STATUS "Assets found")
  530. else()
  531. set (CUR_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  532. get_filename_component(PARENT_DIR ${CUR_DIR} PATH)
  533. message( FATAL_ERROR "${PARENT_DIR}/stk-assets folder doesn't exist. "
  534. "Please download the stk-assets, or disable this test with -DCHECK_ASSETS=off." )
  535. endif()
  536. endif()
  537. # ==== Install target ====
  538. install(TARGETS supertuxkart RUNTIME DESTINATION ${STK_INSTALL_BINARY_DIR} BUNDLE DESTINATION .)
  539. install(DIRECTORY ${STK_DATA_DIR} DESTINATION ${STK_INSTALL_DATA_DIR} PATTERN ".svn" EXCLUDE PATTERN ".git" EXCLUDE)
  540. if(STK_ASSETS_DIR AND CHECK_ASSETS)
  541. install(DIRECTORY ${STK_ASSETS_DIR} DESTINATION ${STK_INSTALL_DATA_DIR}/data PATTERN ".svn" EXCLUDE PATTERN ".git" EXCLUDE)
  542. endif()
  543. install(FILES ${STK_DATA_DIR}/supertuxkart.desktop DESTINATION share/applications)
  544. install(FILES data/supertuxkart_48.png DESTINATION share/icons/hicolor/48x48/apps RENAME supertuxkart.png)
  545. install(FILES data/supertuxkart_128.png DESTINATION share/icons/hicolor/128x128/apps RENAME supertuxkart.png)
  546. install(FILES data/supertuxkart_48.png DESTINATION share/pixmaps RENAME supertuxkart.png)
  547. install(FILES data/supertuxkart.appdata.xml DESTINATION share/metainfo)
  548. if(MINGW)
  549. install(DIRECTORY ${CMAKE_BINARY_DIR}/bin/ DESTINATION ${STK_INSTALL_BINARY_DIR}
  550. FILES_MATCHING PATTERN "*.dll")
  551. endif()