]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
add RELEASE_REAL define to other release build types
[taylor/freespace2.git] / CMakeLists.txt
1
2 project(freespace2)
3
4 cmake_minimum_required(VERSION 2.8.6)
5 cmake_policy(VERSION 2.8.6)
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
20 if(EMSCRIPTEN)
21   # only build for demo with emscripten
22   set(DEMO 1)
23 else()
24   option(DEMO "Create demo build" OFF)
25 endif()
26
27 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
28   message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
29   set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
30   # Set the possible values of build type for cmake-gui
31   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo")
32 endif()
33
34
35 if(FS1)
36   add_definitions(-DMAKE_FS1)
37
38   if(DEMO)
39     add_definitions(-DDEMO -DFS1_DEMO)
40   endif()
41 else()
42   if(DEMO)
43     add_definitions(-DFS2_DEMO)
44   endif()
45 endif()
46
47 # build everything by default
48 set(GAME_ONLY)
49
50 if(DEMO)
51   set(GAME_ONLY 1)
52 endif()
53
54 if(EMSCRIPTEN)
55   set(GAME_ONLY 1)
56   add_definitions(-s USE_SDL=2)
57   add_definitions(-s FULL_ES2=1)
58
59   set(CMAKE_EXECUTABLE_SUFFIX ".html")
60 endif()
61
62 if(NOT EMSCRIPTEN)
63   add_definitions(-DLEGACY_GL)
64 endif()
65
66 if(NOT WIN32)
67   set(PLATFORM_LIBRARIES "")
68
69   add_definitions(-DPLAT_UNIX)
70   add_definitions(-Wall)
71   add_definitions(-Wshadow)
72 # add_definitions(-Wno-format-y2k)
73 # add_definitions(-Wno-deprecated)
74   add_definitions(-fsigned-char)
75
76   set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG -DRELEASE_REAL -g -O2")
77   set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG -DRELEASE_REAL -Os")
78   set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -DRELEASE_REAL -O3")
79   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
80 else()
81   set(SDL2DIR "${CMAKE_SOURCE_DIR}/../Support/SDL2" CACHE PATH "Path to SDL2")
82   set(OPENALDIR "${CMAKE_SOURCE_DIR}/../Support/OpenAL" CACHE PATH "Path to OpenAL")
83   set(LWSDIR "${CMAKE_SOURCE_DIR}/../Support/libwebsockets" CACHE PATH "Path to libwebsockets")
84   set(WXWIDGETSDIR "${CMAKE_SOURCE_DIR}/../Support/wxWidgets" CACHE PATH "Path to wxWidgets")
85   set(ANGLEDIR "${CMAKE_SOURCE_DIR}/../Support/ANGLE" CACHE PATH "Path to ANGLE")
86
87   set(PLATFORM_LIBRARIES
88     ws2_32.lib
89     ${ANGLEDIR}/lib/libEGL.lib
90     ${ANGLEDIR}/lib/libGLESv2.lib
91   )
92
93   add_definitions(/D _CRT_SECURE_NO_WARNINGS)
94   add_definitions(/W4)
95   add_definitions(/wd4100) # unreferenced parameter
96   add_definitions(/wd4127) # conditional expression is constant: do { } while (0)
97   add_definitions(/wd4996) # deprecated functions: fopen, fileno, ...
98 endif()
99
100 set(BIN_SUFFIX "")
101
102 if(NOT FS1)
103         set(BIN_SUFFIX "2")
104 endif()
105
106 if(DEMO)
107         set(BIN_SUFFIX "${BIN_SUFFIX}demo")
108 endif()
109
110 find_package(SDL2 "2.0.5" REQUIRED)
111 find_package(OpenGL REQUIRED)
112 find_package(OpenAL REQUIRED)
113
114 if(NOT EMSCRIPTEN)
115   find_package(LibWebSockets REQUIRED)
116
117   find_package(wxWidgets COMPONENTS core base gl net)
118   include(${wxWidgets_USE_FILE})
119 endif()
120
121 # ##############################################################################
122
123
124 include_directories(
125   ${PROJECT_SOURCE_DIR}/include
126   ${CMAKE_BINARY_DIR}/include
127   ${SDL2_INCLUDE_DIR}
128   ${OPENAL_INCLUDE_DIR}
129   ${LIBWEBSOCKETS_INCLUDE_DIR}
130   ${wxWidgets_INCLUDE_DIRS}
131 )
132
133
134 add_subdirectory(src)
135 add_subdirectory(include)
136
137
138 # ##############################################################################
139 #
140
141 #
142 # custom target for source tree version info
143 #
144
145 add_custom_target(buildver
146   COMMAND ${CMAKE_COMMAND}
147     -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
148     -DBINARY_DIR=${CMAKE_BINARY_DIR}
149     -P ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
150   WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
151   SOURCES ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
152 )
153
154 #
155 # main code/game library
156 #
157
158 add_library(code
159   STATIC
160   ${code_SOURCE}
161   ${code_HEADERS}
162   ${platform_SOURCE}
163   ${platform_HEADERS}
164 )
165
166 CreateSourceGroups(${code_SOURCE} ${platform_SOURCE})
167
168 add_dependencies(code
169   buildver
170 )
171
172 #
173 # the game itself
174 #
175
176 set(FS_BINARY "fs${BIN_SUFFIX}")
177
178 add_executable(${FS_BINARY}
179   WIN32
180   ${freespace_SOURCE}
181   ${freespace_HEADERS}
182 )
183
184 CreateSourceGroups(${freespace_SOURCE})
185
186 target_link_libraries(
187   ${FS_BINARY}
188   code
189   ${SDL2_LIBRARY}
190   ${OPENGL_LIBRARIES}
191   ${OPENAL_LIBRARY}
192   ${LIBWEBSOCKETS_LIBRARIES}
193   ${PLATFORM_LIBRARIES}
194 )
195
196 if (EMSCRIPTEN)
197   set_target_properties(${FS_BINARY}
198     PROPERTIES LINK_FLAGS
199     "-s USE_SDL=2 -s FULL_ES2=1 -s WASM=1 -s TOTAL_MEMORY=184549376 --shell-file ${CMAKE_SOURCE_DIR}/dist/fs_shell.html --preload-file game@/"
200   )
201 endif()
202
203 if(FS1)
204   set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
205 else()
206   set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
207 endif()
208
209 #
210 # launcher
211 #
212
213 if(NOT GAME_ONLY)
214   set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
215
216   add_executable(${LAUNCHER_BINARY}
217   WIN32
218     ${launcher_SOURCE}
219     ${launcher_HEADERS}
220   )
221
222   add_dependencies(${LAUNCHER_BINARY}
223     buildver
224   )
225
226   CreateSourceGroups(${launcher_SOURCE})
227
228   target_link_libraries(
229     ${LAUNCHER_BINARY}
230     ${SDL2_LIBRARY}
231     ${OPENGL_LIBRARIES}
232     ${OPENAL_LIBRARY}
233     ${wxWidgets_LIBRARIES}
234     ${PLATFORM_LIBRARIES}
235   )
236
237   set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
238
239   # wxWidgets appears to need c++11 for one or more headers
240   if(NOT WIN32)
241   set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
242   endif()
243 endif(NOT GAME_ONLY)
244
245 #
246 # standalone server GUI
247 #
248
249 if(NOT GAME_ONLY)
250   # Not for FS1 Demo
251   if(NOT FS1 OR NOT DEMO)
252     if(FS1)
253       set(STANDALONE_BINARY fsstandalone)
254     else()
255       set(STANDALONE_BINARY fs2standalone)
256     endif()
257
258     add_executable(${STANDALONE_BINARY}
259       WIN32
260       ${standalone_SOURCE}
261       ${standalone_HEADERS}
262     )
263
264     CreateSourceGroups(${standalone_SOURCE})
265
266     target_link_libraries(
267       ${STANDALONE_BINARY}
268       ${SDL2_LIBRARY}
269       ${wxWidgets_LIBRARIES}
270       ${LIBWEBSOCKETS_LIBRARIES}
271       ${PLATFORM_LIBRARIES}
272     )
273
274     set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
275
276     # wxWidgets appears to need c++11 for one or more headers
277     if(NOT WIN32)
278       set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
279     endif()
280   endif(NOT FS1 OR NOT DEMO)
281 endif(NOT GAME_ONLY)
282
283 #
284 # extra rule to make sure we cleanup all exe variants
285 #
286
287 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
288   # FS1 demo
289   fsdemo${CMAKE_EXECUTABLE_SUFFIX}
290   fsdemo.wasm
291   fsdemo.js
292   fsdemo.data
293   freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
294   # FS1
295   fs${CMAKE_EXECUTABLE_SUFFIX}
296   fs.wasm
297   fs.js
298   fs.data
299   freespace${CMAKE_EXECUTABLE_SUFFIX}
300   # FS2 demo
301   fs2demo${CMAKE_EXECUTABLE_SUFFIX}
302   fs2demo.wasm
303   fs2demo.js
304   fs2demo.data
305   freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
306   # FS2
307   fs2${CMAKE_EXECUTABLE_SUFFIX}
308   fs2.wasm
309   fs2.js
310   fs2.data
311   freespace2${CMAKE_EXECUTABLE_SUFFIX}
312   # standalone GUI
313   fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
314   fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
315 )
316
317 #
318 # ##############################################################################
319
320 # ##############################################################################
321 #
322 # toolset: targets for creating/modifying game assets
323 #
324
325 # don't build toolset unless it's a full build
326 if(NOT GAME_ONLY)
327
328   #
329   # AC: anim converter
330   #
331
332   add_executable(ac
333     EXCLUDE_FROM_ALL
334     ${ac_SOURCE}
335     ${ac_HEADERS}
336   )
337
338   CreateSourceGroups(${ac_SOURCE})
339
340   target_link_libraries(
341     ac
342     code
343     ${SDL2_LIBRARY}
344     ${OPENGL_LIBRARIES}
345     ${OPENAL_LIBRARY}
346     ${LIBWEBSOCKETS_LIBRARIES}
347     ${PLATFORM_LIBRARIES}
348   )
349
350   #
351   # CFILEARCHIVER: to create VP file archives
352   #
353
354   add_executable(cfilearchiver
355     EXCLUDE_FROM_ALL
356     ${cfilearchiver_SOURCE}
357   )
358
359   CreateSourceGroups(${cfilearchiver_SOURCE})
360
361   #
362   # CRYPTSTRING: string encryption (for embedded cheat codes)
363   #
364
365   add_executable(cryptstring
366     EXCLUDE_FROM_ALL
367     ${cryptstring_SOURCE}
368   )
369
370   CreateSourceGroups(${cryptstring_SOURCE})
371
372   #
373   # NEBEDIT: FS1 style nebula editor/creator
374   #
375
376   add_executable(nebedit
377     EXCLUDE_FROM_ALL
378     WIN32
379     ${nebedit_SOURCE}
380   )
381
382   CreateSourceGroups(${nebedit_SOURCE})
383
384   target_link_libraries(
385     nebedit
386     code
387     ${SDL2_LIBRARY}
388     ${OPENGL_LIBRARIES}
389     ${OPENAL_LIBRARY}
390     ${wxWidgets_LIBRARIES}
391     ${LIBWEBSOCKETS_LIBRARIES}
392     ${PLATFORM_LIBRARIES}
393   )
394
395   # wxWidgets appears to need c++11 for one or more headers
396   if(NOT WIN32)
397     set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
398   endif()
399
400   #
401   # POFVIEW: model viewer
402   #
403
404   add_executable(pofview
405     EXCLUDE_FROM_ALL
406     WIN32
407     ${pofview_SOURCE}
408     ${pofview_HEADERS}
409   )
410
411   CreateSourceGroups(${pofview_SOURCE})
412
413   target_link_libraries(
414     pofview
415     code
416     ${SDL2_LIBRARY}
417     ${OPENGL_LIBRARIES}
418     ${OPENAL_LIBRARY}
419     ${wxWidgets_LIBRARIES}
420     ${LIBWEBSOCKETS_LIBRARIES}
421     ${PLATFORM_LIBRARIES}
422   )
423
424   # wxWidgets appears to need c++11 for one or more headers
425   if(NOT WIN32)
426     set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
427   endif()
428
429   #
430   # SCRAMBLE: file-based encryption for TBLs
431   #
432
433   add_executable(scramble
434     EXCLUDE_FROM_ALL
435     ${scramble_SOURCE}
436     ${scramble_HEADERS}
437   )
438
439   CreateSourceGroups(${scramble_SOURCE})
440
441   #
442   # FONTTOOL: create font files / edit kerning data
443   #
444
445   add_executable(fonttool
446     EXCLUDE_FROM_ALL
447     ${fonttool_SOURCE}
448     ${fonttool_HEADERS}
449   )
450
451   CreateSourceGroups(${fonttool_SOURCE})
452
453   # background setup, to allow running from build location without installing
454   add_custom_command(TARGET fonttool
455     POST_BUILD
456     COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
457     COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
458   )
459
460   target_link_libraries(
461     fonttool
462     code
463     ${SDL2_LIBRARY}
464     ${OPENGL_LIBRARIES}
465     ${OPENAL_LIBRARY}
466     ${LIBWEBSOCKETS_LIBRARIES}
467     ${PLATFORM_LIBRARIES}
468   )
469
470   #
471   # custom target to build all tools in one pass
472   #
473
474   add_custom_target(tools)
475
476   add_dependencies(tools
477     ac
478     cfilearchiver
479     cryptstring
480     nebedit
481     pofview
482     scramble
483     fonttool
484   )
485
486 endif(NOT GAME_ONLY)
487
488 #
489 # ##############################################################################
490
491 #
492 # optionally include any dev/user preferred build commands and/or options
493 #
494
495 include(custom.cmake OPTIONAL)