CMakeLists.txt 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. cmake_minimum_required(VERSION 3.6.0)
  2. # root CMakeLists for the SuperTuxKart project
  3. project(SuperTuxKart)
  4. set(PROJECT_VERSION "git")
  5. add_definitions( -DSUPERTUXKART_VERSION="${PROJECT_VERSION}" )
  6. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
  7. include(CMakeDependentOption)
  8. include(BuildTypeSTKRelease)
  9. if(NOT CMAKE_BUILD_TYPE)
  10. message(STATUS "No build type selected, default to STKRelease")
  11. set(CMAKE_BUILD_TYPE "STKRelease")
  12. endif()
  13. CMAKE_DEPENDENT_OPTION(USE_SWITCH "Build targeting switch" OFF "NOT NINTENDO_SWITCH" ON)
  14. if(WIN32)
  15. option(USE_DIRECTX "Build DirectX 9 driver (requires DirectX SDK)" OFF)
  16. endif()
  17. option(SERVER_ONLY "Create a server only (i.e. no graphics or sound)" OFF)
  18. option(CHECK_ASSETS "Check if assets are installed in ../stk-assets" ON)
  19. 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)
  20. option(USE_SYSTEM_ENET "Use system ENet instead of the built-in version, when available." ON)
  21. CMAKE_DEPENDENT_OPTION(USE_IPV6 "Allow create or connect to game server with IPv6 address, system enet will not be used." ON
  22. "NOT USE_SWITCH" OFF)
  23. option(USE_SYSTEM_WIIUSE "Use system WiiUse instead of the built-in version, when available." OFF)
  24. option(USE_SQLITE3 "Use sqlite to manage server stats and ban list." ON)
  25. if(APPLE)
  26. CMAKE_DEPENDENT_OPTION(DLOPEN_MOLTENVK "Use dlopen to load MoltenVK for Apple." ON
  27. "NOT IOS;NOT SERVER_ONLY" OFF)
  28. endif()
  29. CMAKE_DEPENDENT_OPTION(USE_CRYPTO_OPENSSL "Use OpenSSL instead of MbedTLS for cryptography in STK." ON
  30. "NOT USE_SWITCH;NOT WIN32" OFF)
  31. CMAKE_DEPENDENT_OPTION(BUILD_RECORDER "Build opengl recorder" ON
  32. "NOT SERVER_ONLY;NOT APPLE;NOT USE_SWITCH" OFF)
  33. CMAKE_DEPENDENT_OPTION(USE_SYSTEM_SQUISH "Use system Squish library instead of the built-in version, when available." ON
  34. "NOT SERVER_ONLY" OFF)
  35. CMAKE_DEPENDENT_OPTION(USE_WIIUSE "Support for wiimote input devices" ON
  36. "NOT SERVER_ONLY;NOT CYGWIN;NOT USE_SWITCH;NOT MSVC" OFF)
  37. CMAKE_DEPENDENT_OPTION(USE_DNS_C "Build bundled dns resolver" OFF "NOT CYGWIN;NOT USE_SWITCH" ON)
  38. CMAKE_DEPENDENT_OPTION(USE_MOJOAL "Use bundled MojoAL instead of system OpenAL" OFF "NOT APPLE" ON)
  39. if (DLOPEN_MOLTENVK)
  40. ADD_DEFINITIONS(-DDLOPEN_MOLTENVK)
  41. endif()
  42. if((UNIX AND NOT APPLE) OR NINTENDO_SWITCH)
  43. include(FindPkgConfig)
  44. endif()
  45. if(IOS)
  46. include(cmake/XcodeHelper.cmake)
  47. endif()
  48. if(APPLE AND NOT IOS)
  49. if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
  50. set(ARCHFLAGS "arm64")
  51. list(APPEND CMAKE_PREFIX_PATH /opt/homebrew/opt)
  52. include_directories(/opt/homebrew/opt/openssl@1.1/include/)
  53. include_directories(/opt/homebrew/opt/openssl@1.1/include/openssl/)
  54. include_directories(/opt/homebrew/opt/freetype/include/freetype2/)
  55. include_directories(/opt/homebrew/opt/harfbuzz/include/harfbuzz/)
  56. else()
  57. set(ARCHFLAGS "${CMAKE_SYSTEM_PROCESSOR}")
  58. list(APPEND CMAKE_PREFIX_PATH /usr/local/opt)
  59. include_directories(/usr/local/opt/openssl@1.1/include/)
  60. include_directories(/usr/local/opt/openssl@1.1/include/openssl/)
  61. include_directories(/usr/local/opt/freetype/include/freetype2/)
  62. include_directories(/usr/local/opt/harfbuzz/include/harfbuzz/)
  63. endif()
  64. endif()
  65. if (IOS)
  66. ADD_DEFINITIONS(-DMOBILE_STK)
  67. ADD_DEFINITIONS(-DIOS_STK)
  68. set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
  69. option(USE_GLES2 "Use OpenGL ES2 renderer" ON)
  70. endif()
  71. if((UNIX AND NOT APPLE) AND NOT SERVER_ONLY)
  72. if((${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") OR
  73. (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") OR
  74. (${CMAKE_SYSTEM_PROCESSOR} MATCHES "riscv64"))
  75. option(USE_GLES2 "Use OpenGL ES2 renderer" ON)
  76. else()
  77. option(USE_GLES2 "Use OpenGL ES2 renderer" OFF)
  78. endif()
  79. endif()
  80. if(UNIX OR MINGW)
  81. option(DEBUG_SYMBOLS "Compile with debug symbols" OFF)
  82. endif()
  83. if(MSVC AND (MSVC_VERSION LESS 1900))
  84. # Normally hide the option to build wiiuse on VS, since it depends
  85. # on the installation of the Windows DDK (Driver Developer Kit),
  86. # which also needs an absolute path :(
  87. option(WIIUSE_BUILD "Build wiiuse lib (only for developers)" OFF)
  88. mark_as_advanced(WIIUSE_BUILD)
  89. else()
  90. set(WIIUSE_BUILD ON)
  91. endif()
  92. if(UNIX AND NOT APPLE)
  93. option(USE_ASAN "Build with Leak/Address sanitizer" OFF)
  94. option(USE_TSAN "Build with Thread sanitizer" OFF)
  95. option(USE_USAN "Build with Undefined Behaviour sanitizer" OFF)
  96. option(USE_LIBBFD "Use libbfd for crash reporting and leak check" OFF)
  97. endif()
  98. if(USE_ASAN)
  99. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
  100. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
  101. endif()
  102. if(USE_TSAN)
  103. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
  104. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
  105. endif()
  106. if(USE_USAN)
  107. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-omit-frame-pointer")
  108. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-omit-frame-pointer")
  109. endif()
  110. set(STK_SOURCE_DIR "src")
  111. set(STK_DATA_DIR "${PROJECT_SOURCE_DIR}/data")
  112. # CMAKE_RUNTIME_OUTPUT_DIRECTORY removes dSYMs in Xcode archive
  113. if(NOT CMAKE_GENERATOR MATCHES "Xcode")
  114. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
  115. endif()
  116. # Define install paths
  117. set(STK_INSTALL_BINARY_DIR "bin" CACHE
  118. STRING "Install executable to this directory, absolute or relative to CMAKE_INSTALL_PREFIX")
  119. set(STK_INSTALL_DATA_DIR "share/supertuxkart" CACHE
  120. STRING "Install data folder to this directory, absolute or relative to CMAKE_INSTALL_PREFIX")
  121. # Define dependencies path
  122. string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" arch_lower)
  123. set(BUILD_ARCH "unknown")
  124. if (CMAKE_GENERATOR_PLATFORM)
  125. set(BUILD_ARCH "${CMAKE_GENERATOR_PLATFORM}")
  126. endif()
  127. if(arch_lower MATCHES "arm64" OR arch_lower MATCHES "aarch64" OR ${CMAKE_GENERATOR} MATCHES "(ARM64)" OR ${BUILD_ARCH} MATCHES "(ARM64)")
  128. set(DEPENDENCIES "dependencies-win-aarch64")
  129. elseif(arch_lower MATCHES "armv7" OR arch_lower MATCHES "armv7" OR ${CMAKE_GENERATOR} MATCHES "(ARM)" OR ${BUILD_ARCH} MATCHES "(ARM)")
  130. set(DEPENDENCIES "dependencies-win-armv7")
  131. elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  132. set(DEPENDENCIES "dependencies-win-x86_64")
  133. else()
  134. set(DEPENDENCIES "dependencies-win-i686")
  135. endif()
  136. if(WIN32)
  137. ADD_DEFINITIONS(-DUNICODE)
  138. ADD_DEFINITIONS(-D_UNICODE)
  139. if(NOT IS_DIRECTORY "${PROJECT_SOURCE_DIR}/${DEPENDENCIES}")
  140. message(FATAL_ERROR "Dependencies directory not found, make sure dependencies-win-(arch) exists inside stk-code directory.")
  141. endif()
  142. endif()
  143. # These variables enable MSVC to find libraries located in "dependencies"
  144. if(WIN32)
  145. set(ENV{PATH} "$ENV{PATH};${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/include")
  146. set(ENV{LIB} ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib)
  147. set(ENV{OPENALDIR} ${PROJECT_SOURCE_DIR}/${DEPENDENCIES})
  148. add_definitions(-D_IRR_STATIC_LIB_)
  149. add_definitions(-DNO_IRR_COMPILE_WITH_X11_)
  150. include_directories(${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/include)
  151. endif()
  152. if(WIN32 AND NOT USE_DIRECTX)
  153. add_definitions(-DNO_IRR_COMPILE_WITH_DIRECT3D_9_)
  154. endif()
  155. if(USE_GLES2)
  156. add_definitions(-DUSE_GLES2)
  157. if (NOT IOS)
  158. add_definitions(-D_IRR_COMPILE_WITH_OGLES2_)
  159. endif()
  160. add_definitions(-DNO_IRR_COMPILE_WITH_OPENGL_)
  161. endif()
  162. if(SERVER_ONLY)
  163. add_definitions(-DSERVER_ONLY)
  164. add_definitions(-DNO_IRR_COMPILE_WITH_X11_ -DNO_IRR_COMPILE_WITH_OPENGL_)
  165. endif()
  166. if(UNIX OR MINGW)
  167. if(DEBUG_SYMBOLS)
  168. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
  169. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
  170. endif()
  171. endif()
  172. if(UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
  173. find_package(PkgConfig REQUIRED)
  174. if(NOT PKGCONFIG_FOUND)
  175. message(FATAL_ERROR "Pkg-config not found.")
  176. endif()
  177. endif()
  178. # Build the Bullet physics library
  179. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/bullet")
  180. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/bullet/src")
  181. # Build the DNS C library
  182. if(USE_DNS_C)
  183. add_definitions(-DDNS_C)
  184. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/dnsc")
  185. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/dnsc")
  186. else()
  187. if(WIN32 OR CMAKE_SYSTEM_NAME MATCHES "BSD" OR CMAKE_SYSTEM_NAME MATCHES "DragonFly" OR USE_SWITCH)
  188. set(LIBRESOLV_LIBRARY)
  189. elseif (HAIKU)
  190. find_library(LIBRESOLV_LIBRARY NAMES network socket)
  191. else()
  192. find_library(LIBRESOLV_LIBRARY NAMES resolv libresolv)
  193. endif()
  194. endif()
  195. # Find system ENet library or build it if missing
  196. if((UNIX AND NOT APPLE) AND USE_SYSTEM_ENET AND NOT USE_IPV6)
  197. pkg_check_modules(ENET libenet>=1.3.4)
  198. endif()
  199. if (USE_IPV6)
  200. add_definitions(-DENABLE_IPV6)
  201. endif()
  202. if(ENET_FOUND AND NOT USE_IPV6)
  203. include_directories(${ENET_INCLUDE_DIRS})
  204. else()
  205. # Fallback to built-in version
  206. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/enet")
  207. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/enet/include")
  208. set(ENET_LIBRARIES "enet")
  209. endif()
  210. if(NOT SERVER_ONLY)
  211. if(USE_SYSTEM_SQUISH)
  212. find_library(SQUISH_LIBRARY NAMES squish libsquish)
  213. find_path(SQUISH_INCLUDEDIR NAMES squish.h PATHS)
  214. endif()
  215. if (NOT SQUISH_LIBRARY OR NOT SQUISH_INCLUDEDIR)
  216. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/libsquish")
  217. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/libsquish")
  218. SET(SQUISH_LIBRARY squish)
  219. else()
  220. include_directories("${SQUISH_INCLUDEDIR}")
  221. MESSAGE(STATUS "Use system libsquish: ${SQUISH_LIBRARY}")
  222. endif()
  223. endif()
  224. if(NOT SERVER_ONLY)
  225. if (IOS)
  226. find_library(SHADERC_LIBRARY NAMES shaderc_combined libshaderc_combined)
  227. else()
  228. find_library(SHADERC_LIBRARY NAMES shaderc_shared libshaderc_shared shaderc libshaderc)
  229. endif()
  230. find_path(SHADERC_INCLUDEDIR NAMES shaderc/shaderc.hpp PATHS)
  231. if (NOT SHADERC_LIBRARY OR NOT SHADERC_INCLUDEDIR)
  232. if (NOT NO_SHADERC)
  233. message(FATAL_ERROR "Please install shaderc from your distribution or disable vulkan support with -DNO_SHADERC=on")
  234. endif()
  235. else()
  236. include_directories("${SHADERC_INCLUDEDIR}")
  237. MESSAGE(STATUS "Use system shaderc: ${SHADERC_LIBRARY}")
  238. endif()
  239. if (NO_SHADERC)
  240. add_definitions(-DDISABLE_SHADERC)
  241. endif()
  242. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/graphics_engine")
  243. endif()
  244. # MiniGLM is there
  245. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/graphics_engine/include")
  246. if (NOT SERVER_ONLY)
  247. # Add jpeg library
  248. find_package(JPEG REQUIRED)
  249. include_directories(${JPEG_INCLUDE_DIR})
  250. endif()
  251. if (BUILD_RECORDER)
  252. find_library(OPENGLRECORDER_LIBRARY NAMES openglrecorder libopenglrecorder PATHS "${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib")
  253. find_path(OPENGLRECORDER_INCLUDEDIR NAMES openglrecorder.h PATHS "${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/include")
  254. if (NOT OPENGLRECORDER_LIBRARY OR NOT OPENGLRECORDER_INCLUDEDIR)
  255. if(PROJECT_VERSION STREQUAL "git")
  256. message(WARNING "libopenglrecorder not found, disabling in-game recorder. "
  257. "To use recorder, install libopenglrecorder.")
  258. set(OPENGLRECORDER_LIBRARY CACHE INTERNAL "")
  259. set(OPENGLRECORDER_INCLUDEDIR CACHE INTERNAL "")
  260. set(BUILD_RECORDER OFF)
  261. else()
  262. message(FATAL_ERROR "libopenglrecorder not found. "
  263. "Either install libopenglrecorder or disable in-game recorder with -DBUILD_RECORDER=0")
  264. endif()
  265. else()
  266. include_directories(${OPENGLRECORDER_INCLUDEDIR})
  267. mark_as_advanced(OPENGLRECORDER_LIBRARY OPENGLRECORDER_INCLUDEDIR)
  268. add_definitions(-DENABLE_RECORDER)
  269. endif()
  270. endif()
  271. if(NOT SERVER_ONLY)
  272. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/graphics_utils")
  273. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/graphics_utils")
  274. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/tinygettext")
  275. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/tinygettext/include")
  276. endif()
  277. # Libmcpp
  278. find_library(MCPP_LIBRARY NAMES mcpp libmcpp)
  279. find_path(MCPP_INCLUDEDIR NAMES mcpp_lib.h PATHS)
  280. if (NOT MCPP_LIBRARY OR NOT MCPP_INCLUDEDIR)
  281. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/mcpp")
  282. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/mcpp")
  283. SET(MCPP_LIBRARY mcpp)
  284. message(STATUS "System libmcpp not found, use the bundled one.")
  285. else()
  286. include_directories("${MCPP_INCLUDEDIR}")
  287. MESSAGE(STATUS "Use system libmcpp: ${MCPP_LIBRARY}")
  288. endif()
  289. if (NOT SERVER_ONLY)
  290. # SDL2
  291. find_library(SDL2_LIBRARY NAMES SDL2 libSDL2)
  292. find_path(SDL2_INCLUDEDIR NAMES SDL.h PATH_SUFFIXES SDL2 include/SDL2 include PATHS)
  293. if (NOT SDL2_LIBRARY OR NOT SDL2_INCLUDEDIR)
  294. message(FATAL_ERROR "SDL2 not found. "
  295. "SDL2 is required to handle gamepad in SuperTuxKart.")
  296. else()
  297. include_directories("${SDL2_INCLUDEDIR}")
  298. MESSAGE(STATUS "Use system SDL2: ${SDL2_LIBRARY}")
  299. endif()
  300. # DirectFB. Necessary if system SDL2 is built with DirectFB support.
  301. find_path(DIRECTFB_INCLUDEDIR NAMES directfb.h directfb++.h PATH_SUFFIXES directfb include/directfb include PATHS)
  302. if (DIRECTFB_INCLUDEDIR)
  303. include_directories("${DIRECTFB_INCLUDEDIR}")
  304. message(STATUS "Adding DirectFB include directories for DirectFB support in SDL2")
  305. endif()
  306. endif()
  307. # Build the irrlicht library
  308. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/irrlicht")
  309. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/irrlicht/include")
  310. # Build the Wiiuse library
  311. # Note: wiiuse MUST be declared after irrlicht, since otherwise
  312. # (at least on VS) irrlicht will find wiiuse io.h file because
  313. # of the added include directory.
  314. if(USE_WIIUSE)
  315. # Find system WiiUse library or build it if missing
  316. if((UNIX AND NOT (APPLE OR HAIKU)) AND USE_SYSTEM_WIIUSE)
  317. find_package(WiiUse)
  318. endif()
  319. if(WIIUSE_FOUND)
  320. include_directories(${WIIUSE_INCLUDE_DIR})
  321. else()
  322. # Fallback to built-in version
  323. if(WIIUSE_BUILD)
  324. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/wiiuse")
  325. endif()
  326. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/wiiuse/src/include")
  327. set(WIIUSE_LIBRARIES "wiiuse" "bluetooth")
  328. endif()
  329. endif()
  330. # Set include paths
  331. include_directories(${STK_SOURCE_DIR})
  332. if(APPLE AND NOT IOS)
  333. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch ${ARCHFLAGS}")
  334. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch ${ARCHFLAGS} -F/Library/Frameworks")
  335. elseif(MSVC)
  336. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") # Enable multi-processor compilation (faster)
  337. endif()
  338. if (${CMAKE_SYSTEM_NAME} MATCHES "SunOs")
  339. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
  340. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
  341. endif()
  342. # Build the angelscript library if not in system
  343. if(USE_SYSTEM_ANGELSCRIPT)
  344. find_package(Angelscript)
  345. if(ANGELSCRIPT_FOUND)
  346. include_directories(${Angelscript_INCLUDE_DIRS})
  347. else()
  348. message(FATAL_ERROR "Angelscript not found. "
  349. "Either install angelscript or use built-in version using "
  350. "-DUSE_SYSTEM_ANGELSCRIPT=0")
  351. endif()
  352. else()
  353. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/angelscript/projects/cmake")
  354. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/angelscript/include")
  355. set(Angelscript_LIBRARIES angelscript)
  356. endif()
  357. if(NOT SERVER_ONLY)
  358. # OpenAL
  359. if (USE_MOJOAL)
  360. find_library(LIBSAMPLERATE_LIBRARY NAMES samplerate libsamplerate)
  361. find_path(LIBSAMPLERATE_INCLUDEDIR NAMES samplerate.h PATHS)
  362. if (NOT LIBSAMPLERATE_LIBRARY OR NOT LIBSAMPLERATE_INCLUDEDIR)
  363. message(FATAL_ERROR "libsamplerate not found. "
  364. "libsamplerate is required to handle pitch for MojoAL.")
  365. else()
  366. include_directories("${LIBSAMPLERATE_INCLUDEDIR}")
  367. MESSAGE(STATUS "Use system libsamplerate: ${LIBSAMPLERATE_LIBRARY}")
  368. endif()
  369. add_definitions(-DAL_LIBTYPE_STATIC)
  370. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/mojoal")
  371. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/mojoal")
  372. else()
  373. find_package(OpenAL REQUIRED)
  374. # Unclear why this happens, but on switch OPENAL_LIBRARY never set!
  375. if (NOT OPENAL_LIBRARY)
  376. find_library(OPENAL_LIBRARY NAMES al OpenAL AL openal REQUIRED)
  377. endif()
  378. if (NOT OPENAL_INCLUDE_DIR)
  379. find_path(OPENAL_INCLUDE_DIR NAMES AL/al.h REQUIRED)
  380. endif()
  381. include_directories(${OPENAL_INCLUDE_DIR})
  382. endif()
  383. # OggVorbis
  384. find_package(OggVorbis REQUIRED)
  385. include_directories(${OGGVORBIS_INCLUDE_DIRS})
  386. add_definitions(-DENABLE_SOUND)
  387. endif()
  388. # Text handling in STK (We use freetype, harfbuzz and SheenBidifor i18n text handling)
  389. if (NOT SERVER_ONLY)
  390. # SheenBidi
  391. add_subdirectory("${PROJECT_SOURCE_DIR}/lib/sheenbidi")
  392. include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/sheenbidi/Headers")
  393. SET(SHEENBIDI_LIBRARY sheenbidi)
  394. # Freetype
  395. find_package(Freetype)
  396. if(FREETYPE_FOUND)
  397. include_directories(${FREETYPE_INCLUDE_DIRS})
  398. else()
  399. message(FATAL_ERROR "Freetype not found. "
  400. "Freetype is required to display characters in SuperTuxKart.")
  401. endif()
  402. # Harfbuzz
  403. find_library(HARFBUZZ_LIBRARY NAMES harfbuzz libharfbuzz)
  404. find_path(HARFBUZZ_INCLUDEDIR NAMES harfbuzz/hb.h hb.h PATHS)
  405. if (NOT HARFBUZZ_LIBRARY OR NOT HARFBUZZ_INCLUDEDIR)
  406. message(FATAL_ERROR "Harfbuzz not found. "
  407. "Harfbuzz is required to display characters in SuperTuxKart.")
  408. else()
  409. include_directories("${HARFBUZZ_INCLUDEDIR}")
  410. MESSAGE(STATUS "Use system harfbuzz: ${HARFBUZZ_LIBRARY}")
  411. endif()
  412. endif()
  413. if(USE_LIBBFD)
  414. find_package(Libbfd)
  415. if(LIBBFD_FOUND)
  416. add_definitions(-DENABLE_LIBBFD)
  417. include_directories(${LIBBFD_INCLUDE_DIRS})
  418. else()
  419. set(USE_LIBBFD OFF CACHE BOOL "Use libbfd for crash reporting and leak check" FORCE)
  420. message(WARNING "Libbfd not found, disable integrated stack trace.")
  421. endif()
  422. endif()
  423. # SQLITE
  424. if(USE_SQLITE3)
  425. find_library(SQLITE3_LIBRARY NAMES sqlite3 libsqlite3)
  426. find_path(SQLITE3_INCLUDEDIR NAMES sqlite3.h PATHS)
  427. if (NOT SQLITE3_LIBRARY OR NOT SQLITE3_INCLUDEDIR)
  428. # add_subdirectory("${PROJECT_SOURCE_DIR}/lib/sqlite3")
  429. # include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/sqlite3")
  430. # SET(SQLITE3_LIBRARY sqlite3)
  431. set(USE_SQLITE3 OFF CACHE BOOL "Use sqlite to manage server stats and ban list." FORCE)
  432. message(WARNING "Sqlite3 not found, disable advanced server management.")
  433. else()
  434. add_definitions(-DENABLE_SQLITE3)
  435. include_directories("${SQLITE3_INCLUDEDIR}")
  436. MESSAGE(STATUS "Use system libsqlite3: ${SQLITE3_LIBRARY}")
  437. endif()
  438. endif()
  439. # Set some compiler options
  440. if(UNIX OR MINGW)
  441. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
  442. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-function")
  443. endif()
  444. if(MINGW AND CMAKE_BUILD_TYPE MATCHES Release)
  445. SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--subsystem,windows")
  446. endif()
  447. if(WIN32)
  448. # By default windows.h has macros defined for min and max that screw up everything
  449. add_definitions(-DNOMINMAX)
  450. # And shut up about unsafe stuff
  451. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  452. # Avoid timespec structure redeclaration on Visual Studio 2015
  453. if (NOT (MSVC_VERSION LESS 1900))
  454. add_definitions(-DHAVE_STRUCT_TIMESPEC)
  455. endif()
  456. endif()
  457. if(MSVC)
  458. # VS will automatically add NDEBUG for release mode, but only _DEBUG in debug mode.
  459. # Since STK uses DEBUG, this is added for debug compilation only:
  460. cmake_policy(SET CMP0043 OLD)
  461. set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG)
  462. else()
  463. # All non VS generators used create only a single compile mode, so
  464. # compile flags can be simplye be added
  465. if(CMAKE_BUILD_TYPE MATCHES Debug)
  466. add_definitions(-DDEBUG)
  467. else()
  468. add_definitions(-DNDEBUG)
  469. endif()
  470. endif()
  471. if(WIN32)
  472. configure_file("${STK_SOURCE_DIR}/../tools/windows_installer/icon_rc.template" "${PROJECT_BINARY_DIR}/tmp/icon.rc")
  473. endif()
  474. # Provides list of source and header files (STK_SOURCES and STK_HEADERS)
  475. include(sources.cmake)
  476. # Generate source groups useful for MSVC project explorer
  477. include(cmake/SourceGroupFunctions.cmake)
  478. source_group_hierarchy(STK_SOURCES STK_HEADERS)
  479. if(APPLE AND NOT IOS)
  480. # icon files to copy in the bundle
  481. set(OSX_ICON_FILES ${PROJECT_SOURCE_DIR}/data/supertuxkart.icns)
  482. set_source_files_properties(${OSX_ICON_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  483. set(STK_SOURCES ${STK_SOURCES} ${OSX_ICON_FILES})
  484. # build the executable and create an app bundle
  485. add_executable(supertuxkart MACOSX_BUNDLE ${STK_SOURCES})
  486. find_library(IOKIT_LIBRARY IOKit)
  487. find_library(COCOA_LIBRARY Cocoa)
  488. target_link_libraries(supertuxkart
  489. ${IOKIT_LIBRARY}
  490. ${COCOA_LIBRARY})
  491. # configure CMake to use a custom Info.plist
  492. set_target_properties(supertuxkart PROPERTIES
  493. MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/data/SuperTuxKart-Info.plist)
  494. if(CMAKE_GENERATOR MATCHES "Xcode")
  495. add_custom_command(TARGET supertuxkart POST_BUILD
  496. COMMAND ln -f -s ${PROJECT_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/\${CONFIGURATION}/supertuxkart.app/Contents/Resources)
  497. else()
  498. add_custom_command(TARGET supertuxkart POST_BUILD
  499. COMMAND ln -f -s ${PROJECT_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/bin/supertuxkart.app/Contents/Resources)
  500. endif()
  501. else()
  502. if (NOT WIN32)
  503. find_library(PTHREAD_LIBRARY NAMES pthread ${PTHREAD_NAMES} PATHS ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib)
  504. mark_as_advanced(PTHREAD_LIBRARY)
  505. endif()
  506. # Set data dir (absolute or relative to CMAKE_INSTALL_PREFIX)
  507. if(NOT STK_INSTALL_DATA_DIR_ABSOLUTE)
  508. get_filename_component(STK_INSTALL_DATA_DIR_ABSOLUTE ${STK_INSTALL_DATA_DIR} ABSOLUTE)
  509. if(${STK_INSTALL_DATA_DIR_ABSOLUTE} STREQUAL ${STK_INSTALL_DATA_DIR})
  510. add_definitions(-DSUPERTUXKART_DATADIR=\"${STK_INSTALL_DATA_DIR_ABSOLUTE}\")
  511. else()
  512. add_definitions(-DSUPERTUXKART_DATADIR=\"${CMAKE_INSTALL_PREFIX}/${STK_INSTALL_DATA_DIR}\")
  513. endif()
  514. else()
  515. add_definitions(-DSUPERTUXKART_DATADIR=\"${STK_INSTALL_DATA_DIR_ABSOLUTE}\")
  516. endif()
  517. # Build the final executable
  518. if (IOS)
  519. file(GLOB IOS_ASSETS_FILES ${IOS_ASSETS} ${IOS_LAUNCHSCREEN} ${IOS_IMAGES_XCASSETS})
  520. set_source_files_properties(${IOS_ASSETS_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  521. add_executable(supertuxkart ${STK_SOURCES} ${STK_RESOURCES} ${STK_HEADERS} ${IOS_ASSETS_FILES})
  522. set_target_properties(supertuxkart PROPERTIES
  523. MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/data/SuperTuxKart-Info-iOS.plist
  524. XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 9.0
  525. XCODE_ATTRIBUTE_INSTALL_PATH /Applications
  526. XCODE_ATTRIBUTE_SKIP_INSTALL No
  527. XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
  528. if(CMAKE_GENERATOR MATCHES "Xcode")
  529. get_all_targets(supertuxkart_targets ${CMAKE_CURRENT_LIST_DIR})
  530. foreach(target IN LISTS supertuxkart_targets)
  531. if (NOT target MATCHES "supertuxkart")
  532. set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib$(EFFECTIVE_PLATFORM_NAME)/${target})
  533. endif()
  534. configure_xcode_defaults(${target})
  535. endforeach()
  536. endif()
  537. else()
  538. add_executable(supertuxkart ${STK_SOURCES} ${STK_RESOURCES} ${STK_HEADERS})
  539. endif()
  540. if (NOT WIN32)
  541. target_link_libraries(supertuxkart ${PTHREAD_LIBRARY})
  542. endif()
  543. endif()
  544. # check if linking against libatomic is required
  545. include(CheckCXXSourceCompiles)
  546. check_cxx_source_compiles("
  547. #include <atomic>
  548. #include <cstdint>
  549. int main() {
  550. std::atomic<uint64_t> x{0};
  551. x.load();
  552. return 0;
  553. }
  554. " NO_LIBATOMIC_NEEDED)
  555. if (NOT NO_LIBATOMIC_NEEDED)
  556. target_link_libraries(supertuxkart atomic)
  557. endif()
  558. # CURL and OpenSSL or MbedTLS
  559. # 1.0.1d for compatible AES GCM handling
  560. SET(OPENSSL_MINIMUM_VERSION "1.0.1d")
  561. find_package(CURL REQUIRED)
  562. include_directories(${CURL_INCLUDE_DIRS})
  563. find_path(MBEDTLS_INCLUDE_DIRS mbedtls/version.h)
  564. find_library(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto)
  565. if (NOT MBEDCRYPTO_LIBRARY OR NOT MBEDTLS_INCLUDE_DIRS OR USE_CRYPTO_OPENSSL)
  566. set(USE_CRYPTO_OPENSSL ON)
  567. find_package(OpenSSL REQUIRED)
  568. if(${OPENSSL_VERSION} VERSION_LESS ${OPENSSL_MINIMUM_VERSION} OR
  569. (${OPENSSL_VERSION} VERSION_EQUAL ${OPENSSL_MINIMUM_VERSION} AND ${OPENSSL_VERSION} STRLESS ${OPENSSL_MINIMUM_VERSION}))
  570. message(FATAL_ERROR "OpenSSL version found (${OPENSSL_VERSION}) is less then the minimum required (${OPENSSL_MINIMUM_VERSION}), aborting.")
  571. endif()
  572. include_directories(${OpenSSL_INCLUDE_DIRS})
  573. else()
  574. set(USE_CRYPTO_OPENSSL OFF)
  575. include_directories(${MBEDTLS_INCLUDE_DIRS})
  576. endif()
  577. if (USE_CRYPTO_OPENSSL)
  578. message(STATUS "OpenSSL will be used for cryptography in STK.")
  579. add_definitions(-DENABLE_CRYPTO_OPENSSL)
  580. else()
  581. message(STATUS "MbedTLS will be used for cryptography in STK.")
  582. add_definitions(-DENABLE_CRYPTO_MBEDTLS)
  583. endif()
  584. # Common library dependencies
  585. target_link_libraries(supertuxkart
  586. bulletdynamics
  587. bulletcollision
  588. bulletmath
  589. ${ENET_LIBRARIES}
  590. stkirrlicht
  591. ${Angelscript_LIBRARIES}
  592. ${CURL_LIBRARIES}
  593. ${MCPP_LIBRARY}
  594. )
  595. if (USE_SWITCH)
  596. include(cmake/FindEGL.cmake)
  597. find_library(NX_LIBRARY NAMES nx libnx REQUIRED)
  598. find_library(DRM_LIBRARY NAMES drm_nouveau libdrm_nouveau REQUIRED)
  599. find_library(GLAPI_LIBRARY NAMES glapi libglapi REQUIRED)
  600. find_library(ZLIB_LIBRARY NAMES z libz REQUIRED)
  601. find_library(PNG_LIBRARY NAMES png libpng REQUIRED)
  602. find_library(BZ2_LIBRARY NAMES bz2 libbz2 REQUIRED)
  603. target_link_libraries(supertuxkart
  604. ${NX_LIBRARY}
  605. ${ZLIB_LIBRARY}
  606. ${FREETYPE_LIBRARIES}
  607. -logg
  608. -lvorbis
  609. ${SDL2_LIBRARY}
  610. ${PNG_LIBRARY}
  611. ${BZ2_LIBRARY}
  612. ${HARFBUZZ_LIBRARY}
  613. ${OPENAL_LIBRARY}
  614. ${EGL_LIBRARY}
  615. ${DRM_LIBRARY}
  616. ${GLAPI_LIBRARY}
  617. ${NX_LIBRARY}
  618. )
  619. endif()
  620. if(NOT SERVER_ONLY)
  621. if (USE_MOJOAL)
  622. target_link_libraries(supertuxkart mojoal ${LIBSAMPLERATE_LIBRARY})
  623. else()
  624. target_link_libraries(supertuxkart ${OPENAL_LIBRARY})
  625. endif()
  626. endif()
  627. if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
  628. target_link_libraries(supertuxkart nsl socket vorbisfile)
  629. endif()
  630. if (${CMAKE_SYSTEM_NAME} MATCHES "Haiku")
  631. target_link_libraries(supertuxkart be network vorbisfile)
  632. endif()
  633. if (USE_DNS_C)
  634. target_link_libraries(supertuxkart dnsc)
  635. else()
  636. target_link_libraries(supertuxkart ${LIBRESOLV_LIBRARY})
  637. endif()
  638. if (USE_SQLITE3)
  639. target_link_libraries(supertuxkart ${SQLITE3_LIBRARY})
  640. endif()
  641. if (USE_CRYPTO_OPENSSL)
  642. target_link_libraries(supertuxkart ${OPENSSL_CRYPTO_LIBRARY})
  643. else()
  644. target_link_libraries(supertuxkart ${MBEDCRYPTO_LIBRARY})
  645. endif()
  646. if(NOT SERVER_ONLY)
  647. if (APPLE AND NOT DLOPEN_MOLTENVK)
  648. find_library(MOLTENVK_LIBRARY NAMES MoltenVK libMoltenVK REQUIRED)
  649. target_link_libraries(supertuxkart "-framework Metal -weak_framework IOSurface -framework QuartzCore ${MOLTENVK_LIBRARY}")
  650. endif()
  651. if (IOS)
  652. target_link_libraries(supertuxkart "-weak_framework CoreHaptics -framework QuartzCore -framework CoreGraphics -framework AVFoundation -framework AudioToolbox -framework Metal -framework GameController -framework OpenGLES -framework UIKit -framework CoreAudio -framework Foundation -framework GLKit")
  653. # tvOS doesn't have CoreMotion framwork
  654. include(CheckCSourceCompiles)
  655. set(prev_req_lib ${CMAKE_REQUIRED_LIBRARIES})
  656. set(CMAKE_REQUIRED_LIBRARIES "-framework CoreMotion")
  657. check_c_source_compiles("int main() { return 0; }" COREMOTION_EXISTS)
  658. set(CMAKE_REQUIRED_LIBRARIES ${prev_req_lib})
  659. if (COREMOTION_EXISTS)
  660. target_link_libraries(supertuxkart "-framework CoreMotion")
  661. endif()
  662. endif()
  663. target_link_libraries(supertuxkart
  664. ${SQUISH_LIBRARY}
  665. ${JPEG_LIBRARIES}
  666. ${OGGVORBIS_LIBRARIES}
  667. ${FREETYPE_LIBRARIES}
  668. ${HARFBUZZ_LIBRARY}
  669. ${SHEENBIDI_LIBRARY}
  670. graphics_utils
  671. graphics_engine
  672. ${SDL2_LIBRARY}
  673. tinygettext)
  674. if (NOT NO_SHADERC)
  675. target_link_libraries(supertuxkart ${SHADERC_LIBRARY})
  676. endif()
  677. endif()
  678. if(UNIX AND NOT APPLE)
  679. if(USE_LIBBFD)
  680. target_link_libraries(supertuxkart ${LIBBFD_LIBRARIES})
  681. if (CMAKE_SYSTEM_NAME MATCHES "BSD")
  682. target_link_libraries(supertuxkart execinfo)
  683. endif()
  684. endif()
  685. if(USE_ASAN)
  686. target_link_libraries(supertuxkart "-fsanitize=address")
  687. endif()
  688. if(USE_TSAN)
  689. target_link_libraries(supertuxkart "-fsanitize=thread")
  690. endif()
  691. if(USE_USAN)
  692. target_link_libraries(supertuxkart "-fsanitize=undefined")
  693. endif()
  694. endif()
  695. if(BUILD_RECORDER)
  696. target_link_libraries(supertuxkart ${OPENGLRECORDER_LIBRARY})
  697. endif()
  698. # FreeBSD does not search in /usr/local/lib, but at least Freetype is installed there :(
  699. if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
  700. SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
  701. endif()
  702. if(HAIKU)
  703. target_link_libraries(supertuxkart -lbe -lnetwork)
  704. endif()
  705. # Wiiuse
  706. # ------
  707. if(USE_WIIUSE)
  708. if(APPLE)
  709. find_library(BLUETOOTH_LIBRARY NAMES IOBluetooth PATHS /Developer/Library/Frameworks/IOBluetooth.framework)
  710. target_link_libraries(supertuxkart wiiuse ${BLUETOOTH_LIBRARY})
  711. elseif(WIN32)
  712. add_definitions(-DWIIUSE_STATIC)
  713. if(WIIUSE_BUILD)
  714. target_link_libraries(supertuxkart wiiuse)
  715. else()
  716. target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/wiiuse.lib)
  717. endif()
  718. else()
  719. target_link_libraries(supertuxkart ${WIIUSE_LIBRARIES})
  720. endif()
  721. add_definitions(-DENABLE_WIIUSE)
  722. endif()
  723. if(MSVC OR MINGW)
  724. target_link_libraries(supertuxkart iphlpapi.lib)
  725. add_custom_command(TARGET supertuxkart POST_BUILD
  726. COMMAND ${CMAKE_COMMAND} -E copy_directory
  727. "${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/bin"
  728. $<TARGET_FILE_DIR:supertuxkart>)
  729. add_custom_target(stkshaders SOURCES ${STK_SHADERS})
  730. endif()
  731. if(MSVC)
  732. SET(CMAKE_SHARED_LINKER_FLAGS /MANIFEST:NO)
  733. add_custom_command(
  734. TARGET supertuxkart POST_BUILD COMMAND "mt.exe"
  735. -manifest \"${PROJECT_SOURCE_DIR}\\windows\\dpi_aware.manifest\"
  736. -inputresource:\"$<TARGET_FILE:supertuxkart>\"\;\#1
  737. -outputresource:\"$<TARGET_FILE:supertuxkart>\"\;\#1)
  738. endif()
  739. if(MINGW)
  740. SET(CMAKE_SHARED_LINKER_FLAGS /MANIFEST:NO)
  741. target_sources(supertuxkart PRIVATE windows/windows_config.rc)
  742. endif()
  743. if(MINGW)
  744. target_link_libraries(supertuxkart -ldxguid -ldnsapi)
  745. if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
  746. target_link_libraries(supertuxkart -mwindows)
  747. endif()
  748. find_library(LIBGCC NAMES "libgcc_s_dw2-1.dll" "libgcc_s_sjlj-1.dll" "libgcc_s_seh-1.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
  749. if (LIBGCC)
  750. file(COPY ${LIBGCC} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
  751. endif()
  752. find_library(LIBSTDCPP NAMES "libstdc++-6.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
  753. if (LIBSTDCPP)
  754. file(COPY ${LIBSTDCPP} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
  755. endif()
  756. find_library(LIBPTHREAD NAMES "winpthread-1.dll" "libwinpthread-1.dll" "pthreadGC2.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
  757. if(LIBPTHREAD)
  758. file(COPY ${LIBPTHREAD} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
  759. endif()
  760. endif()
  761. # Find LibGamerzilla library or build it if missing
  762. if (NOT APPLE)
  763. include(FindPkgConfig)
  764. pkg_search_module(GAMERZILLA OPTIONAL gamerzilla)
  765. if (GAMERZILLA_LIBRARIES)
  766. message(STATUS "Gamerzilla found")
  767. include_directories(${GAMERZILLA_INCLUDE_DIRS})
  768. target_link_libraries(supertuxkart ${GAMERZILLA_LIBRARIES})
  769. add_definitions(-DGAMERZILLA)
  770. endif()
  771. endif()
  772. # ==== Checking if data folder exists ====
  773. if(NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)
  774. message( FATAL_ERROR "${CMAKE_CURRENT_SOURCE_DIR}/data folder doesn't exist" )
  775. endif()
  776. # ==== Checking if stk-assets folder exists ====
  777. if(CHECK_ASSETS)
  778. if((IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/karts) AND
  779. (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/library) AND
  780. (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/music) AND
  781. (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/sfx) AND
  782. (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/textures) AND
  783. (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/tracks))
  784. message(STATUS "Assets found in data directory")
  785. elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../stk-assets)
  786. set(STK_ASSETS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../stk-assets/)
  787. message(STATUS "Assets found")
  788. elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../supertuxkart-assets)
  789. set(STK_ASSETS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../supertuxkart-assets/)
  790. message(STATUS "Assets found")
  791. else()
  792. set (CUR_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  793. get_filename_component(PARENT_DIR ${CUR_DIR} PATH)
  794. message( FATAL_ERROR "${PARENT_DIR}/stk-assets folder doesn't exist. "
  795. "Please download the stk-assets, or disable this test with -DCHECK_ASSETS=off." )
  796. endif()
  797. endif()
  798. # ==== Install target ====
  799. install(TARGETS supertuxkart RUNTIME DESTINATION ${STK_INSTALL_BINARY_DIR} BUNDLE DESTINATION .)
  800. install(DIRECTORY ${STK_DATA_DIR} DESTINATION ${STK_INSTALL_DATA_DIR} PATTERN ".svn" EXCLUDE PATTERN ".git" EXCLUDE)
  801. if(STK_ASSETS_DIR AND CHECK_ASSETS)
  802. install(DIRECTORY ${STK_ASSETS_DIR} DESTINATION ${STK_INSTALL_DATA_DIR}/data PATTERN ".svn" EXCLUDE PATTERN ".git" EXCLUDE)
  803. endif()
  804. install(FILES ${STK_DATA_DIR}/supertuxkart.desktop DESTINATION share/applications)
  805. install(FILES data/supertuxkart_16.png DESTINATION share/icons/hicolor/16x16/apps RENAME supertuxkart.png)
  806. install(FILES data/supertuxkart_32.png DESTINATION share/icons/hicolor/32x32/apps RENAME supertuxkart.png)
  807. install(FILES data/supertuxkart_48.png DESTINATION share/icons/hicolor/48x48/apps RENAME supertuxkart.png)
  808. install(FILES data/supertuxkart_64.png DESTINATION share/icons/hicolor/64x64/apps RENAME supertuxkart.png)
  809. install(FILES data/supertuxkart_128.png DESTINATION share/icons/hicolor/128x128/apps RENAME supertuxkart.png)
  810. install(FILES data/supertuxkart_256.png DESTINATION share/icons/hicolor/256x256/apps RENAME supertuxkart.png)
  811. install(FILES data/supertuxkart_512.png DESTINATION share/icons/hicolor/512x512/apps RENAME supertuxkart.png)
  812. install(FILES data/supertuxkart_1024.png DESTINATION share/icons/hicolor/1024x1024/apps RENAME supertuxkart.png)
  813. install(FILES data/net.supertuxkart.SuperTuxKart.metainfo.xml DESTINATION share/metainfo)
  814. if(MINGW)
  815. install(DIRECTORY ${CMAKE_BINARY_DIR}/bin/ DESTINATION ${STK_INSTALL_BINARY_DIR}
  816. FILES_MATCHING PATTERN "*.dll")
  817. endif()