Some CMake vars for experimental Debian packs
[supertux.git] / CMakeLists.txt
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
21 #
22 # INSTRUCTIONS:
23 # -------------
24 #
25 # Create a directory build/ and change to it. Run
26 #
27 #   cmake ..
28 #
29 # This creates a set of Makefiles to build the project. Run
30 #
31 #   make
32 #
33
34
35 #
36 # Open Issues:
37 #  - none?
38 #
39
40
41 ## Project name to use as command prefix
42
43 PROJECT(SUPERTUX)
44
45
46 ### CMake configuration
47
48 # allow building with old CMake. Use some bundled modules as a fallback
49 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
50 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${SUPERTUX_SOURCE_DIR}/mk/cmake)
51
52 # move some config clutter to the advanced section
53 MARK_AS_ADVANCED(
54         CMAKE_BACKWARDS_COMPATIBILITY
55         CMAKE_BUILD_TYPE
56         CMAKE_INSTALL_PREFIX
57         EXECUTABLE_OUTPUT_PATH
58         LIBRARY_OUTPUT_PATH
59         CMAKE_OSX_ARCHITECTURES
60         CMAKE_OSX_SYSROOT
61 )
62
63 ## For autopackage
64 MARK_AS_ADVANCED(
65         ENABLE_BINRELOC
66         APPDATADIR
67 )
68 OPTION(ENABLE_BINRELOC "Enable autopackage's BINRELOC features" OFF)
69 SET(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/games" CACHE STRING "APPDATADIR for autopackage's BINRELOC features")
70
71 ## Check endianess
72
73 INCLUDE(TestBigEndian)
74 TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
75
76 ## Add lots of dependencies to compiler switches
77
78 FIND_PACKAGE(SDL REQUIRED)
79 MARK_AS_ADVANCED(
80         SDLMAIN_LIBRARY
81         SDL_INCLUDE_DIR
82         SDL_LIBRARY
83 )
84 INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
85 LINK_LIBRARIES(${SDL_LIBRARY})
86
87 FIND_PACKAGE(SDL_image REQUIRED)
88 MARK_AS_ADVANCED(
89         SDLIMAGE_INCLUDE_DIR
90         SDLIMAGE_LIBRARY
91 )
92 INCLUDE_DIRECTORIES(${SDLIMAGE_INCLUDE_DIR})
93 LINK_LIBRARIES(${SDLIMAGE_LIBRARY})
94
95 OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
96 IF(ENABLE_OPENGL)
97   FIND_PACKAGE(OpenGL)
98   IF(${OPENGL_FOUND} STREQUAL "YES")
99     INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
100     LINK_LIBRARIES(${OPENGL_LIBRARY})
101     SET(HAVE_OPENGL TRUE)
102   ENDIF(${OPENGL_FOUND} STREQUAL "YES")
103 ENDIF(ENABLE_OPENGL)
104
105 FIND_PACKAGE(OpenAL REQUIRED)
106 MARK_AS_ADVANCED(
107         OPENAL_INCLUDE_DIR
108         OPENAL_LIBRARY
109 )
110 INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR})
111 LINK_LIBRARIES(${OPENAL_LIBRARY})
112
113 FIND_PACKAGE(OggVorbis REQUIRED)
114 MARK_AS_ADVANCED(
115         OGG_LIBRARY
116         VORBISENC_LIBRARY
117         VORBISFILE_LIBRARY
118         VORBIS_INCLUDE_DIR
119         VORBIS_LIBRARY
120 )
121 INCLUDE_DIRECTORIES(${OGGVORBIS_INCLUDE_DIR})
122 LINK_LIBRARIES(${OGGVORBIS_LIBRARIES})
123
124 FIND_PACKAGE(PhysFS REQUIRED)
125 MARK_AS_ADVANCED(
126         PHYSFS_INCLUDE_DIR
127         PHYSFS_LIBRARY
128 )
129 INCLUDE_DIRECTORIES(${PHYSFS_INCLUDE_DIR})
130 LINK_LIBRARIES(${PHYSFS_LIBRARY})
131
132 FIND_PACKAGE(CURL)
133 IF(CURL_FOUND)
134   INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
135   LINK_LIBRARIES(${CURL_LIBRARY})
136   SET(HAVE_LIBCURL TRUE)
137 ENDIF(CURL_FOUND)
138
139 #FIND_PACKAGE(ICONV REQUIRED)
140 #INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
141 #LINK_LIBRARIES(${ICONV_LIBRARY})
142
143 ## Check platform-dependent build options
144
145 INCLUDE(ConfigureChecks)
146
147 ## Create config.h
148
149 configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )
150 include_directories (${CMAKE_BINARY_DIR}/)
151
152 ## Also execute instructions in src/squirrel/CMakeLists.txt
153
154 ADD_SUBDIRECTORY(src/squirrel)
155
156 ## Add squirrel lib dir to search path
157
158 LINK_DIRECTORIES(src/squirrel)
159
160 ## Some additional include paths
161
162 include_directories (${SUPERTUX_SOURCE_DIR}/src/)
163 include_directories (${SUPERTUX_SOURCE_DIR}/src/squirrel/include/)
164
165 ## Build list of sources for supertux binary
166
167 FILE(GLOB SUPERTUX_SOURCES RELATIVE ${SUPERTUX_SOURCE_DIR} src/*.cpp src/audio/*.cpp src/badguy/*.cpp src/binreloc/*.cpp src/control/*.cpp src/gui/*.cpp src/lisp/*.cpp src/math/*.cpp src/object/*.cpp src/physfs/*.cpp src/sprite/*.cpp src/tinygettext/*.cpp src/trigger/*.cpp src/video/*.cpp src/worldmap/*.cpp src/scripting/*.cpp src/obstack/*.c)
168
169 ## Debug options
170
171 OPTION(DEBUG "Build with debugging options" OFF)
172 OPTION(PROFILE "Build with profiling information" OFF)
173 IF(CMAKE_COMPILER_IS_GNUCC)
174   IF (DEBUG)
175     REMOVE_DEFINITIONS(-O2)
176     ADD_DEFINITIONS(-O0 -g -Wall -Werror)
177   ELSE (DEBUG)
178     ADD_DEFINITIONS(-O2)
179     REMOVE_DEFINITIONS(-O0 -g -Wall -Werror)
180   ENDIF (DEBUG)
181   IF (PROFILE)
182     ADD_DEFINITIONS(-pg)
183   ELSE (PROFILE)
184     REMOVE_DEFINITIONS(-pg)
185   ENDIF (PROFILE)
186 ENDIF(CMAKE_COMPILER_IS_GNUCC)
187
188 ## Add in squirrel debug stuff
189
190 OPTION(ENABLE_SQDBG "Build squirrel script interpreter with debugging options" OFF)
191 IF(ENABLE_SQDBG)
192   include_directories (${SUPERTUX_SOURCE_DIR}/src/squirrel/)
193   FILE(GLOB SQDBG_SOURCES RELATIVE ${SUPERTUX_SOURCE_DIR} src/squirrel/sqdbg/*.cpp)
194   SET(SUPERTUX_SOURCES ${SQDBG_SOURCES} ${SUPERTUX_SOURCES})
195 ENDIF(ENABLE_SQDBG)
196
197 ## Build miniswig and generate miniswig wrapper
198
199 OPTION(GENERATE_WRAPPER "Build miniswig and generate the wrapper" ${DEBUG})
200 IF(GENERATE_WRAPPER)
201   ADD_SUBDIRECTORY(tools/miniswig)
202   ADD_CUSTOM_COMMAND(
203     OUTPUT ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.cpp ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.hpp
204     COMMAND cd ${SUPERTUX_SOURCE_DIR} && ${CMAKE_CXX_COMPILER}
205     ARGS -x "c++" -E -CC -DSCRIPTING_API src/scripting/wrapper.interface.hpp -o ${SUPERTUX_BINARY_DIR}/miniswig.tmp
206     COMMAND tools/miniswig/miniswig
207     ARGS --input miniswig.tmp --output-cpp ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.cpp --output-hpp ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.hpp --module supertux --select-namespace Scripting
208     DEPENDS src/scripting/wrapper.interface.hpp tools/miniswig/miniswig
209   )
210 ENDIF(GENERATE_WRAPPER)
211
212 IF(NOT EXISTS ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.cpp)
213   SET(SUPERTUX_SOURCES ${SUPERTUX_SOURCES} ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.cpp)
214 ENDIF(NOT EXISTS ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.cpp)
215
216 ## If xgettext is available, generate messages.pot for sources
217
218 OPTION(GENERATE_MESSAGESPOT "Generate messages.pot files" ${DEBUG})
219 IF(GENERATE_MESSAGESPOT)
220   MARK_AS_ADVANCED(
221     XGETTEXT_EXECUTABLE
222   )
223   FIND_PROGRAM(XGETTEXT_EXECUTABLE xgettext)
224   IF(NOT XGETTEXT_EXECUTABLE)
225     MESSAGE(STATUS "Warning: xgettext not found - will not update messages.pot")
226   ELSE(NOT XGETTEXT_EXECUTABLE)
227     MESSAGE(STATUS "Found xgettext: ${XGETTEXT_EXECUTABLE}")
228
229     SET(MESSAGES_POT_FILE ${SUPERTUX_SOURCE_DIR}/data/locale/messages.pot)
230     ADD_CUSTOM_COMMAND(
231       OUTPUT ${MESSAGES_POT_FILE}
232       COMMAND ${XGETTEXT_EXECUTABLE}
233       ARGS --keyword=_ --language=C++ --output=${MESSAGES_POT_FILE} ${SUPERTUX_SOURCES}
234       DEPENDS ${SUPERTUX_SOURCES}
235       WORKING_DIRECTORY ${SUPERTUX_SOURCE_DIR}
236       COMMENT "Generating POT file ${MESSAGES_POT_FILE}"
237     )
238     LIST(APPEND MESSAGES_POT_FILES ${MESSAGES_POT_FILE})
239
240     FILE(GLOB SUPERTUX_LEVEL_DIRS RELATIVE ${SUPERTUX_SOURCE_DIR} data/levels/*)
241     LIST(REMOVE_ITEM SUPERTUX_LEVEL_DIRS "data/levels/.svn")
242     FOREACH(SUPERTUX_LEVEL_DIR ${SUPERTUX_LEVEL_DIRS})
243       FILE(GLOB SUPERTUX_LEVELS RELATIVE ${SUPERTUX_SOURCE_DIR} ${SUPERTUX_LEVEL_DIR}/*.stl ${SUPERTUX_LEVEL_DIR}/*.stwm ${SUPERTUX_LEVEL_DIR}/*.txt)
244
245       SET(MESSAGES_POT_FILE ${SUPERTUX_SOURCE_DIR}/${SUPERTUX_LEVEL_DIR}/messages.pot)
246       ADD_CUSTOM_COMMAND(
247         OUTPUT ${MESSAGES_POT_FILE}
248         COMMAND ${XGETTEXT_EXECUTABLE}
249         ARGS --keyword="_:1" --language=Lisp --sort-by-file --output=${MESSAGES_POT_FILE} ${SUPERTUX_LEVELS}
250         DEPENDS ${SUPERTUX_LEVELS}
251         WORKING_DIRECTORY ${SUPERTUX_SOURCE_DIR}
252         COMMENT "Generating POT file ${MESSAGES_POT_FILE}"
253       )
254       LIST(APPEND MESSAGES_POT_FILES ${MESSAGES_POT_FILE})
255
256     ENDFOREACH(SUPERTUX_LEVEL_DIR)
257
258     ADD_CUSTOM_TARGET(
259       supertux2-messages ALL 
260       DEPENDS ${MESSAGES_POT_FILES}
261     )
262
263   ENDIF(NOT XGETTEXT_EXECUTABLE)
264 ENDIF(GENERATE_MESSAGESPOT)
265
266 ## Some additional compiler switches
267 IF(CMAKE_COMPILER_IS_GNUCC)
268   ADD_DEFINITIONS(-fno-strict-aliasing)
269 ENDIF(CMAKE_COMPILER_IS_GNUCC)
270
271 IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
272   ADD_DEFINITIONS(-DMACOSX)
273 ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
274
275
276 ## On Windows, add an icon
277
278 IF(WIN32)
279   SET(SUPERTUX_SOURCES ${SUPERTUX_SOURCES} ${SUPERTUX_SOURCE_DIR}/data/images/engine/icons/supertux.rc)
280   IF(MINGW)
281     ADD_CUSTOM_COMMAND(
282     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o
283     COMMAND windres.exe -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)
284     SET(SUPERTUX_SOURCES ${SUPERTUX_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o)
285   ELSE(MINGW)
286     SET(SUPERTUX_EXE_SRCS ${SUPERTUX_EXE_SRCS} supertux.rc)
287   ENDIF(MINGW)
288 ENDIF(WIN32)
289
290
291 ## Generate supertux executable in the right place
292
293 SET(EXECUTABLE_OUTPUT_PATH ${SUPERTUX_SOURCE_DIR})
294
295 ## Add target for supertux binary
296
297 ADD_EXECUTABLE(supertux2 ${SUPERTUX_SOURCES})
298
299 ## Link supertux binary with squirrel
300
301 TARGET_LINK_LIBRARIES(supertux2 squirrel)
302
303
304 ## Install stuff
305
306 IF(WIN32 AND NOT UNIX)
307
308   SET(INSTALL_SUBDIR_BIN ".")
309   SET(INSTALL_SUBDIR_SHARE "data/")
310   SET(INSTALL_SUBDIR_DOC ".")
311
312   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/SDL.dll DESTINATION ${INSTALL_SUBDIR_BIN})
313   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/SDL_image.dll DESTINATION ${INSTALL_SUBDIR_BIN})
314   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/iconv.dll DESTINATION ${INSTALL_SUBDIR_BIN})
315   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/libogg-0.dll DESTINATION ${INSTALL_SUBDIR_BIN})
316   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/libphysfs-1-0-0.dll DESTINATION ${INSTALL_SUBDIR_BIN})
317   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/OpenAl32.dll DESTINATION ${INSTALL_SUBDIR_BIN})
318   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/wrap_oal.dll DESTINATION ${INSTALL_SUBDIR_BIN})
319   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/libcurl-4.dll DESTINATION ${INSTALL_SUBDIR_BIN})
320
321   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/data/images/engine/icons/supertux.png ${SUPERTUX_SOURCE_DIR}/data/images/engine/icons/supertux.ico DESTINATION ".")
322
323 ELSE(WIN32 AND NOT UNIX)
324 IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
325
326   SET(INSTALL_SUBDIR_BIN "SuperTux.app/Contents/MacOS/")
327   SET(INSTALL_SUBDIR_SHARE "SuperTux.app/Contents/Resources/data/")
328   SET(INSTALL_SUBDIR_DOC "SuperTux.app/Contents/Resources/")
329
330   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/tools/darwin/info.plist DESTINATION "SuperTux.app/Contents/")
331
332   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/data/images/engine/icons/supertux.png ${SUPERTUX_SOURCE_DIR}/data/images/engine/icons/supertux.icns DESTINATION "SuperTux.app/Contents/Resources/")
333
334 ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
335
336   SET(INSTALL_SUBDIR_BIN "games/")
337   SET(INSTALL_SUBDIR_SHARE "share/games/supertux2/")
338   SET(INSTALL_SUBDIR_DOC "share/doc/supertux2/")
339
340   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/supertux2.desktop DESTINATION "share/applications")
341
342   INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/data/images/engine/icons/supertux.png ${SUPERTUX_SOURCE_DIR}/data/images/engine/icons/supertux.xpm DESTINATION "share/pixmaps/")
343
344 ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
345 ENDIF(WIN32 AND NOT UNIX)
346
347 INSTALL(TARGETS supertux2 DESTINATION ${INSTALL_SUBDIR_BIN})
348
349 INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/INSTALL ${SUPERTUX_SOURCE_DIR}/README ${SUPERTUX_SOURCE_DIR}/COPYING ${SUPERTUX_SOURCE_DIR}/WHATSNEW.txt DESTINATION ${INSTALL_SUBDIR_DOC})
350
351 INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/data/credits.txt ${SUPERTUX_SOURCE_DIR}/data/camera.cfg DESTINATION ${INSTALL_SUBDIR_SHARE})
352 INSTALL(DIRECTORY data/images DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
353 INSTALL(DIRECTORY data/levels DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
354 INSTALL(DIRECTORY data/music DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
355 INSTALL(DIRECTORY data/scripts DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
356 INSTALL(DIRECTORY data/speech DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
357 INSTALL(DIRECTORY data/sounds DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
358 INSTALL(DIRECTORY data/locale DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
359
360
361 ## CPack/Installation-specific stuff
362
363 INCLUDE(InstallRequiredSystemLibraries)
364 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "SuperTux")
365 SET(CPACK_PACKAGE_VENDOR "SuperTux Devel Team")
366 SET(CPACK_PACKAGE_CONTACT "SuperTux Devel Team <supertux-devel@lists.lethargik.org>")
367 SET(CPACK_DEBIAN_PACKAGE_NAME "supertux2")
368 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)")
369 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 completly 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/")
370 IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
371   # The OS X PackageMaker doesn't seem to like files with no extension
372 ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
373   SET(CPACK_PACKAGE_DESCRIPTION_FILE "${SUPERTUX_SOURCE_DIR}/README")
374   SET(CPACK_RESOURCE_FILE_LICENSE "${SUPERTUX_SOURCE_DIR}/COPYING")
375 ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
376 SET(CPACK_PACKAGE_VERSION_MAJOR "0")
377 SET(CPACK_PACKAGE_VERSION_MINOR "3")
378 SET(CPACK_PACKAGE_VERSION_PATCH "1-SVN")
379 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "SuperTux ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
380 SET(CPACK_PACKAGE_EXECUTABLES "..\\\\supertux2" "SuperTux ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
381 IF(WIN32 AND NOT UNIX)
382   SET(CPACK_NSIS_INSTALLED_ICON_NAME "..\\\\supertux2")
383   SET(CPACK_NSIS_DISPLAY_NAME "SuperTux ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
384 ELSE(WIN32 AND NOT UNIX)
385 ENDIF(WIN32 AND NOT UNIX)
386 INCLUDE(CPack)
387