CMakeLists.txt 34 KB

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