Detect and active the addon manager in the cmake build
[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 # FIXME: create config.h from config.h.in
37 # FIXME: create messages.pot for levels
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 )
60
61
62 ## Some default settings
63
64 OPTION(ENABLE_SQDBG "Build squirrel script interpreter with debugging options" FALSE)
65 OPTION(ENABLE_OPENGL "Enable OpenGL support" TRUE)
66 OPTION(GENERATE_WRAPPER "Build miniswig and generate the wrapper" ${DEBUG})
67
68
69 ## For autopackage
70 MARK_AS_ADVANCED(
71         ENABLE_BINRELOC
72         APPDATADIR
73 )
74 OPTION(ENABLE_BINRELOC "Enable autopackage's BINRELOC features" FALSE)
75 OPTION(APPDATADIR "APPDATADIR for autopackage's BINRELOC features" "${CMAKE_INSTALL_PREFIX}/share")
76
77 ## Check endianess
78
79 INCLUDE(TestBigEndian)
80 TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
81
82 ## Add lots of dependencies to compiler switches
83
84 FIND_PACKAGE(SDL REQUIRED)
85 MARK_AS_ADVANCED(
86         SDLMAIN_LIBRARY
87         SDL_INCLUDE_DIR
88         SDL_LIBRARY
89 )
90 INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
91 LINK_LIBRARIES(${SDL_LIBRARY})
92
93 FIND_PACKAGE(SDL_image REQUIRED)
94 MARK_AS_ADVANCED(
95         SDLIMAGE_INCLUDE_DIR
96         SDLIMAGE_LIBRARY
97 )
98 INCLUDE_DIRECTORIES(${SDLIMAGE_INCLUDE_DIR})
99 LINK_LIBRARIES(${SDLIMAGE_LIBRARY})
100
101 IF(ENABLE_OPENGL)
102   FIND_PACKAGE(OpenGL)
103   IF(${OPENGL_FOUND} STREQUAL "YES")
104     INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
105     LINK_LIBRARIES(${OPENGL_LIBRARY})
106     SET(HAVE_OPENGL TRUE)
107   ENDIF(${OPENGL_FOUND} STREQUAL "YES")
108 ENDIF(ENABLE_OPENGL)
109
110 FIND_PACKAGE(OpenAL REQUIRED)
111 MARK_AS_ADVANCED(
112         OPENAL_INCLUDE_DIR
113         OPENAL_LIBRARY
114 )
115 INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR})
116 LINK_LIBRARIES(${OPENAL_LIBRARY})
117
118 FIND_PACKAGE(OggVorbis REQUIRED)
119 MARK_AS_ADVANCED(
120         OGG_LIBRARY
121         VORBISENC_LIBRARY
122         VORBISFILE_LIBRARY
123         VORBIS_INCLUDE_DIR
124         VORBIS_LIBRARY
125 )
126 INCLUDE_DIRECTORIES(${OGGVORBIS_INCLUDE_DIR})
127 LINK_LIBRARIES(${OGGVORBIS_LIBRARIES})
128
129 FIND_PACKAGE(PhysFS REQUIRED)
130 MARK_AS_ADVANCED(
131         PHYSFS_INCLUDE_DIR
132         PHYSFS_LIBRARY
133 )
134 INCLUDE_DIRECTORIES(${PHYSFS_INCLUDE_DIR})
135 LINK_LIBRARIES(${PHYSFS_LIBRARY})
136
137 FIND_PACKAGE(CURL)
138 IF(${CURL_FOUND})
139   INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
140   LINK_LIBRARIES(${CURL_LIBRARY})
141   SET(HAVE_LIBCURL TRUE)
142 ENDIF(${CURL_FOUND})
143
144 #FIND_PACKAGE(ICONV REQUIRED)
145 #INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
146 #LINK_LIBRARIES(${ICONV_LIBRARY})
147
148 ## Check platform-dependent build options
149
150 INCLUDE(ConfigureChecks)
151
152 ## Create config.h
153
154 configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )
155 include_directories (${CMAKE_BINARY_DIR}/)
156
157 ## Also execute instructions in src/squirrel/CMakeLists.txt
158
159 ADD_SUBDIRECTORY(src/squirrel)
160
161 ## Add squirrel lib dir to search path
162
163 LINK_DIRECTORIES(src/squirrel)
164
165 ## Some additional include paths
166
167 include_directories (${SUPERTUX_SOURCE_DIR}/src/)
168 include_directories (${SUPERTUX_SOURCE_DIR}/src/squirrel/include/)
169
170 ## Build list of sources for supertux binary
171
172 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)
173
174 ## Add in squirrel debug stuff
175
176 IF(ENABLE_SQDBG)
177   include_directories (${SUPERTUX_SOURCE_DIR}/src/squirrel/)
178   FILE(GLOB SQDBG_SOURCES RELATIVE ${SUPERTUX_SOURCE_DIR} src/squirrel/sqdbg/*.cpp)
179   SET(SUPERTUX_SOURCES ${SQDBG_SOURCES} ${SUPERTUX_SOURCES})
180 ENDIF(ENABLE_SQDBG)
181
182 ## Build miniswig and generate miniswig wrapper
183
184 IF(GENERATE_WRAPPER)
185   ADD_SUBDIRECTORY(tools/miniswig)
186   ADD_CUSTOM_COMMAND(
187     OUTPUT ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.cpp ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.hpp
188     COMMAND cd ${SUPERTUX_SOURCE_DIR} && ${CMAKE_CXX_COMPILER}
189     ARGS -x "c++" -E -CC -DSCRIPTING_API src/scripting/wrapper.interface.hpp -o ${SUPERTUX_BINARY_DIR}/miniswig.tmp
190     COMMAND tools/miniswig/miniswig
191     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
192     DEPENDS src/scripting/wrapper.interface.hpp tools/miniswig/miniswig
193   )
194 ENDIF(GENERATE_WRAPPER)
195
196 IF(NOT EXISTS ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.cpp)
197   SET(SUPERTUX_SOURCES ${SUPERTUX_SOURCES})
198 ENDIF(NOT EXISTS ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.cpp)
199
200 ## If xgettext is available, generate messages.pot for sources
201
202 #FIND_PROGRAM(
203 #  XGETTEXT 
204 #  NAMES "xgettext"
205 #  PATHS "/usr/bin"
206 #)
207 #IF(${XGETTEXT} STREQUAL "XGETTEXT-NOTFOUND")
208 #  MESSAGE(STATUS "Warning: xgettext not found - will not update messages.pot")
209 #ELSE(${XGETTEXT} STREQUAL "XGETTEXT-NOTFOUND")
210 #  MESSAGE(STATUS "Found xgettext: ${XGETTEXT}")
211 #  SET(MESSAGES_POT_FILE ${SUPERTUX_SOURCE_DIR}/data/locale/messages.pot)
212 #  ADD_CUSTOM_TARGET(
213 #    supertux-messages.pot ALL 
214 #    COMMAND "/usr/bin/xgettext" -k_ -C -o ${MESSAGES_POT_FILE} ${SUPERTUX_SOURCES}
215 #    DEPENDS ${SUPERTUX_SOURCES}
216 #    WORKING_DIRECTORY ${SUPERTUX_SOURCE_DIR}
217 #  )
218 #ENDIF(${XGETTEXT} STREQUAL "XGETTEXT-NOTFOUND")
219
220
221 ## Debug options
222
223 OPTION(DEBUG "Build with debugging options" FALSE)
224 IF (DEBUG)
225         REMOVE_DEFINITIONS(-O2)
226         ADD_DEFINITIONS(-O0 -g -pg -Wall -Werror)
227 ELSE (DEBUG)
228         ADD_DEFINITIONS(-O2)
229         REMOVE_DEFINITIONS(-O0 -g -pg -Wall -Werror)
230 ENDIF (DEBUG)
231
232
233 ## Some additional compiler switches
234 ADD_DEFINITIONS(-fno-strict-aliasing)
235
236
237 ## Generate supertux executable in the right place
238
239 SET(EXECUTABLE_OUTPUT_PATH ${SUPERTUX_SOURCE_DIR})
240
241 ## Add target for supertux binary
242
243 ADD_EXECUTABLE(supertux2 ${SUPERTUX_SOURCES})
244
245 ## Link supertux binary with squirrel
246
247 TARGET_LINK_LIBRARIES(supertux2 squirrel)
248
249 ## Install stuff
250
251 INSTALL(TARGETS supertux2 DESTINATION bin)
252
253 INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/data/images/engine/icons/supertux.png ${SUPERTUX_SOURCE_DIR}/data/images/engine/icons/supertux.xpm DESTINATION share/pixmaps)
254
255 INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/supertux2.desktop DESTINATION share/applications)
256
257 INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/INSTALL ${SUPERTUX_SOURCE_DIR}/README ${SUPERTUX_SOURCE_DIR}/COPYING ${SUPERTUX_SOURCE_DIR}/WHATSNEW.txt DESTINATION doc/supertux-0.3.x)
258
259 INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/data/credits.txt ${SUPERTUX_SOURCE_DIR}/data/camera.cfg DESTINATION share/supertux2)
260 INSTALL(DIRECTORY data/images DESTINATION share/supertux2 PATTERN ".svn" EXCLUDE)
261 INSTALL(DIRECTORY data/levels DESTINATION share/supertux2 PATTERN ".svn" EXCLUDE)
262 INSTALL(DIRECTORY data/music DESTINATION share/supertux2 PATTERN ".svn" EXCLUDE)
263 INSTALL(DIRECTORY data/scripts DESTINATION share/supertux2 PATTERN ".svn" EXCLUDE)
264 INSTALL(DIRECTORY data/speech DESTINATION share/supertux2 PATTERN ".svn" EXCLUDE)
265 INSTALL(DIRECTORY data/sounds DESTINATION share/supertux2 PATTERN ".svn" EXCLUDE)
266 INSTALL(DIRECTORY data/locale DESTINATION share/supertux2 PATTERN ".svn" EXCLUDE)