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