]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
set game window as resizable for emscripten
[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   add_dependencies(${LAUNCHER_BINARY}
217     buildver
218   )
219
220   CreateSourceGroups(${launcher_SOURCE})
221
222   target_link_libraries(
223     ${LAUNCHER_BINARY}
224     ${SDL2_LIBRARY}
225     ${OPENGL_LIBRARIES}
226     ${OPENAL_LIBRARY}
227     ${wxWidgets_LIBRARIES}
228     ${PLATFORM_LIBRARIES}
229   )
230
231   set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
232
233   # wxWidgets appears to need c++11 for one or more headers
234   if(NOT WIN32)
235   set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
236   endif()
237 endif(NOT GAME_ONLY)
238
239 #
240 # standalone server GUI
241 #
242
243 if(NOT GAME_ONLY)
244   # Not for FS1 Demo
245   if(NOT FS1 OR NOT DEMO)
246     if(FS1)
247       set(STANDALONE_BINARY fsstandalone)
248     else()
249       set(STANDALONE_BINARY fs2standalone)
250     endif()
251
252     add_executable(${STANDALONE_BINARY}
253       WIN32
254       ${standalone_SOURCE}
255       ${standalone_HEADERS}
256     )
257
258     CreateSourceGroups(${standalone_SOURCE})
259
260     target_link_libraries(
261       ${STANDALONE_BINARY}
262       ${SDL2_LIBRARY}
263       ${wxWidgets_LIBRARIES}
264       ${LIBWEBSOCKETS_LIBRARIES}
265       ${PLATFORM_LIBRARIES}
266     )
267
268     set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
269
270     # wxWidgets appears to need c++11 for one or more headers
271     if(NOT WIN32)
272       set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
273     endif()
274   endif(NOT FS1 OR NOT DEMO)
275 endif(NOT GAME_ONLY)
276
277 #
278 # extra rule to make sure we cleanup all exe variants
279 #
280
281 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
282   # FS1 demo
283   fsdemo${CMAKE_EXECUTABLE_SUFFIX}
284   fsdemo.wasm
285   fsdemo.js
286   fsdemo.data
287   freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
288   # FS1
289   fs${CMAKE_EXECUTABLE_SUFFIX}
290   fs.wasm
291   fs.js
292   fs.data
293   freespace${CMAKE_EXECUTABLE_SUFFIX}
294   # FS2 demo
295   fs2demo${CMAKE_EXECUTABLE_SUFFIX}
296   fs2demo.wasm
297   fs2demo.js
298   fs2demo.data
299   freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
300   # FS2
301   fs2${CMAKE_EXECUTABLE_SUFFIX}
302   fs2.wasm
303   fs2.js
304   fs2.data
305   freespace2${CMAKE_EXECUTABLE_SUFFIX}
306   # standalone GUI
307   fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
308   fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
309 )
310
311 #
312 # ##############################################################################
313
314 # ##############################################################################
315 #
316 # toolset: targets for creating/modifying game assets
317 #
318
319 # don't build toolset unless it's a full build
320 if(NOT GAME_ONLY)
321
322   #
323   # AC: anim converter
324   #
325
326   add_executable(ac
327     EXCLUDE_FROM_ALL
328     ${ac_SOURCE}
329     ${ac_HEADERS}
330   )
331
332   CreateSourceGroups(${ac_SOURCE})
333
334   target_link_libraries(
335     ac
336     code
337     ${SDL2_LIBRARY}
338     ${OPENGL_LIBRARIES}
339     ${OPENAL_LIBRARY}
340     ${LIBWEBSOCKETS_LIBRARIES}
341     ${PLATFORM_LIBRARIES}
342   )
343
344   #
345   # CFILEARCHIVER: to create VP file archives
346   #
347
348   add_executable(cfilearchiver
349     EXCLUDE_FROM_ALL
350     ${cfilearchiver_SOURCE}
351   )
352
353   CreateSourceGroups(${cfilearchiver_SOURCE})
354
355   #
356   # CRYPTSTRING: string encryption (for embedded cheat codes)
357   #
358
359   add_executable(cryptstring
360     EXCLUDE_FROM_ALL
361     ${cryptstring_SOURCE}
362   )
363
364   CreateSourceGroups(${cryptstring_SOURCE})
365
366   #
367   # NEBEDIT: FS1 style nebula editor/creator
368   #
369
370   add_executable(nebedit
371     EXCLUDE_FROM_ALL
372     WIN32
373     ${nebedit_SOURCE}
374   )
375
376   CreateSourceGroups(${nebedit_SOURCE})
377
378   target_link_libraries(
379     nebedit
380     code
381     ${SDL2_LIBRARY}
382     ${OPENGL_LIBRARIES}
383     ${OPENAL_LIBRARY}
384     ${wxWidgets_LIBRARIES}
385     ${LIBWEBSOCKETS_LIBRARIES}
386     ${PLATFORM_LIBRARIES}
387   )
388
389   # wxWidgets appears to need c++11 for one or more headers
390   if(NOT WIN32)
391     set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
392   endif()
393
394   #
395   # POFVIEW: model viewer
396   #
397
398   add_executable(pofview
399     EXCLUDE_FROM_ALL
400     WIN32
401     ${pofview_SOURCE}
402     ${pofview_HEADERS}
403   )
404
405   CreateSourceGroups(${pofview_SOURCE})
406
407   target_link_libraries(
408     pofview
409     code
410     ${SDL2_LIBRARY}
411     ${OPENGL_LIBRARIES}
412     ${OPENAL_LIBRARY}
413     ${wxWidgets_LIBRARIES}
414     ${LIBWEBSOCKETS_LIBRARIES}
415     ${PLATFORM_LIBRARIES}
416   )
417
418   # wxWidgets appears to need c++11 for one or more headers
419   if(NOT WIN32)
420     set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
421   endif()
422
423   #
424   # SCRAMBLE: file-based encryption for TBLs
425   #
426
427   add_executable(scramble
428     EXCLUDE_FROM_ALL
429     ${scramble_SOURCE}
430     ${scramble_HEADERS}
431   )
432
433   CreateSourceGroups(${scramble_SOURCE})
434
435   #
436   # FONTTOOL: create font files / edit kerning data
437   #
438
439   add_executable(fonttool
440     EXCLUDE_FROM_ALL
441     ${fonttool_SOURCE}
442     ${fonttool_HEADERS}
443   )
444
445   CreateSourceGroups(${fonttool_SOURCE})
446
447   # background setup, to allow running from build location without installing
448   add_custom_command(TARGET fonttool
449     POST_BUILD
450     COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
451     COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
452   )
453
454   target_link_libraries(
455     fonttool
456     code
457     ${SDL2_LIBRARY}
458     ${OPENGL_LIBRARIES}
459     ${OPENAL_LIBRARY}
460     ${LIBWEBSOCKETS_LIBRARIES}
461     ${PLATFORM_LIBRARIES}
462   )
463
464   #
465   # custom target to build all tools in one pass
466   #
467
468   add_custom_target(tools)
469
470   add_dependencies(tools
471     ac
472     cfilearchiver
473     cryptstring
474     nebedit
475     pofview
476     scramble
477     fonttool
478   )
479
480 endif(NOT GAME_ONLY)
481
482 #
483 # ##############################################################################
484
485 #
486 # optionally include any dev/user preferred build commands and/or options
487 #
488
489 include(custom.cmake OPTIONAL)