CMakeLists.txt 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  1. #
  2. # SuperTux - root build script
  3. # Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. #
  19. #
  20. # INSTRUCTIONS:
  21. # -------------
  22. #
  23. # Create a directory build/ and change to it. Run
  24. #
  25. # cmake ..
  26. #
  27. # This creates a set of Makefiles to build the project. Run
  28. #
  29. # make
  30. #
  31. ## Project name to use as command prefix.
  32. project(SUPERTUX)
  33. ### CMake configuration
  34. cmake_minimum_required(VERSION 3.1)
  35. if(COMMAND cmake_policy)
  36. cmake_policy(SET CMP0003 NEW)
  37. cmake_policy(SET CMP0008 NEW)
  38. cmake_policy(SET CMP0023 NEW)
  39. endif(COMMAND cmake_policy)
  40. set(CMAKE_CXX_STANDARD 14)
  41. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  42. set(CMAKE_CXX_EXTENSIONS OFF)
  43. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/mk/cmake)
  44. include(ConfigureFiles)
  45. include(ExternalProject)
  46. include(CheckCXXCompilerFlag)
  47. ## For autopackage
  48. set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/games/supertux2")
  49. set(BUILD_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/data")
  50. set(BUILD_CONFIG_DATA_DIR "${CMAKE_BINARY_DIR}/data")
  51. ## Check endianess
  52. if(NOT EMSCRIPTEN)
  53. # FIXME: Any reason why we need this?
  54. include(TestBigEndian)
  55. test_big_endian(WORDS_BIGENDIAN)
  56. endif(NOT EMSCRIPTEN)
  57. ## Add definitions
  58. if(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo")
  59. add_definitions(-DRELEASE)
  60. elseif(CMAKE_BUILD_TYPE MATCHES Debug)
  61. add_definitions(-DDEBUG)
  62. endif()
  63. if(EMSCRIPTEN)
  64. set(CMAKE_EXECUTABLE_SUFFIX .html)
  65. set(IS_EMSCRIPTEN_BUILD ON)
  66. set(USE_FLAGS " -sUSE_SDL=2 -sFULL_ES2=1 -sUSE_SDL_IMAGE=2 -sUSE_FREETYPE=2 -sUSE_PTHREADS=1 -sDISABLE_EXCEPTION_CATCHING=0 --preload-file ${BUILD_CONFIG_DATA_DIR} -sTOTAL_MEMORY=67108864 -sALLOW_MEMORY_GROWTH=1 -sSDL2_IMAGE_FORMATS='[\"png\",\"jpg\"]' --use-preload-plugins")
  67. if(CMAKE_BUILD_TYPE MATCHES Debug)
  68. set(USE_FLAGS "${USE_FLAGS} -fsanitize=undefined -sSAFE_HEAP=1 -sASSERTIONS=1 -sDEMANGLE_SUPPORT=1")
  69. endif()
  70. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${USE_FLAGS} -sERROR_ON_UNDEFINED_SYMBOLS=0")
  71. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${USE_FLAGS} -sERROR_ON_UNDEFINED_SYMBOLS=0")
  72. set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${USE_FLAGS} -sERROR_ON_UNDEFINED_SYMBOLS=0 -lidbfs.js")
  73. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${USE_FLAGS} -sERROR_ON_UNDEFINED_SYMBOLS=0 -lidbfs.js")
  74. endif()
  75. # TODO: Add " OR ANDROID OR IOS" to this
  76. if(EMSCRIPTEN OR UBUNTU_TOUCH)
  77. option(REMOVE_QUIT_BUTTON "Remove the option to quit the game (useful on mobile devices)" ON)
  78. else()
  79. option(REMOVE_QUIT_BUTTON "Remove the option to quit the game (useful on mobile devices)" OFF)
  80. endif()
  81. set(SUPERTUX_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
  82. set(VCPKG_BUILD OFF CACHE BOOL "Use dependencies installed via vcpkg (not dependency package)")
  83. set(VCPKG_APPLOCAL_DEPS ${VCPKG_BUILD} BOOL)
  84. ## These variables enable MSVC to find libraries located in "dependencies{32|64}"
  85. if(WIN32)
  86. if(NOT VCPKG_BUILD)
  87. ## Store path of dependecy folder
  88. set(DEPENDENCY_FOLDER "${PROJECT_SOURCE_DIR}/dependencies")
  89. endif()
  90. ## To test if the host (not the build) is x64:
  91. ## "$ENV{PROCESSOR_ARCHITEW6432}" STREQUAL "AMD64"
  92. if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
  93. set(WIN64 ON)
  94. if(NOT VCPKG_BUILD)
  95. set(DEPENDENCY_FOLDER "${DEPENDENCY_FOLDER}64")
  96. endif()
  97. else(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
  98. set(WIN64 OFF)
  99. if(NOT VCPKG_BUILD)
  100. set(DEPENDENCY_FOLDER "${DEPENDENCY_FOLDER}32")
  101. endif()
  102. endif(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
  103. if(WIN64)
  104. set(SUPERTUX_SYSTEM_NAME win64)
  105. else(WIN64)
  106. set(SUPERTUX_SYSTEM_NAME win32)
  107. endif(WIN64)
  108. if(NOT VCPKG_BUILD)
  109. set(ENV{PATH} "$ENV{PATH};${DEPENDENCY_FOLDER}/include")
  110. set(ENV{LIB} "${DEPENDENCY_FOLDER}/lib")
  111. set(ENV{OPENALDIR} "${DEPENDENCY_FOLDER}")
  112. endif()
  113. ## Enable multi-processor compilation (faster)
  114. if(MSVC)
  115. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  116. endif(MSVC)
  117. ## And shut up about unsafe stuff
  118. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  119. ## Add an icon
  120. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/mk/msvc/icon_rc.template" "${PROJECT_BINARY_DIR}/tmp/icon.rc")
  121. ## Find all used libraries
  122. if(NOT VCPKG_BUILD)
  123. file(GLOB DLLS "${DEPENDENCY_FOLDER}/dll/*")
  124. endif()
  125. endif(WIN32)
  126. # Detect mobile builds
  127. option(UBUNTU_TOUCH "Compile the project for an Ubuntu Touch target" OFF)
  128. # Mobile builds
  129. option(ENABLE_TOUCHSCREEN_SUPPORT "Enable on-screen controls and event detection for touchscreen devices" ON)
  130. if (UBUNTU_TOUCH)
  131. option(SHOW_TOUCHSCREEN_CONTROLS "Show mobile controls by default" ON)
  132. option(HIDE_NONMOBILE_OPTIONS "Hide options that are impractical on mobile devices (e. g. changing screen resolution)" ON)
  133. else()
  134. option(SHOW_TOUCHSCREEN_CONTROLS "Show mobile controls by default" OFF)
  135. option(HIDE_NONMOBILE_OPTIONS "Hide options that are impractical on mobile devices (e. g. changing screen resolution)" OFF)
  136. endif()
  137. ## Add lots of dependencies to compiler switches
  138. set(Boost_ADDITIONAL_VERSIONS "1.41" "1.41.0")
  139. if(WIN32)
  140. option(ENABLE_BOOST_STATIC_LIBS "Use boost static libraries" ON)
  141. else(WIN32)
  142. option(ENABLE_BOOST_STATIC_LIBS "Use boost static libraries" OFF)
  143. endif(WIN32)
  144. if(ENABLE_BOOST_STATIC_LIBS)
  145. set(Boost_USE_STATIC_LIBS TRUE)
  146. else(ENABLE_BOOST_STATIC_LIBS)
  147. set(Boost_USE_STATIC_LIBS FALSE)
  148. endif(ENABLE_BOOST_STATIC_LIBS)
  149. find_package(Boost REQUIRED COMPONENTS filesystem system date_time locale)
  150. include_directories(SYSTEM ${Boost_INCLUDE_DIR})
  151. link_directories(${Boost_LIBRARY_DIRS})
  152. find_package(glm QUIET)
  153. if(glm_FOUND)
  154. if(TARGET glm::glm)
  155. message(STATUS "Found glm")
  156. else()
  157. # fallback for old glm version in EmuELEC and Nix
  158. get_target_property(GLM_INCLUDE_DIR glm INTERFACE_INCLUDE_DIRECTORIES)
  159. message(STATUS "Found glm: ${GLM_INCLUDE_DIR}")
  160. add_library(glm::glm INTERFACE IMPORTED)
  161. set_target_properties(glm::glm PROPERTIES
  162. INTERFACE_INCLUDE_DIRECTORIES ${GLM_INCLUDE_DIR})
  163. endif()
  164. else()
  165. # fallback for old glm version in UBPorts
  166. find_path(GLM_INCLUDE_DIR
  167. NAMES glm/glm.hpp
  168. PATHS ${GLM_ROOT_DIR}/include)
  169. if(NOT GLM_INCLUDE_DIR)
  170. message(FATAL_ERROR "glm library missing")
  171. endif()
  172. message(STATUS "Found glm: ${GLM_INCLUDE_DIR}")
  173. add_library(glm::glm INTERFACE IMPORTED)
  174. set_target_properties(glm::glm PROPERTIES
  175. INTERFACE_INCLUDE_DIRECTORIES ${GLM_INCLUDE_DIR})
  176. endif()
  177. find_package(PNG REQUIRED)
  178. if(WIN32)
  179. if(VCPKG_BUILD)
  180. find_package(SDL2 CONFIG REQUIRED)
  181. find_library(SDL2IMAGE_LIBRARIES SDL2_image)
  182. find_library(SDL2MAIN_LIBRARIES SDL2main)
  183. message(STATUS "SDL2_INCLUDE_DIR is ${SDL2_INCLUDE_DIRS}")
  184. else(VCPKG_BUILD)
  185. find_path(SDL2_INCLUDE_DIRS NAMES SDL.h PATHS "${DEPENDENCY_FOLDER}/include/SDL2")
  186. find_path(SDL2IMAGE_INCLUDE_DIRS NAMES SDL_image.h PATHS "${DEPENDENCY_FOLDER}/include/SDL2_image")
  187. find_library(SDL2_LIBRARIES NAMES SDL2 PATHS "${DEPENDENCY_FOLDER}/lib")
  188. find_library(SDL2IMAGE_LIBRARIES NAMES SDL2_image PATHS "${DEPENDENCY_FOLDER}/lib")
  189. find_library(SDL2MAIN_LIBRARIES NAMES SDL2main PATHS "${DEPENDENCY_FOLDER}/lib")
  190. find_path(PHYSFS_INCLUDE_DIR NAMES physfs.h PATHS "${DEPENDENCY_FOLDER}/include/physfs")
  191. endif(VCPKG_BUILD)
  192. else(WIN32)
  193. if (NOT EMSCRIPTEN)
  194. if (VCPKG_BUILD)
  195. find_package(SDL2 CONFIG REQUIRED)
  196. find_package(sdl2-image CONFIG REQUIRED)
  197. find_path(SDL2_INCLUDE_DIRS SDL2/SDL.h)
  198. find_path(SDL2IMAGE_INCLUDE_DIRS SDL2/SDL_image.h)
  199. set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS}/SDL2)
  200. set(SDL2IMAGE_INCLUDE_DIRS ${SDL2IMAGE_INCLUDE_DIRS}/SDL2)
  201. find_library(SDL2_LIBRARIES SDL2)
  202. find_library(SDL2IMAGE_LIBRARIES SDL2_image)
  203. message(STATUS "SDL2_INCLUDE_DIR is ${SDL2_INCLUDE_DIRS}")
  204. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  205. # 32-bit
  206. find_library(SDL2_LIBRARIES SDL2)
  207. find_library(SDL2IMAGE_LIBRARIES SDL2_image)
  208. find_path(SDL2_INCLUDE_DIRS SDL2/SDL.h)
  209. find_path(SDL2IMAGE_INCLUDE_DIRS SDL2/SDL_image.h)
  210. set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS}/SDL2)
  211. set(SDL2IMAGE_INCLUDE_DIRS ${SDL2IMAGE_INCLUDE_DIRS}/SDL2)
  212. message(STATUS "SDL LIBS: ${SDL2_LIBRARIES}")
  213. message(STATUS "SDL INCL: ${SDL2_INCLUDE_DIRS}")
  214. else()
  215. # 64-bit
  216. include(FindPkgConfig)
  217. pkg_search_module(SDL2 REQUIRED sdl2>=2.0.1)
  218. pkg_search_module(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
  219. endif()
  220. endif(NOT EMSCRIPTEN)
  221. endif(WIN32)
  222. set(HAVE_SDL TRUE)
  223. option(IS_SUPERTUX_RELEASE "Build as official SuperTux release" OFF)
  224. option(BUILD_TESTS "Build test cases" OFF)
  225. option(ENABLE_OPENGL "Enable OpenGL support" ON)
  226. option(ENABLE_OPENGLES2 "Enable OpenGLES2 support" OFF)
  227. option(GLBINDING_ENABLED "Use glbinding instead of GLEW" OFF)
  228. option(GLBINDING_DEBUG_OUTPUT "Enable glbinding debug output for each called OpenGL function" OFF)
  229. if(ENABLE_OPENGL)
  230. if(EMSCRIPTEN AND ENABLE_OPENGLES2)
  231. set(HAVE_OPENGL TRUE)
  232. add_definitions(-DUSE_OPENGLES2)
  233. elseif(ENABLE_OPENGLES2 AND NOT EMSCRIPTEN)
  234. pkg_check_modules(GLESV2 REQUIRED glesv2)
  235. set(HAVE_OPENGL TRUE)
  236. set(OPENGL_INCLUDE_DIR ${GLESV2_INCLUDE_DIRS})
  237. set(OPENGL_LIBRARY ${GLESV2_LIBRARIES})
  238. add_definitions(-DUSE_OPENGLES2)
  239. else(NOT EMSCRIPTEN)
  240. set(OpenGL_GL_PREFERENCE "LEGACY")
  241. find_package(OpenGL)
  242. if(OPENGL_FOUND)
  243. include_directories(SYSTEM ${OPENGL_INCLUDE_DIR})
  244. set(HAVE_OPENGL TRUE)
  245. endif(OPENGL_FOUND)
  246. if(GLBINDING_ENABLED)
  247. find_package(GLBINDING REQUIRED)
  248. if(GLBINDING_FOUND)
  249. include_directories(SYSTEM ${GLBINDING_INCLUDES})
  250. add_definitions(-DUSE_GLBINDING)
  251. IF (GLBINDING_DEBUG_OUTPUT)
  252. add_definitions(-DUSE_GLBINDING_DEBUG_OUTPUT)
  253. endif()
  254. endif()
  255. else()
  256. find_package(GLEW REQUIRED)
  257. if(GLEW_FOUND)
  258. include_directories(SYSTEM ${GLEW_INCLUDE_DIR})
  259. endif(GLEW_FOUND)
  260. endif()
  261. endif()
  262. endif(ENABLE_OPENGL)
  263. if(NOT EMSCRIPTEN)
  264. if(VCPKG_BUILD)
  265. find_package(OpenAL CONFIG REQUIRED)
  266. else()
  267. find_package(OpenAL REQUIRED)
  268. endif()
  269. include_directories(SYSTEM ${OPENAL_INCLUDE_DIR})
  270. else()
  271. include_directories(${CMAKE_SOURCE_DIR}/mk/emscripten/AL)
  272. endif()
  273. find_package(OggVorbis REQUIRED)
  274. include_directories(SYSTEM ${VORBIS_INCLUDE_DIR})
  275. include(CheckSymbolExists)
  276. find_package(PhysFS)
  277. if(PHYSFS_LIBRARY)
  278. set(CMAKE_REQUIRED_LIBRARIES ${PHYSFS_LIBRARY})
  279. check_symbol_exists("PHYSFS_getPrefDir" "${PHYSFS_INCLUDE_DIR}/physfs.h" HAVE_PHYSFS_GETPREFDIR)
  280. endif()
  281. if(HAVE_PHYSFS_GETPREFDIR)
  282. set(USE_SYSTEM_PHYSFS ON CACHE BOOL "Use preinstalled physfs (must support getPrefDir)")
  283. else(HAVE_PHYSFS_GETPREFDIR)
  284. set(USE_SYSTEM_PHYSFS OFF CACHE BOOL "Use preinstalled physfs (must support getPrefDir)")
  285. endif(HAVE_PHYSFS_GETPREFDIR)
  286. if(NOT USE_SYSTEM_PHYSFS)
  287. if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/physfs/CMakeLists.txt)
  288. message(FATAL_ERROR "physfs submodule is not checked out or ${CMAKE_CURRENT_SOURCE_DIR}/external/physfs/CMakeLists.txt is missing")
  289. endif()
  290. if(WIN32)
  291. set(PHYSFS_BUILD_SHARED TRUE)
  292. set(PHYSFS_BUILD_STATIC FALSE)
  293. else(WIN32)
  294. set(PHYSFS_BUILD_SHARED FALSE)
  295. set(PHYSFS_BUILD_STATIC TRUE)
  296. endif()
  297. set(PHYSFS_PREFIX ${CMAKE_BINARY_DIR}/physfs/)
  298. ExternalProject_Add(physfs
  299. SOURCE_DIR "${CMAKE_SOURCE_DIR}/external/physfs/"
  300. BUILD_BYPRODUCTS
  301. "${PHYSFS_PREFIX}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}physfs${CMAKE_SHARED_LIBRARY_SUFFIX}"
  302. "${PHYSFS_PREFIX}/lib${LIB_SUFFIX}/physfs${CMAKE_LINK_LIBRARY_SUFFIX}"
  303. "${PHYSFS_PREFIX}/lib${LIB_SUFFIX}/${CMAKE_STATIC_LIBRARY_PREFIX}physfs${CMAKE_STATIC_LIBRARY_SUFFIX}"
  304. CMAKE_ARGS
  305. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  306. -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
  307. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  308. -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
  309. -DCMAKE_INSTALL_PREFIX=${PHYSFS_PREFIX}
  310. -DLIB_SUFFIX=${LIB_SUFFIX}
  311. -DPHYSFS_BUILD_SHARED=${PHYSFS_BUILD_SHARED}
  312. -DPHYSFS_BUILD_STATIC=${PHYSFS_BUILD_STATIC}
  313. -DPHYSFS_BUILD_TEST=FALSE)
  314. if(WIN32)
  315. add_library(physfs_lib SHARED IMPORTED)
  316. set_target_properties(physfs_lib PROPERTIES IMPORTED_LOCATION "${PHYSFS_PREFIX}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}physfs${CMAKE_SHARED_LIBRARY_SUFFIX}")
  317. set_target_properties(physfs_lib PROPERTIES IMPORTED_IMPLIB "${PHYSFS_PREFIX}/lib${LIB_SUFFIX}/physfs${CMAKE_LINK_LIBRARY_SUFFIX}")
  318. else()
  319. add_library(physfs_lib STATIC IMPORTED)
  320. set_target_properties(physfs_lib PROPERTIES IMPORTED_LOCATION "${PHYSFS_PREFIX}/lib${LIB_SUFFIX}/${CMAKE_STATIC_LIBRARY_PREFIX}physfs${CMAKE_STATIC_LIBRARY_SUFFIX}")
  321. endif()
  322. set(PHYSFS_INCLUDE_DIR "${PHYSFS_PREFIX}/include/")
  323. endif()
  324. include_directories(BEFORE SYSTEM ${PHYSFS_INCLUDE_DIR})
  325. ## The curl headers are in the standard include path in dependencies
  326. ## so it's not required to add them here
  327. if (NOT EMSCRIPTEN)
  328. find_package(CURL REQUIRED)
  329. if(WIN32 AND VCPKG_BUILD)
  330. list(LENGTH CURL_LIBRARY CURL_LIBRARY_LENGTH)
  331. if (CURL_LIBRARY_LENGTH EQUAL 1)
  332. set(CURL_LIBRARY_DEBUG_LIB ${CURL_LIBRARY})
  333. set(CURL_LIBRARY_RELEASE_LIB ${CURL_LIBRARY_DEBUG_LIB}/../../../lib/libcurl.lib)
  334. get_filename_component(CURL_LIBRARY_RELEASE_LIB ${CURL_LIBRARY_RELEASE_LIB} REALPATH)
  335. unset(CURL_LIBRARY CACHE)
  336. unset(CURL_LIBRARY)
  337. unset(CURL_LIBRARIES CACHE)
  338. unset(CURL_LIBRARIES)
  339. set(CURL_LIBRARY "debug;${CURL_LIBRARY_DEBUG_LIB};optimized;${CURL_LIBRARY_RELEASE_LIB}")
  340. set(CURL_LIBRARIES ${CURL_LIBRARY})
  341. endif()
  342. endif()
  343. if(CURL_FOUND)
  344. include_directories(SYSTEM ${CURL_INCLUDE_DIR})
  345. set(HAVE_LIBCURL TRUE)
  346. endif(CURL_FOUND)
  347. endif(NOT EMSCRIPTEN)
  348. find_package(ZLIB REQUIRED)
  349. #find_package(ICONV REQUIRED)
  350. #include_directories(SYSTEM ${ICONV_INCLUDE_DIR})
  351. #link_libraries(${ICONV_LIBRARY})
  352. if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
  353. ## Find revision of WC
  354. mark_as_advanced(GIT_EXECUTABLE)
  355. find_program(GIT_EXECUTABLE git)
  356. if(NOT GIT_EXECUTABLE EQUAL "GIT_EXECUTABLE-NOTFOUND")
  357. include(GetGitRevisionDescription)
  358. git_describe(VERSION_STRING_GIT "--tags" "--match" "?[0-9]*.[0-9]*.[0-9]*")
  359. string(REPLACE "v" "" VERSION_LIST ${VERSION_STRING_GIT})
  360. string(REGEX REPLACE "[^\\-]+\\-([0-9]+)\\-.*" "\\1" VERSION_NUMBER_GIT "${VERSION_LIST}")
  361. string(REGEX REPLACE "(-|_|\\.)" ";" VERSION_LIST ";${VERSION_LIST}")
  362. endif()
  363. endif(EXISTS "${CMAKE_SOURCE_DIR}/.git")
  364. get_filename_component(BASEDIR ${CMAKE_SOURCE_DIR} NAME)
  365. if("${VERSION_LIST}" STREQUAL "")
  366. if(${BASEDIR} MATCHES "supertux2-[0-9\\.]*")
  367. string(REGEX REPLACE "(\\.|_|-)" ";" VERSION_LIST ${BASEDIR})
  368. endif()
  369. endif()
  370. file(GLOB ORIG_TGZ ../*.orig.tar.gz)
  371. if("${VERSION_LIST}" STREQUAL "" AND (NOT "${ORIG_TGZ}" STREQUAL ""))
  372. get_filename_component(BASEDIR ${ORIG_TGZ} NAME)
  373. string(REGEX REPLACE "(\\.|_|-)" ";" VERSION_LIST ${BASEDIR})
  374. endif()
  375. list(LENGTH VERSION_LIST VERSION_LIST_SIZE)
  376. if(${VERSION_LIST_SIZE} GREATER 0)
  377. list(GET VERSION_LIST 1 MAJOR_VERSION_GIT)
  378. list(GET VERSION_LIST 2 MINOR_VERSION_GIT)
  379. list(GET VERSION_LIST 3 PATCH_VERSION_GIT)
  380. if("${VERSION_STRING_GIT}" STREQUAL "")
  381. set(VERSION_STRING_GIT "${MAJOR_VERSION_GIT}.${MINOR_VERSION_GIT}.${PATCH_VERSION_GIT}")
  382. endif()
  383. configure_file("${CMAKE_SOURCE_DIR}/version.cmake.in" "${CMAKE_SOURCE_DIR}/version.cmake")
  384. endif()
  385. if(NOT EXISTS "${CMAKE_SOURCE_DIR}/version.cmake")
  386. message( SEND_ERROR "Could not find GIT or valid version.cmake. Version information will be invalid." )
  387. endif(NOT EXISTS "${CMAKE_SOURCE_DIR}/version.cmake")
  388. include("${CMAKE_SOURCE_DIR}/version.cmake")
  389. set(SUPERTUX_VERSION ${SUPERTUX_VERSION_STRING})
  390. configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h )
  391. set_source_files_properties(${CMAKE_BINARY_DIR}/version.h
  392. PROPERTIES GENERATED true)
  393. set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/supertux/main.cpp
  394. PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")
  395. set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/supertux/title_screen.cpp
  396. PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")
  397. set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/addon/addon_manager.cpp
  398. PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")
  399. ## Configure doxygen
  400. # Adapted from https://tty1.net/blog/2014/cmake-doxygen_en.html
  401. # add a target to generate API documentation with Doxygen
  402. find_package(Doxygen)
  403. option(BUILD_DOCUMENTATION "Build API documentation using Doxygen" ${DOXYGEN_FOUND})
  404. if(BUILD_DOCUMENTATION)
  405. if(NOT DOXYGEN_FOUND)
  406. message(FATAL_ERROR "Doxygen is needed to build the documentation.")
  407. endif()
  408. set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
  409. set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile)
  410. configure_file(${doxyfile_in} ${doxyfile} @ONLY)
  411. add_custom_target(doc
  412. COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
  413. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  414. COMMENT "Generating API documentation with Doxygen"
  415. VERBATIM)
  416. endif()
  417. ## Check platform-dependent build options
  418. include(ConfigureChecks)
  419. # Include altivec wrapper on ppc
  420. if(CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc.*")
  421. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/ppc)
  422. endif()
  423. ## Also build external/squirrel
  424. if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/squirrel/CMakeLists.txt)
  425. message(FATAL_ERROR "squirrel submodule is not checked out or ${CMAKE_CURRENT_SOURCE_DIR}/external/squirrel/CMakeLists.txt is missing")
  426. endif()
  427. set(SQUIRREL_PREFIX ${CMAKE_BINARY_DIR}/squirrel/ex)
  428. ExternalProject_Add(squirrel
  429. SOURCE_DIR "${CMAKE_SOURCE_DIR}/external/squirrel/"
  430. BUILD_BYPRODUCTS
  431. "${SQUIRREL_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}sqstdlib_static${CMAKE_STATIC_LIBRARY_SUFFIX}"
  432. "${SQUIRREL_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}squirrel_static${CMAKE_STATIC_LIBRARY_SUFFIX}"
  433. CMAKE_ARGS
  434. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  435. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  436. -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
  437. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  438. -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
  439. -DCMAKE_INSTALL_PREFIX=${SQUIRREL_PREFIX}
  440. -DINSTALL_INC_DIR=include
  441. -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
  442. if(WIN32)
  443. add_library(squirrel_lib SHARED IMPORTED)
  444. set_target_properties(squirrel_lib PROPERTIES IMPORTED_LOCATION "${SQUIRREL_PREFIX}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}squirrel${CMAKE_SHARED_LIBRARY_SUFFIX}")
  445. set_target_properties(squirrel_lib PROPERTIES IMPORTED_IMPLIB "${SQUIRREL_PREFIX}/lib/squirrel${CMAKE_LINK_LIBRARY_SUFFIX}")
  446. add_library(sqstdlib_lib SHARED IMPORTED)
  447. set_target_properties(sqstdlib_lib PROPERTIES IMPORTED_LOCATION "${SQUIRREL_PREFIX}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}sqstdlib${CMAKE_SHARED_LIBRARY_SUFFIX}")
  448. set_target_properties(sqstdlib_lib PROPERTIES IMPORTED_IMPLIB "${SQUIRREL_PREFIX}/lib/sqstdlib${CMAKE_LINK_LIBRARY_SUFFIX}")
  449. #For debug run purposes
  450. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/mk/msvc/run_supertux.bat.in" "${PROJECT_BINARY_DIR}/run_supertux.bat")
  451. else()
  452. add_library(squirrel_lib STATIC IMPORTED)
  453. set_target_properties(squirrel_lib PROPERTIES IMPORTED_LOCATION "${SQUIRREL_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}squirrel_static${CMAKE_STATIC_LIBRARY_SUFFIX}")
  454. add_library(sqstdlib_lib STATIC IMPORTED)
  455. set_target_properties(sqstdlib_lib PROPERTIES IMPORTED_LOCATION "${SQUIRREL_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}sqstdlib_static${CMAKE_STATIC_LIBRARY_SUFFIX}")
  456. endif()
  457. include_directories(SYSTEM ${SQUIRREL_PREFIX}/include)
  458. ## Also build external/tinygettext
  459. if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinygettext/CMakeLists.txt)
  460. message(FATAL_ERROR "tinygettext submodule is not checked out or ${CMAKE_CURRENT_SOURCE_DIR}/external/tinygettext/CMakeLists.txt is missing")
  461. endif()
  462. # Include altivec wrapper on ppc
  463. if(CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc.*")
  464. set(TINYGETTEXT_CXX_FLAGS "-isystem ${CMAKE_CURRENT_SOURCE_DIR}/src/ppc ${CMAKE_CXX_FLAGS}")
  465. else()
  466. set(TINYGETTEXT_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  467. endif()
  468. # CMake lists are just strings with ';' separators, thus passing lists
  469. # of lists is impossible. ExternalProject_Add provides LIST_SEPARATOR
  470. # to work around this limitations by using a different separator.
  471. string(REPLACE ";" "|" TINYGETTEXT_SDL2_INCLUDE_DIRS "${SDL2_INCLUDE_DIRS}")
  472. set(TINYGETTEXT_PREFIX ${CMAKE_BINARY_DIR}/tinygettext/)
  473. ExternalProject_Add(tinygettext
  474. SOURCE_DIR "${CMAKE_SOURCE_DIR}/external/tinygettext/"
  475. BUILD_BYPRODUCTS "${TINYGETTEXT_PREFIX}/lib${LIB_SUFFIX}/${CMAKE_STATIC_LIBRARY_PREFIX}tinygettext${CMAKE_STATIC_LIBRARY_SUFFIX}"
  476. LIST_SEPARATOR "|"
  477. CMAKE_ARGS
  478. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  479. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  480. -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
  481. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  482. -DCMAKE_CXX_FLAGS=${TINYGETTEXT_CXX_FLAGS}
  483. -DBUILD_SHARED_LIBS=OFF
  484. -DHAVE_SDL=ON
  485. -DVCPKG_BUILD=${VCPKG_BUILD}
  486. -DCMAKE_INSTALL_PREFIX=${TINYGETTEXT_PREFIX}
  487. -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
  488. -DSDL2_LIBRARIES=${SDL2_LIBRARIES}
  489. -DSDL2_INCLUDE_DIRS=${TINYGETTEXT_SDL2_INCLUDE_DIRS}
  490. -DLIB_SUFFIX=${LIB_SUFFIX})
  491. add_library(tinygettext_lib STATIC IMPORTED)
  492. set_target_properties(tinygettext_lib PROPERTIES IMPORTED_LOCATION "${TINYGETTEXT_PREFIX}/lib${LIB_SUFFIX}/${CMAKE_STATIC_LIBRARY_PREFIX}tinygettext${CMAKE_STATIC_LIBRARY_SUFFIX}")
  493. include_directories(SYSTEM ${TINYGETTEXT_PREFIX}/include)
  494. ## external/SDL_ttf with patches
  495. if (NOT EMSCRIPTEN)
  496. if (VCPKG_BUILD)
  497. find_package(freetype CONFIG REQUIRED)
  498. else()
  499. find_package(Freetype REQUIRED)
  500. endif()
  501. endif(NOT EMSCRIPTEN)
  502. find_package(RAQM)
  503. set(SDL_TTF_PREFIX ${CMAKE_BINARY_DIR}/SDL_ttf/)
  504. ExternalProject_Add(SDL_ttf
  505. SOURCE_DIR "${CMAKE_SOURCE_DIR}/external/SDL_ttf/"
  506. BUILD_BYPRODUCTS "${SDL_TTF_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SDL2_ttf${CMAKE_STATIC_LIBRARY_SUFFIX}"
  507. CMAKE_ARGS
  508. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  509. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  510. -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
  511. -DCMAKE_INSTALL_PREFIX=${SDL_TTF_PREFIX}
  512. -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
  513. -DWITH_RAQM=${RAQM_FOUND}
  514. -DRAQM_LIBRARIES=${RAQM_LIBRARY}
  515. -DRAQM_INCLUDE_DIR=${RAQM_INCLUDE_DIR}
  516. -DBUILD_SHARED_LIBS=OFF
  517. -DEMSCRIPTEN=${EMSCRIPTEN})
  518. add_library(SDL_ttf_lib STATIC IMPORTED)
  519. set_target_properties(SDL_ttf_lib PROPERTIES IMPORTED_LOCATION "${SDL_TTF_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SDL2_ttf${CMAKE_STATIC_LIBRARY_SUFFIX}")
  520. link_directories(${SDL_TTF_PREFIX}/lib)
  521. include_directories(SYSTEM ${SDL_TTF_PREFIX}/include/SDL2)
  522. if(RAQM_FOUND)
  523. find_package(FriBidi REQUIRED)
  524. find_package(HarfBuzz REQUIRED)
  525. set_target_properties(SDL_ttf_lib PROPERTIES INTERFACE_LINK_LIBRARIES "${RAQM_LIBRARIES}")
  526. endif()
  527. ## Some additional include paths
  528. include_directories(${CMAKE_BINARY_DIR}/)
  529. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
  530. include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/findlocale/)
  531. include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/obstack/)
  532. include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/sexp-cpp/include/)
  533. include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/SDL_SavePNG/)
  534. include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/partio_zip/)
  535. # Discord SDK
  536. # Before removing messages, please check with the community if no one minds that the Discord SDK gets bundled with ST.
  537. # Some privay-concerned users or free software package managers might need an option to compile ST without the Discord integration.
  538. option(ENABLE_DISCORD "Compile the Discord integration" OFF)
  539. if(ENABLE_DISCORD)
  540. message(STATUS "Discord WILL be compiled. To disable Discord, pass -DENABLE_DISCORD=Off")
  541. include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/discord-sdk/include)
  542. set(BUILD_EXAMPLES OFF CACHE BOOL "Skip Discord's sample programs" FORCE)
  543. add_subdirectory(external/discord-sdk)
  544. else(ENABLE_DISCORD)
  545. message(STATUS "## WARNING : Discord integration will NOT be compiled. To enable Discord, pass -DENABLE_DISCORD=On")
  546. endif(ENABLE_DISCORD)
  547. if(WIN32)
  548. add_definitions(-D_USE_MATH_DEFINES -DNOMINMAX)
  549. add_definitions(-DWIN32)
  550. endif(WIN32)
  551. ## Lint
  552. if(CMAKE_VERSION VERSION_GREATER 3.6)
  553. if (USE_CLANG_TIDY)
  554. find_program(
  555. CLANG_TIDY_EXE
  556. NAMES "clang-tidy"
  557. DOC "Path to clang-tidy executable"
  558. )
  559. if(NOT CLANG_TIDY_EXE)
  560. message(FATAL_ERROR "clang-tidy not found.")
  561. else()
  562. message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
  563. set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
  564. endif()
  565. endif()
  566. endif()
  567. ## Build list of sources for supertux binary
  568. file(GLOB SUPERTUX_SOURCES_C RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} external/obstack/*.c external/findlocale/findlocale.c)
  569. file(GLOB SUPERTUX_SOURCES_CXX RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*/*.cpp src/supertux/menu/*.cpp src/video/sdl/*.cpp src/video/null/*.cpp)
  570. file(GLOB SUPERTUX_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${PROJECT_BINARY_DIR}/tmp/*.rc")
  571. if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/sexp-cpp/CMakeLists.txt)
  572. message(FATAL_ERROR "sexp-cpp submodule is not checked out or ${CMAKE_CURRENT_SOURCE_DIR}/external/sexp-cpp/CMakeLists.txt is missing")
  573. endif()
  574. file(GLOB SEXP_SOURCES_CXX RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} external/sexp-cpp/src/*.cpp)
  575. add_library(sexp STATIC ${SEXP_SOURCES_CXX})
  576. target_compile_definitions(sexp PRIVATE -DSEXP_USE_LOCALE)
  577. file(GLOB SAVEPNG_SOURCES_CXX RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} external/SDL_SavePNG/savepng.c)
  578. add_library(savepng STATIC ${SAVEPNG_SOURCES_CXX})
  579. target_include_directories(savepng SYSTEM PUBLIC ${SDL2_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS})
  580. target_link_libraries(savepng PUBLIC ${PNG_LIBRARIES})
  581. add_library(partio_zip_lib STATIC ${CMAKE_CURRENT_SOURCE_DIR}/external/partio_zip/zip_manager.cpp)
  582. target_include_directories(partio_zip_lib PUBLIC ${ZLIB_INCLUDE_DIRS})
  583. target_link_libraries(partio_zip_lib PUBLIC ${ZLIB_LIBRARIES})
  584. if(HAVE_OPENGL)
  585. file(GLOB SUPERTUX_OPENGL_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/video/gl/*.cpp)
  586. set(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${SUPERTUX_OPENGL_SOURCES})
  587. endif(HAVE_OPENGL)
  588. ## Sort source lists to have deterministic linking order
  589. list(SORT SUPERTUX_SOURCES_C)
  590. list(SORT SUPERTUX_SOURCES_CXX)
  591. list(SORT SUPERTUX_RESOURCES)
  592. if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
  593. set(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
  594. endif(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
  595. ## Compile everything at once (roughly equivalent to cat *.cpp | gcc)
  596. option(COMPILE_AMALGATION "Compile all the files together at once (experimental)" OFF)
  597. if(COMPILE_AMALGATION)
  598. file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp "// Includes all source files of the project\n")
  599. foreach(ST_FILE ${SUPERTUX_SOURCES_CXX})
  600. file(RELATIVE_PATH CXX_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src "${CMAKE_CURRENT_SOURCE_DIR}/${ST_FILE}")
  601. file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp "#include \"${CXX_FILE}\"\n")
  602. endforeach(ST_FILE)
  603. ## Build instead of CXX sources
  604. set(SUPERTUX_SOURCES_CXX ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  605. else(COMPILE_AMALGATION)
  606. if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  607. file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  608. endif(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  609. endif(COMPILE_AMALGATION)
  610. ## Debug options
  611. option(WERROR "Stop on first compiler warning" OFF)
  612. option(WARNINGS "Enable long list of warnings for compiler to check" OFF)
  613. option(USE_CLANG_TIDY "Run clang-tidy" OFF)
  614. if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  615. set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
  616. set(CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
  617. set(CMAKE_CXX_FLAGS_PROFILE "-pg" CACHE STRING "Profile flags")
  618. set(CMAKE_C_FLAGS_PROFILE "-pg" CACHE STRING "Profile flags")
  619. set(CMAKE_LD_FLAGS_PROFILE "-lgmon" CACHE STRING "Profile flags")
  620. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -funit-at-a-time")
  621. if(WERROR)
  622. add_definitions(-Werror)
  623. else(WERROR)
  624. remove_definitions(-Werror)
  625. endif(WERROR)
  626. if(WARNINGS)
  627. # temporarily disabled:
  628. # -Wsign-conversion -Wfloat-equal -Wundef -Wswitch-default
  629. # -Wswitch-enum -Wsign-promo -Wcast-qual -Woverloaded-virtual -Wmissing-format-attribute
  630. # -Wpadded -Wabi -Winline -Wunsafe-loop-optimizations -Wstrict-overflow=5
  631. # fails on MinGW:
  632. # -ansi
  633. if(CMAKE_COMPILER_IS_GNUCXX)
  634. string(CONCAT SUPERTUX2_EXTRA_WARNING_FLAGS
  635. "-fdiagnostics-show-option "
  636. "-pedantic "
  637. "-Wno-long-long "
  638. "-Wcast-align "
  639. "-Wdisabled-optimization "
  640. "-Winit-self -Winvalid-pch "
  641. "-Wmissing-include-dirs "
  642. "-Wmissing-noreturn "
  643. "-Wpacked -Wredundant-decls "
  644. "-Wformat=2 "
  645. "-Weffc++ "
  646. "-Wctor-dtor-privacy "
  647. "-Wno-unused-parameter "
  648. "-Wshadow "
  649. "-Wnon-virtual-dtor "
  650. "-Wcast-qual "
  651. "-Wold-style-cast "
  652. "-Wzero-as-null-pointer-constant "
  653. "-Wconversion "
  654. "-Wlogical-op "
  655. "-Wstrict-null-sentinel "
  656. "-Wsuggest-override "
  657. )
  658. if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8)
  659. string(CONCAT SUPERTUX2_EXTRA_WARNING_FLAGS
  660. "${SUPERTUX2_EXTRA_WARNING_FLAGS} "
  661. "-Wint-in-bool-context "
  662. )
  663. endif()
  664. if(Boost_VERSION LESS 106500)
  665. string(CONCAT SUPERTUX2_EXTRA_WARNING_FLAGS
  666. "${SUPERTUX2_EXTRA_WARNING_FLAGS} "
  667. "-Wno-implicit-fallthrough ")
  668. endif()
  669. elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  670. string(CONCAT SUPERTUX2_EXTRA_WARNING_FLAGS
  671. "${SUPERTUX2_EXTRA_WARNING_FLAGS} "
  672. "-Weverything "
  673. # flags that we deliberately ignore
  674. "-Wno-c++98-compat "
  675. "-Wno-c++98-compat-pedantic "
  676. "-Wno-float-equal "
  677. "-Wno-padded "
  678. "-Wno-weak-vtables "
  679. "-Wno-disabled-macro-expansion "
  680. "-Wno-documentation "
  681. "-Wno-reserved-id-macro "
  682. "-Wno-sign-conversion "
  683. # warnings that should probably be fixed in code
  684. "-Wno-documentation-unknown-command "
  685. "-Wno-inconsistent-missing-destructor-override "
  686. "-Wno-deprecated-dynamic-exception-spec "
  687. "-Wno-deprecated "
  688. "-Wno-switch-enum "
  689. "-Wno-covered-switch-default "
  690. "-Wno-exit-time-destructors "
  691. "-Wno-global-constructors "
  692. "-Wno-duplicate-enum "
  693. "-Wno-unreachable-code "
  694. )
  695. # This snipped adapted from AOMediaCodec cmakefile
  696. # The detection of cross compilation by -Wpoison-system-directories has false positives on macOS because
  697. # --sysroot is implicitly added. Turn the warning off.
  698. if(NOT DEFINED HAVE_POISON_SYSTEM_DIRECTORIES_WARNING)
  699. check_cxx_compiler_flag(-Wpoison-system-directories HAVE_POISON_SYSTEM_DIRECTORIES_WARNING)
  700. endif()
  701. if(HAVE_POISON_SYSTEM_DIRECTORIES_WARNING)
  702. string(CONCAT SUPERTUX2_EXTRA_WARNING_FLAGS
  703. "${SUPERTUX2_EXTRA_WARNING_FLAGS} "
  704. "-Wno-poison-system-directories ")
  705. endif()
  706. endif()
  707. endif(WARNINGS)
  708. endif()
  709. ## If xgettext is available, generate messages.pot for sources
  710. option(GENERATE_MESSAGESPOT "Generate messages.pot files" OFF)
  711. if(GENERATE_MESSAGESPOT)
  712. mark_as_advanced(
  713. XGETTEXT_EXECUTABLE
  714. )
  715. find_program(XGETTEXT_EXECUTABLE xgettext)
  716. if(NOT XGETTEXT_EXECUTABLE)
  717. message(STATUS "Warning: xgettext not found - will not update messages.pot")
  718. else(NOT XGETTEXT_EXECUTABLE)
  719. message(STATUS "Found xgettext: ${XGETTEXT_EXECUTABLE}")
  720. set(MESSAGES_POT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/data/locale/messages.pot)
  721. add_custom_command(
  722. OUTPUT ${MESSAGES_POT_FILE}
  723. COMMAND ${XGETTEXT_EXECUTABLE}
  724. ARGS --keyword=_ --language=C++ --output=${MESSAGES_POT_FILE} ${SUPERTUX_SOURCES_CXX}
  725. DEPENDS ${SUPERTUX_SOURCES_CXX}
  726. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  727. COMMENT "Generating POT file ${MESSAGES_POT_FILE}"
  728. )
  729. list(APPEND MESSAGES_POT_FILES ${MESSAGES_POT_FILE})
  730. file(GLOB SUPERTUX_LEVEL_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} data/levels/*)
  731. foreach(SUPERTUX_LEVEL_DIR ${SUPERTUX_LEVEL_DIRS})
  732. file(GLOB SUPERTUX_LEVELS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${SUPERTUX_LEVEL_DIR}/*.stl ${SUPERTUX_LEVEL_DIR}/*.stwm ${SUPERTUX_LEVEL_DIR}/*.txt)
  733. ## Do not add target if SUPERTUX_LEVELS is empty. This is needed for cmake <=2.4
  734. if(SUPERTUX_LEVELS)
  735. set(MESSAGES_POT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${SUPERTUX_LEVEL_DIR}/messages.pot)
  736. add_custom_command(
  737. OUTPUT ${MESSAGES_POT_FILE}
  738. COMMAND ${XGETTEXT_EXECUTABLE}
  739. ARGS --keyword="_:1" --language=Lisp --force-po --sort-by-file "--output=${MESSAGES_POT_FILE}" ${SUPERTUX_LEVELS}
  740. DEPENDS ${SUPERTUX_LEVELS}
  741. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  742. COMMENT "Generating POT file ${MESSAGES_POT_FILE}"
  743. )
  744. list(APPEND MESSAGES_POT_FILES ${MESSAGES_POT_FILE})
  745. endif(SUPERTUX_LEVELS)
  746. endforeach(SUPERTUX_LEVEL_DIR)
  747. add_custom_target(
  748. supertux2-messages ALL
  749. DEPENDS ${MESSAGES_POT_FILES}
  750. )
  751. endif(NOT XGETTEXT_EXECUTABLE)
  752. endif(GENERATE_MESSAGESPOT)
  753. ## Some additional compiler switches
  754. if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  755. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
  756. endif()
  757. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  758. add_definitions(-DMACOSX)
  759. endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  760. ## On Windows, add an icon
  761. if(WIN32)
  762. # set(SUPERTUX_SOURCES_C ${SUPERTUX_SOURCES_C} ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc)
  763. if(MINGW)
  764. add_custom_command(
  765. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o
  766. COMMAND ${CMAKE_RC_COMPILER} -I${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons -i${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc -o ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o)
  767. set(SUPERTUX_SOURCES_C ${SUPERTUX_SOURCES_C} ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o)
  768. endif(MINGW)
  769. endif(WIN32)
  770. ## Build miniswig and generate miniswig wrapper
  771. option(GENERATE_WRAPPER "Build miniswig and generate the wrapper" OFF)
  772. if(GENERATE_WRAPPER)
  773. add_subdirectory(tools/miniswig)
  774. add_custom_command(
  775. OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp
  776. COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_CXX_COMPILER}
  777. ARGS -x "c++" -E -CC -DSCRIPTING_API src/scripting/wrapper.interface.hpp -o ${CMAKE_CURRENT_BINARY_DIR}/miniswig.tmp -I${CMAKE_CURRENT_SOURCE_DIR}/src
  778. COMMAND tools/miniswig/miniswig
  779. ARGS --input miniswig.tmp --output-cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp --output-hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp --module supertux --select-namespace scripting
  780. DEPENDS tools/miniswig/miniswig
  781. IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.interface.hpp
  782. )
  783. if(USE_CLANG_TIDY)
  784. set_target_properties(miniswig PROPERTIES CXX_CLANG_TIDY "")
  785. endif()
  786. endif(GENERATE_WRAPPER)
  787. ## Generate supertux executable in the right place
  788. #set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
  789. set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
  790. ## Add target for supertux binary
  791. add_library(supertux2_c OBJECT ${SUPERTUX_SOURCES_C})
  792. add_library(supertux2_lib STATIC ${CMAKE_BINARY_DIR}/version.h ${SUPERTUX_SOURCES_CXX} ${SUPERTUX_RESOURCES} $<TARGET_OBJECTS:supertux2_c>)
  793. target_link_libraries(supertux2_lib PUBLIC glm::glm)
  794. target_compile_definitions(supertux2_lib PUBLIC -DGLM_ENABLE_EXPERIMENTAL)
  795. if(WIN32)
  796. add_executable(supertux2 WIN32 src/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc)
  797. target_link_libraries(supertux2 ${SDL2MAIN_LIBRARIES})
  798. else()
  799. add_executable(supertux2 src/main.cpp)
  800. endif(WIN32)
  801. target_link_libraries(supertux2 supertux2_lib Boost::filesystem Boost::locale)
  802. set_target_properties(supertux2_lib PROPERTIES OUTPUT_NAME supertux2_lib)
  803. set_target_properties(supertux2_lib PROPERTIES COMPILE_FLAGS "${SUPERTUX2_EXTRA_WARNING_FLAGS}")
  804. if(EMSCRIPTEN)
  805. target_link_options(supertux2 PUBLIC -sEXPORTED_FUNCTIONS=['_main','_set_resolution','_save_config','_onDownloadProgress','_onDownloadFinished','_onDownloadError','_onDownloadAborted','_getExceptionMessage'] PUBLIC -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'] PUBLIC -sEXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap'])
  806. endif(EMSCRIPTEN)
  807. if(WIN32 AND NOT VCPKG_BUILD)
  808. ## Copy dlls on windows
  809. add_custom_command(TARGET supertux2_lib POST_BUILD
  810. COMMAND ${CMAKE_COMMAND} -E copy_directory
  811. "${DEPENDENCY_FOLDER}/dll"
  812. $<TARGET_FILE_DIR:supertux2_lib>)
  813. endif(WIN32 AND NOT VCPKG_BUILD)
  814. ## Link supertux binary with squirrel and other libraries
  815. add_dependencies(supertux2_lib tinygettext)
  816. add_dependencies(supertux2_lib squirrel)
  817. add_dependencies(supertux2_lib SDL_ttf)
  818. if(VCPKG_BUILD AND NOT EMSCRIPTEN)
  819. target_include_directories(supertux2_lib PUBLIC ${CURL_INCLUDE_DIRS})
  820. endif()
  821. target_include_directories(partio_zip_lib PUBLIC external/partio_zip/)
  822. if (NOT EMSCRIPTEN)
  823. target_include_directories(supertux2_lib SYSTEM PUBLIC ${SDL2_INCLUDE_DIRS})
  824. target_include_directories(supertux2_lib SYSTEM PUBLIC ${SDL2IMAGE_INCLUDE_DIRS})
  825. if(VCPKG_BUILD AND NOT WIN32)
  826. target_link_libraries(supertux2_lib PRIVATE SDL2::SDL2main SDL2::SDL2 SDL2::SDL2_image)
  827. else()
  828. target_link_libraries(supertux2_lib PUBLIC ${SDL2_LIBRARIES})
  829. target_link_libraries(supertux2_lib PUBLIC ${SDL2IMAGE_LIBRARIES})
  830. endif()
  831. endif()
  832. target_include_directories(supertux2_lib SYSTEM PUBLIC ${SDL_TTF_PREFIX}/include/SDL2)
  833. target_link_libraries(supertux2_lib PUBLIC SDL_ttf_lib)
  834. if(VCPKG_BUILD)
  835. target_link_libraries(supertux2_lib PUBLIC freetype)
  836. else()
  837. target_link_libraries(supertux2_lib PUBLIC ${FREETYPE_LIBRARIES})
  838. endif()
  839. if(RAQM_FOUND)
  840. target_link_libraries(supertux2_lib PUBLIC ${HARFBUZZ_LIBRARY} ${FRIBIDI_LIBRARY} ${RAQM_LIBRARY})
  841. endif()
  842. target_link_libraries(supertux2_lib PUBLIC squirrel_lib)
  843. target_link_libraries(supertux2_lib PUBLIC sqstdlib_lib)
  844. target_link_libraries(supertux2_lib PUBLIC tinygettext_lib)
  845. target_link_libraries(supertux2_lib PUBLIC sexp)
  846. target_link_libraries(supertux2_lib PUBLIC savepng)
  847. target_link_libraries(supertux2_lib PUBLIC partio_zip_lib)
  848. if(ENABLE_DISCORD)
  849. target_link_libraries(supertux2_lib PUBLIC discord-rpc)
  850. endif(ENABLE_DISCORD)
  851. if(NOT EMSCRIPTEN)
  852. if(VCPKG_BUILD)
  853. target_link_libraries(supertux2_lib PUBLIC OpenAL::OpenAL)
  854. else()
  855. target_link_libraries(supertux2_lib PUBLIC ${OPENAL_LIBRARY})
  856. endif()
  857. else()
  858. link_libraries(-lopenal)
  859. endif()
  860. target_link_libraries(supertux2_lib PUBLIC ${OGGVORBIS_LIBRARIES})
  861. target_link_libraries(supertux2_lib PUBLIC ${Boost_LIBRARIES})
  862. if(USE_SYSTEM_PHYSFS)
  863. target_link_libraries(supertux2_lib PUBLIC ${PHYSFS_LIBRARY})
  864. else()
  865. add_dependencies(supertux2_lib physfs)
  866. target_link_libraries(supertux2_lib PUBLIC physfs_lib)
  867. if(APPLE)
  868. target_link_libraries(supertux2_lib PUBLIC "-framework CoreFoundation")
  869. target_link_libraries(supertux2_lib PUBLIC "-framework Foundation")
  870. target_link_libraries(supertux2_lib PUBLIC "-framework IOKit")
  871. endif()
  872. endif()
  873. if(HAVE_OPENGL)
  874. target_link_libraries(supertux2_lib PUBLIC ${OPENGL_LIBRARY})
  875. if(NOT ENABLE_OPENGLES2)
  876. if(GLBINDING_FOUND)
  877. target_link_libraries(supertux2_lib PUBLIC ${GLBINDING_LIBRARIES})
  878. else()
  879. target_link_libraries(supertux2_lib PUBLIC GLEW::GLEW)
  880. endif()
  881. endif()
  882. endif(HAVE_OPENGL)
  883. if(NOT EMSCRIPTEN)
  884. if(HAVE_LIBCURL)
  885. if(VCPKG_BUILD)
  886. target_link_libraries(supertux2_lib PUBLIC ${CURL_LIBRARIES})
  887. else()
  888. target_link_libraries(supertux2_lib PUBLIC ${CURL_LIBRARY})
  889. endif()
  890. endif(HAVE_LIBCURL)
  891. endif(NOT EMSCRIPTEN)
  892. if(BUILD_TESTS)
  893. find_package(Threads REQUIRED)
  894. find_package(GTest REQUIRED)
  895. # build SuperTux tests
  896. file(GLOB_RECURSE TEST_SUPERTUX_SOURCES tests/*.cpp)
  897. add_executable(test_supertux2 ${TEST_SUPERTUX_SOURCES})
  898. target_compile_options(test_supertux2 PRIVATE ${WARNINGS_CXX_FLAGS})
  899. target_link_libraries(test_supertux2
  900. GTest::GTest GTest::Main
  901. supertux2_lib
  902. ${CMAKE_THREAD_LIBS_INIT})
  903. # add 'make test' target, use 'make test ARGS="-V"' or 'ctest -V' for verbose
  904. enable_testing()
  905. add_test(NAME test_supertux2
  906. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  907. COMMAND test_supertux2)
  908. # Prepare coverage with gcov/lcov
  909. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  910. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  911. target_compile_options(supertux2_lib PUBLIC -fprofile-arcs -ftest-coverage)
  912. target_link_options(supertux2_lib PUBLIC -lgcov --coverage)
  913. add_custom_target(coverage_clear_unix
  914. COMMAND find . -name "*.gcda" | xargs rm || true # FIXME: Make this platform-neutral
  915. COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/coverage.info
  916. COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/coverage)
  917. add_custom_target(coverage_unix
  918. COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target coverage_clear_unix
  919. COMMAND ${CMAKE_CTEST_COMMAND}
  920. COMMAND lcov --capture --directory ${CMAKE_CURRENT_BINARY_DIR} --exclude '/usr/*' --exclude '*/tests/*' --exclude '*/external/*' --output-file ${CMAKE_CURRENT_BINARY_DIR}/coverage.info
  921. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/coverage
  922. COMMAND genhtml ${CMAKE_CURRENT_BINARY_DIR}/coverage.info -o ${CMAKE_CURRENT_BINARY_DIR}/coverage -t "${SUPERTUX_VERSION_STRING}")
  923. else(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  924. message(WARNING "Coverage for non-GNU compilers has yet to be implemented")
  925. endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  926. else(CMAKE_BUILD_TYPE STREQUAL "Debug")
  927. message(WARNING "Building tests in a non-Debug build will NOT make files for coverage! Change CMAKE_BUILD_TYPE to Debug to prepare for coverage analysis.")
  928. endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
  929. endif()
  930. ## Install stuff
  931. option(DISABLE_CPACK_BUNDLING "Build an .app bundle without CPack" OFF)
  932. if(WIN32 AND NOT UNIX)
  933. set(INSTALL_SUBDIR_BIN "bin" CACHE STRING "Installation subdir for binaries")
  934. set(INSTALL_SUBDIR_SHARE "data" CACHE STRING "Installation subdir for data")
  935. set(INSTALL_SUBDIR_DOC "doc" CACHE STRING "Installation subdir for docs")
  936. if(VCPKG_BUILD)
  937. install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/" DESTINATION ${INSTALL_SUBDIR_BIN} FILES_MATCHING PATTERN "*.dll")
  938. else()
  939. install(FILES ${DLLS} DESTINATION ${INSTALL_SUBDIR_BIN})
  940. endif()
  941. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.png ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.ico DESTINATION ".")
  942. option(PACKAGE_VCREDIST "Package the VCREDIST libraries with the program" OFF)
  943. if(PACKAGE_VCREDIST)
  944. set(CMAKE_INSTALL_UCRT_LIBRARIES true)
  945. include(InstallRequiredSystemLibraries)
  946. endif()
  947. else(WIN32 AND NOT UNIX)
  948. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND DISABLE_CPACK_BUNDLING)
  949. set(INFOPLIST_CFBUNDLEEXECUTABLE "supertux2")
  950. set(INSTALL_SUBDIR_BIN "SuperTux.app/Contents/MacOS" CACHE STRING "Installation subdir for binaries")
  951. set(INSTALL_SUBDIR_SHARE "SuperTux.app/Contents/Resources/data" CACHE STRING "Installation subdir for data")
  952. set(INSTALL_SUBDIR_DOC "SuperTux.app/Contents/Resources" CACHE STRING "Installation subdir for docs")
  953. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/info.plist.in ${CMAKE_BINARY_DIR}/tools/darwin/info.plist)
  954. install(FILES ${CMAKE_BINARY_DIR}/tools/darwin/info.plist DESTINATION "SuperTux.app/Contents/")
  955. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/receipt DESTINATION "SuperTux.app/Contents/_MASReceipt/")
  956. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.png ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.icns DESTINATION "SuperTux.app/Contents/Resources/")
  957. else(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND DISABLE_CPACK_BUNDLING)
  958. set(INSTALL_SUBDIR_BIN "games" CACHE STRING "Installation subdir for binaries")
  959. set(INSTALL_SUBDIR_SHARE "share/games/supertux2" CACHE STRING "Installation subdir for data")
  960. set(INSTALL_SUBDIR_DOC "share/doc/supertux2" CACHE STRING "Installation subdir for docs")
  961. if(UBUNTU_TOUCH)
  962. set(LINUX_DESKTOP_ICON "assets/supertux-256x256.png")
  963. # FIXME: The "install" folder is a folder managed by Clickable and shouldn't be hardcoded here
  964. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/supertux2.desktop.in "install/supertux2.desktop")
  965. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mk/clickable/supertux2.apparmor DESTINATION ".")
  966. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mk/clickable/manifest.json.in ${CMAKE_CURRENT_BINARY_DIR}/install/manifest.json)
  967. set(APPS "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/supertux2")
  968. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux-256x256.png DESTINATION "assets")
  969. else(UBUNTU_TOUCH)
  970. set(LINUX_DESKTOP_ICON "supertux2")
  971. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/supertux2.desktop.in "supertux2.desktop")
  972. install(FILES ${CMAKE_BINARY_DIR}/supertux2.desktop DESTINATION "share/applications")
  973. set(APPS "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${INSTALL_SUBDIR_BIN}/supertux2")
  974. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.png ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.xpm DESTINATION "share/pixmaps/")
  975. endif(UBUNTU_TOUCH)
  976. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/supertux2.svg DESTINATION "share/icons/hicolor/scalable/apps")
  977. endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND DISABLE_CPACK_BUNDLING)
  978. endif(WIN32 AND NOT UNIX)
  979. if(UBUNTU_TOUCH)
  980. install(TARGETS supertux2 DESTINATION ".")
  981. else(UBUNTU_TOUCH)
  982. install(TARGETS supertux2 DESTINATION ${INSTALL_SUBDIR_BIN})
  983. endif(UBUNTU_TOUCH)
  984. if(WIN32)
  985. get_property(SQUIRREL_LIB_PATH TARGET squirrel_lib PROPERTY IMPORTED_LOCATION)
  986. get_property(SQSTDLIB_LIB_PATH TARGET sqstdlib_lib PROPERTY IMPORTED_LOCATION)
  987. if(NOT USE_SYSTEM_PHYSFS)
  988. get_property(PHYSFS_LIB_PATH TARGET physfs_lib PROPERTY IMPORTED_LOCATION)
  989. endif()
  990. install(FILES ${SQUIRREL_LIB_PATH} ${SQSTDLIB_LIB_PATH} ${PHYSFS_LIB_PATH} DESTINATION ${INSTALL_SUBDIR_BIN})
  991. endif()
  992. if(EMSCRIPTEN)
  993. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mk/emscripten/template.html.in ${CMAKE_CURRENT_BINARY_DIR}/template.html)
  994. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mk/emscripten/supertux2.png ${CMAKE_CURRENT_BINARY_DIR}/supertux2.png COPYONLY)
  995. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mk/emscripten/supertux2_bkg.png ${CMAKE_CURRENT_BINARY_DIR}/supertux2_bkg.png COPYONLY)
  996. endif(EMSCRIPTEN)
  997. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/INSTALL.md ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt ${CMAKE_CURRENT_SOURCE_DIR}/NEWS.md DESTINATION ${INSTALL_SUBDIR_DOC})
  998. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/credits.stxt DESTINATION ${INSTALL_SUBDIR_SHARE})
  999. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/supertux2.appdata.xml DESTINATION "share/metainfo" )
  1000. install(DIRECTORY
  1001. ${CMAKE_CURRENT_SOURCE_DIR}/data/images
  1002. ${CMAKE_CURRENT_SOURCE_DIR}/data/fonts
  1003. ${CMAKE_CURRENT_SOURCE_DIR}/data/music
  1004. ${CMAKE_CURRENT_SOURCE_DIR}/data/particles
  1005. ${CMAKE_CURRENT_SOURCE_DIR}/data/scripts
  1006. ${CMAKE_CURRENT_SOURCE_DIR}/data/shader
  1007. ${CMAKE_CURRENT_SOURCE_DIR}/data/speech
  1008. ${CMAKE_CURRENT_SOURCE_DIR}/data/sounds
  1009. ${CMAKE_CURRENT_SOURCE_DIR}/data/locale
  1010. DESTINATION ${INSTALL_SUBDIR_SHARE})
  1011. if(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo")
  1012. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/levels
  1013. DESTINATION ${INSTALL_SUBDIR_SHARE}
  1014. PATTERN "data/levels/test" EXCLUDE
  1015. PATTERN "data/levels/test_old" EXCLUDE
  1016. PATTERN "data/levels/incubator" EXCLUDE
  1017. PATTERN "data/levels/misc/menu.stl.in" EXCLUDE)
  1018. else()
  1019. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/levels
  1020. DESTINATION ${INSTALL_SUBDIR_SHARE}
  1021. PATTERN "data/levels/misc/menu.stl.in" EXCLUDE)
  1022. endif()
  1023. install(FILES "${CMAKE_BINARY_DIR}/data/levels/misc/menu.stl" DESTINATION "${INSTALL_SUBDIR_SHARE}/levels/misc")
  1024. ## Create config.h now that INSTALL_SUBDIR_* have been set.
  1025. configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )
  1026. ## Configure main menu logo
  1027. if(("${SUPERTUX_VERSION_STRING}" MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+$") OR IS_SUPERTUX_RELEASE)
  1028. set(LOGO_FILE "logo_final.sprite")
  1029. else()
  1030. set(LOGO_FILE "logo.sprite")
  1031. endif()
  1032. configure_file(data/levels/misc/menu.stl.in ${CMAKE_BINARY_DIR}/data/levels/misc/menu.stl )
  1033. ## CPack/Installation-specific stuff
  1034. include(InstallRequiredSystemLibraries)
  1035. set(DIRS ${Boost_LIBRARY_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/external/squirrel ${CMAKE_CURRENT_BINARY_DIR}/external/tinygettext)
  1036. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT DISABLE_CPACK_BUNDLING)
  1037. set(INFOPLIST_CFBUNDLEEXECUTABLE "SuperTux")
  1038. find_package(png)
  1039. foreach (_file ${PNG_LIBRARIES})
  1040. get_filename_component(_resolvedFile "${_file}" REALPATH)
  1041. get_filename_component(_name "${_file}" NAME)
  1042. install(FILES ${_resolvedFile} DESTINATION "MacOS" RENAME ${_name})
  1043. endforeach()
  1044. find_package(jpeg)
  1045. foreach (_file ${JPEG_LIBRARIES})
  1046. get_filename_component(_resolvedFile "${_file}" REALPATH)
  1047. get_filename_component(_name "${_file}" NAME)
  1048. install(FILES ${_resolvedFile} DESTINATION "MacOS" RENAME ${_name})
  1049. endforeach()
  1050. install(CODE "
  1051. if(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/\" MATCHES \".*\\\\.app.*\")
  1052. include(BundleUtilities)
  1053. fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")
  1054. endif()
  1055. ")
  1056. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/info.plist.in" "${CMAKE_BINARY_DIR}/tools/darwin/info.plist")
  1057. set(CPACK_BUNDLE_NAME "SuperTux")
  1058. set(CPACK_BUNDLE_PLIST "${CMAKE_BINARY_DIR}/tools/darwin/info.plist")
  1059. set(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.icns")
  1060. set(CPACK_BUNDLE_STARTUP_COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/startup.sh")
  1061. set(CPACK_DMG_VOLUME_NAME "SuperTux ${SUPERTUX_VERSION_STRING}")
  1062. set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/dsstore_setup.scpt")
  1063. set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/background.png")
  1064. endif()
  1065. set(CPACK_PACKAGE_NAME "SuperTux")
  1066. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Jump'n'Run Game featuring Tux")
  1067. set(CPACK_PACKAGE_VENDOR "SuperTux Devel Team")
  1068. set(CPACK_PACKAGE_CONTACT "SuperTux Devel Team <supertux-devel@lists.lethargik.org>")
  1069. set(CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;${CMAKE_BINARY_DIR};/\\\\..*")
  1070. set(CPACK_DEBIAN_PACKAGE_NAME "supertux2")
  1071. set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.5), libgcc1 (>= 1:4.1), libgl1-mesa-glx | libgl1, libogg0 (>= 1.1.3), libopenal0a, libphysfs-1.0-0, libsdl-image1.2 (>= 1.2.5), libsdl1.2debian (>= 1.2.10-1), libstdc++6 (>= 4.1.2), libvorbis0a (>= 1.1.2), libvorbisfile3 (>= 1.1.2), libcurl3 (>= 7.16)")
  1072. set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Classic 2D jump 'n run sidescroller with Tux\n SuperTux is a classic 2D jump 'n run sidescroller game in a similar\n style like the original SuperMario games. This release of SuperTux\n features 9 enemies, 26 playable levels, software and OpenGL rendering\n modes, configurable joystick and keyboard input, new music and\n completely redone graphics.\n .\n This is a development snapshot of SuperTux. It may suffer from\n critical bugs and has not been fully tested. \n .\n Homepage: http://supertux.lethargik.org/")
  1073. set(CPACK_DEBIAN_PACKAGE_SECTION "games")
  1074. set(CPACK_RPM_PACKAGE_NAME "supertux2")
  1075. set(CPACK_RPM_PACKAGE_DESCRIPTION "Classic 2D jump 'n run sidescroller with Tux\n SuperTux is a classic 2D jump 'n run sidescroller game in a similar\n style like the original SuperMario games. This release of SuperTux\n features 9 enemies, 26 playable levels, software and OpenGL rendering\n modes, configurable joystick and keyboard input, new music and\n completely redone graphics.\n .\n This is a development snapshot of SuperTux. It may suffer from\n critical bugs and has not been fully tested. \n .\n Homepage: http://supertux.lethargik.org/")
  1076. set(CPACK_RPM_PACKAGE_LICENSE "GNU General Public License (GPL)")
  1077. set(CPACK_RPM_PACKAGE_GROUP "Amusements/Games/Action/Arcade")
  1078. set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  1079. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
  1080. set(CPACK_PACKAGE_VERSION_MAJOR ${SUPERTUX_VERSION_MAJOR})
  1081. set(CPACK_PACKAGE_VERSION_MINOR ${SUPERTUX_VERSION_MINOR})
  1082. if(SUPERTUX_VERSION_TWEAK)
  1083. set(CPACK_PACKAGE_VERSION_PATCH "${SUPERTUX_VERSION_PATCH}.${SUPERTUX_VERSION_TWEAK}")
  1084. else()
  1085. set(CPACK_PACKAGE_VERSION_PATCH ${SUPERTUX_VERSION_PATCH})
  1086. endif(SUPERTUX_VERSION_TWEAK)
  1087. set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${SUPERTUX_VERSION_STRING}-${SUPERTUX_SYSTEM_NAME}")
  1088. set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${SUPERTUX_VERSION_STRING}-Source")
  1089. set(CPACK_PACKAGE_INSTALL_DIRECTORY "SuperTux")
  1090. set(CPACK_PACKAGE_EXECUTABLES "supertux2" "SuperTux")
  1091. if(WIN32 AND NOT UNIX)
  1092. set(CPACK_NSIS_INSTALLED_ICON_NAME "supertux2")
  1093. set(CPACK_NSIS_DISPLAY_NAME "SuperTux")
  1094. set(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
  1095. set(CPACK_WIX_PROGRAM_MENU_FOLDER "")
  1096. set(CPACK_WIX_UPGRADE_GUID "93E16F4E-0A68-422A-8ADC-47BE5B9433B2")
  1097. set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.ico")
  1098. set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/mk/wix/banner.png")
  1099. set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/mk/wix/dialog.png")
  1100. set(CPACK_GENERATOR WIX)
  1101. else(WIN32 AND NOT UNIX)
  1102. endif(WIN32 AND NOT UNIX)
  1103. include(CPack)
  1104. # move some config clutter to the advanced section
  1105. mark_as_advanced(
  1106. INSTALL_SUBDIR_BIN
  1107. INSTALL_SUBDIR_SHARE
  1108. INSTALL_SUBDIR_DOC
  1109. )
  1110. mark_as_advanced(
  1111. CMAKE_BACKWARDS_COMPATIBILITY
  1112. CMAKE_BUILD_TYPE
  1113. CMAKE_INSTALL_PREFIX
  1114. EXECUTABLE_OUTPUT_PATH
  1115. LIBRARY_OUTPUT_PATH
  1116. CMAKE_OSX_ARCHITECTURES
  1117. CMAKE_OSX_SYSROOT
  1118. )
  1119. mark_as_advanced(
  1120. APPDATADIR
  1121. )
  1122. mark_as_advanced(
  1123. Boost_INCLUDE_DIR
  1124. Boost_LIBRARIES
  1125. )
  1126. mark_as_advanced(
  1127. GLEW_INCLUDE_DIR
  1128. GLEW_LIBRARY
  1129. )
  1130. mark_as_advanced(
  1131. SDL2_INCLUDE_DIRS
  1132. SDL2_LIBRARIES
  1133. )
  1134. mark_as_advanced(
  1135. SDL2IMAGE_INCLUDE_DIRS
  1136. SDL2IMAGE_LIBRARIES
  1137. )
  1138. mark_as_advanced(
  1139. OPENAL_INCLUDE_DIR
  1140. OPENAL_LIBRARY
  1141. )
  1142. mark_as_advanced(
  1143. SDL2TTF_INCLUDE_DIRS
  1144. SDL2TTF_LIBRARIES
  1145. )
  1146. mark_as_advanced(
  1147. OGG_LIBRARY
  1148. VORBISENC_LIBRARY
  1149. VORBISFILE_LIBRARY
  1150. VORBIS_INCLUDE_DIR
  1151. VORBIS_LIBRARY
  1152. )
  1153. mark_as_advanced(
  1154. PHYSFS_INCLUDE_DIR
  1155. PHYSFS_LIBRARY
  1156. )