4 cmake_minimum_required(VERSION 2.8.6)
5 cmake_policy(VERSION 2.8.6)
8 cmake_policy(SET CMP0043 OLD)
11 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
13 include(CreateSourceGroups)
16 # ##############################################################################
18 option(FS1 "Build original FreeSpace" OFF)
21 # only build for demo with emscripten
24 option(DEMO "Create demo build" OFF)
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")
36 add_definitions(-DMAKE_FS1)
39 add_definitions(-DDEMO -DFS1_DEMO)
43 add_definitions(-DFS2_DEMO)
47 # build everything by default
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)
59 set(CMAKE_EXECUTABLE_SUFFIX ".html")
63 add_definitions(-DLEGACY_GL)
67 set(PLATFORM_LIBRARIES "")
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)
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")
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")
86 set(PLATFORM_LIBRARIES
88 ${ANGLEDIR}/lib/libEGL.lib
89 ${ANGLEDIR}/lib/libGLESv2.lib
92 add_definitions(/D _CRT_SECURE_NO_WARNINGS)
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, ...
106 set(BIN_SUFFIX "${BIN_SUFFIX}demo")
109 find_package(SDL2 "2.0.5" REQUIRED)
110 find_package(OpenGL REQUIRED)
111 find_package(OpenAL REQUIRED)
114 find_package(LibWebSockets REQUIRED)
116 find_package(wxWidgets COMPONENTS core base gl net)
117 include(${wxWidgets_USE_FILE})
120 # ##############################################################################
124 ${PROJECT_SOURCE_DIR}/include
125 ${CMAKE_BINARY_DIR}/include
127 ${OPENAL_INCLUDE_DIR}
128 ${LIBWEBSOCKETS_INCLUDE_DIR}
129 ${wxWidgets_INCLUDE_DIRS}
133 add_subdirectory(src)
134 add_subdirectory(include)
137 # ##############################################################################
141 # custom target for source tree version info
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
154 # main code/game library
165 CreateSourceGroups(${code_SOURCE} ${platform_SOURCE})
167 add_dependencies(code
175 set(FS_BINARY "fs${BIN_SUFFIX}")
177 add_executable(${FS_BINARY}
183 CreateSourceGroups(${freespace_SOURCE})
185 target_link_libraries(
191 ${LIBWEBSOCKETS_LIBRARIES}
192 ${PLATFORM_LIBRARIES}
205 gameseq_process_events
210 freespace_mission_load_stuff
212 game_loading_callback
213 game_loading_callback_close
216 gamesnd_preload_common_sounds
220 list(GET ASYNC_FUNCTIONS -1 LastOne)
222 set(EMTERPRETIFY_WHITELIST "[")
224 foreach(func ${ASYNC_FUNCTIONS})
225 if (${func} STREQUAL ${LastOne})
226 set(EMTERPRETIFY_WHITELIST "${EMTERPRETIFY_WHITELIST}\"_${func}\"]")
228 set(EMTERPRETIFY_WHITELIST "${EMTERPRETIFY_WHITELIST}\"_${func}\",")
237 "--shell-file ${CMAKE_BINARY_DIR}/dist/demo_shell.html"
238 "--pre-js ${FS_BINARY}_preload.js"
240 # "-s EMTERPRETIFY=1"
241 # "-s EMTERPRETIFY_ASYNC=1"
242 # "-s 'EMTERPRETIFY_FILE=\"${FS_BINARY}.binary\"'"
243 # "-s 'EMTERPRETIFY_WHITELIST=${EMTERPRETIFY_WHITELIST}'"
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
250 set(LINK_FLAGS "${LINK_FLAGS} -s TOTAL_MEMORY=94371840")
252 set(LINK_FLAGS "${LINK_FLAGS} -s TOTAL_MEMORY=153092096")
255 foreach(Flag ${LINK_FLAGS})
256 set_property(TARGET ${FS_BINARY} APPEND_STRING PROPERTY LINK_FLAGS " ${Flag}")
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")
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")
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)
279 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
281 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
289 set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
291 add_executable(${LAUNCHER_BINARY}
297 add_dependencies(${LAUNCHER_BINARY}
301 CreateSourceGroups(${launcher_SOURCE})
303 target_link_libraries(
308 ${wxWidgets_LIBRARIES}
309 ${PLATFORM_LIBRARIES}
312 set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
314 # wxWidgets appears to need c++11 for one or more headers
316 set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
321 # standalone server GUI
326 if(NOT FS1 OR NOT DEMO)
328 set(STANDALONE_BINARY fsstandalone)
330 set(STANDALONE_BINARY fs2standalone)
333 add_executable(${STANDALONE_BINARY}
336 ${standalone_HEADERS}
339 CreateSourceGroups(${standalone_SOURCE})
341 target_link_libraries(
344 ${wxWidgets_LIBRARIES}
345 ${LIBWEBSOCKETS_LIBRARIES}
346 ${PLATFORM_LIBRARIES}
349 set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
351 # wxWidgets appears to need c++11 for one or more headers
353 set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
355 endif(NOT FS1 OR NOT DEMO)
359 # extra rule to make sure we cleanup all exe variants
362 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
364 fsdemo${CMAKE_EXECUTABLE_SUFFIX}
371 freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
373 fs${CMAKE_EXECUTABLE_SUFFIX}
374 freespace${CMAKE_EXECUTABLE_SUFFIX}
376 fs2demo${CMAKE_EXECUTABLE_SUFFIX}
383 freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
385 fs2${CMAKE_EXECUTABLE_SUFFIX}
386 freespace2${CMAKE_EXECUTABLE_SUFFIX}
388 fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
389 fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
393 # ##############################################################################
395 # ##############################################################################
397 # toolset: targets for creating/modifying game assets
400 # don't build toolset unless it's a full build
413 CreateSourceGroups(${ac_SOURCE})
415 target_link_libraries(
421 ${LIBWEBSOCKETS_LIBRARIES}
422 ${PLATFORM_LIBRARIES}
426 # CFILEARCHIVER: to create VP file archives
429 add_executable(cfilearchiver
431 ${cfilearchiver_SOURCE}
434 CreateSourceGroups(${cfilearchiver_SOURCE})
437 # CFILEUTIL: work with VP file archives
440 add_executable(cfileutil
445 CreateSourceGroups(${cfileutil_SOURCE})
448 set_target_properties(cfileutil PROPERTIES COMPILE_FLAGS -std=c++11)
452 # CRYPTSTRING: string encryption (for embedded cheat codes)
455 add_executable(cryptstring
457 ${cryptstring_SOURCE}
460 CreateSourceGroups(${cryptstring_SOURCE})
463 # NEBEDIT: FS1 style nebula editor/creator
466 add_executable(nebedit
472 CreateSourceGroups(${nebedit_SOURCE})
474 target_link_libraries(
480 ${wxWidgets_LIBRARIES}
481 ${LIBWEBSOCKETS_LIBRARIES}
482 ${PLATFORM_LIBRARIES}
485 # wxWidgets appears to need c++11 for one or more headers
487 set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
491 # POFVIEW: model viewer
494 add_executable(pofview
501 CreateSourceGroups(${pofview_SOURCE})
503 target_link_libraries(
509 ${wxWidgets_LIBRARIES}
510 ${LIBWEBSOCKETS_LIBRARIES}
511 ${PLATFORM_LIBRARIES}
514 # wxWidgets appears to need c++11 for one or more headers
516 set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
520 # SCRAMBLE: file-based encryption for TBLs
523 add_executable(scramble
529 CreateSourceGroups(${scramble_SOURCE})
532 # FONTTOOL: create font files / edit kerning data
535 add_executable(fonttool
541 CreateSourceGroups(${fonttool_SOURCE})
543 # background setup, to allow running from build location without installing
544 add_custom_command(TARGET fonttool
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"
550 target_link_libraries(
556 ${LIBWEBSOCKETS_LIBRARIES}
557 ${PLATFORM_LIBRARIES}
561 # custom target to build all tools in one pass
564 add_custom_target(tools)
566 add_dependencies(tools
580 # ##############################################################################
583 # optionally include any dev/user preferred build commands and/or options
586 include(custom.cmake OPTIONAL)