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