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 "Debug" "Release" "RelWithDebInfo")
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 -O2")
77 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG -DRELEASE_REAL -Os")
78 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -DRELEASE_REAL -O3")
79 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
81 set(SDL2DIR "${CMAKE_SOURCE_DIR}/../Support/SDL2" CACHE PATH "Path to SDL2")
82 set(OPENALDIR "${CMAKE_SOURCE_DIR}/../Support/OpenAL" CACHE PATH "Path to OpenAL")
83 set(LWSDIR "${CMAKE_SOURCE_DIR}/../Support/libwebsockets" CACHE PATH "Path to libwebsockets")
84 set(WXWIDGETSDIR "${CMAKE_SOURCE_DIR}/../Support/wxWidgets" CACHE PATH "Path to wxWidgets")
85 set(ANGLEDIR "${CMAKE_SOURCE_DIR}/../Support/ANGLE" CACHE PATH "Path to ANGLE")
87 set(PLATFORM_LIBRARIES
89 ${ANGLEDIR}/lib/libEGL.lib
90 ${ANGLEDIR}/lib/libGLESv2.lib
93 add_definitions(/D _CRT_SECURE_NO_WARNINGS)
95 add_definitions(/wd4100) # unreferenced parameter
96 add_definitions(/wd4127) # conditional expression is constant: do { } while (0)
97 add_definitions(/wd4996) # deprecated functions: fopen, fileno, ...
107 set(BIN_SUFFIX "${BIN_SUFFIX}demo")
110 find_package(SDL2 "2.0.5" REQUIRED)
111 find_package(OpenGL REQUIRED)
112 find_package(OpenAL REQUIRED)
115 find_package(LibWebSockets REQUIRED)
117 find_package(wxWidgets COMPONENTS core base gl net)
118 include(${wxWidgets_USE_FILE})
121 # ##############################################################################
125 ${PROJECT_SOURCE_DIR}/include
126 ${CMAKE_BINARY_DIR}/include
128 ${OPENAL_INCLUDE_DIR}
129 ${LIBWEBSOCKETS_INCLUDE_DIR}
130 ${wxWidgets_INCLUDE_DIRS}
134 add_subdirectory(src)
135 add_subdirectory(include)
138 # ##############################################################################
142 # custom target for source tree version info
145 add_custom_target(buildver
146 COMMAND ${CMAKE_COMMAND}
147 -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
148 -DBINARY_DIR=${CMAKE_BINARY_DIR}
149 -P ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
150 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
151 SOURCES ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
155 # main code/game library
166 CreateSourceGroups(${code_SOURCE} ${platform_SOURCE})
168 add_dependencies(code
176 set(FS_BINARY "fs${BIN_SUFFIX}")
178 add_executable(${FS_BINARY}
184 CreateSourceGroups(${freespace_SOURCE})
186 target_link_libraries(
192 ${LIBWEBSOCKETS_LIBRARIES}
193 ${PLATFORM_LIBRARIES}
206 gameseq_process_events
211 freespace_mission_load_stuff
213 game_loading_callback
214 game_loading_callback_close
217 gamesnd_preload_common_sounds
221 list(GET ASYNC_FUNCTIONS -1 LastOne)
223 set(EMTERPRETIFY_WHITELIST "[")
225 foreach(func ${ASYNC_FUNCTIONS})
226 if (${func} STREQUAL ${LastOne})
227 set(EMTERPRETIFY_WHITELIST "${EMTERPRETIFY_WHITELIST}\"_${func}\"]")
229 set(EMTERPRETIFY_WHITELIST "${EMTERPRETIFY_WHITELIST}\"_${func}\",")
237 "-s TOTAL_MEMORY=184549376"
238 "--shell-file ${CMAKE_SOURCE_DIR}/dist/fs_shell.html"
239 "--preload-file game@/"
241 "-s DEMANGLE_SUPPORT=1"
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}")
256 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
258 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
266 set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
268 add_executable(${LAUNCHER_BINARY}
274 add_dependencies(${LAUNCHER_BINARY}
278 CreateSourceGroups(${launcher_SOURCE})
280 target_link_libraries(
285 ${wxWidgets_LIBRARIES}
286 ${PLATFORM_LIBRARIES}
289 set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
291 # wxWidgets appears to need c++11 for one or more headers
293 set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
298 # standalone server GUI
303 if(NOT FS1 OR NOT DEMO)
305 set(STANDALONE_BINARY fsstandalone)
307 set(STANDALONE_BINARY fs2standalone)
310 add_executable(${STANDALONE_BINARY}
313 ${standalone_HEADERS}
316 CreateSourceGroups(${standalone_SOURCE})
318 target_link_libraries(
321 ${wxWidgets_LIBRARIES}
322 ${LIBWEBSOCKETS_LIBRARIES}
323 ${PLATFORM_LIBRARIES}
326 set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
328 # wxWidgets appears to need c++11 for one or more headers
330 set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
332 endif(NOT FS1 OR NOT DEMO)
336 # extra rule to make sure we cleanup all exe variants
339 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
341 fsdemo${CMAKE_EXECUTABLE_SUFFIX}
348 freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
350 fs${CMAKE_EXECUTABLE_SUFFIX}
351 freespace${CMAKE_EXECUTABLE_SUFFIX}
353 fs2demo${CMAKE_EXECUTABLE_SUFFIX}
360 freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
362 fs2${CMAKE_EXECUTABLE_SUFFIX}
363 freespace2${CMAKE_EXECUTABLE_SUFFIX}
365 fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
366 fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
370 # ##############################################################################
372 # ##############################################################################
374 # toolset: targets for creating/modifying game assets
377 # don't build toolset unless it's a full build
390 CreateSourceGroups(${ac_SOURCE})
392 target_link_libraries(
398 ${LIBWEBSOCKETS_LIBRARIES}
399 ${PLATFORM_LIBRARIES}
403 # CFILEARCHIVER: to create VP file archives
406 add_executable(cfilearchiver
408 ${cfilearchiver_SOURCE}
411 CreateSourceGroups(${cfilearchiver_SOURCE})
414 # CRYPTSTRING: string encryption (for embedded cheat codes)
417 add_executable(cryptstring
419 ${cryptstring_SOURCE}
422 CreateSourceGroups(${cryptstring_SOURCE})
425 # NEBEDIT: FS1 style nebula editor/creator
428 add_executable(nebedit
434 CreateSourceGroups(${nebedit_SOURCE})
436 target_link_libraries(
442 ${wxWidgets_LIBRARIES}
443 ${LIBWEBSOCKETS_LIBRARIES}
444 ${PLATFORM_LIBRARIES}
447 # wxWidgets appears to need c++11 for one or more headers
449 set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
453 # POFVIEW: model viewer
456 add_executable(pofview
463 CreateSourceGroups(${pofview_SOURCE})
465 target_link_libraries(
471 ${wxWidgets_LIBRARIES}
472 ${LIBWEBSOCKETS_LIBRARIES}
473 ${PLATFORM_LIBRARIES}
476 # wxWidgets appears to need c++11 for one or more headers
478 set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
482 # SCRAMBLE: file-based encryption for TBLs
485 add_executable(scramble
491 CreateSourceGroups(${scramble_SOURCE})
494 # FONTTOOL: create font files / edit kerning data
497 add_executable(fonttool
503 CreateSourceGroups(${fonttool_SOURCE})
505 # background setup, to allow running from build location without installing
506 add_custom_command(TARGET fonttool
508 COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
509 COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
512 target_link_libraries(
518 ${LIBWEBSOCKETS_LIBRARIES}
519 ${PLATFORM_LIBRARIES}
523 # custom target to build all tools in one pass
526 add_custom_target(tools)
528 add_dependencies(tools
541 # ##############################################################################
544 # optionally include any dev/user preferred build commands and/or options
547 include(custom.cmake OPTIONAL)