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