Fix OpenGL detection and miniswig wrapper generation for CMake
[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 # FIXME: provide working install target
39 #
40
41
42 ## (Optional) Generate noisy Makefile
43
44 #SET(CMAKE_VERBOSE_MAKEFILE on)
45
46 ## Project name to use as command prefix
47
48 PROJECT(SUPERTUX)
49
50 ## Some default settings
51
52 set(DEBUG 0 CACHE BOOL "Build with debugging options")
53 set(ENABLE_BINRELOC 0 CACHE BOOL "Enable autopackage's BINRELOC features")
54 set(APPDATADIR "" CACHE STRING "APPDATADIR for autopackage's BINRELOC features")
55 set(ENABLE_SQDBG 0 CACHE BOOL "Build squirrel script interpreter with debugging options")
56 set(ENABLE_OPENGL 1 CACHE BOOL "Enable OpenGL support")
57
58 ## Search here for additional cmake modules (for finding deps)
59
60 set(CMAKE_MODULE_PATH ${SUPERTUX_SOURCE_DIR}/mk/cmake ${CMAKE_MODULE_PATH})
61
62 ## Add lots of dependencies to compiler switches
63
64 FIND_PACKAGE(SDL REQUIRED)
65 INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
66 LINK_LIBRARIES(${SDL_LIBRARY})
67
68 FIND_PACKAGE(SDL_image REQUIRED)
69 INCLUDE_DIRECTORIES(${SDLIMAGE_INCLUDE_DIR})
70 LINK_LIBRARIES(${SDLIMAGE_LIBRARY})
71
72 IF(ENABLE_OPENGL)
73   FIND_PACKAGE(OpenGL)
74   INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
75   LINK_LIBRARIES(${OPENGL_LIBRARY})
76   SET(HAVE_OPENGL OPENGL_FOUND)
77 ENDIF(ENABLE_OPENGL)
78
79 FIND_PACKAGE(OpenAL REQUIRED)
80 INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR})
81 LINK_LIBRARIES(${OPENAL_LIBRARY})
82
83 FIND_PACKAGE(OggVorbis REQUIRED)
84 INCLUDE_DIRECTORIES(${OGGVORBIS_INCLUDE_DIR})
85 LINK_LIBRARIES(${OGGVORBIS_LIBRARIES})
86
87 FIND_PACKAGE(PhysFS REQUIRED)
88 INCLUDE_DIRECTORIES(${PHYSFS_INCLUDE_DIR})
89 LINK_LIBRARIES(${PHYSFS_LIBRARY})
90
91 #FIND_PACKAGE(ICONV REQUIRED)
92 #INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
93 #LINK_LIBRARIES(${ICONV_LIBRARY})
94
95 ## Check platform-dependent build options
96
97 INCLUDE(ConfigureChecks)
98
99 ## Create config.h
100
101 configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )
102 include_directories (${CMAKE_BINARY_DIR}/)
103
104 ## Also execute instructions in tools/miniswig/CMakeLists.txt
105 ADD_SUBDIRECTORY(tools/miniswig)
106
107 ## Also execute instructions in src/squirrel/CMakeLists.txt
108
109 ADD_SUBDIRECTORY(src/squirrel)
110
111 ## Add squirrel lib dir to search path
112
113 LINK_DIRECTORIES(src/squirrel)
114
115 ## Some additional include paths
116
117 include_directories (${SUPERTUX_SOURCE_DIR}/src/)
118 include_directories (${SUPERTUX_SOURCE_DIR}/src/squirrel/include/)
119
120 ## Build list of sources for supertux binary
121
122 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)
123
124 ## Generate miniswig wrapper
125
126 ADD_CUSTOM_COMMAND(
127   OUTPUT ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.cpp ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.hpp
128   COMMAND ${CMAKE_CXX_COMPILER}
129   ARGS -x "c++" -E -CC -DSCRIPTING_API -I${SUPERTUX_SOURCE_DIR}/src/ -I${SUPERTUX_SOURCE_DIR}/src/squirrel/include/ ${SUPERTUX_SOURCE_DIR}/src/scripting/wrapper.interface.hpp -o miniswig.tmp
130   COMMAND tools/miniswig/miniswig
131   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
132   DEPENDS src/scripting/wrapper.interface.hpp tools/miniswig/miniswig
133 )
134
135 ## If xgettext is available, generate messages.pot for sources
136
137 FIND_PROGRAM(
138   XGETTEXT 
139   NAMES "xgettext"
140   PATHS "/usr/bin"
141 )
142 IF(${XGETTEXT} STREQUAL "XGETTEXT-NOTFOUND")
143   MESSAGE(STATUS "Warning: xgettext not found - will not update messages.pot")
144 ELSE(${XGETTEXT} STREQUAL "XGETTEXT-NOTFOUND")
145   MESSAGE(STATUS "Found xgettext: ${XGETTEXT}")
146   SET(MESSAGES_POT_FILE ${SUPERTUX_SOURCE_DIR}/data/locale/messages.pot)
147   ADD_CUSTOM_TARGET(
148     supertux-messages.pot ALL 
149     COMMAND "/usr/bin/xgettext" -k_ -C -o ${MESSAGES_POT_FILE} ${SUPERTUX_SOURCES}
150     DEPENDS ${SUPERTUX_SOURCES}
151     WORKING_DIRECTORY ${SUPERTUX_SOURCE_DIR}
152   )
153 ENDIF(${XGETTEXT} STREQUAL "XGETTEXT-NOTFOUND")
154
155 ## Some additional compiler switches
156
157 ADD_DEFINITIONS(-O2 -fno-strict-aliasing)
158
159 ## Add target for supertux binary
160
161 ADD_EXECUTABLE(supertux2 ${SUPERTUX_SOURCES} )
162
163 ## Link supertux binary with squirrel
164
165 TARGET_LINK_LIBRARIES(supertux2 squirrel)
166
167 ## After building, copy binary to source root
168
169 ADD_CUSTOM_COMMAND(
170   TARGET supertux2
171   POST_BUILD
172   COMMAND ${CMAKE_COMMAND}
173   ARGS -E copy supertux2 ${SUPERTUX_SOURCE_DIR}/supertux2
174 )
175