CMakeLists.txt 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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. ## Version, for display in title bar.
  34. ## Will add 'commit <hash>' to the end if git is available and this is a git repository.
  35. SET(SUPERTUX_VERSION "0.4.0-git")
  36. ### CMake configuration
  37. # allow building with CMake 2.6. Set compatibility options. Use some bundled modules as a fallback
  38. CMAKE_MINIMUM_REQUIRED(VERSION 2.6.1)
  39. IF(COMMAND cmake_policy)
  40. CMAKE_POLICY(SET CMP0003 NEW)
  41. CMAKE_POLICY(SET CMP0008 NEW)
  42. IF(POLICY CMP0043)
  43. CMAKE_POLICY(SET CMP0043 OLD)
  44. ENDIF(POLICY CMP0043)
  45. ENDIF(COMMAND cmake_policy)
  46. SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/mk/cmake)
  47. INCLUDE(ConfigureFiles)
  48. ## For autopackage
  49. SET(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/games/supertux2")
  50. ## Check endianess
  51. INCLUDE(TestBigEndian)
  52. TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
  53. ## These variables enable MSVC to find libraries located in "dependencies{32|64}"
  54. IF(WIN32)
  55. ## Store path of dependecy folder
  56. SET(DEPENDENCY_FOLDER "${PROJECT_SOURCE_DIR}/dependencies")
  57. ## To test if the host (not the build) is x64:
  58. ## "$ENV{PROCESSOR_ARCHITEW6432}" STREQUAL "AMD64"
  59. IF(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
  60. SET(WIN64 ON)
  61. SET(DEPENDENCY_FOLDER "${DEPENDENCY_FOLDER}64")
  62. ELSE(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
  63. SET(WIN64 OFF)
  64. SET(DEPENDENCY_FOLDER "${DEPENDENCY_FOLDER}32")
  65. ENDIF(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
  66. SET(ENV{PATH} "$ENV{PATH};${DEPENDENCY_FOLDER}/include")
  67. SET(ENV{LIB} "${DEPENDENCY_FOLDER}/lib")
  68. SET(ENV{OPENALDIR} "${DEPENDENCY_FOLDER}")
  69. SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG)
  70. ## Enable multi-processor compilation (faster)
  71. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  72. ## And shut up about unsafe stuff
  73. ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
  74. ## Add an icon
  75. CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/mk/msvc/icon_rc.template" "${PROJECT_BINARY_DIR}/tmp/icon.rc")
  76. ## Find all used libraries
  77. FILE(GLOB DLLS "${DEPENDENCY_FOLDER}/dll/*")
  78. ENDIF(WIN32)
  79. ## Add lots of dependencies to compiler switches
  80. SET(Boost_ADDITIONAL_VERSIONS "1.41" "1.41.0")
  81. FIND_PATH(PHYSFS_INCLUDE_DIR NAMES physfs.h PATHS "${DEPENDENCY_FOLDER}/include/physfs")
  82. FIND_PACKAGE(Boost REQUIRED)
  83. INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIR})
  84. LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
  85. IF(WIN32)
  86. FIND_PATH(SDL2_INCLUDE_DIRS NAMES SDL.h PATHS "${DEPENDENCY_FOLDER}/include/SDL2")
  87. FIND_PATH(SDL2IMAGE_INCLUDE_DIRS NAMES SDL_image.h PATHS "${DEPENDENCY_FOLDER}/include/SDL2_image")
  88. FIND_LIBRARY(SDL2_LIBRARIES NAMES SDL2 PATHS "${DEPENDENCY_FOLDER}/lib")
  89. FIND_LIBRARY(SDL2IMAGE_LIBRARIES NAMES SDL2_image PATHS "${DEPENDENCY_FOLDER}/lib")
  90. ELSE(WIN32)
  91. INCLUDE(FindPkgConfig)
  92. PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2>=2.0.1)
  93. PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
  94. ENDIF(WIN32)
  95. SET(HAVE_SDL TRUE)
  96. OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
  97. OPTION(GLBINDING_ENABLED "Use glbinding instead of GLEW" OFF)
  98. OPTION(GLBINDING_DEBUG_OUTPUT "Enable glbinding debug output for each called OpenGL function" OFF)
  99. IF(ENABLE_OPENGL)
  100. FIND_PACKAGE(OpenGL)
  101. IF(OPENGL_FOUND)
  102. INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
  103. SET(HAVE_OPENGL TRUE)
  104. ENDIF(OPENGL_FOUND)
  105. IF(GLBINDING_ENABLED)
  106. FIND_PACKAGE(GLBINDING REQUIRED)
  107. IF(GLBINDING_FOUND)
  108. INCLUDE_DIRECTORIES(${GLBINDING_INCLUDES})
  109. ADD_DEFINITIONS(-DUSE_GLBINDING)
  110. IF (GLBINDING_DEBUG_OUTPUT)
  111. ADD_DEFINITIONS(-DUSE_GLBINDING_DEBUG_OUTPUT)
  112. ENDIF()
  113. ENDIF()
  114. ELSE()
  115. FIND_PACKAGE(GLEW REQUIRED)
  116. IF(GLEW_FOUND)
  117. INCLUDE_DIRECTORIES(${GLEW_INCLUDE_DIR})
  118. ENDIF(GLEW_FOUND)
  119. ENDIF()
  120. ENDIF(ENABLE_OPENGL)
  121. FIND_PACKAGE(OpenAL REQUIRED)
  122. INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR})
  123. FIND_PACKAGE(OggVorbis REQUIRED)
  124. INCLUDE_DIRECTORIES(${VORBIS_INCLUDE_DIR})
  125. FIND_PACKAGE(PhysFS REQUIRED)
  126. INCLUDE_DIRECTORIES(${PHYSFS_INCLUDE_DIR})
  127. ## The curl headers are in the standard include path in dependencies
  128. ## so it's not required to add them here
  129. IF(NOT WIN32 OR WIN64)
  130. FIND_PACKAGE(CURL REQUIRED)
  131. IF(CURL_FOUND)
  132. INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
  133. SET(HAVE_LIBCURL TRUE)
  134. ENDIF(CURL_FOUND)
  135. ENDIF(NOT WIN32 OR WIN64)
  136. #FIND_PACKAGE(ICONV REQUIRED)
  137. #INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
  138. #LINK_LIBRARIES(${ICONV_LIBRARY})
  139. ## Find revision of WC
  140. MARK_AS_ADVANCED(GIT_EXECUTABLE)
  141. FIND_PROGRAM(GIT_EXECUTABLE git)
  142. # The .git directory inside the base directory
  143. SET(GIT_CFG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.git/")
  144. IF(GIT_EXECUTABLE AND EXISTS ${GIT_CFG_DIR})
  145. ADD_CUSTOM_COMMAND(OUTPUT "${CMAKE_BINARY_DIR}/version.h"
  146. COMMAND ${CMAKE_COMMAND} -E echo "#ifndef VERSION_H" > "${CMAKE_BINARY_DIR}/version.h.tmp"
  147. COMMAND ${CMAKE_COMMAND} -E echo "#define VERSION_H" >> "${CMAKE_BINARY_DIR}/version.h.tmp"
  148. COMMAND ${CMAKE_COMMAND} >> "${CMAKE_BINARY_DIR}/version.h.tmp" -E echo_append "#define PACKAGE_VERSION \"${SUPERTUX_VERSION} commit "
  149. COMMAND ${GIT_EXECUTABLE} rev-parse --sq HEAD >> "${CMAKE_BINARY_DIR}/version.h.tmp"
  150. COMMAND ${CMAKE_COMMAND} >> "${CMAKE_BINARY_DIR}/version.h.tmp" -E echo "\""
  151. COMMAND ${CMAKE_COMMAND} -E echo "#endif" >> "${CMAKE_BINARY_DIR}/version.h.tmp"
  152. COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_BINARY_DIR}/version.h.tmp" "${CMAKE_BINARY_DIR}/version.h"
  153. COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_BINARY_DIR}/version.h.tmp"
  154. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  155. COMMENT "Updating ${CMAKE_BINARY_DIR}/version.h..."
  156. VERBATIM)
  157. ELSE(GIT_EXECUTABLE AND EXISTS ${GIT_CFG_DIR})
  158. ADD_CUSTOM_COMMAND(OUTPUT "${CMAKE_BINARY_DIR}/version.h"
  159. COMMAND ${CMAKE_COMMAND} -E echo "#ifndef VERSION_H" > "${CMAKE_BINARY_DIR}/version.h.tmp"
  160. COMMAND ${CMAKE_COMMAND} -E echo "#define VERSION_H" >> "${CMAKE_BINARY_DIR}/version.h.tmp"
  161. COMMAND ${CMAKE_COMMAND} >> "${CMAKE_BINARY_DIR}/version.h.tmp" -E echo "#define PACKAGE_VERSION \"${SUPERTUX_VERSION}\""
  162. COMMAND ${CMAKE_COMMAND} -E echo "#endif" >> "${CMAKE_BINARY_DIR}/version.h.tmp"
  163. COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_BINARY_DIR}/version.h.tmp" "${CMAKE_BINARY_DIR}/version.h"
  164. COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_BINARY_DIR}/version.h.tmp"
  165. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  166. COMMENT "Updating ${CMAKE_BINARY_DIR}/version.h..."
  167. VERBATIM)
  168. ENDIF(GIT_EXECUTABLE AND EXISTS ${GIT_CFG_DIR})
  169. SET_SOURCE_FILES_PROPERTIES(${CMAKE_BINARY_DIR}/version.h
  170. PROPERTIES GENERATED true)
  171. SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/src/supertux/main.cpp
  172. PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")
  173. SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/src/supertux/title_screen.cpp
  174. PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")
  175. SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/src/addon/addon_manager.cpp
  176. PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")
  177. ## Check platform-dependent build options
  178. INCLUDE(ConfigureChecks)
  179. ## Also execute instructions in external/squirrel/CMakeLists.txt
  180. IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/squirrel/CMakeLists.txt)
  181. message(FATAL_ERROR "squirrel submodule is not checked out or ${CMAKE_CURRENT_SOURCE_DIR}/external/squirrel/CMakeLists.txt is missing")
  182. ENDIF()
  183. ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/external/squirrel)
  184. ## Add squirrel lib dir to search path
  185. LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/external/squirrel)
  186. ## Also execute instructions in external/squirrel/CMakeLists.txt
  187. IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinygettext/CMakeLists.txt)
  188. message(FATAL_ERROR "tinygettext submodule is not checked out or ${CMAKE_CURRENT_SOURCE_DIR}/external/tinygettext/CMakeLists.txt is missing")
  189. ENDIF()
  190. ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/external/tinygettext)
  191. ## Add tinygettext lib dir to search path
  192. LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/external/tinygettext)
  193. ## Some additional include paths
  194. include_directories (${CMAKE_BINARY_DIR}/)
  195. include_directories (${CMAKE_CURRENT_SOURCE_DIR}/src/)
  196. include_directories (${CMAKE_CURRENT_SOURCE_DIR}/external/squirrel/include/)
  197. include_directories (${CMAKE_CURRENT_SOURCE_DIR}/external/tinygettext/include/)
  198. include_directories (${CMAKE_CURRENT_SOURCE_DIR}/external/findlocale/)
  199. include_directories (${CMAKE_CURRENT_SOURCE_DIR}/external/obstack/)
  200. IF(WIN32)
  201. ADD_DEFINITIONS(-D_USE_MATH_DEFINES -DNOMINMAX)
  202. ENDIF(WIN32)
  203. ## Build list of sources for supertux binary
  204. FILE(GLOB SUPERTUX_SOURCES_C RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} external/obstack/*.c external/findlocale/findlocale.c)
  205. FILE(GLOB SUPERTUX_SOURCES_CXX RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/main.cpp src/*/*.cpp src/supertux/menu/*.cpp src/video/sdl/*.cpp)
  206. FILE(GLOB SUPERTUX_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${PROJECT_BINARY_DIR}/tmp/*.rc")
  207. FILE(GLOB TINYGETTEXT_SOURCES_CXX RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} external/tinygettext/src/*.cpp)
  208. SET_SOURCE_FILES_PROPERTIES(${TINYGETTEXT_SOURCES_CXX} PROPERTIES COMPILE_DEFINITIONS HAVE_SDL)
  209. IF(HAVE_OPENGL)
  210. FILE(GLOB SUPERTUX_OPENGL_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/video/gl/*.cpp)
  211. SET(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${SUPERTUX_OPENGL_SOURCES})
  212. ENDIF(HAVE_OPENGL)
  213. ## Build miniswig and generate miniswig wrapper
  214. OPTION(GENERATE_WRAPPER "Build miniswig and generate the wrapper" OFF)
  215. IF(GENERATE_WRAPPER)
  216. ADD_SUBDIRECTORY(tools/miniswig)
  217. ADD_CUSTOM_COMMAND(
  218. OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp
  219. COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_CXX_COMPILER}
  220. 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
  221. COMMAND tools/miniswig/miniswig
  222. 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
  223. DEPENDS tools/miniswig/miniswig
  224. IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.interface.hpp
  225. )
  226. ENDIF(GENERATE_WRAPPER)
  227. IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
  228. SET(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
  229. ENDIF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
  230. ## Compile everything at once (roughly equivalent to cat *.cpp | gcc)
  231. OPTION(COMPILE_AMALGATION "Compile all the files together at once (experimental)" OFF)
  232. IF(COMPILE_AMALGATION)
  233. FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp "// Includes all source files of the project\n")
  234. FOREACH(ST_FILE ${SUPERTUX_SOURCES_CXX})
  235. FILE(RELATIVE_PATH CXX_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src "${CMAKE_CURRENT_SOURCE_DIR}/${ST_FILE}")
  236. FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp "#include \"${CXX_FILE}\"\n")
  237. ENDFOREACH(ST_FILE)
  238. ## Build instead of CXX sources
  239. SET(SUPERTUX_SOURCES_CXX ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  240. ELSE(COMPILE_AMALGATION)
  241. IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  242. FILE(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  243. ENDIF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
  244. ENDIF(COMPILE_AMALGATION)
  245. ## Debug options
  246. OPTION(WERROR "Stop on first compiler warning" OFF)
  247. OPTION(WARNINGS "Enable long list of warnings for compiler to check" OFF)
  248. # http://www.guyrutenberg.com/2014/01/05/enabling-c11-c0x-in-cmake/
  249. include(CheckCXXCompilerFlag)
  250. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  251. if(COMPILER_SUPPORTS_CXX11)
  252. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  253. else(COMPILER_SUPPORTS_CXX11)
  254. CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
  255. if(COMPILER_SUPPORTS_CXX0X)
  256. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  257. else(COMPILER_SUPPORTS_CXX0X)
  258. message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  259. endif(COMPILER_SUPPORTS_CXX0X)
  260. endif(COMPILER_SUPPORTS_CXX11)
  261. IF(CMAKE_COMPILER_IS_GNUCC)
  262. SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
  263. SET(CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
  264. SET(CMAKE_CXX_FLAGS_PROFILE "-pg" CACHE STRING "Profile flags")
  265. SET(CMAKE_C_FLAGS_PROFILE "-pg" CACHE STRING "Profile flags")
  266. SET(CMAKE_LD_FLAGS_PROFILE "-lgmon" CACHE STRING "Profile flags")
  267. ADD_DEFINITIONS(-Wall -Wextra -Wno-unused-parameter -funit-at-a-time)
  268. IF(WERROR)
  269. ADD_DEFINITIONS(-Werror)
  270. ELSE(WERROR)
  271. REMOVE_DEFINITIONS(-Werror)
  272. ENDIF(WERROR)
  273. IF(WARNINGS)
  274. # temporarily disabled:
  275. # -Wsign-conversion -Wfloat-equal -Wconversion -Wundef -Wswitch-default
  276. # -Wswitch-enum -Wsign-promo -Wcast-qual -Woverloaded-virtual -Wmissing-format-attribute
  277. # -Wold-style-cast -Wpadded -Wabi -Winline -Wunsafe-loop-optimizations -Wstrict-overflow=5
  278. # fails on MinGW:
  279. # -ansi
  280. # fails on clang:
  281. # -Wlogical-op -Wstrict-null-sentinel
  282. 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")
  283. ENDIF(WARNINGS)
  284. ENDIF(CMAKE_COMPILER_IS_GNUCC)
  285. ## If xgettext is available, generate messages.pot for sources
  286. OPTION(GENERATE_MESSAGESPOT "Generate messages.pot files" OFF)
  287. IF(GENERATE_MESSAGESPOT)
  288. MARK_AS_ADVANCED(
  289. XGETTEXT_EXECUTABLE
  290. )
  291. FIND_PROGRAM(XGETTEXT_EXECUTABLE xgettext)
  292. IF(NOT XGETTEXT_EXECUTABLE)
  293. MESSAGE(STATUS "Warning: xgettext not found - will not update messages.pot")
  294. ELSE(NOT XGETTEXT_EXECUTABLE)
  295. MESSAGE(STATUS "Found xgettext: ${XGETTEXT_EXECUTABLE}")
  296. SET(MESSAGES_POT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/data/locale/messages.pot)
  297. ADD_CUSTOM_COMMAND(
  298. OUTPUT ${MESSAGES_POT_FILE}
  299. COMMAND ${XGETTEXT_EXECUTABLE}
  300. ARGS --keyword=_ --language=C++ --output=${MESSAGES_POT_FILE} ${SUPERTUX_SOURCES_CXX}
  301. DEPENDS ${SUPERTUX_SOURCES_CXX}
  302. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  303. COMMENT "Generating POT file ${MESSAGES_POT_FILE}"
  304. )
  305. LIST(APPEND MESSAGES_POT_FILES ${MESSAGES_POT_FILE})
  306. FILE(GLOB SUPERTUX_LEVEL_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} data/levels/*)
  307. FOREACH(SUPERTUX_LEVEL_DIR ${SUPERTUX_LEVEL_DIRS})
  308. FILE(GLOB SUPERTUX_LEVELS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${SUPERTUX_LEVEL_DIR}/*.stl ${SUPERTUX_LEVEL_DIR}/*.stwm ${SUPERTUX_LEVEL_DIR}/*.txt)
  309. ## Do not add target if SUPERTUX_LEVELS is empty. This is needed for cmake <=2.4
  310. IF(SUPERTUX_LEVELS)
  311. SET(MESSAGES_POT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${SUPERTUX_LEVEL_DIR}/messages.pot)
  312. ADD_CUSTOM_COMMAND(
  313. OUTPUT ${MESSAGES_POT_FILE}
  314. COMMAND ${XGETTEXT_EXECUTABLE}
  315. ARGS --keyword="_:1" --language=Lisp --force-po --sort-by-file "--output=${MESSAGES_POT_FILE}" ${SUPERTUX_LEVELS}
  316. DEPENDS ${SUPERTUX_LEVELS}
  317. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  318. COMMENT "Generating POT file ${MESSAGES_POT_FILE}"
  319. )
  320. LIST(APPEND MESSAGES_POT_FILES ${MESSAGES_POT_FILE})
  321. ENDIF(SUPERTUX_LEVELS)
  322. ENDFOREACH(SUPERTUX_LEVEL_DIR)
  323. ADD_CUSTOM_TARGET(
  324. supertux2-messages ALL
  325. DEPENDS ${MESSAGES_POT_FILES}
  326. )
  327. ENDIF(NOT XGETTEXT_EXECUTABLE)
  328. ENDIF(GENERATE_MESSAGESPOT)
  329. ## Some additional compiler switches
  330. IF(CMAKE_COMPILER_IS_GNUCC)
  331. ADD_DEFINITIONS(-fno-strict-aliasing)
  332. ENDIF(CMAKE_COMPILER_IS_GNUCC)
  333. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  334. ADD_DEFINITIONS(-DMACOSX)
  335. ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  336. ## On Windows, add an icon
  337. IF(WIN32)
  338. # SET(SUPERTUX_SOURCES_C ${SUPERTUX_SOURCES_C} ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc)
  339. IF(MINGW)
  340. ADD_CUSTOM_COMMAND(
  341. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o
  342. 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)
  343. SET(SUPERTUX_SOURCES_C ${SUPERTUX_SOURCES_C} ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o)
  344. ENDIF(MINGW)
  345. ENDIF(WIN32)
  346. ## Generate supertux executable in the right place
  347. #SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
  348. SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
  349. CONFIGURE_FILES(${CMAKE_CURRENT_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/data)
  350. ## Add target for supertux binary
  351. ADD_LIBRARY(supertux2_c OBJECT ${SUPERTUX_SOURCES_C})
  352. ADD_EXECUTABLE(supertux2 ${CMAKE_BINARY_DIR}/version.h ${SUPERTUX_SOURCES_CXX} ${SUPERTUX_RESOURCES} $<TARGET_OBJECTS:supertux2_c>)
  353. SET_TARGET_PROPERTIES(supertux2 PROPERTIES COMPILE_FLAGS "${SUPERTUX2_EXTRA_WARNING_FLAGS}")
  354. IF(WIN32)
  355. ## Copy dlls on windows
  356. ADD_CUSTOM_COMMAND(TARGET supertux2 POST_BUILD
  357. COMMAND ${CMAKE_COMMAND} -E copy_directory
  358. "${DEPENDENCY_FOLDER}/dll"
  359. $<TARGET_FILE_DIR:supertux2>)
  360. ADD_CUSTOM_COMMAND(TARGET supertux2 POST_BUILD
  361. COMMAND ${CMAKE_COMMAND} -E copy
  362. "${DEPENDENCY_FOLDER}/DigiCertHighAssuranceEVRootCA.pem"
  363. $<TARGET_FILE_DIR:supertux2>)
  364. ENDIF(WIN32)
  365. ## Link supertux binary with squirrel and other libraries
  366. TARGET_INCLUDE_DIRECTORIES(supertux2 SYSTEM PUBLIC ${SDL2_INCLUDE_DIRS})
  367. TARGET_INCLUDE_DIRECTORIES(supertux2 SYSTEM PUBLIC ${SDL2IMAGE_INCLUDE_DIRS})
  368. TARGET_LINK_LIBRARIES(supertux2 ${SDL2_LIBRARIES})
  369. TARGET_LINK_LIBRARIES(supertux2 ${SDL2IMAGE_LIBRARIES})
  370. TARGET_LINK_LIBRARIES(supertux2 squirrel)
  371. TARGET_LINK_LIBRARIES(supertux2 tinygettext)
  372. TARGET_LINK_LIBRARIES(supertux2 ${OPENAL_LIBRARY})
  373. TARGET_LINK_LIBRARIES(supertux2 ${OGGVORBIS_LIBRARIES})
  374. TARGET_LINK_LIBRARIES(supertux2 ${PHYSFS_LIBRARY})
  375. IF(HAVE_OPENGL)
  376. TARGET_LINK_LIBRARIES(supertux2 ${OPENGL_LIBRARY})
  377. IF(GLBINDING_FOUND)
  378. TARGET_LINK_LIBRARIES(supertux2 ${GLBINDING_LIBRARIES})
  379. ELSE()
  380. TARGET_LINK_LIBRARIES(supertux2 ${GLEW_LIBRARY})
  381. ENDIF()
  382. ENDIF(HAVE_OPENGL)
  383. IF(HAVE_LIBCURL)
  384. TARGET_LINK_LIBRARIES(supertux2 ${CURL_LIBRARY})
  385. ENDIF(HAVE_LIBCURL)
  386. ## Link curl on windows
  387. IF(WIN32 AND NOT WIN64)
  388. TARGET_LINK_LIBRARIES(supertux2 "${DEPENDENCY_FOLDER}/lib/libcurldll.a")
  389. ENDIF()
  390. ## Install stuff
  391. IF(WIN32 AND NOT UNIX)
  392. SET(INSTALL_SUBDIR_BIN "." CACHE STRING "Installation subdir for binaries")
  393. SET(INSTALL_SUBDIR_SHARE "data" CACHE STRING "Installation subdir for data")
  394. SET(INSTALL_SUBDIR_DOC "." CACHE STRING "Installation subdir for docs")
  395. INSTALL(FILES ${DLLS} DESTINATION ${INSTALL_SUBDIR_BIN})
  396. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.png ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.ico DESTINATION ".")
  397. ELSE(WIN32 AND NOT UNIX)
  398. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  399. SET(INSTALL_SUBDIR_BIN "SuperTux.app/Contents/MacOS" CACHE STRING "Installation subdir for binaries")
  400. SET(INSTALL_SUBDIR_SHARE "SuperTux.app/Contents/Resources/data" CACHE STRING "Installation subdir for data")
  401. SET(INSTALL_SUBDIR_DOC "SuperTux.app/Contents/Resources" CACHE STRING "Installation subdir for docs")
  402. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/info.plist DESTINATION "SuperTux.app/Contents/")
  403. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tools/darwin/receipt DESTINATION "SuperTux.app/Contents/_MASReceipt/")
  404. 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/")
  405. ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  406. SET(INSTALL_SUBDIR_BIN "games" CACHE STRING "Installation subdir for binaries")
  407. SET(INSTALL_SUBDIR_SHARE "share/games/supertux2" CACHE STRING "Installation subdir for data")
  408. SET(INSTALL_SUBDIR_DOC "share/doc/supertux2" CACHE STRING "Installation subdir for docs")
  409. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/supertux2.desktop DESTINATION "share/applications")
  410. 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/")
  411. ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  412. ENDIF(WIN32 AND NOT UNIX)
  413. INSTALL(TARGETS supertux2 DESTINATION ${INSTALL_SUBDIR_BIN})
  414. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/INSTALL.md ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/NEWS.md DESTINATION ${INSTALL_SUBDIR_DOC})
  415. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/credits.txt DESTINATION ${INSTALL_SUBDIR_SHARE})
  416. INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/supertux2.appdata.xml DESTINATION "share/appdata" )
  417. INSTALL(DIRECTORY data/images
  418. data/fonts
  419. data/music
  420. data/scripts
  421. data/speech
  422. data/sounds
  423. data/locale
  424. DESTINATION ${INSTALL_SUBDIR_SHARE})
  425. IF(CMAKE_BUILD_TYPE MATCHES Release)
  426. INSTALL(DIRECTORY data/levels
  427. DESTINATION ${INSTALL_SUBDIR_SHARE}
  428. PATTERN "data/levels/test" EXCLUDE
  429. PATTERN "data/levels/test_old" EXCLUDE)
  430. ELSE()
  431. INSTALL(DIRECTORY data/levels
  432. DESTINATION ${INSTALL_SUBDIR_SHARE})
  433. ENDIF()
  434. ## Create config.h now that INSTALL_SUBDIR_* have been set.
  435. configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )
  436. ## CPack/Installation-specific stuff
  437. INCLUDE(InstallRequiredSystemLibraries)
  438. SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Jump'n'Run Game featuring Tux")
  439. SET(CPACK_PACKAGE_VENDOR "SuperTux Devel Team")
  440. SET(CPACK_PACKAGE_CONTACT "SuperTux Devel Team <supertux-devel@lists.lethargik.org>")
  441. SET(CPACK_DEBIAN_PACKAGE_NAME "supertux2")
  442. 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)")
  443. 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/")
  444. SET(CPACK_DEBIAN_PACKAGE_SECTION "games")
  445. SET(CPACK_RPM_PACKAGE_NAME "supertux2")
  446. 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/")
  447. SET(CPACK_RPM_PACKAGE_LICENSE "GNU General Public License (GPL)")
  448. SET(CPACK_RPM_PACKAGE_GROUP "Amusements/Games/Action/Arcade")
  449. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  450. # The OS X PackageMaker doesn't seem to like files with no extension
  451. ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  452. SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  453. SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
  454. ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  455. SET(CPACK_PACKAGE_VERSION_MAJOR "0")
  456. SET(CPACK_PACKAGE_VERSION_MINOR "3")
  457. SET(CPACK_PACKAGE_VERSION_PATCH "4-GIT")
  458. SET(CPACK_PACKAGE_INSTALL_DIRECTORY "SuperTux ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
  459. SET(CPACK_PACKAGE_EXECUTABLES "..\\\\supertux2" "SuperTux ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
  460. IF(WIN32 AND NOT UNIX)
  461. SET(CPACK_NSIS_INSTALLED_ICON_NAME "..\\\\supertux2")
  462. SET(CPACK_NSIS_DISPLAY_NAME "SuperTux ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
  463. SET(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
  464. ELSE(WIN32 AND NOT UNIX)
  465. ENDIF(WIN32 AND NOT UNIX)
  466. INCLUDE(CPack)
  467. # move some config clutter to the advanced section
  468. MARK_AS_ADVANCED(
  469. INSTALL_SUBDIR_BIN
  470. INSTALL_SUBDIR_SHARE
  471. INSTALL_SUBDIR_DOC
  472. )
  473. MARK_AS_ADVANCED(
  474. CMAKE_BACKWARDS_COMPATIBILITY
  475. CMAKE_BUILD_TYPE
  476. CMAKE_INSTALL_PREFIX
  477. EXECUTABLE_OUTPUT_PATH
  478. LIBRARY_OUTPUT_PATH
  479. CMAKE_OSX_ARCHITECTURES
  480. CMAKE_OSX_SYSROOT
  481. )
  482. MARK_AS_ADVANCED(
  483. APPDATADIR
  484. )
  485. MARK_AS_ADVANCED(
  486. Boost_INCLUDE_DIR
  487. Boost_LIBRARIES
  488. )
  489. MARK_AS_ADVANCED(
  490. GLEW_INCLUDE_DIR
  491. GLEW_LIBRARY
  492. )
  493. MARK_AS_ADVANCED(
  494. SDL2_INCLUDE_DIRS
  495. SDL2_LIBRARIES
  496. )
  497. MARK_AS_ADVANCED(
  498. SDL2IMAGE_INCLUDE_DIRS
  499. SDL2IMAGE_LIBRARIES
  500. )
  501. MARK_AS_ADVANCED(
  502. OPENAL_INCLUDE_DIR
  503. OPENAL_LIBRARY
  504. )
  505. MARK_AS_ADVANCED(
  506. OGG_LIBRARY
  507. VORBISENC_LIBRARY
  508. VORBISFILE_LIBRARY
  509. VORBIS_INCLUDE_DIR
  510. VORBIS_LIBRARY
  511. )
  512. MARK_AS_ADVANCED(
  513. PHYSFS_INCLUDE_DIR
  514. PHYSFS_LIBRARY
  515. )