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 "-s TOTAL_MEMORY=184549376"
238 "--shell-file ${CMAKE_BINARY_DIR}/dist/demo_shell.html"
239 "--pre-js ${FS_BINARY}_preload.js"
241 # "-s DEMANGLE_SUPPORT=1"
243 # "--profiling-funcs"
244 # "-s EMTERPRETIFY=1"
245 # "-s EMTERPRETIFY_ASYNC=1"
246 # "-s 'EMTERPRETIFY_FILE=\"${FS_BINARY}.binary\"'"
247 # "-s 'EMTERPRETIFY_WHITELIST=${EMTERPRETIFY_WHITELIST}'"
250 foreach(Flag ${LINK_FLAGS})
251 set_property(TARGET ${FS_BINARY} APPEND_STRING PROPERTY LINK_FLAGS " ${Flag}")
255 set(TEXT_COLOR "#4C442D")
256 set(BG_COLOR "#3E4559")
257 set(OUTLINE_COLOR "#353B4C")
258 set(BG_COLOR2 "#798199")
259 set(GAME_TITLE "FreeSpace Demo")
261 set(TEXT_COLOR "#FFF")
262 set(BG_COLOR "#457573")
263 set(OUTLINE_COLOR "#4D8280")
264 set(BG_COLOR2 "#182928")
265 set(GAME_TITLE "FreeSpace 2 Demo")
268 configure_file(${CMAKE_SOURCE_DIR}/dist/demo_shell.html.in ${CMAKE_BINARY_DIR}/dist/demo_shell.html @ONLY)
269 configure_file(${CMAKE_SOURCE_DIR}/dist/demo-play.css.in ${CMAKE_BINARY_DIR}/dist/demo-play.css @ONLY)
270 configure_file(${CMAKE_SOURCE_DIR}/dist/demo-play.js.in ${CMAKE_BINARY_DIR}/dist/demo-play.js @ONLY)
274 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
276 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
284 set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
286 add_executable(${LAUNCHER_BINARY}
292 add_dependencies(${LAUNCHER_BINARY}
296 CreateSourceGroups(${launcher_SOURCE})
298 target_link_libraries(
303 ${wxWidgets_LIBRARIES}
304 ${PLATFORM_LIBRARIES}
307 set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
309 # wxWidgets appears to need c++11 for one or more headers
311 set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
316 # standalone server GUI
321 if(NOT FS1 OR NOT DEMO)
323 set(STANDALONE_BINARY fsstandalone)
325 set(STANDALONE_BINARY fs2standalone)
328 add_executable(${STANDALONE_BINARY}
331 ${standalone_HEADERS}
334 CreateSourceGroups(${standalone_SOURCE})
336 target_link_libraries(
339 ${wxWidgets_LIBRARIES}
340 ${LIBWEBSOCKETS_LIBRARIES}
341 ${PLATFORM_LIBRARIES}
344 set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
346 # wxWidgets appears to need c++11 for one or more headers
348 set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
350 endif(NOT FS1 OR NOT DEMO)
354 # extra rule to make sure we cleanup all exe variants
357 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
359 fsdemo${CMAKE_EXECUTABLE_SUFFIX}
366 freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
368 fs${CMAKE_EXECUTABLE_SUFFIX}
369 freespace${CMAKE_EXECUTABLE_SUFFIX}
371 fs2demo${CMAKE_EXECUTABLE_SUFFIX}
378 freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
380 fs2${CMAKE_EXECUTABLE_SUFFIX}
381 freespace2${CMAKE_EXECUTABLE_SUFFIX}
383 fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
384 fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
388 # ##############################################################################
390 # ##############################################################################
392 # toolset: targets for creating/modifying game assets
395 # don't build toolset unless it's a full build
408 CreateSourceGroups(${ac_SOURCE})
410 target_link_libraries(
416 ${LIBWEBSOCKETS_LIBRARIES}
417 ${PLATFORM_LIBRARIES}
421 # CFILEARCHIVER: to create VP file archives
424 add_executable(cfilearchiver
426 ${cfilearchiver_SOURCE}
429 CreateSourceGroups(${cfilearchiver_SOURCE})
432 # CFILEUTIL: work with VP file archives
435 add_executable(cfileutil
440 CreateSourceGroups(${cfileutil_SOURCE})
443 set_target_properties(cfileutil PROPERTIES COMPILE_FLAGS -std=c++11)
447 # CRYPTSTRING: string encryption (for embedded cheat codes)
450 add_executable(cryptstring
452 ${cryptstring_SOURCE}
455 CreateSourceGroups(${cryptstring_SOURCE})
458 # NEBEDIT: FS1 style nebula editor/creator
461 add_executable(nebedit
467 CreateSourceGroups(${nebedit_SOURCE})
469 target_link_libraries(
475 ${wxWidgets_LIBRARIES}
476 ${LIBWEBSOCKETS_LIBRARIES}
477 ${PLATFORM_LIBRARIES}
480 # wxWidgets appears to need c++11 for one or more headers
482 set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
486 # POFVIEW: model viewer
489 add_executable(pofview
496 CreateSourceGroups(${pofview_SOURCE})
498 target_link_libraries(
504 ${wxWidgets_LIBRARIES}
505 ${LIBWEBSOCKETS_LIBRARIES}
506 ${PLATFORM_LIBRARIES}
509 # wxWidgets appears to need c++11 for one or more headers
511 set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
515 # SCRAMBLE: file-based encryption for TBLs
518 add_executable(scramble
524 CreateSourceGroups(${scramble_SOURCE})
527 # FONTTOOL: create font files / edit kerning data
530 add_executable(fonttool
536 CreateSourceGroups(${fonttool_SOURCE})
538 # background setup, to allow running from build location without installing
539 add_custom_command(TARGET fonttool
541 COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
542 COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
545 target_link_libraries(
551 ${LIBWEBSOCKETS_LIBRARIES}
552 ${PLATFORM_LIBRARIES}
556 # custom target to build all tools in one pass
559 add_custom_target(tools)
561 add_dependencies(tools
575 # ##############################################################################
578 # optionally include any dev/user preferred build commands and/or options
581 include(custom.cmake OPTIONAL)