]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
merge updated graphics code
[taylor/freespace2.git] / CMakeLists.txt
1
2 project(freespace2)
3
4 cmake_minimum_required(VERSION 2.8)
5 cmake_policy(VERSION 2.8)
6
7 if(POLICY CMP0043)
8   cmake_policy(SET CMP0043 OLD)
9 endif()
10
11 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
12
13 include(CreateSourceGroups)
14
15
16 # ##############################################################################
17
18 option(FS1 "Build original FreeSpace" OFF)
19 option(DEMO "Create demo build" OFF)
20
21 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
22   message(STATUS "Setting build type to 'Debug' as none was specified.")
23   set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
24   # Set the possible values of build type for cmake-gui
25   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
26     "MinSizeRel" "RelWithDebInfo")
27 endif()
28
29
30 if(FS1)
31   add_definitions(-DMAKE_FS1)
32
33   if(DEMO)
34         add_definitions(-DDEMO -DFS1_DEMO)
35   endif()
36 else()
37   if(DEMO)
38         add_definitions(-DFS2_DEMO)
39   endif()
40 endif()
41
42 if(NOT WIN32)
43   set(PLATFORM_LIBRARIES "")
44
45   add_definitions(-DPLAT_UNIX)
46   add_definitions(-Wall)
47   add_definitions(-Wshadow)
48 # add_definitions(-Wno-format-y2k)
49 # add_definitions(-Wno-deprecated)
50   add_definitions(-fsigned-char)
51
52   set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG -g -O2")
53   set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG -Os")
54   set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
55   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
56 else()
57   set(SDL2DIR "${CMAKE_SOURCE_DIR}/../Support/SDL2" CACHE PATH "Path to SDL2")
58   set(OPENALDIR "${CMAKE_SOURCE_DIR}/../Support/OpenAL" CACHE PATH "Path to OpenAL")
59   set(LWSDIR "${CMAKE_SOURCE_DIR}/../Support/libwebsockets" CACHE PATH "Path to libwebsockets")
60   set(WXWIDGETSDIR "${CMAKE_SOURCE_DIR}/../Support/wxWidgets" CACHE PATH "Path to wxWidgets")
61   set(ANGLEDIR "${CMAKE_SOURCE_DIR}/../Support/ANGLE" CACHE PATH "Path to ANGLE")
62
63   set(PLATFORM_LIBRARIES
64         ws2_32.lib
65         ${ANGLEDIR}/lib/libEGL.lib
66         ${ANGLEDIR}/lib/libGLESv2.lib
67   )
68
69   add_definitions(/D _CRT_SECURE_NO_WARNINGS)
70   add_definitions(/W4)
71   add_definitions(/wd4100) # unreferenced parameter
72   add_definitions(/wd4127) # conditional expression is constant: do { } while (0)
73   add_definitions(/wd4996) # deprecated functions: fopen, fileno, ...
74 endif()
75
76 set(BIN_SUFFIX "")
77
78 if(NOT FS1)
79         set(BIN_SUFFIX "2")
80 endif()
81
82 if(DEMO)
83         set(BIN_SUFFIX "${BIN_SUFFIX}demo")
84 endif()
85
86 find_package(SDL2 "2.0.1" REQUIRED)
87 find_package(OpenGL REQUIRED)
88 find_package(OpenAL REQUIRED)
89 find_package(LibWebSockets REQUIRED)
90
91 find_package(wxWidgets COMPONENTS core base gl net)
92 include(${wxWidgets_USE_FILE})
93
94 # ##############################################################################
95
96
97 include_directories(
98   ${PROJECT_SOURCE_DIR}/include
99   ${SDL2_INCLUDE_DIR}
100   ${OPENAL_INCLUDE_DIR}
101   ${LIBWEBSOCKETS_INCLUDE_DIR}
102   ${wxWidgets_INCLUDE_DIRS}
103 )
104
105
106 add_subdirectory(src)
107 add_subdirectory(include)
108
109
110 # ##############################################################################
111 #
112
113 #
114 # main code/game library
115 #
116
117 add_library(code
118   STATIC
119   ${code_SOURCE}
120   ${code_HEADERS}
121   ${platform_SOURCE}
122   ${platform_HEADERS}
123 )
124
125 CreateSourceGroups(${code_SOURCE} ${platform_SOURCE})
126
127 #
128 # the game itself
129 #
130
131 set(FS_BINARY "fs${BIN_SUFFIX}")
132
133 add_executable(${FS_BINARY}
134   WIN32
135   ${freespace_SOURCE}
136   ${freespace_HEADERS}
137 )
138
139 CreateSourceGroups(${freespace_SOURCE})
140
141 target_link_libraries(
142   ${FS_BINARY}
143   code
144   ${SDL2_LIBRARY}
145   ${OPENGL_LIBRARIES}
146   ${OPENAL_LIBRARY}
147   ${LIBWEBSOCKETS_LIBRARIES}
148   ${PLATFORM_LIBRARIES}
149 )
150
151 if(FS1)
152   set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
153 else()
154   set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
155 endif()
156
157 #
158 # launcher
159 #
160
161 set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
162
163 add_executable(${LAUNCHER_BINARY}
164   WIN32
165   ${launcher_SOURCE}
166   ${launcher_HEADERS}
167 )
168
169 CreateSourceGroups(${launcher_SOURCE})
170
171 target_link_libraries(
172   ${LAUNCHER_BINARY}
173   ${SDL2_LIBRARY}
174   ${OPENGL_LIBRARIES}
175   ${OPENAL_LIBRARY}
176   ${wxWidgets_LIBRARIES}
177   ${PLATFORM_LIBRARIES}
178 )
179
180 set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
181
182 # wxWidgets appears to need c++11 for one or more headers
183 if(NOT WIN32)
184   set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
185 endif()
186
187 #
188 # standalone server GUI
189 #
190
191 if(FS1)
192   set(STANDALONE_BINARY fsstandalone)
193 else()
194   set(STANDALONE_BINARY fs2standalone)
195 endif()
196
197 add_executable(${STANDALONE_BINARY}
198   WIN32
199   ${standalone_SOURCE}
200   ${standalone_HEADERS}
201 )
202
203 CreateSourceGroups(${standalone_SOURCE})
204
205 target_link_libraries(
206   ${STANDALONE_BINARY}
207   ${SDL2_LIBRARY}
208   ${wxWidgets_LIBRARIES}
209   ${LIBWEBSOCKETS_LIBRARIES}
210   ${PLATFORM_LIBRARIES}
211 )
212
213 set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
214
215 # wxWidgets appears to need c++11 for one or more headers
216 if(NOT WIN32)
217   set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
218 endif()
219
220 #
221 # ##############################################################################
222
223 # ##############################################################################
224 #
225 # toolset: targets for creating/modifying game assets
226 #
227
228 #
229 # AC: anim converter
230 #
231
232 add_executable(ac
233   EXCLUDE_FROM_ALL
234   ${ac_SOURCE}
235   ${ac_HEADERS}
236 )
237
238 CreateSourceGroups(${ac_SOURCE})
239
240 target_link_libraries(
241   ac
242   code
243   ${SDL2_LIBRARY}
244   ${OPENGL_LIBRARIES}
245   ${OPENAL_LIBRARY}
246   ${LIBWEBSOCKETS_LIBRARIES}
247   ${PLATFORM_LIBRARIES}
248 )
249
250 #
251 # CFILEARCHIVER: to create VP file archives
252 #
253
254 add_executable(cfilearchiver
255   EXCLUDE_FROM_ALL
256   ${cfilearchiver_SOURCE}
257 )
258
259 CreateSourceGroups(${cfilearchiver_SOURCE})
260
261 #
262 # CRYPTSTRING: string encryption (for embedded cheat codes)
263 #
264
265 add_executable(cryptstring
266   EXCLUDE_FROM_ALL
267   ${cryptstring_SOURCE}
268 )
269
270 CreateSourceGroups(${cryptstring_SOURCE})
271
272 #
273 # NEBEDIT: FS1 style nebula editor/creator
274 #
275
276 add_executable(nebedit
277   EXCLUDE_FROM_ALL
278   WIN32
279   ${nebedit_SOURCE}
280 )
281
282 CreateSourceGroups(${nebedit_SOURCE})
283
284 target_link_libraries(
285   nebedit
286   code
287   ${SDL2_LIBRARY}
288   ${OPENGL_LIBRARIES}
289   ${OPENAL_LIBRARY}
290   ${wxWidgets_LIBRARIES}
291   ${LIBWEBSOCKETS_LIBRARIES}
292   ${PLATFORM_LIBRARIES}
293 )
294
295 # wxWidgets appears to need c++11 for one or more headers
296 if(NOT WIN32)
297   set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
298 endif()
299
300 #
301 # POFVIEW: model viewer
302 #
303
304 add_executable(pofview
305   EXCLUDE_FROM_ALL
306   WIN32
307   ${pofview_SOURCE}
308   ${pofview_HEADERS}
309 )
310
311 CreateSourceGroups(${pofview_SOURCE})
312
313 target_link_libraries(
314   pofview
315   code
316   ${SDL2_LIBRARY}
317   ${OPENGL_LIBRARIES}
318   ${OPENAL_LIBRARY}
319   ${wxWidgets_LIBRARIES}
320   ${LIBWEBSOCKETS_LIBRARIES}
321   ${PLATFORM_LIBRARIES}
322 )
323
324 # wxWidgets appears to need c++11 for one or more headers
325 if(NOT WIN32)
326   set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
327 endif()
328
329 #
330 # SCRAMBLE: file-based encryption for TBLs
331 #
332
333 add_executable(scramble
334   EXCLUDE_FROM_ALL
335   ${scramble_SOURCE}
336   ${scramble_HEADERS}
337 )
338
339 CreateSourceGroups(${scramble_SOURCE})
340
341 #
342 # FONTTOOL: create font files / edit kerning data
343 #
344
345 add_executable(fonttool
346   EXCLUDE_FROM_ALL
347   ${fonttool_SOURCE}
348   ${fonttool_HEADERS}
349 )
350
351 CreateSourceGroups(${fonttool_SOURCE})
352
353 # background setup, to allow running from build location without installing
354 add_custom_command(TARGET fonttool
355   POST_BUILD
356   COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
357   COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
358 )
359
360 target_link_libraries(
361   fonttool
362   code
363   ${SDL2_LIBRARY}
364   ${OPENGL_LIBRARIES}
365   ${OPENAL_LIBRARY}
366   ${LIBWEBSOCKETS_LIBRARIES}
367   ${PLATFORM_LIBRARIES}
368 )
369
370 #
371 # custom target to build all tools in one pass
372 #
373
374 add_custom_target(tools)
375
376 add_dependencies(tools
377   ac
378   cfilearchiver
379   cryptstring
380   nebedit
381   pofview
382   scramble
383   fonttool
384 )
385
386 #
387 # ##############################################################################
388
389 #
390 # optionally include any dev/user preferred build commands and/or options
391 #
392
393 include(custom.cmake OPTIONAL)