]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
send quit game event when OS window gets closed
[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 -DRELEASE_REAL -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 -DRELEASE_REAL -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.5" 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   ${CMAKE_BINARY_DIR}/include
100   ${SDL2_INCLUDE_DIR}
101   ${OPENAL_INCLUDE_DIR}
102   ${LIBWEBSOCKETS_INCLUDE_DIR}
103   ${wxWidgets_INCLUDE_DIRS}
104 )
105
106
107 add_subdirectory(src)
108 add_subdirectory(include)
109
110
111 # ##############################################################################
112 #
113
114 #
115 # custom target for source tree version info
116 #
117
118 add_custom_target(buildver
119   COMMAND ${CMAKE_COMMAND}
120     -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
121     -DBINARY_DIR=${CMAKE_BINARY_DIR}
122     -P ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
123   WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
124   SOURCES ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
125 )
126
127 #
128 # main code/game library
129 #
130
131 add_library(code
132   STATIC
133   ${code_SOURCE}
134   ${code_HEADERS}
135   ${platform_SOURCE}
136   ${platform_HEADERS}
137 )
138
139 CreateSourceGroups(${code_SOURCE} ${platform_SOURCE})
140
141 add_dependencies(code
142   buildver
143 )
144
145 #
146 # the game itself
147 #
148
149 set(FS_BINARY "fs${BIN_SUFFIX}")
150
151 add_executable(${FS_BINARY}
152   WIN32
153   ${freespace_SOURCE}
154   ${freespace_HEADERS}
155 )
156
157 CreateSourceGroups(${freespace_SOURCE})
158
159 target_link_libraries(
160   ${FS_BINARY}
161   code
162   ${SDL2_LIBRARY}
163   ${OPENGL_LIBRARIES}
164   ${OPENAL_LIBRARY}
165   ${LIBWEBSOCKETS_LIBRARIES}
166   ${PLATFORM_LIBRARIES}
167 )
168
169 if(FS1)
170   set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
171 else()
172   set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
173 endif()
174
175 #
176 # launcher
177 #
178
179 set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
180
181 add_executable(${LAUNCHER_BINARY}
182   WIN32
183   ${launcher_SOURCE}
184   ${launcher_HEADERS}
185 )
186
187 CreateSourceGroups(${launcher_SOURCE})
188
189 target_link_libraries(
190   ${LAUNCHER_BINARY}
191   ${SDL2_LIBRARY}
192   ${OPENGL_LIBRARIES}
193   ${OPENAL_LIBRARY}
194   ${wxWidgets_LIBRARIES}
195   ${PLATFORM_LIBRARIES}
196 )
197
198 set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
199
200 # wxWidgets appears to need c++11 for one or more headers
201 if(NOT WIN32)
202   set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
203 endif()
204
205 #
206 # standalone server GUI
207 #
208
209 # Not for FS1 Demo
210 if(NOT FS1 OR NOT DEMO)
211         if(FS1)
212           set(STANDALONE_BINARY fsstandalone)
213         else()
214           set(STANDALONE_BINARY fs2standalone)
215         endif()
216
217         add_executable(${STANDALONE_BINARY}
218           WIN32
219           ${standalone_SOURCE}
220           ${standalone_HEADERS}
221         )
222
223         CreateSourceGroups(${standalone_SOURCE})
224
225         target_link_libraries(
226           ${STANDALONE_BINARY}
227           ${SDL2_LIBRARY}
228           ${wxWidgets_LIBRARIES}
229           ${LIBWEBSOCKETS_LIBRARIES}
230           ${PLATFORM_LIBRARIES}
231         )
232
233         set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
234
235         # wxWidgets appears to need c++11 for one or more headers
236         if(NOT WIN32)
237           set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
238         endif()
239 endif()
240
241 #
242 # extra rule to make sure we cleanup all exe variants
243 #
244
245 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
246   # FS1 demo
247   fsdemo${CMAKE_EXECUTABLE_SUFFIX}
248   freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
249   # FS1
250   fs${CMAKE_EXECUTABLE_SUFFIX}
251   freespace${CMAKE_EXECUTABLE_SUFFIX}
252   # FS2 demo
253   fs2demo${CMAKE_EXECUTABLE_SUFFIX}
254   freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
255   # FS2
256   fs2${CMAKE_EXECUTABLE_SUFFIX}
257   freespace2${CMAKE_EXECUTABLE_SUFFIX}
258   # standalone GUI
259   fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
260   fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
261 )
262
263 #
264 # ##############################################################################
265
266 # ##############################################################################
267 #
268 # toolset: targets for creating/modifying game assets
269 #
270
271 # don't build toolset unless it's a full build
272 if(NOT DEMO)
273
274         #
275         # AC: anim converter
276         #
277
278         add_executable(ac
279           EXCLUDE_FROM_ALL
280           ${ac_SOURCE}
281           ${ac_HEADERS}
282         )
283
284         CreateSourceGroups(${ac_SOURCE})
285
286         target_link_libraries(
287           ac
288           code
289           ${SDL2_LIBRARY}
290           ${OPENGL_LIBRARIES}
291           ${OPENAL_LIBRARY}
292           ${LIBWEBSOCKETS_LIBRARIES}
293           ${PLATFORM_LIBRARIES}
294         )
295
296         #
297         # CFILEARCHIVER: to create VP file archives
298         #
299
300         add_executable(cfilearchiver
301           EXCLUDE_FROM_ALL
302           ${cfilearchiver_SOURCE}
303         )
304
305         CreateSourceGroups(${cfilearchiver_SOURCE})
306
307         #
308         # CRYPTSTRING: string encryption (for embedded cheat codes)
309         #
310
311         add_executable(cryptstring
312           EXCLUDE_FROM_ALL
313           ${cryptstring_SOURCE}
314         )
315
316         CreateSourceGroups(${cryptstring_SOURCE})
317
318         #
319         # NEBEDIT: FS1 style nebula editor/creator
320         #
321
322         add_executable(nebedit
323           EXCLUDE_FROM_ALL
324           WIN32
325           ${nebedit_SOURCE}
326         )
327
328         CreateSourceGroups(${nebedit_SOURCE})
329
330         target_link_libraries(
331           nebedit
332           code
333           ${SDL2_LIBRARY}
334           ${OPENGL_LIBRARIES}
335           ${OPENAL_LIBRARY}
336           ${wxWidgets_LIBRARIES}
337           ${LIBWEBSOCKETS_LIBRARIES}
338           ${PLATFORM_LIBRARIES}
339         )
340
341         # wxWidgets appears to need c++11 for one or more headers
342         if(NOT WIN32)
343           set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
344         endif()
345
346         #
347         # POFVIEW: model viewer
348         #
349
350         add_executable(pofview
351           EXCLUDE_FROM_ALL
352           WIN32
353           ${pofview_SOURCE}
354           ${pofview_HEADERS}
355         )
356
357         CreateSourceGroups(${pofview_SOURCE})
358
359         target_link_libraries(
360           pofview
361           code
362           ${SDL2_LIBRARY}
363           ${OPENGL_LIBRARIES}
364           ${OPENAL_LIBRARY}
365           ${wxWidgets_LIBRARIES}
366           ${LIBWEBSOCKETS_LIBRARIES}
367           ${PLATFORM_LIBRARIES}
368         )
369
370         # wxWidgets appears to need c++11 for one or more headers
371         if(NOT WIN32)
372           set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
373         endif()
374
375         #
376         # SCRAMBLE: file-based encryption for TBLs
377         #
378
379         add_executable(scramble
380           EXCLUDE_FROM_ALL
381           ${scramble_SOURCE}
382           ${scramble_HEADERS}
383         )
384
385         CreateSourceGroups(${scramble_SOURCE})
386
387         #
388         # FONTTOOL: create font files / edit kerning data
389         #
390
391         add_executable(fonttool
392           EXCLUDE_FROM_ALL
393           ${fonttool_SOURCE}
394           ${fonttool_HEADERS}
395         )
396
397         CreateSourceGroups(${fonttool_SOURCE})
398
399         # background setup, to allow running from build location without installing
400         add_custom_command(TARGET fonttool
401           POST_BUILD
402           COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
403           COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
404         )
405
406         target_link_libraries(
407           fonttool
408           code
409           ${SDL2_LIBRARY}
410           ${OPENGL_LIBRARIES}
411           ${OPENAL_LIBRARY}
412           ${LIBWEBSOCKETS_LIBRARIES}
413           ${PLATFORM_LIBRARIES}
414         )
415
416         #
417         # custom target to build all tools in one pass
418         #
419
420         add_custom_target(tools)
421
422         add_dependencies(tools
423           ac
424           cfilearchiver
425           cryptstring
426           nebedit
427           pofview
428           scramble
429           fonttool
430         )
431
432 endif(NOT DEMO)
433
434 #
435 # ##############################################################################
436
437 #
438 # optionally include any dev/user preferred build commands and/or options
439 #
440
441 include(custom.cmake OPTIONAL)