]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
make mount/sync options clearer with an order change
[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 "RelWithDebInfo" "Release" "Debug")
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)  # don't build launcher or toolset
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 -O3")
77   set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -DRELEASE_REAL -O3")
78   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
79 else()
80   set(SDL2DIR "${CMAKE_SOURCE_DIR}/../Support/SDL2" CACHE PATH "Path to SDL2")
81   set(OPENALDIR "${CMAKE_SOURCE_DIR}/../Support/OpenAL" CACHE PATH "Path to OpenAL")
82   set(LWSDIR "${CMAKE_SOURCE_DIR}/../Support/libwebsockets" CACHE PATH "Path to libwebsockets")
83   set(WXWIDGETSDIR "${CMAKE_SOURCE_DIR}/../Support/wxWidgets" CACHE PATH "Path to wxWidgets")
84   set(ANGLEDIR "${CMAKE_SOURCE_DIR}/../Support/ANGLE" CACHE PATH "Path to ANGLE")
85
86   set(PLATFORM_LIBRARIES
87     ws2_32.lib
88     ${ANGLEDIR}/lib/libEGL.lib
89     ${ANGLEDIR}/lib/libGLESv2.lib
90   )
91
92   add_definitions(/D _CRT_SECURE_NO_WARNINGS)
93   add_definitions(/W4)
94   add_definitions(/wd4100) # unreferenced parameter
95   add_definitions(/wd4127) # conditional expression is constant: do { } while (0)
96   add_definitions(/wd4996) # deprecated functions: fopen, fileno, ...
97 endif()
98
99 set(BIN_SUFFIX "")
100
101 if(NOT FS1)
102         set(BIN_SUFFIX "2")
103 endif()
104
105 if(DEMO)
106         set(BIN_SUFFIX "${BIN_SUFFIX}demo")
107 endif()
108
109 find_package(SDL2 "2.0.5" REQUIRED)
110 find_package(OpenGL REQUIRED)
111 find_package(OpenAL REQUIRED)
112
113 if(NOT EMSCRIPTEN)
114   find_package(LibWebSockets REQUIRED)
115
116   find_package(wxWidgets COMPONENTS core base gl net)
117   include(${wxWidgets_USE_FILE})
118 endif()
119
120 # ##############################################################################
121
122
123 include_directories(
124   ${PROJECT_SOURCE_DIR}/include
125   ${CMAKE_BINARY_DIR}/include
126   ${SDL2_INCLUDE_DIR}
127   ${OPENAL_INCLUDE_DIR}
128   ${LIBWEBSOCKETS_INCLUDE_DIR}
129   ${wxWidgets_INCLUDE_DIRS}
130 )
131
132
133 add_subdirectory(src)
134 add_subdirectory(include)
135
136
137 # ##############################################################################
138 #
139
140 #
141 # custom target for source tree version info
142 #
143
144 add_custom_target(buildver
145   COMMAND ${CMAKE_COMMAND}
146     -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
147     -DBINARY_DIR=${CMAKE_BINARY_DIR}
148     -P ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
149   WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
150   SOURCES ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
151 )
152
153 #
154 # main code/game library
155 #
156
157 add_library(code
158   STATIC
159   ${code_SOURCE}
160   ${code_HEADERS}
161   ${platform_SOURCE}
162   ${platform_HEADERS}
163 )
164
165 CreateSourceGroups(${code_SOURCE} ${platform_SOURCE})
166
167 add_dependencies(code
168   buildver
169 )
170
171 #
172 # the game itself
173 #
174
175 set(FS_BINARY "fs${BIN_SUFFIX}")
176
177 add_executable(${FS_BINARY}
178   WIN32
179   ${freespace_SOURCE}
180   ${freespace_HEADERS}
181 )
182
183 CreateSourceGroups(${freespace_SOURCE})
184
185 target_link_libraries(
186   ${FS_BINARY}
187   code
188   ${SDL2_LIBRARY}
189   ${OPENGL_LIBRARIES}
190   ${OPENAL_LIBRARY}
191   ${LIBWEBSOCKETS_LIBRARIES}
192   ${PLATFORM_LIBRARIES}
193 )
194
195 if(EMSCRIPTEN)
196   set(ASYNC_FUNCTIONS
197         # common
198     main
199     game_main
200     game_init
201     # fs2 title screen
202     display_title_screen
203     # loading screen
204     game_loop_caller
205     gameseq_process_events
206     game_process_event
207     gameseq_set_state
208     game_enter_state
209     game_start_mission
210     freespace_mission_load_stuff
211     game_busy_callback
212     game_loading_callback
213     game_loading_callback_close
214     level_page_in
215     bm_page_in_stop
216     gamesnd_preload_common_sounds
217     game_busy
218   )
219
220   list(GET ASYNC_FUNCTIONS -1 LastOne)
221
222   set(EMTERPRETIFY_WHITELIST "[")
223
224   foreach(func ${ASYNC_FUNCTIONS})
225     if (${func} STREQUAL ${LastOne})
226       set(EMTERPRETIFY_WHITELIST "${EMTERPRETIFY_WHITELIST}\"_${func}\"]")
227     else()
228       set(EMTERPRETIFY_WHITELIST "${EMTERPRETIFY_WHITELIST}\"_${func}\",")
229     endif()
230   endforeach()
231
232   set(LINK_FLAGS
233     "-O3"
234     "-s USE_SDL=2"
235     "-s FULL_ES2=1"
236     "-s WASM=1"
237     "--shell-file ${CMAKE_BINARY_DIR}/dist/demo_shell.html"
238     "--pre-js ${FS_BINARY}_preload.js"
239     "--emit-symbol-map"
240   # "-s EMTERPRETIFY=1"
241   # "-s EMTERPRETIFY_ASYNC=1"
242   # "-s 'EMTERPRETIFY_FILE=\"${FS_BINARY}.binary\"'"
243   # "-s 'EMTERPRETIFY_WHITELIST=${EMTERPRETIFY_WHITELIST}'"
244   )
245
246   # memory is calculated as such: 1024 * 1024 * (48 + (data size + 4))
247   # 48 to run the game itself, plus in-memory filesystem+data
248   # FS1 demo data size is 38MB, FS2 demo is 94MB
249   if(FS1)
250     set(LINK_FLAGS "${LINK_FLAGS} -s TOTAL_MEMORY=94371840")
251   else()
252     set(LINK_FLAGS "${LINK_FLAGS} -s TOTAL_MEMORY=153092096")
253   endif()
254
255   foreach(Flag ${LINK_FLAGS})
256     set_property(TARGET ${FS_BINARY} APPEND_STRING PROPERTY LINK_FLAGS " ${Flag}")
257   endforeach()
258
259   if(FS1)
260     set(TEXT_COLOR "#4C442D")
261     set(BG_COLOR "#3E4559")
262     set(OUTLINE_COLOR "#353B4C")
263     set(BG_COLOR2 "#798199")
264     set(GAME_TITLE "FreeSpace Demo")
265   else()
266     set(TEXT_COLOR "#FFF")
267     set(BG_COLOR "#457573")
268     set(OUTLINE_COLOR "#4D8280")
269     set(BG_COLOR2 "#182928")
270     set(GAME_TITLE "FreeSpace 2 Demo")
271   endif()
272
273   configure_file(${CMAKE_SOURCE_DIR}/dist/demo_shell.html.in ${CMAKE_BINARY_DIR}/dist/demo_shell.html @ONLY)
274   configure_file(${CMAKE_SOURCE_DIR}/dist/demo-play.css.in ${CMAKE_BINARY_DIR}/dist/demo-play.css @ONLY)
275   configure_file(${CMAKE_SOURCE_DIR}/dist/demo-play.js.in ${CMAKE_BINARY_DIR}/dist/demo-play.js @ONLY)
276 endif(EMSCRIPTEN)
277
278 if(FS1)
279   set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
280 else()
281   set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
282 endif()
283
284 #
285 # launcher
286 #
287
288 if(NOT GAME_ONLY)
289   set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
290
291   add_executable(${LAUNCHER_BINARY}
292   WIN32
293     ${launcher_SOURCE}
294     ${launcher_HEADERS}
295   )
296
297   add_dependencies(${LAUNCHER_BINARY}
298     buildver
299   )
300
301   CreateSourceGroups(${launcher_SOURCE})
302
303   target_link_libraries(
304     ${LAUNCHER_BINARY}
305     ${SDL2_LIBRARY}
306     ${OPENGL_LIBRARIES}
307     ${OPENAL_LIBRARY}
308     ${wxWidgets_LIBRARIES}
309     ${PLATFORM_LIBRARIES}
310   )
311
312   set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
313
314   # wxWidgets appears to need c++11 for one or more headers
315   if(NOT WIN32)
316     set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
317   endif()
318 endif(NOT GAME_ONLY)
319
320 #
321 # standalone server GUI
322 #
323
324 if(NOT GAME_ONLY)
325   # Not for FS1 Demo
326   if(NOT FS1 OR NOT DEMO)
327     if(FS1)
328       set(STANDALONE_BINARY fsstandalone)
329     else()
330       set(STANDALONE_BINARY fs2standalone)
331     endif()
332
333     add_executable(${STANDALONE_BINARY}
334       WIN32
335       ${standalone_SOURCE}
336       ${standalone_HEADERS}
337     )
338
339     CreateSourceGroups(${standalone_SOURCE})
340
341     target_link_libraries(
342       ${STANDALONE_BINARY}
343       ${SDL2_LIBRARY}
344       ${wxWidgets_LIBRARIES}
345       ${LIBWEBSOCKETS_LIBRARIES}
346       ${PLATFORM_LIBRARIES}
347     )
348
349     set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
350
351     # wxWidgets appears to need c++11 for one or more headers
352     if(NOT WIN32)
353       set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
354     endif()
355   endif(NOT FS1 OR NOT DEMO)
356 endif(NOT GAME_ONLY)
357
358 #
359 # extra rule to make sure we cleanup all exe variants
360 #
361
362 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
363   # FS1 demo
364   fsdemo${CMAKE_EXECUTABLE_SUFFIX}
365   fsdemo.html.mem
366   fsdemo.binary
367   fsdemo.wast
368   fsdemo.wasm
369   fsdemo.js
370   fsdemo.data
371   freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
372   # FS1
373   fs${CMAKE_EXECUTABLE_SUFFIX}
374   freespace${CMAKE_EXECUTABLE_SUFFIX}
375   # FS2 demo
376   fs2demo${CMAKE_EXECUTABLE_SUFFIX}
377   fs2demo.html.mem
378   fs2demo.binary
379   fs2demo.wast
380   fs2demo.wasm
381   fs2demo.js
382   fs2demo.data
383   freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
384   # FS2
385   fs2${CMAKE_EXECUTABLE_SUFFIX}
386   freespace2${CMAKE_EXECUTABLE_SUFFIX}
387   # standalone GUI
388   fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
389   fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
390 )
391
392 #
393 # ##############################################################################
394
395 # ##############################################################################
396 #
397 # toolset: targets for creating/modifying game assets
398 #
399
400 # don't build toolset unless it's a full build
401 if(NOT GAME_ONLY)
402
403   #
404   # AC: anim converter
405   #
406
407   add_executable(ac
408     EXCLUDE_FROM_ALL
409     ${ac_SOURCE}
410     ${ac_HEADERS}
411   )
412
413   CreateSourceGroups(${ac_SOURCE})
414
415   target_link_libraries(
416     ac
417     code
418     ${SDL2_LIBRARY}
419     ${OPENGL_LIBRARIES}
420     ${OPENAL_LIBRARY}
421     ${LIBWEBSOCKETS_LIBRARIES}
422     ${PLATFORM_LIBRARIES}
423   )
424
425   #
426   # CFILEARCHIVER: to create VP file archives
427   #
428
429   add_executable(cfilearchiver
430     EXCLUDE_FROM_ALL
431     ${cfilearchiver_SOURCE}
432   )
433
434   CreateSourceGroups(${cfilearchiver_SOURCE})
435
436   #
437   # CFILEUTIL: work with VP file archives
438   #
439
440   add_executable(cfileutil
441     EXCLUDE_FROM_ALL
442     ${cfileutil_SOURCE}
443   )
444
445   CreateSourceGroups(${cfileutil_SOURCE})
446
447   if(NOT WIN32)
448     set_target_properties(cfileutil PROPERTIES COMPILE_FLAGS -std=c++11)
449   endif()
450
451   #
452   # CRYPTSTRING: string encryption (for embedded cheat codes)
453   #
454
455   add_executable(cryptstring
456     EXCLUDE_FROM_ALL
457     ${cryptstring_SOURCE}
458   )
459
460   CreateSourceGroups(${cryptstring_SOURCE})
461
462   #
463   # NEBEDIT: FS1 style nebula editor/creator
464   #
465
466   add_executable(nebedit
467     EXCLUDE_FROM_ALL
468     WIN32
469     ${nebedit_SOURCE}
470   )
471
472   CreateSourceGroups(${nebedit_SOURCE})
473
474   target_link_libraries(
475     nebedit
476     code
477     ${SDL2_LIBRARY}
478     ${OPENGL_LIBRARIES}
479     ${OPENAL_LIBRARY}
480     ${wxWidgets_LIBRARIES}
481     ${LIBWEBSOCKETS_LIBRARIES}
482     ${PLATFORM_LIBRARIES}
483   )
484
485   # wxWidgets appears to need c++11 for one or more headers
486   if(NOT WIN32)
487     set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
488   endif()
489
490   #
491   # POFVIEW: model viewer
492   #
493
494   add_executable(pofview
495     EXCLUDE_FROM_ALL
496     WIN32
497     ${pofview_SOURCE}
498     ${pofview_HEADERS}
499   )
500
501   CreateSourceGroups(${pofview_SOURCE})
502
503   target_link_libraries(
504     pofview
505     code
506     ${SDL2_LIBRARY}
507     ${OPENGL_LIBRARIES}
508     ${OPENAL_LIBRARY}
509     ${wxWidgets_LIBRARIES}
510     ${LIBWEBSOCKETS_LIBRARIES}
511     ${PLATFORM_LIBRARIES}
512   )
513
514   # wxWidgets appears to need c++11 for one or more headers
515   if(NOT WIN32)
516     set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
517   endif()
518
519   #
520   # SCRAMBLE: file-based encryption for TBLs
521   #
522
523   add_executable(scramble
524     EXCLUDE_FROM_ALL
525     ${scramble_SOURCE}
526     ${scramble_HEADERS}
527   )
528
529   CreateSourceGroups(${scramble_SOURCE})
530
531   #
532   # FONTTOOL: create font files / edit kerning data
533   #
534
535   add_executable(fonttool
536     EXCLUDE_FROM_ALL
537     ${fonttool_SOURCE}
538     ${fonttool_HEADERS}
539   )
540
541   CreateSourceGroups(${fonttool_SOURCE})
542
543   # background setup, to allow running from build location without installing
544   add_custom_command(TARGET fonttool
545     POST_BUILD
546     COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
547     COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
548   )
549
550   target_link_libraries(
551     fonttool
552     code
553     ${SDL2_LIBRARY}
554     ${OPENGL_LIBRARIES}
555     ${OPENAL_LIBRARY}
556     ${LIBWEBSOCKETS_LIBRARIES}
557     ${PLATFORM_LIBRARIES}
558   )
559
560   #
561   # custom target to build all tools in one pass
562   #
563
564   add_custom_target(tools)
565
566   add_dependencies(tools
567     ac
568     cfilearchiver
569     cfileutil
570     cryptstring
571     nebedit
572     pofview
573     scramble
574     fonttool
575   )
576
577 endif(NOT GAME_ONLY)
578
579 #
580 # ##############################################################################
581
582 #
583 # optionally include any dev/user preferred build commands and/or options
584 #
585
586 include(custom.cmake OPTIONAL)