CMakeLists.txt 52 KB

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