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)
52 #add_definitions(-s EXPORTED_FUNCTIONS="[_main]")
54 set(CMAKE_EXECUTABLE_SUFFIX ".html")
58 add_definitions(-DLEGACY_GL)
62 set(PLATFORM_LIBRARIES "")
64 add_definitions(-DPLAT_UNIX)
65 add_definitions(-Wall)
66 add_definitions(-Wshadow)
67 # add_definitions(-Wno-format-y2k)
68 # add_definitions(-Wno-deprecated)
69 add_definitions(-fsigned-char)
71 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG -g -O2")
72 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG -Os")
73 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -DRELEASE_REAL -O3")
74 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
76 set(SDL2DIR "${CMAKE_SOURCE_DIR}/../Support/SDL2" CACHE PATH "Path to SDL2")
77 set(OPENALDIR "${CMAKE_SOURCE_DIR}/../Support/OpenAL" CACHE PATH "Path to OpenAL")
78 set(LWSDIR "${CMAKE_SOURCE_DIR}/../Support/libwebsockets" CACHE PATH "Path to libwebsockets")
79 set(WXWIDGETSDIR "${CMAKE_SOURCE_DIR}/../Support/wxWidgets" CACHE PATH "Path to wxWidgets")
80 set(ANGLEDIR "${CMAKE_SOURCE_DIR}/../Support/ANGLE" CACHE PATH "Path to ANGLE")
82 set(PLATFORM_LIBRARIES
84 ${ANGLEDIR}/lib/libEGL.lib
85 ${ANGLEDIR}/lib/libGLESv2.lib
88 add_definitions(/D _CRT_SECURE_NO_WARNINGS)
90 add_definitions(/wd4100) # unreferenced parameter
91 add_definitions(/wd4127) # conditional expression is constant: do { } while (0)
92 add_definitions(/wd4996) # deprecated functions: fopen, fileno, ...
102 set(BIN_SUFFIX "${BIN_SUFFIX}demo")
105 find_package(SDL2 "2.0.5" REQUIRED)
106 find_package(OpenGL REQUIRED)
107 find_package(OpenAL REQUIRED)
110 find_package(LibWebSockets REQUIRED)
112 find_package(wxWidgets COMPONENTS core base gl net)
113 include(${wxWidgets_USE_FILE})
116 # ##############################################################################
120 ${PROJECT_SOURCE_DIR}/include
121 ${CMAKE_BINARY_DIR}/include
123 ${OPENAL_INCLUDE_DIR}
124 ${LIBWEBSOCKETS_INCLUDE_DIR}
125 ${wxWidgets_INCLUDE_DIRS}
129 add_subdirectory(src)
130 add_subdirectory(include)
133 # ##############################################################################
137 # custom target for source tree version info
140 add_custom_target(buildver
141 COMMAND ${CMAKE_COMMAND}
142 -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
143 -DBINARY_DIR=${CMAKE_BINARY_DIR}
144 -P ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
145 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
146 SOURCES ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
150 # main code/game library
161 CreateSourceGroups(${code_SOURCE} ${platform_SOURCE})
163 add_dependencies(code
171 set(FS_BINARY "fs${BIN_SUFFIX}")
173 add_executable(${FS_BINARY}
179 CreateSourceGroups(${freespace_SOURCE})
181 target_link_libraries(
187 ${LIBWEBSOCKETS_LIBRARIES}
188 ${PLATFORM_LIBRARIES}
192 set_target_properties(${FS_BINARY} PROPERTIES LINK_FLAGS "-s USE_SDL=2 -s FULL_ES2=1 -s TOTAL_MEMORY=184549376 --preload-file game@/")
196 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
198 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
206 set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
208 add_executable(${LAUNCHER_BINARY}
214 CreateSourceGroups(${launcher_SOURCE})
216 target_link_libraries(
221 ${wxWidgets_LIBRARIES}
222 ${PLATFORM_LIBRARIES}
225 set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
227 # wxWidgets appears to need c++11 for one or more headers
229 set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
234 # standalone server GUI
239 if(NOT FS1 OR NOT DEMO)
241 set(STANDALONE_BINARY fsstandalone)
243 set(STANDALONE_BINARY fs2standalone)
246 add_executable(${STANDALONE_BINARY}
249 ${standalone_HEADERS}
252 CreateSourceGroups(${standalone_SOURCE})
254 target_link_libraries(
257 ${wxWidgets_LIBRARIES}
258 ${LIBWEBSOCKETS_LIBRARIES}
259 ${PLATFORM_LIBRARIES}
262 set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
264 # wxWidgets appears to need c++11 for one or more headers
266 set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
272 # extra rule to make sure we cleanup all exe variants
275 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
277 fsdemo${CMAKE_EXECUTABLE_SUFFIX}
278 fsdemo${CMAKE_EXECUTABLE_SUFFIX}.mem
281 freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
283 fs${CMAKE_EXECUTABLE_SUFFIX}
284 fs${CMAKE_EXECUTABLE_SUFFIX}.mem
287 freespace${CMAKE_EXECUTABLE_SUFFIX}
289 fs2demo${CMAKE_EXECUTABLE_SUFFIX}
290 fs2demo${CMAKE_EXECUTABLE_SUFFIX}.mem
293 freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
295 fs2${CMAKE_EXECUTABLE_SUFFIX}
296 fs2${CMAKE_EXECUTABLE_SUFFIX}.mem
299 freespace2${CMAKE_EXECUTABLE_SUFFIX}
301 fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
302 fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
306 # ##############################################################################
308 # ##############################################################################
310 # toolset: targets for creating/modifying game assets
313 # don't build toolset unless it's a full build
326 CreateSourceGroups(${ac_SOURCE})
328 target_link_libraries(
334 ${LIBWEBSOCKETS_LIBRARIES}
335 ${PLATFORM_LIBRARIES}
339 # CFILEARCHIVER: to create VP file archives
342 add_executable(cfilearchiver
344 ${cfilearchiver_SOURCE}
347 CreateSourceGroups(${cfilearchiver_SOURCE})
350 # CRYPTSTRING: string encryption (for embedded cheat codes)
353 add_executable(cryptstring
355 ${cryptstring_SOURCE}
358 CreateSourceGroups(${cryptstring_SOURCE})
361 # NEBEDIT: FS1 style nebula editor/creator
364 add_executable(nebedit
370 CreateSourceGroups(${nebedit_SOURCE})
372 target_link_libraries(
378 ${wxWidgets_LIBRARIES}
379 ${LIBWEBSOCKETS_LIBRARIES}
380 ${PLATFORM_LIBRARIES}
383 # wxWidgets appears to need c++11 for one or more headers
385 set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
389 # POFVIEW: model viewer
392 add_executable(pofview
399 CreateSourceGroups(${pofview_SOURCE})
401 target_link_libraries(
407 ${wxWidgets_LIBRARIES}
408 ${LIBWEBSOCKETS_LIBRARIES}
409 ${PLATFORM_LIBRARIES}
412 # wxWidgets appears to need c++11 for one or more headers
414 set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
418 # SCRAMBLE: file-based encryption for TBLs
421 add_executable(scramble
427 CreateSourceGroups(${scramble_SOURCE})
430 # FONTTOOL: create font files / edit kerning data
433 add_executable(fonttool
439 CreateSourceGroups(${fonttool_SOURCE})
441 # background setup, to allow running from build location without installing
442 add_custom_command(TARGET fonttool
444 COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
445 COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
448 target_link_libraries(
454 ${LIBWEBSOCKETS_LIBRARIES}
455 ${PLATFORM_LIBRARIES}
459 # custom target to build all tools in one pass
462 add_custom_target(tools)
464 add_dependencies(tools
477 # ##############################################################################
480 # optionally include any dev/user preferred build commands and/or options
483 include(custom.cmake OPTIONAL)