add wraparound support to C2 physics
[openc2e.git] / CMakeLists.txt
blob6fa33e10e05067cc97ba6c37e0eb77e719df5829
1 PROJECT (OPENC2E CXX C)
3 SET(SRC "${OPENC2E_SOURCE_DIR}")
4 SET(BIN "${OPENC2E_BINARY_DIR}")
5 SET(GEN "${BIN}/generated")
6 EXECUTE_PROCESS(COMMAND mkdir "${GEN}" -p)
8 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS 1)
9 SET(CMAKE_MODULE_PATH "${SRC}/cmake")
11 SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "The type of build to perform. Valid values are: RelWithDebInfo (default), Debug, Release, MinSizeRel")
12 IF (CMAKE_BUILD_TYPE STREQUAL "")
13         SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "The type of build to perform. Valid values are: RelWithDebInfo (default), Debug, Release, MinSizeRel" FORCE)
14 ENDIF (CMAKE_BUILD_TYPE STREQUAL "")
16 SET(OPENC2E_USE_QT "TRUE" CACHE BOOL "Build the qt GUI")
17 SET(OPENC2E_USE_OPENAL "AUTO" CACHE STRING "Use OpenAL (YES/NO/AUTO)")
18 IF (OPENC2E_USE_OPENAL MATCHES "^(YES|NO|AUTO)$")
19 ELSE (OPENC2E_USE_OPENAL MATCHES "^(YES|NO|AUTO)$")
20         MESSAGE(SEND_ERROR "The value of OPENC2E_USE_OPENAL must be YES, NO, or AUTO.")
21 ENDIF (OPENC2E_USE_OPENAL MATCHES "^(YES|NO|AUTO)$")
23 SET(OPENC2E_USE_SERIALIZATION "FALSE" CACHE BOOL "Build the experimental serialization code")
24 MARK_AS_ADVANCED(FORCE OPENC2E_USE_SERIALIZATION)
25 IF (OPENC2E_USE_SERIALIZATION)
26         SET(SER_SRCS caosVM_ser_real.cpp)
27 ELSE (OPENC2E_USE_SERIALIZATION)
28         SET(SER_SRCS caosVM_ser_stub.cpp)
29 ENDIF (OPENC2E_USE_SERIALIZATION)
32 SET(OPENC2E_CORE
33         Agent.cpp
34         AgentHelpers.cpp
35         AgentRef.cpp
36         attFile.cpp
37         Backend.cpp
38         Blackboard.cpp
39         blkImage.cpp
40         bmpImage.cpp
41         Bubble.cpp
42         bytecode.cpp
43         c16Image.cpp
44         c2eBrain.cpp
45         CallButton.cpp
46         Camera.cpp
47         caosScript.cpp
48         caosVar.cpp
49         caosVM_agent.cpp
50         caosVM_camera.cpp
51         caosVM_compound.cpp
52         caosVM_core.cpp
53         caosVM_creatures.cpp
54         caosVM_debug.cpp
55         caosVM_files.cpp
56         caosVM_flow.cpp
57         caosVM_genetics.cpp
58         caosVM_history.cpp
59         caosVM_input.cpp
60         caosVM_map.cpp
61         caosVM_motion.cpp
62         caosVM_net.cpp
63         caosVM.cpp
64         caosVM_ports.cpp
65         caosVM_resources.cpp
66         caosVM_scripts.cpp
67         caosVM_sounds.cpp
68         caosVM_time.cpp
69         caosVM_variables.cpp
70         caosVM_vectors.cpp
71         caosVM_vehicles.cpp
72         caosVM_world.cpp
73         ${GEN}/cataloglexer.cpp
74         Catalogue.cpp
75         ${GEN}/catalogue.tab.cpp
76         ${GEN}/cmddata.cpp
77         cobFile.cpp
78         CompoundAgent.cpp
79         CompoundPart.cpp
80         Creature.cpp
81         CreatureAgent.cpp
82         creaturesImage.cpp
83         dialect.cpp
84         Engine.cpp
85         exceptions.cpp
86         fileSwapper.cpp
87         genomeFile.cpp
88         historyManager.cpp
89         imageManager.cpp
90         #       ${GEN}/lex.mng.cpp
91         ${GEN}/caoslexer.cpp
92         Lift.cpp
93         Map.cpp
94         MetaRoom.cpp
95         mmapifstream.cpp
96         #       mngfile.cpp
97         #       ${GEN}/mngparser.tab.cpp
98         oldBrain.cpp
99         PathResolver.cpp
100         physics.cpp
101         PointerAgent.cpp
102         Port.cpp
103         pray.cpp
104         prayManager.cpp
105         renderable.cpp
106         Room.cpp
107         Scriptorium.cpp
108         SDLBackend.cpp
109         SFCFile.cpp
110         SimpleAgent.cpp
111         SkeletalCreature.cpp
112         sprImage.cpp
113         streamutils.cpp
114         Vehicle.cpp
115         World.cpp
116         main.cpp
117         util.cpp
120 SET(OPENC2E_SDL
121         # all in the main openc2e listing
122         # XXX: non-sdl-based backends?
125 SET(OPENC2E_QT
126         qtgui/qtopenc2e.cpp
127         qtgui/openc2eview.cpp
128         qtgui/AgentInjector.cpp
129         qtgui/BrainViewer.cpp
130         qtgui/imagepreview.cpp
131         qtgui/c1cobfile.cpp
132         qtgui/QtBackend.cpp
133         qtgui/GraphWidget.cpp
134         qtgui/CreatureGrapher.cpp
135         qtgui/Hatchery.cpp
136         tools/braininavat/brainview.cpp)
138 SET(OPENC2E_QT_MOC_HDRS
139         qtgui/qtopenc2e.h
140         qtgui/openc2eview.h
141         qtgui/AgentInjector.h
142         qtgui/BrainViewer.h
143         qtgui/imagepreview.h
144         qtgui/GraphWidget.h
145         qtgui/CreatureGrapher.h
146         qtgui/Hatchery.h
147         tools/braininavat/brainview.h)
149 SET(OPENC2E_QT_UIS
150         qtgui/agents.ui)
154 cmake_minimum_required(VERSION 2.4.0)
155 INCLUDE(TestBigEndian)
156 INCLUDE(CheckIncludeFile)
157 TEST_BIG_ENDIAN(BIG_ENDIAN)
158 IF(BIG_ENDIAN)
159         ADD_DEFINITIONS("-DOC2E_BIG_ENDIAN=1")
160         CHECK_INCLUDE_FILE(byteswap.h HAVE_BYTESWAP_H)
161         IF(HAVE_BYTESWAP_H)
162                 ADD_DEFINITIONS("-DHAVE_BYTESWAP_H=1")
163         ELSE(HAVE_BYTESWAP_H)
164                 ADD_DEFINITIONS("-DHAVE_BYTESWAP_H=0")
165         ENDIF(HAVE_BYTESWAP_H)
166 ELSE(BIG_ENDIAN)
167         ADD_DEFINITIONS("-DOC2E_BIG_ENDIAN=0")
168 ENDIF(BIG_ENDIAN)
169 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
170 IF(HAVE_STDINT_H)
171         ADD_DEFINITIONS("-DHAVE_STDINT_H=1")
172 ELSE(HAVE_STDINT_H)
173 ENDIF(HAVE_STDINT_H)
175 FIND_PACKAGE(SDL REQUIRED)
176 #FIND_PACKAGE(SDL_mixer REQUIRED)
177 FIND_PACKAGE(SDL_net REQUIRED)
178 FIND_PACKAGE(SDL_gfx REQUIRED)
179 FIND_PACKAGE(SDL_ttf REQUIRED)
180 IF(OPENC2E_USE_OPENAL MATCHES "^(YES|AUTO)$")
181         FIND_PACKAGE(OpenAL)
182 ELSE(OPENC2E_USE_OPENAL MATCHES "^(YES|AUTO)$")
183         SET(OPENAL_FOUND "NO")
184 ENDIF(OPENC2E_USE_OPENAL MATCHES "^(YES|AUTO)$")
185 FIND_PACKAGE(ALUT)
186 FIND_PACKAGE(Boost REQUIRED)
187 IF(OPENC2E_USE_QT)
188         find_package(Qt4 REQUIRED)
189 ENDIF(OPENC2E_USE_QT)
191 SET(USE_OPENAL "NO")
193 IF(OPENAL_FOUND STREQUAL "YES")
194     IF(ALUT_FOUND STREQUAL "YES")
195         SET(USE_OPENAL "YES")
196     ENDIF(ALUT_FOUND STREQUAL "YES")
197 ENDIF(OPENAL_FOUND STREQUAL "YES")
198      
199 IF(USE_OPENAL STREQUAL "NO")
200         IF (OPENC2E_USE_OPENAL MATCHES "^YES")
201                 MESSAGE(FATAL_ERROR "OpenAL not found.")
202         ENDIF (OPENC2E_USE_OPENAL MATCHES "^YES")
203         
204     SET(ALUT_INCLUDE_DIR "")
205     SET(OPENAL_INCLUDE_DIR "")
206     SET(ALUT_LIBRARY "")
207     SET(OPENAL_LIBRARY "")
208     SET(OPENAL_SRC "")
209     SET(OPENAL_DEF "")
210 ELSE(OPENAL_SRC STREQUAL "")
211     SET(OPENAL_SRC "OpenALBackend.cpp")
212     SET(OPENAL_DEF "-DOPENAL_SUPPORT")
213 ENDIF(OPENAL_SRC STREQUAL "")
215 IF(OPENC2E_USE_QT)
216         include(${QT_USE_FILE})
217         SET(SAVED_CMAKE_CURRENT_BINARY_DIR CMAKE_CURRENT_BINARY_DIR)
218         SET(CMAKE_CURRENT_BINARY_DIR ${GEN})
219         QT4_WRAP_UI(OPENC2E_QT_UIS_H ${OPENC2E_QT_UIS})
220         QT4_WRAP_CPP(OPENC2E_QT_MOC_SRCS ${OPENC2E_QT_MOC_HDRS})
221         SET(CMAKE_CURRENT_BINARY_DIR SAVED_CMAKE_CURRENT_BINARY_DIR)
222         SET(QT_DEF "-DQT_SUPPORT")
223 ENDIF(OPENC2E_USE_QT)
225 # Pass flags to the compiler
226 ADD_DEFINITIONS("-W -Wall -Wno-conversion -Wno-unused -pthread -D_REENTRANT -DYYERROR_VERBOSE ${OPENAL_DEF} ${QT_DEF}")
228 IF(OPENC2E_USE_QT)
229         SET(FRONTEND_SRCS ${OPENC2E_QT} ${OPENC2E_QT_UIS_H} ${OPENC2E_QT_MOC_SRCS})
230         SET(FRONTEND_LIBS ${QT_LIBRARIES})
231 ELSE(OPENC2E_USE_QT)
232         SET(FRONTEND_SRCS ${OPENC2E_SDL})
233         SET(FRONTEND_LIBS)
234 ENDIF(OPENC2E_USE_QT)
235 ADD_EXECUTABLE(openc2e ${OPENC2E_CORE} ${FRONTEND_SRCS} ${OPENAL_SRC} ${SER_SRCS})
237 TARGET_LINK_LIBRARIES(openc2e z m pthread 
238         ${SDL_LIBRARY}
239 #       ${SDLMIXER_LIBRARY} 
240         ${SDLNET_LIBRARY}
241         ${SDLTTF_LIBRARY}
242         ${SDLGFX_LIBRARY}
243         ${OPENAL_LIBRARY}
244         ${ALUT_LIBRARY}
245         ${FRONTEND_LIBS}
246         boost_program_options-mt
247         boost_serialization-mt
248         boost_filesystem-mt
249         boost_thread-mt
250         boost_regex-mt
251         )
253 LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
255 INCLUDE_DIRECTORIES(BEFORE
256         ${GEN}
257         ${SRC}
258         ${SDL_INCLUDE_DIR}
259 #       ${SDLMIXER_INCLUDE_DIR}
260         ${SDLNET_INCLUDE_DIR}
261         ${SDLTTF_INCLUDE_DIR}
262         ${SDLGFX_INCLUDE_DIR}
263         ${OPENAL_INCLUDE_DIR}
264         ${ALUT_INCLUDE_DIR}
265         ${Boost_INCLUDE_DIR}
266         )
268 FILE(GLOB CAOSVM_FILES ${SRC}/caosVM_*.cpp)
269 ADD_CUSTOM_COMMAND(
270         OUTPUT ${GEN}/commandinfo.yml
271         COMMAND perl parsedocs.pl ${CAOSVM_FILES} > ${GEN}/commandinfo.yml
272         DEPENDS parsedocs.pl ${CAOSVM_FILES}
273         WORKING_DIRECTORY ${SRC})
275 ADD_CUSTOM_COMMAND(
276         OUTPUT ${BIN}/caosdocs.html
277         COMMAND perl writehtml.pl ${GEN}/commandinfo.yml > ${BIN}/caosdocs.html
278         DEPENDS writehtml.pl ${GEN}/commandinfo.yml
279         WORKING_DIRECTORY ${SRC})
280 ADD_CUSTOM_COMMAND(
281         OUTPUT ${BIN}/docs.css
282         COMMAND cp docs.css ${BIN}/docs.css
283         DEPENDS docs.css
284         WORKING_DIRECTORY ${SRC})
285 ADD_CUSTOM_COMMAND(
286         OUTPUT ${BIN}/openc2e.6
287         COMMAND pod2man --center="Openc2e Documentation" --section=6 ${SRC}/openc2e.pod ${BIN}/openc2e.6
288         DEPENDS openc2e.pod
289         )
290 # it seems these ADD_CUSTOM_COMMANDS for flex and bison could be made
291 # into a macro... e.g. FLEX(file1) FLEX(file2) etc...
292 ADD_CUSTOM_COMMAND(
293         OUTPUT ${GEN}/cataloglexer.cpp
294         COMMAND re2c -o ${GEN}/cataloglexer.cpp ${SRC}/cataloglexer.re2c
295         DEPENDS ${SRC}/cataloglexer.re2c
296         WORKING_DIRECTORY ${SRC})
298 ADD_CUSTOM_COMMAND(
299         OUTPUT ${GEN}/catalogue.tab.cpp ${GEN}/catalogue.tab.hpp
300         COMMAND bison -d --name-prefix=cata --file-prefix="${GEN}/catalogue" catalogue.ypp
301         DEPENDS catalogue.ypp
302         WORKING_DIRECTORY ${SRC})
304 ADD_CUSTOM_COMMAND(
305         OUTPUT ${GEN}/cmddata.cpp
306         COMMAND perl writecmds.pl ${GEN}/commandinfo.yml > ${GEN}/cmddata.cpp
307         DEPENDS ${GEN}/commandinfo.yml writecmds.pl
308         WORKING_DIRECTORY ${SRC})
310 ADD_CUSTOM_COMMAND(
311         OUTPUT ${GEN}/caoslexer.cpp
312         COMMAND re2c -o ${GEN}/caoslexer.cpp ${SRC}/caoslexer.re2c
313         DEPENDS ${SRC}/caoslexer.re2c
314         WORKING_DIRECTORY ${SRC})
316 #ADD_CUSTOM_COMMAND(
317 #       OUTPUT ${GEN}/lex.mng.cpp ${GEN}/lex.mng.h
318 #       COMMAND flex -+ --prefix=mng -d -o ${GEN}/lex.mng.cpp --header-file=${GEN}/lex.mng.h mng.l
319 #       DEPENDS mng.l
320 #       WORKING_DIRECTORY ${SRC})
322 #ADD_CUSTOM_COMMAND(
323 #       OUTPUT ${GEN}/mngparser.tab.cpp ${GEN}/mngparser.tab.hpp
324 #       COMMAND bison -d --name-prefix=mng --file-prefix="${GEN}/mngparser" mngparser.ypp
325 #       DEPENDS mngparser.ypp
326 #       WORKING_DIRECTORY ${SRC})
328 ADD_CUSTOM_TARGET(docs ALL DEPENDS ${BIN}/caosdocs.html ${BIN}/docs.css ${BIN}/openc2e.6)
329 ADD_CUSTOM_TARGET(generated DEPENDS
330         ${GEN}/catalogue.tab.cpp ${GEN}/catalogue.tab.hpp
331         ${GEN}/caoslexer.cpp
332         ${GEN}/cataloglexer.cpp
333         ${GEN}/cmddata.cpp
334         #       ${GEN}/lex.mng.cpp ${GEN}/lex.mng.h
335         #       ${GEN}/mngparser.tab.cpp ${GEN}/mngparser.tab.hpp