CMakeLists.txt 51 KB

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