4 cmake_minimum_required(VERSION 2.8)
5 cmake_policy(VERSION 2.8)
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)
19 option(DEMO "Create demo build" OFF)
21 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
22 message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
23 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
24 # Set the possible values of build type for cmake-gui
25 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo")
30 add_definitions(-DMAKE_FS1)
33 add_definitions(-DDEMO -DFS1_DEMO)
37 add_definitions(-DFS2_DEMO)
41 # build everything by default
50 add_definitions(-s USE_SDL=2)
51 add_definitions(-s FULL_ES2=1)
53 set(CMAKE_EXECUTABLE_SUFFIX ".html")
57 add_definitions(-DLEGACY_GL)
61 set(PLATFORM_LIBRARIES "")
63 add_definitions(-DPLAT_UNIX)
64 add_definitions(-Wall)
65 add_definitions(-Wshadow)
66 # add_definitions(-Wno-format-y2k)
67 # add_definitions(-Wno-deprecated)
68 add_definitions(-fsigned-char)
70 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG -g -O2")
71 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG -Os")
72 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -DRELEASE_REAL -O3")
73 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
75 set(SDL2DIR "${CMAKE_SOURCE_DIR}/../Support/SDL2" CACHE PATH "Path to SDL2")
76 set(OPENALDIR "${CMAKE_SOURCE_DIR}/../Support/OpenAL" CACHE PATH "Path to OpenAL")
77 set(LWSDIR "${CMAKE_SOURCE_DIR}/../Support/libwebsockets" CACHE PATH "Path to libwebsockets")
78 set(WXWIDGETSDIR "${CMAKE_SOURCE_DIR}/../Support/wxWidgets" CACHE PATH "Path to wxWidgets")
79 set(ANGLEDIR "${CMAKE_SOURCE_DIR}/../Support/ANGLE" CACHE PATH "Path to ANGLE")
81 set(PLATFORM_LIBRARIES
83 ${ANGLEDIR}/lib/libEGL.lib
84 ${ANGLEDIR}/lib/libGLESv2.lib
87 add_definitions(/D _CRT_SECURE_NO_WARNINGS)
89 add_definitions(/wd4100) # unreferenced parameter
90 add_definitions(/wd4127) # conditional expression is constant: do { } while (0)
91 add_definitions(/wd4996) # deprecated functions: fopen, fileno, ...
101 set(BIN_SUFFIX "${BIN_SUFFIX}demo")
104 find_package(SDL2 "2.0.5" REQUIRED)
105 find_package(OpenGL REQUIRED)
106 find_package(OpenAL REQUIRED)
109 find_package(LibWebSockets REQUIRED)
111 find_package(wxWidgets COMPONENTS core base gl net)
112 include(${wxWidgets_USE_FILE})
115 # ##############################################################################
119 ${PROJECT_SOURCE_DIR}/include
120 ${CMAKE_BINARY_DIR}/include
122 ${OPENAL_INCLUDE_DIR}
123 ${LIBWEBSOCKETS_INCLUDE_DIR}
124 ${wxWidgets_INCLUDE_DIRS}
128 add_subdirectory(src)
129 add_subdirectory(include)
132 # ##############################################################################
136 # custom target for source tree version info
139 add_custom_target(buildver
140 COMMAND ${CMAKE_COMMAND}
141 -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
142 -DBINARY_DIR=${CMAKE_BINARY_DIR}
143 -P ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
144 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
145 SOURCES ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
149 # main code/game library
160 CreateSourceGroups(${code_SOURCE} ${platform_SOURCE})
162 add_dependencies(code
170 set(FS_BINARY "fs${BIN_SUFFIX}")
172 add_executable(${FS_BINARY}
178 CreateSourceGroups(${freespace_SOURCE})
180 target_link_libraries(
186 ${LIBWEBSOCKETS_LIBRARIES}
187 ${PLATFORM_LIBRARIES}
191 set_target_properties(${FS_BINARY}
192 PROPERTIES LINK_FLAGS
193 "-s USE_SDL=2 -s FULL_ES2=1 -s WASM=1 -s TOTAL_MEMORY=184549376 --shell-file ${CMAKE_SOURCE_DIR}/dist/fs_shell.html --preload-file game@/"
198 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
200 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
208 set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
210 add_executable(${LAUNCHER_BINARY}
216 CreateSourceGroups(${launcher_SOURCE})
218 target_link_libraries(
223 ${wxWidgets_LIBRARIES}
224 ${PLATFORM_LIBRARIES}
227 set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
229 # wxWidgets appears to need c++11 for one or more headers
231 set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
236 # standalone server GUI
241 if(NOT FS1 OR NOT DEMO)
243 set(STANDALONE_BINARY fsstandalone)
245 set(STANDALONE_BINARY fs2standalone)
248 add_executable(${STANDALONE_BINARY}
251 ${standalone_HEADERS}
254 CreateSourceGroups(${standalone_SOURCE})
256 target_link_libraries(
259 ${wxWidgets_LIBRARIES}
260 ${LIBWEBSOCKETS_LIBRARIES}
261 ${PLATFORM_LIBRARIES}
264 set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
266 # wxWidgets appears to need c++11 for one or more headers
268 set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
270 endif(NOT FS1 OR NOT DEMO)
274 # extra rule to make sure we cleanup all exe variants
277 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
279 fsdemo${CMAKE_EXECUTABLE_SUFFIX}
283 freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
285 fs${CMAKE_EXECUTABLE_SUFFIX}
289 freespace${CMAKE_EXECUTABLE_SUFFIX}
291 fs2demo${CMAKE_EXECUTABLE_SUFFIX}
295 freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
297 fs2${CMAKE_EXECUTABLE_SUFFIX}
301 freespace2${CMAKE_EXECUTABLE_SUFFIX}
303 fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
304 fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
308 # ##############################################################################
310 # ##############################################################################
312 # toolset: targets for creating/modifying game assets
315 # don't build toolset unless it's a full build
328 CreateSourceGroups(${ac_SOURCE})
330 target_link_libraries(
336 ${LIBWEBSOCKETS_LIBRARIES}
337 ${PLATFORM_LIBRARIES}
341 # CFILEARCHIVER: to create VP file archives
344 add_executable(cfilearchiver
346 ${cfilearchiver_SOURCE}
349 CreateSourceGroups(${cfilearchiver_SOURCE})
352 # CRYPTSTRING: string encryption (for embedded cheat codes)
355 add_executable(cryptstring
357 ${cryptstring_SOURCE}
360 CreateSourceGroups(${cryptstring_SOURCE})
363 # NEBEDIT: FS1 style nebula editor/creator
366 add_executable(nebedit
372 CreateSourceGroups(${nebedit_SOURCE})
374 target_link_libraries(
380 ${wxWidgets_LIBRARIES}
381 ${LIBWEBSOCKETS_LIBRARIES}
382 ${PLATFORM_LIBRARIES}
385 # wxWidgets appears to need c++11 for one or more headers
387 set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
391 # POFVIEW: model viewer
394 add_executable(pofview
401 CreateSourceGroups(${pofview_SOURCE})
403 target_link_libraries(
409 ${wxWidgets_LIBRARIES}
410 ${LIBWEBSOCKETS_LIBRARIES}
411 ${PLATFORM_LIBRARIES}
414 # wxWidgets appears to need c++11 for one or more headers
416 set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
420 # SCRAMBLE: file-based encryption for TBLs
423 add_executable(scramble
429 CreateSourceGroups(${scramble_SOURCE})
432 # FONTTOOL: create font files / edit kerning data
435 add_executable(fonttool
441 CreateSourceGroups(${fonttool_SOURCE})
443 # background setup, to allow running from build location without installing
444 add_custom_command(TARGET fonttool
446 COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
447 COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
450 target_link_libraries(
456 ${LIBWEBSOCKETS_LIBRARIES}
457 ${PLATFORM_LIBRARIES}
461 # custom target to build all tools in one pass
464 add_custom_target(tools)
466 add_dependencies(tools
479 # ##############################################################################
482 # optionally include any dev/user preferred build commands and/or options
485 include(custom.cmake OPTIONAL)