CMakeLists.txt 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  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. # allow building with CMake 2.8. Set compatibility options. Use some bundled modules as a fallback
  35. CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
  36. IF(COMMAND cmake_policy)
  37. CMAKE_POLICY(SET CMP0003 NEW)
  38. CMAKE_POLICY(SET CMP0008 NEW)
  39. CMAKE_POLICY(SET CMP0023 NEW)
  40. IF(POLICY CMP0043)
  41. CMAKE_POLICY(SET CMP0043 OLD)
  42. ENDIF(POLICY CMP0043)
  43. ENDIF(COMMAND cmake_policy)
  44. SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/mk/cmake)
  45. INCLUDE(ConfigureFiles)
  46. INCLUDE(ExternalProject)
  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. INCLUDE(TestBigEndian)
  53. TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
  54. ## Add definitions
  55. IF(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo")
  56. ADD_DEFINITIONS(-DRELEASE)
  57. ELSEIF(CMAKE_BUILD_TYPE MATCHES Debug)
  58. ADD_DEFINITIONS(-DDEBUG)
  59. ENDIF()
  60. SET(SUPERTUX_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
  61. ## These variables enable MSVC to find libraries located in "dependencies{32|64}"
  62. IF(WIN32)
  63. ## Store path of dependecy folder
  64. SET(DEPENDENCY_FOLDER "${PROJECT_SOURCE_DIR}/dependencies")
  65. ## To test if the host (not the build) is x64:
  66. ## "$ENV{PROCESSOR_ARCHITEW6432}" STREQUAL "AMD64"
  67. IF(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
  68. SET(WIN64 ON)
  69. SET(DEPENDENCY_FOLDER "${DEPENDENCY_FOLDER}64")
  70. ELSE(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
  71. SET(WIN64 OFF)
  72. SET(DEPENDENCY_FOLDER "${DEPENDENCY_FOLDER}32")
  73. ENDIF(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
  74. IF(WIN64)
  75. SET(SUPERTUX_SYSTEM_NAME win64)
  76. ELSE(WIN64)
  77. SET(SUPERTUX_SYSTEM_NAME win32)
  78. ENDIF(WIN64)
  79. SET(ENV{PATH} "$ENV{PATH};${DEPENDENCY_FOLDER}/include")
  80. SET(ENV{LIB} "${DEPENDENCY_FOLDER}/lib")
  81. SET(ENV{OPENALDIR} "${DEPENDENCY_FOLDER}")
  82. SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG)
  83. ## Enable multi-processor compilation (faster)
  84. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  85. ## And shut up about unsafe stuff
  86. ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
  87. ## Add an icon
  88. CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/mk/msvc/icon_rc.template" "${PROJECT_BINARY_DIR}/tmp/icon.rc")
  89. ## Find all used libraries
  90. FILE(GLOB DLLS "${DEPENDENCY_FOLDER}/dll/*")
  91. ENDIF(WIN32)
  92. ## Add lots of dependencies to compiler switches
  93. SET(Boost_ADDITIONAL_VERSIONS "1.41" "1.41.0")
  94. IF(WIN32)
  95. OPTION(ENABLE_BOOST_STATIC_LIBS "Use boost static libraries" ON)
  96. ELSE(WIN32)
  97. OPTION(ENABLE_BOOST_STATIC_LIBS "Use boost static libraries" OFF)
  98. ENDIF(WIN32)
  99. IF(ENABLE_BOOST_STATIC_LIBS)
  100. SET(Boost_USE_STATIC_LIBS TRUE)
  101. ELSE(ENABLE_BOOST_STATIC_LIBS)
  102. SET(Boost_USE_STATIC_LIBS FALSE)
  103. ENDIF(ENABLE_BOOST_STATIC_LIBS)
  104. FIND_PACKAGE(Boost REQUIRED COMPONENTS filesystem system date_time locale)
  105. INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIR})
  106. LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
  107. IF(WIN32)
  108. FIND_PATH(SDL2_INCLUDE_DIRS NAMES SDL.h PATHS "${DEPENDENCY_FOLDER}/include/SDL2")
  109. FIND_PATH(SDL2IMAGE_INCLUDE_DIRS NAMES SDL_image.h PATHS "${DEPENDENCY_FOLDER}/include/SDL2_image")
  110. FIND_LIBRARY(SDL2_LIBRARIES NAMES SDL2 PATHS "${DEPENDENCY_FOLDER}/lib")
  111. FIND_LIBRARY(SDL2IMAGE_LIBRARIES NAMES SDL2_image PATHS "${DEPENDENCY_FOLDER}/lib")
  112. FIND_LIBRARY(SDL2MAIN_LIBRARIES NAMES SDL2main PATHS "${DEPENDENCY_FOLDER}/lib")
  113. FIND_PATH(PHYSFS_INCLUDE_DIR NAMES physfs.h PATHS "${DEPENDENCY_FOLDER}/include/physfs")
  114. ELSE(WIN32)
  115. INCLUDE(FindPkgConfig)
  116. PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2>=2.0.1)
  117. PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
  118. ENDIF(WIN32)
  119. SET(HAVE_SDL TRUE)
  120. OPTION(BUILD_TESTS "Build test cases" OFF)
  121. OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
  122. OPTION(GLBINDING_ENABLED "Use glbinding instead of GLEW" OFF)
  123. OPTION(GLBINDING_DEBUG_OUTPUT "Enable glbinding debug output for each called OpenGL function" OFF)
  124. IF(ENABLE_OPENGL)
  125. FIND_PACKAGE(OpenGL)
  126. IF(OPENGL_FOUND)
  127. INCLUDE_DIRECTORIES(SYSTEM ${OPENGL_INCLUDE_DIR})
  128. SET(HAVE_OPENGL TRUE)
  129. ENDIF(OPENGL_FOUND)
  130. IF(GLBINDING_ENABLED)
  131. FIND_PACKAGE(GLBINDING REQUIRED)
  132. IF(GLBINDING_FOUND)
  133. INCLUDE_DIRECTORIES(SYSTEM ${GLBINDING_INCLUDES})
  134. ADD_DEFINITIONS(-DUSE_GLBINDING)
  135. IF (GLBINDING_DEBUG_OUTPUT)
  136. ADD_DEFINITIONS(-DUSE_GLBINDING_DEBUG_OUTPUT)
  137. ENDIF()
  138. ENDIF()
  139. ELSE()
  140. FIND_PACKAGE(GLEW REQUIRED)
  141. IF(GLEW_FOUND)
  142. INCLUDE_DIRECTORIES(SYSTEM ${GLEW_INCLUDE_DIR})
  143. ENDIF(GLEW_FOUND)
  144. ENDIF()
  145. ENDIF(ENABLE_OPENGL)
  146. FIND_PACKAGE(OpenAL REQUIRED)
  147. INCLUDE_DIRECTORIES(SYSTEM ${OPENAL_INCLUDE_DIR})
  148. FIND_PACKAGE(OggVorbis REQUIRED)
  149. INCLUDE_DIRECTORIES(SYSTEM ${VORBIS_INCLUDE_DIR})
  150. INCLUDE(CheckSymbolExists)
  151. FIND_PACKAGE(PhysFS)
  152. CHECK_SYMBOL_EXISTS("PHYSFS_getPrefDir" "${PHYSFS_INCLUDE_DIR}/physfs.h" HAVE_PHYSFS_GETPREFDIR)
  153. IF(HAVE_PHYSFS_GETPREFDIR)
  154. SET(USE_SYSTEM_PHYSFS ON CACHE BOOL "Use preinstalled physfs (must support getPrefDir)")
  155. ELSE(HAVE_PHYSFS_GETPREFDIR)
  156. SET(USE_SYSTEM_PHYSFS OFF CACHE BOOL "Use preinstalled physfs (must support getPrefDir)")
  157. ENDIF(HAVE_PHYSFS_GETPREFDIR)
  158. IF(NOT USE_SYSTEM_PHYSFS)
  159. IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/physfs/CMakeLists.txt)
  160. message(FATAL_ERROR "physfs submodule is not checked out or ${CMAKE_CURRENT_SOURCE_DIR}/external/physfs/CMakeLists.txt is missing")
  161. ENDIF()
  162. IF(WIN32)
  163. SET(PHYSFS_BUILD_SHARED TRUE)
  164. SET(PHYSFS_BUILD_STATIC FALSE)
  165. ELSE(WIN32)
  166. SET(PHYSFS_BUILD_SHARED FALSE)
  167. SET(PHYSFS_BUILD_STATIC TRUE)
  168. ENDIF()
  169. SET(PHYSFS_PREFIX ${CMAKE_BINARY_DIR}/physfs/)
  170. ExternalProject_Add(physfs
  171. SOURCE_DIR "${CMAKE_SOURCE_DIR}/external/physfs/"
  172. CMAKE_ARGS
  173. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  174. -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
  175. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  176. -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
  177. -DCMAKE_INSTALL_PREFIX=${PHYSFS_PREFIX}
  178. -DLIB_SUFFIX=${LIB_SUFFIX}
  179. -DPHYSFS_BUILD_SHARED=${PHYSFS_BUILD_SHARED}
  180. -DPHYSFS_BUILD_STATIC=${PHYSFS_BUILD_STATIC}
  181. -DPHYSFS_BUILD_TEST=FALSE)
  182. IF(WIN32)
  183. ADD_LIBRARY(physfs_lib SHARED IMPORTED)
  184. SET_TARGET_PROPERTIES(physfs_lib PROPERTIES IMPORTED_LOCATION "${PHYSFS_PREFIX}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}physfs${CMAKE_SHARED_LIBRARY_SUFFIX}")
  185. SET_TARGET_PROPERTIES(physfs_lib PROPERTIES IMPORTED_IMPLIB "${PHYSFS_PREFIX}/lib${LIB_SUFFIX}/physfs${CMAKE_LINK_LIBRARY_SUFFIX}")
  186. ELSE()
  187. ADD_LIBRARY(physfs_lib STATIC IMPORTED)
  188. SET_TARGET_PROPERTIES(physfs_lib PROPERTIES IMPORTED_LOCATION "${PHYSFS_PREFIX}/lib${LIB_SUFFIX}/${CMAKE_STATIC_LIBRARY_PREFIX}physfs${CMAKE_STATIC_LIBRARY_SUFFIX}")
  189. ENDIF()
  190. SET(PHYSFS_INCLUDE_DIR "${PHYSFS_PREFIX}/include/")
  191. ENDIF()
  192. INCLUDE_DIRECTORIES(BEFORE SYSTEM ${PHYSFS_INCLUDE_DIR})
  193. ## The curl headers are in the standard include path in dependencies
  194. ## so it's not required to add them here
  195. FIND_PACKAGE(CURL REQUIRED)
  196. IF(CURL_FOUND)
  197. INCLUDE_DIRECTORIES(SYSTEM ${CURL_INCLUDE_DIR})
  198. SET(HAVE_LIBCURL TRUE)
  199. ENDIF(CURL_FOUND)
  200. #FIND_PACKAGE(ICONV REQUIRED)
  201. #INCLUDE_DIRECTORIES(SYSTEM ${ICONV_INCLUDE_DIR})
  202. #LINK_LIBRARIES(${ICONV_LIBRARY})
  203. IF(EXISTS "${CMAKE_SOURCE_DIR}/.git")
  204. ## Find revision of WC
  205. MARK_AS_ADVANCED(GIT_EXECUTABLE)
  206. FIND_PROGRAM(GIT_EXECUTABLE git)
  207. IF(NOT GIT_EXECUTABLE EQUAL "GIT_EXECUTABLE-NOTFOUND")
  208. INCLUDE(GetGitRevisionDescription)
  209. git_describe(VERSION_STRING_GIT "--tags" "--match" "?[0-9]*.[0-9]*.[0-9]*")
  210. STRING(REPLACE "v" "" VERSION_LIST ${VERSION_STRING_GIT})
  211. STRING(REGEX REPLACE "(-|_|\\.)" ";" VERSION_LIST ";${VERSION_LIST}")
  212. ENDIF()
  213. ENDIF(EXISTS "${CMAKE_SOURCE_DIR}/.git")
  214. GET_FILENAME_COMPONENT(BASEDIR ${CMAKE_SOURCE_DIR} NAME)
  215. IF("${VERSION_LIST}" STREQUAL "")
  216. IF(${BASEDIR} MATCHES "supertux2-[0-9\\.]*")
  217. STRING(REGEX REPLACE "(\\.|_|-)" ";" VERSION_LIST ${BASEDIR})
  218. ENDIF()
  219. ENDIF()
  220. FILE(GLOB ORIG_TGZ ../*.orig.tar.gz)
  221. IF("${VERSION_LIST}" STREQUAL "" AND (NOT "${ORIG_TGZ}" STREQUAL ""))
  222. GET_FILENAME_COMPONENT(BASEDIR ${ORIG_TGZ} NAME)
  223. STRING(REGEX REPLACE "(\\.|_|-)" ";" VERSION_LIST ${BASEDIR})
  224. ENDIF()
  225. LIST(LENGTH VERSION_LIST VERSION_LIST_SIZE)
  226. IF(${VERSION_LIST_SIZE} GREATER 0)
  227. LIST(GET VERSION_LIST 1 MAJOR_VERSION_GIT)
  228. LIST(GET VERSION_LIST 2 MINOR_VERSION_GIT)
  229. LIST(GET VERSION_LIST 3 PATCH_VERSION_GIT)
  230. IF("${VERSION_STRING_GIT}" STREQUAL "")
  231. SET(VERSION_STRING_GIT "${MAJOR_VERSION_GIT}.${MINOR_VERSION_GIT}.${PATCH_VERSION_GIT}")
  232. ENDIF()
  233. CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/version.cmake.in" "${CMAKE_SOURCE_DIR}/version.cmake")
  234. ENDIF()
  235. IF(NOT EXISTS "${CMAKE_SOURCE_DIR}/version.cmake")
  236. MESSAGE( SEND_ERROR "Cound not find GIT or valid version.cmake. Version information will be invalid." )
  237. ENDIF(NOT EXISTS "${CMAKE_SOURCE_DIR}/version.cmake")
  238. INCLUDE("${CMAKE_SOURCE_DIR}/version.cmake")
  239. SET(SUPERTUX_VERSION ${SUPERTUX_VERSION_STRING})
  240. configure_file(version.h.in ${CMAKE_BINARY_DIR}/version.h )
  241. SET_SOURCE_FILES_PROPERTIES(${CMAKE_BINARY_DIR}/version.h
  242. PROPERTIES GENERATED true)
  243. SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/src/supertux/main.cpp
  244. PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")
  245. SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/src/supertux/title_screen.cpp
  246. PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")
  247. SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/src/addon/addon_manager.cpp
  248. PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")
  249. ## Configure doxygen
  250. # Adapted from https://tty1.net/blog/2014/cmake-doxygen_en.html
  251. # add a target to generate API documentation with Doxygen
  252. find_package(Doxygen)
  253. option(BUILD_DOCUMENTATION "Build API documentation using Doxygen" ${DOXYGEN_FOUND})
  254. if(BUILD_DOCUMENTATION)
  255. if(NOT DOXYGEN_FOUND)
  256. message(FATAL_ERROR "Doxygen is needed to build the documentation.")
  257. endif()
  258. set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
  259. set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile)
  260. configure_file(${doxyfile_in} ${doxyfile} @ONLY)
  261. add_custom_target(doc
  262. COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
  263. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  264. COMMENT "Generating API documentation with Doxygen"
  265. VERBATIM)
  266. endif()
  267. ## Check platform-dependent build options
  268. INCLUDE(ConfigureChecks)
  269. ## Also build external/squirrel
  270. IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/squirrel/CMakeLists.txt)
  271. message(FATAL_ERROR "squirrel submodule is not checked out or ${CMAKE_CURRENT_SOURCE_DIR}/external/squirrel/CMakeLists.txt is missing")
  272. ENDIF()
  273. SET(SQUIRREL_PREFIX ${CMAKE_BINARY_DIR}/squirrel/)
  274. ExternalProject_Add(squirrel
  275. SOURCE_DIR "${CMAKE_SOURCE_DIR}/external/squirrel/"
  276. CMAKE_ARGS
  277. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  278. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  279. -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
  280. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  281. -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
  282. -DCMAKE_INSTALL_PREFIX=${SQUIRREL_PREFIX}
  283. -DINSTALL_INC_DIR=include)
  284. IF(WIN32)
  285. ADD_LIBRARY(squirrel_lib SHARED IMPORTED)
  286. SET_TARGET_PROPERTIES(squirrel_lib PROPERTIES IMPORTED_LOCATION "${SQUIRREL_PREFIX}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}squirrel${CMAKE_SHARED_LIBRARY_SUFFIX}")
  287. SET_TARGET_PROPERTIES(squirrel_lib PROPERTIES IMPORTED_IMPLIB "${SQUIRREL_PREFIX}/lib/squirrel${CMAKE_LINK_LIBRARY_SUFFIX}")
  288. ADD_LIBRARY(sqstdlib_lib SHARED IMPORTED)
  289. SET_TARGET_PROPERTIES(sqstdlib_lib PROPERTIES IMPORTED_LOCATION "${SQUIRREL_PREFIX}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}sqstdlib${CMAKE_SHARED_LIBRARY_SUFFIX}")
  290. SET_TARGET_PROPERTIES(sqstdlib_lib PROPERTIES IMPORTED_IMPLIB "${SQUIRREL_PREFIX}/lib/sqstdlib${CMAKE_LINK_LIBRARY_SUFFIX}")
  291. #For debug run purposes
  292. CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/mk/msvc/run_supertux.bat.in" "${PROJECT_BINARY_DIR}/run_supertux.bat")
  293. ELSE()
  294. ADD_LIBRARY(squirrel_lib STATIC IMPORTED)
  295. SET_TARGET_PROPERTIES(squirrel_lib PROPERTIES IMPORTED_LOCATION "${SQUIRREL_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}squirrel_static${CMAKE_STATIC_LIBRARY_SUFFIX}")
  296. ADD_LIBRARY(sqstdlib_lib STATIC IMPORTED)
  297. SET_TARGET_PROPERTIES(sqstdlib_lib PROPERTIES IMPORTED_LOCATION "${SQUIRREL_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}sqstdlib_static${CMAKE_STATIC_LIBRARY_SUFFIX}")
  298. ENDIF()
  299. INCLUDE_DIRECTORIES(SYSTEM ${SQUIRREL_PREFIX}/include)
  300. ## Also build external/tinygettext
  301. IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinygettext/CMakeLists.txt)
  302. message(FATAL_ERROR "tinygettext submodule is not checked out or ${CMAKE_CURRENT_SOURCE_DIR}/external/tinygettext/CMakeLists.txt is missing")
  303. ENDIF()
  304. set(TINYGETTEXT_PREFIX ${CMAKE_BINARY_DIR}/tinygettext/)
  305. ExternalProject_Add(tinygettext
  306. SOURCE_DIR "${CMAKE_SOURCE_DIR}/external/tinygettext/"
  307. CMAKE_ARGS
  308. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  309. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  310. -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
  311. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  312. -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
  313. -DBUILD_SHARED_LIBS=OFF
  314. -DHAVE_SDL=ON
  315. -DCMAKE_INSTALL_PREFIX=${TINYGETTEXT_PREFIX}
  316. -DSDL2_INCLUDE_DIRS=${SDL2_INCLUDE_DIRS}
  317. -DLIB_SUFFIX=${LIB_SUFFIX})
  318. ADD_LIBRARY(tinygettext_lib STATIC IMPORTED)
  319. SET_TARGET_PROPERTIES(tinygettext_lib PROPERTIES IMPORTED_LOCATION "${TINYGETTEXT_PREFIX}/lib${LIB_SUFFIX}/${CMAKE_STATIC_LIBRARY_PREFIX}tinygettext${CMAKE_STATIC_LIBRARY_SUFFIX}")
  320. INCLUDE_DIRECTORIES(SYSTEM ${TINYGETTEXT_PREFIX}/include)
  321. ## Some additional include paths
  322. include_directories(${CMAKE_BINARY_DIR}/)
  323. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
  324. include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/findlocale/)
  325. include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/obstack/)
  326. include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/sexp-cpp/include/)
  327. IF(WIN32)
  328. ADD_DEFINITIONS(-D_USE_MATH_DEFINES -DNOMINMAX)
  329. ADD_DEFINITIONS(-DWIN32)
  330. ENDIF(WIN32)
  331. ## Build list of sources for supertux binary
  332. FILE(GLOB SUPERTUX_SOURCES_C RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} external/obstack/*.c external/findlocale/findlocale.c)
  333. FILE(GLOB SUPERTUX_SOURCES_CXX RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*/*.cpp src/supertux/menu/*.cpp src/video/sdl/*.cpp)
  334. FILE(GLOB SUPERTUX_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${PROJECT_BINARY_DIR}/tmp/*.rc")
  335. IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/sexp-cpp/CMakeLists.txt)
  336. message(FATAL_ERROR "sexp-cpp submodule is not checked out or ${CMAKE_CURRENT_SOURCE_DIR}/external/sexp-cpp/CMakeLists.txt is missing")
  337. ENDIF()
  338. FILE(GLOB SEXP_SOURCES_CXX RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} external/sexp-cpp/src/*.cpp)
  339. ADD_LIBRARY(sexp STATIC ${SEXP_SOURCES_CXX})
  340. IF(HAVE_OPENGL)
  341. FILE(GLOB SUPERTUX_OPENGL_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/video/gl/*.cpp)
  342. SET(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${SUPERTUX_OPENGL_SOURCES})
  343. ENDIF(HAVE_OPENGL)
  344. ## Sort source lists to have deterministic linking order
  345. LIST(SORT SUPERTUX_SOURCES_C)
  346. LIST(SORT SUPERTUX_SOURCES_CXX)
  347. LIST(SORT SUPERTUX_RESOURCES)
  348. IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
  349. SET(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
  350. ENDIF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
  351. ## Compile everything at once (roughly equivalent to cat *.cpp | gcc)
  352. OPTION(COMPILE_AMALGATION "Compile all the files together at once (experimental)" OFF)
  353. IF(COMPILE_AMALGATION)
  354. FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp "// Includes all source files of the project\n")
  355. FOREACH(ST_FILE ${SUPERTUX_SOURCES_CXX})
  356. FILE(RELATIVE_PATH CXX_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src "${CMAKE_CURRENT_SOURCE_DIR}/${ST_FILE}")
  357. FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp "#include \"${CXX_FILE}\"\n")
  358. ENDFOREACH(ST_FILE)
  359. ## Build instead of CXX sources
  360. SET(SUPERTUX_SOURCES_CXX ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  361. ELSE(COMPILE_AMALGATION)
  362. IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  363. FILE(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  364. ENDIF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  365. ENDIF(COMPILE_AMALGATION)
  366. ## Debug options
  367. OPTION(WERROR "Stop on first compiler warning" OFF)
  368. OPTION(WARNINGS "Enable long list of warnings for compiler to check" OFF)
  369. if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  370. # http://www.guyrutenberg.com/2014/01/05/enabling-c11-c0x-in-cmake/
  371. include(CheckCXXCompilerFlag)
  372. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  373. if(COMPILER_SUPPORTS_CXX11)
  374. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  375. else(COMPILER_SUPPORTS_CXX11)
  376. CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
  377. if(COMPILER_SUPPORTS_CXX0X)
  378. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  379. else(COMPILER_SUPPORTS_CXX0X)
  380. message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  381. endif(COMPILER_SUPPORTS_CXX0X)
  382. endif(COMPILER_SUPPORTS_CXX11)
  383. SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
  384. SET(CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
  385. SET(CMAKE_CXX_FLAGS_PROFILE "-pg" CACHE STRING "Profile flags")
  386. SET(CMAKE_C_FLAGS_PROFILE "-pg" CACHE STRING "Profile flags")
  387. SET(CMAKE_LD_FLAGS_PROFILE "-lgmon" CACHE STRING "Profile flags")
  388. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -funit-at-a-time")
  389. IF(WERROR)
  390. ADD_DEFINITIONS(-Werror)
  391. ELSE(WERROR)
  392. REMOVE_DEFINITIONS(-Werror)
  393. ENDIF(WERROR)
  394. IF(WARNINGS)
  395. # temporarily disabled:
  396. # -Wsign-conversion -Wfloat-equal -Wconversion -Wundef -Wswitch-default
  397. # -Wswitch-enum -Wsign-promo -Wcast-qual -Woverloaded-virtual -Wmissing-format-attribute
  398. # -Wold-style-cast -Wpadded -Wabi -Winline -Wunsafe-loop-optimizations -Wstrict-overflow=5
  399. # fails on MinGW:
  400. # -ansi
  401. # fails on clang:
  402. # -Wlogical-op -Wstrict-null-sentinel
  403. SET(SUPERTUX2_EXTRA_WARNING_FLAGS "-fdiagnostics-show-option -pedantic -Wno-long-long -Wcast-align -Wdisabled-optimization -Winit-self -Winvalid-pch -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wredundant-decls -Wstack-protector -Wformat=2 -Weffc++ -Wctor-dtor-privacy -Wno-unused-parameter -Wshadow -Wnon-virtual-dtor -Wcast-qual")
  404. ENDIF(WARNINGS)
  405. endif()
  406. ## If xgettext is available, generate messages.pot for sources
  407. OPTION(GENERATE_MESSAGESPOT "Generate messages.pot files" OFF)
  408. IF(GENERATE_MESSAGESPOT)
  409. MARK_AS_ADVANCED(
  410. XGETTEXT_EXECUTABLE
  411. )
  412. FIND_PROGRAM(XGETTEXT_EXECUTABLE xgettext)
  413. IF(NOT XGETTEXT_EXECUTABLE)
  414. MESSAGE(STATUS "Warning: xgettext not found - will not update messages.pot")
  415. ELSE(NOT XGETTEXT_EXECUTABLE)
  416. MESSAGE(STATUS "Found xgettext: ${XGETTEXT_EXECUTABLE}")
  417. SET(MESSAGES_POT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/data/locale/messages.pot)
  418. ADD_CUSTOM_COMMAND(
  419. OUTPUT ${MESSAGES_POT_FILE}
  420. COMMAND ${XGETTEXT_EXECUTABLE}
  421. ARGS --keyword=_ --language=C++ --output=${MESSAGES_POT_FILE} ${SUPERTUX_SOURCES_CXX}
  422. DEPENDS ${SUPERTUX_SOURCES_CXX}
  423. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  424. COMMENT "Generating POT file ${MESSAGES_POT_FILE}"
  425. )
  426. LIST(APPEND MESSAGES_POT_FILES ${MESSAGES_POT_FILE})
  427. FILE(GLOB SUPERTUX_LEVEL_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} data/levels/*)
  428. FOREACH(SUPERTUX_LEVEL_DIR ${SUPERTUX_LEVEL_DIRS})
  429. FILE(GLOB SUPERTUX_LEVELS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${SUPERTUX_LEVEL_DIR}/*.stl ${SUPERTUX_LEVEL_DIR}/*.stwm ${SUPERTUX_LEVEL_DIR}/*.txt)
  430. ## Do not add target if SUPERTUX_LEVELS is empty. This is needed for cmake <=2.4
  431. IF(SUPERTUX_LEVELS)
  432. SET(MESSAGES_POT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${SUPERTUX_LEVEL_DIR}/messages.pot)
  433. ADD_CUSTOM_COMMAND(
  434. OUTPUT ${MESSAGES_POT_FILE}
  435. COMMAND ${XGETTEXT_EXECUTABLE}
  436. ARGS --keyword="_:1" --language=Lisp --force-po --sort-by-file "--output=${MESSAGES_POT_FILE}" ${SUPERTUX_LEVELS}
  437. DEPENDS ${SUPERTUX_LEVELS}
  438. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  439. COMMENT "Generating POT file ${MESSAGES_POT_FILE}"
  440. )
  441. LIST(APPEND MESSAGES_POT_FILES ${MESSAGES_POT_FILE})
  442. ENDIF(SUPERTUX_LEVELS)
  443. ENDFOREACH(SUPERTUX_LEVEL_DIR)
  444. ADD_CUSTOM_TARGET(
  445. supertux2-messages ALL
  446. DEPENDS ${MESSAGES_POT_FILES}
  447. )
  448. ENDIF(NOT XGETTEXT_EXECUTABLE)
  449. ENDIF(GENERATE_MESSAGESPOT)
  450. ## Some additional compiler switches
  451. if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  452. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
  453. endif()
  454. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  455. ADD_DEFINITIONS(-DMACOSX)
  456. ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  457. ## On Windows, add an icon
  458. IF(WIN32)
  459. # SET(SUPERTUX_SOURCES_C ${SUPERTUX_SOURCES_C} ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc)
  460. IF(MINGW)
  461. ADD_CUSTOM_COMMAND(
  462. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o
  463. 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)
  464. SET(SUPERTUX_SOURCES_C ${SUPERTUX_SOURCES_C} ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o)
  465. ENDIF(MINGW)
  466. ENDIF(WIN32)
  467. ## Build miniswig and generate miniswig wrapper
  468. OPTION(GENERATE_WRAPPER "Build miniswig and generate the wrapper" OFF)
  469. IF(GENERATE_WRAPPER)
  470. ADD_SUBDIRECTORY(tools/miniswig)
  471. ADD_CUSTOM_COMMAND(
  472. OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp
  473. COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_CXX_COMPILER}
  474. 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
  475. COMMAND tools/miniswig/miniswig
  476. 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
  477. DEPENDS tools/miniswig/miniswig
  478. IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.interface.hpp
  479. )
  480. ENDIF(GENERATE_WRAPPER)
  481. ## Generate supertux executable in the right place
  482. #SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
  483. SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
  484. ## Add target for supertux binary
  485. add_library(supertux2_c OBJECT ${SUPERTUX_SOURCES_C})
  486. add_library(supertux2_lib STATIC ${CMAKE_BINARY_DIR}/version.h ${SUPERTUX_SOURCES_CXX} ${SUPERTUX_RESOURCES} $<TARGET_OBJECTS:supertux2_c>)
  487. IF(WIN32)
  488. add_executable(supertux2 WIN32 src/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc)
  489. TARGET_LINK_LIBRARIES(supertux2 ${SDL2MAIN_LIBRARIES})
  490. ELSE()
  491. add_executable(supertux2 src/main.cpp)
  492. ENDIF(WIN32)
  493. target_link_libraries(supertux2 supertux2_lib)
  494. set_target_properties(supertux2 PROPERTIES OUTPUT_NAME supertux2)
  495. set_target_properties(supertux2_lib PROPERTIES OUTPUT_NAME supertux2)
  496. set_target_properties(supertux2_lib PROPERTIES COMPILE_FLAGS "${SUPERTUX2_EXTRA_WARNING_FLAGS}")
  497. IF(WIN32)
  498. ## Copy dlls on windows
  499. ADD_CUSTOM_COMMAND(TARGET supertux2_lib POST_BUILD
  500. COMMAND ${CMAKE_COMMAND} -E copy_directory
  501. "${DEPENDENCY_FOLDER}/dll"
  502. $<TARGET_FILE_DIR:supertux2_lib>)
  503. # ADD_CUSTOM_COMMAND(TARGET supertux2 POST_BUILD
  504. # COMMAND ${CMAKE_COMMAND} -E copy
  505. # "${DEPENDENCY_FOLDER}/DigiCertHighAssuranceEVRootCA.pem"
  506. # $<TARGET_FILE_DIR:supertux2_lib>)
  507. ENDIF(WIN32)
  508. ## Link supertux binary with squirrel and other libraries
  509. ADD_DEPENDENCIES(supertux2_lib tinygettext)
  510. ADD_DEPENDENCIES(supertux2_lib squirrel)
  511. TARGET_INCLUDE_DIRECTORIES(supertux2_lib SYSTEM PUBLIC ${SDL2_INCLUDE_DIRS})
  512. TARGET_INCLUDE_DIRECTORIES(supertux2_lib SYSTEM PUBLIC ${SDL2IMAGE_INCLUDE_DIRS})
  513. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC ${SDL2_LIBRARIES})
  514. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC ${SDL2IMAGE_LIBRARIES})
  515. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC squirrel_lib)
  516. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC sqstdlib_lib)
  517. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC tinygettext_lib)
  518. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC sexp)
  519. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC ${OPENAL_LIBRARY})
  520. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC ${OGGVORBIS_LIBRARIES})
  521. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC ${Boost_LIBRARIES})
  522. IF(USE_SYSTEM_PHYSFS)
  523. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC ${PHYSFS_LIBRARY})
  524. ELSE()
  525. ADD_DEPENDENCIES(supertux2_lib physfs)
  526. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC physfs_lib)
  527. IF(APPLE)
  528. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC "-framework CoreFoundation")
  529. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC "-framework Foundation")
  530. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC "-framework IOKit")
  531. ENDIF()
  532. ENDIF()
  533. IF(HAVE_OPENGL)
  534. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC ${OPENGL_LIBRARY})
  535. IF(GLBINDING_FOUND)
  536. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC ${GLBINDING_LIBRARIES})
  537. ELSE()
  538. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC ${GLEW_LIBRARY})
  539. ENDIF()
  540. ENDIF(HAVE_OPENGL)
  541. IF(HAVE_LIBCURL)
  542. TARGET_LINK_LIBRARIES(supertux2_lib PUBLIC ${CURL_LIBRARY})
  543. ENDIF(HAVE_LIBCURL)
  544. if(BUILD_TESTS)
  545. find_package(Threads REQUIRED)
  546. # build gtest
  547. # ${CMAKE_CURRENT_SOURCE_DIR} in include_directories is needed to generate -isystem instead of -I flags
  548. add_library(gtest_main STATIC ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googletest/src/gtest_main.cc)
  549. target_include_directories(gtest_main SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googletest/include/)
  550. add_library(gtest STATIC ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googletest/src/gtest-all.cc)
  551. target_include_directories(gtest SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googletest/)
  552. target_include_directories(gtest SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googletest/include/)
  553. # build SuperTux tests
  554. file(GLOB TEST_SUPERTUX_SOURCES tests/*.cpp)
  555. add_executable(test_supertux2 ${TEST_SUPERTUX_SOURCES})
  556. target_compile_options(test_supertux2 PRIVATE ${WARNINGS_CXX_FLAGS})
  557. target_link_libraries(test_supertux2
  558. gtest gtest_main
  559. supertux2_lib
  560. ${CMAKE_THREAD_LIBS_INIT})
  561. # add 'make test' target, use 'make test ARGS="-V"' or 'ctest -V' for verbose
  562. enable_testing()
  563. add_test(NAME test_supertux2
  564. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  565. COMMAND test_supertux2)
  566. endif()
  567. ## Install stuff
  568. OPTION(DISABLE_CPACK_BUNDLING "Build an .app bundle without CPack" OFF)
  569. IF(WIN32 AND NOT UNIX)
  570. SET(INSTALL_SUBDIR_BIN "bin" CACHE STRING "Installation subdir for binaries")
  571. SET(INSTALL_SUBDIR_SHARE "data" CACHE STRING "Installation subdir for data")
  572. SET(INSTALL_SUBDIR_DOC "doc" CACHE STRING "Installation subdir for docs")
  573. INSTALL(FILES ${DLLS} DESTINATION ${INSTALL_SUBDIR_BIN})
  574. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.png ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.ico DESTINATION ".")
  575. OPTION(PACKAGE_VCREDIST "Package the VCREDIST libraries with the program" OFF)
  576. IF(PACKAGE_VCREDIST)
  577. include(InstallRequiredSystemLibraries)
  578. INSTALL(FILES ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION ${INSTALL_SUBDIR_BIN})
  579. include(FindWindowsSDK)
  580. IF(${CMAKE_VS_PLATFORM_NAME} STREQUAL "Win32")
  581. SET(UCRT_PATH "${WINDOWSSDK_PREFERRED_DIR}/Redist/ucrt/DLLs/x86")
  582. ELSE()
  583. SET(UCRT_PATH "${WINDOWSSDK_PREFERRED_DIR}/Redist/ucrt/DLLs/x64")
  584. ENDIF()
  585. FILE(GLOB UCRT_DLLS "${UCRT_PATH}/*")
  586. INSTALL(FILES ${UCRT_DLLS} DESTINATION ${INSTALL_SUBDIR_BIN})
  587. ENDIF()
  588. ELSE(WIN32 AND NOT UNIX)
  589. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND DISABLE_CPACK_BUNDLING)
  590. SET(INFOPLIST_CFBUNDLEEXECUTABLE "supertux2")
  591. SET(INSTALL_SUBDIR_BIN "SuperTux.app/Contents/MacOS" CACHE STRING "Installation subdir for binaries")
  592. SET(INSTALL_SUBDIR_SHARE "SuperTux.app/Contents/Resources/data" CACHE STRING "Installation subdir for data")
  593. SET(INSTALL_SUBDIR_DOC "SuperTux.app/Contents/Resources" CACHE STRING "Installation subdir for docs")
  594. CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/info.plist.in ${CMAKE_BINARY_DIR}/tools/darwin/info.plist)
  595. INSTALL(FILES ${CMAKE_BINARY_DIR}/tools/darwin/info.plist DESTINATION "SuperTux.app/Contents/")
  596. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/receipt DESTINATION "SuperTux.app/Contents/_MASReceipt/")
  597. 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/")
  598. ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND DISABLE_CPACK_BUNDLING)
  599. SET(INSTALL_SUBDIR_BIN "games" CACHE STRING "Installation subdir for binaries")
  600. SET(INSTALL_SUBDIR_SHARE "share/games/supertux2" CACHE STRING "Installation subdir for data")
  601. SET(INSTALL_SUBDIR_DOC "share/doc/supertux2" CACHE STRING "Installation subdir for docs")
  602. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/supertux2.desktop DESTINATION "share/applications")
  603. SET(APPS "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${INSTALL_SUBDIR_BIN}/supertux2")
  604. 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/")
  605. ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND DISABLE_CPACK_BUNDLING)
  606. ENDIF(WIN32 AND NOT UNIX)
  607. INSTALL(TARGETS supertux2 DESTINATION ${INSTALL_SUBDIR_BIN})
  608. IF(WIN32)
  609. GET_PROPERTY(SQUIRREL_LIB_PATH TARGET squirrel_lib PROPERTY IMPORTED_LOCATION)
  610. GET_PROPERTY(SQSTDLIB_LIB_PATH TARGET sqstdlib_lib PROPERTY IMPORTED_LOCATION)
  611. GET_PROPERTY(PHYSFS_LIB_PATH TARGET physfs_lib PROPERTY IMPORTED_LOCATION)
  612. INSTALL(FILES ${SQUIRREL_LIB_PATH} ${SQSTDLIB_LIB_PATH} ${PHYSFS_LIB_PATH} DESTINATION ${INSTALL_SUBDIR_BIN})
  613. ENDIF()
  614. 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})
  615. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/credits.stxt DESTINATION ${INSTALL_SUBDIR_SHARE})
  616. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/supertux2.appdata.xml DESTINATION "share/appdata" )
  617. INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/images
  618. ${CMAKE_CURRENT_SOURCE_DIR}/data/fonts
  619. ${CMAKE_CURRENT_SOURCE_DIR}/data/music
  620. ${CMAKE_CURRENT_SOURCE_DIR}/data/scripts
  621. ${CMAKE_CURRENT_SOURCE_DIR}/data/speech
  622. ${CMAKE_CURRENT_SOURCE_DIR}/data/sounds
  623. ${CMAKE_CURRENT_SOURCE_DIR}/data/locale
  624. DESTINATION ${INSTALL_SUBDIR_SHARE})
  625. IF(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo")
  626. INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/levels
  627. DESTINATION ${INSTALL_SUBDIR_SHARE}
  628. PATTERN "data/levels/test" EXCLUDE
  629. PATTERN "data/levels/test_old" EXCLUDE
  630. PATTERN "data/levels/incubator" EXCLUDE
  631. PATTERN "data/levels/misc/menu.stl.in" EXCLUDE)
  632. ELSE()
  633. INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/levels
  634. DESTINATION ${INSTALL_SUBDIR_SHARE}
  635. PATTERN "data/levels/misc/menu.stl.in" EXCLUDE)
  636. ENDIF()
  637. INSTALL(FILES "${CMAKE_BINARY_DIR}/data/levels/misc/menu.stl" DESTINATION "${INSTALL_SUBDIR_SHARE}/levels/misc")
  638. ## Create config.h now that INSTALL_SUBDIR_* have been set.
  639. configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )
  640. ## Configure main menu logo
  641. IF("${SUPERTUX_VERSION_STRING}" MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+$")
  642. SET(LOGO_FILE "logo_final.sprite")
  643. ELSE()
  644. SET(LOGO_FILE "logo.sprite")
  645. ENDIF()
  646. configure_file(data/levels/misc/menu.stl.in ${CMAKE_BINARY_DIR}/data/levels/misc/menu.stl )
  647. ## CPack/Installation-specific stuff
  648. INCLUDE(InstallRequiredSystemLibraries)
  649. SET(DIRS ${Boost_LIBRARY_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/external/squirrel ${CMAKE_CURRENT_BINARY_DIR}/external/tinygettext)
  650. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT DISABLE_CPACK_BUNDLING)
  651. SET(INFOPLIST_CFBUNDLEEXECUTABLE "SuperTux")
  652. FIND_PACKAGE(png)
  653. foreach (_file ${PNG_LIBRARIES})
  654. get_filename_component(_resolvedFile "${_file}" REALPATH)
  655. get_filename_component(_name "${_file}" NAME)
  656. INSTALL(FILES ${_resolvedFile} DESTINATION "MacOS" RENAME ${_name})
  657. endforeach()
  658. FIND_PACKAGE(jpeg)
  659. foreach (_file ${JPEG_LIBRARIES})
  660. get_filename_component(_resolvedFile "${_file}" REALPATH)
  661. get_filename_component(_name "${_file}" NAME)
  662. INSTALL(FILES ${_resolvedFile} DESTINATION "MacOS" RENAME ${_name})
  663. endforeach()
  664. INSTALL(CODE "
  665. if(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/\" MATCHES \".*\\\\.app.*\")
  666. include(BundleUtilities)
  667. fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")
  668. endif()
  669. ")
  670. CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/info.plist.in" "${CMAKE_BINARY_DIR}/tools/darwin/info.plist")
  671. SET(CPACK_BUNDLE_NAME "SuperTux")
  672. SET(CPACK_BUNDLE_PLIST "${CMAKE_BINARY_DIR}/tools/darwin/info.plist")
  673. SET(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.icns")
  674. SET(CPACK_BUNDLE_STARTUP_COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/startup.sh")
  675. SET(CPACK_DMG_VOLUME_NAME "SuperTux ${SUPERTUX_VERSION_STRING}")
  676. SET(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/dsstore_setup.scpt")
  677. SET(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/background.png")
  678. ENDIF()
  679. SET(CPACK_PACKAGE_NAME "SuperTux")
  680. SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Jump'n'Run Game featuring Tux")
  681. SET(CPACK_PACKAGE_VENDOR "SuperTux Devel Team")
  682. SET(CPACK_PACKAGE_CONTACT "SuperTux Devel Team <supertux-devel@lists.lethargik.org>")
  683. SET(CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;${CMAKE_BINARY_DIR};/\\\\..*")
  684. SET(CPACK_DEBIAN_PACKAGE_NAME "supertux2")
  685. 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)")
  686. 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/")
  687. SET(CPACK_DEBIAN_PACKAGE_SECTION "games")
  688. SET(CPACK_RPM_PACKAGE_NAME "supertux2")
  689. 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/")
  690. SET(CPACK_RPM_PACKAGE_LICENSE "GNU General Public License (GPL)")
  691. SET(CPACK_RPM_PACKAGE_GROUP "Amusements/Games/Action/Arcade")
  692. SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  693. SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
  694. SET(CPACK_PACKAGE_VERSION_MAJOR ${SUPERTUX_VERSION_MAJOR})
  695. SET(CPACK_PACKAGE_VERSION_MINOR ${SUPERTUX_VERSION_MINOR})
  696. IF(SUPERTUX_VERSION_TWEAK)
  697. SET(CPACK_PACKAGE_VERSION_PATCH "${SUPERTUX_VERSION_PATCH}.${SUPERTUX_VERSION_TWEAK}")
  698. ELSE()
  699. SET(CPACK_PACKAGE_VERSION_PATCH ${SUPERTUX_VERSION_PATCH})
  700. ENDIF(SUPERTUX_VERSION_TWEAK)
  701. SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${SUPERTUX_VERSION_STRING}-${SUPERTUX_SYSTEM_NAME}")
  702. SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${SUPERTUX_VERSION_STRING}-Source")
  703. SET(CPACK_PACKAGE_INSTALL_DIRECTORY "SuperTux")
  704. SET(CPACK_PACKAGE_EXECUTABLES "supertux2" "SuperTux")
  705. IF(WIN32 AND NOT UNIX)
  706. SET(CPACK_NSIS_INSTALLED_ICON_NAME "supertux2")
  707. SET(CPACK_NSIS_DISPLAY_NAME "SuperTux")
  708. SET(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
  709. SET(CPACK_WIX_PROGRAM_MENU_FOLDER "")
  710. SET(CPACK_WIX_UPGRADE_GUID "93E16F4E-0A68-422A-8ADC-47BE5B9433B2")
  711. SET(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.ico")
  712. SET(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/mk/wix/banner.png")
  713. SET(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/mk/wix/dialog.png")
  714. SET(CPACK_GENERATOR WIX)
  715. ELSE(WIN32 AND NOT UNIX)
  716. ENDIF(WIN32 AND NOT UNIX)
  717. INCLUDE(CPack)
  718. # move some config clutter to the advanced section
  719. MARK_AS_ADVANCED(
  720. INSTALL_SUBDIR_BIN
  721. INSTALL_SUBDIR_SHARE
  722. INSTALL_SUBDIR_DOC
  723. )
  724. MARK_AS_ADVANCED(
  725. CMAKE_BACKWARDS_COMPATIBILITY
  726. CMAKE_BUILD_TYPE
  727. CMAKE_INSTALL_PREFIX
  728. EXECUTABLE_OUTPUT_PATH
  729. LIBRARY_OUTPUT_PATH
  730. CMAKE_OSX_ARCHITECTURES
  731. CMAKE_OSX_SYSROOT
  732. )
  733. MARK_AS_ADVANCED(
  734. APPDATADIR
  735. )
  736. MARK_AS_ADVANCED(
  737. Boost_INCLUDE_DIR
  738. Boost_LIBRARIES
  739. )
  740. MARK_AS_ADVANCED(
  741. GLEW_INCLUDE_DIR
  742. GLEW_LIBRARY
  743. )
  744. MARK_AS_ADVANCED(
  745. SDL2_INCLUDE_DIRS
  746. SDL2_LIBRARIES
  747. )
  748. MARK_AS_ADVANCED(
  749. SDL2IMAGE_INCLUDE_DIRS
  750. SDL2IMAGE_LIBRARIES
  751. )
  752. MARK_AS_ADVANCED(
  753. OPENAL_INCLUDE_DIR
  754. OPENAL_LIBRARY
  755. )
  756. MARK_AS_ADVANCED(
  757. OGG_LIBRARY
  758. VORBISENC_LIBRARY
  759. VORBISFILE_LIBRARY
  760. VORBIS_INCLUDE_DIR
  761. VORBIS_LIBRARY
  762. )
  763. MARK_AS_ADVANCED(
  764. PHYSFS_INCLUDE_DIR
  765. PHYSFS_LIBRARY
  766. )