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)
42 add_definitions(-s USE_SDL=2)
43 add_definitions(-s FULL_ES2=1)
44 add_definitions(-s DISABLE_EXCEPTION_CATCHING=0)
46 set(CMAKE_EXECUTABLE_SUFFIX ".html")
50 add_definitions(-DLEGACY_GL)
54 set(PLATFORM_LIBRARIES "")
56 add_definitions(-DPLAT_UNIX)
57 add_definitions(-Wall)
58 add_definitions(-Wshadow)
59 # add_definitions(-Wno-format-y2k)
60 # add_definitions(-Wno-deprecated)
61 add_definitions(-fsigned-char)
63 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG -g -O2")
64 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG -Os")
65 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -DRELEASE_REAL -O3")
66 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
68 set(SDL2DIR "${CMAKE_SOURCE_DIR}/../Support/SDL2" CACHE PATH "Path to SDL2")
69 set(OPENALDIR "${CMAKE_SOURCE_DIR}/../Support/OpenAL" CACHE PATH "Path to OpenAL")
70 set(LWSDIR "${CMAKE_SOURCE_DIR}/../Support/libwebsockets" CACHE PATH "Path to libwebsockets")
71 set(WXWIDGETSDIR "${CMAKE_SOURCE_DIR}/../Support/wxWidgets" CACHE PATH "Path to wxWidgets")
72 set(ANGLEDIR "${CMAKE_SOURCE_DIR}/../Support/ANGLE" CACHE PATH "Path to ANGLE")
74 set(PLATFORM_LIBRARIES
76 ${ANGLEDIR}/lib/libEGL.lib
77 ${ANGLEDIR}/lib/libGLESv2.lib
80 add_definitions(/D _CRT_SECURE_NO_WARNINGS)
82 add_definitions(/wd4100) # unreferenced parameter
83 add_definitions(/wd4127) # conditional expression is constant: do { } while (0)
84 add_definitions(/wd4996) # deprecated functions: fopen, fileno, ...
94 set(BIN_SUFFIX "${BIN_SUFFIX}demo")
97 find_package(SDL2 "2.0.5" REQUIRED)
98 find_package(OpenGL REQUIRED)
99 find_package(OpenAL REQUIRED)
102 find_package(LibWebSockets REQUIRED)
104 find_package(wxWidgets COMPONENTS core base gl net)
105 include(${wxWidgets_USE_FILE})
108 # ##############################################################################
112 ${PROJECT_SOURCE_DIR}/include
113 ${CMAKE_BINARY_DIR}/include
115 ${OPENAL_INCLUDE_DIR}
116 ${LIBWEBSOCKETS_INCLUDE_DIR}
117 ${wxWidgets_INCLUDE_DIRS}
121 add_subdirectory(src)
122 add_subdirectory(include)
125 # ##############################################################################
129 # custom target for source tree version info
132 add_custom_target(buildver
133 COMMAND ${CMAKE_COMMAND}
134 -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
135 -DBINARY_DIR=${CMAKE_BINARY_DIR}
136 -P ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
137 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
138 SOURCES ${CMAKE_SOURCE_DIR}/cmake/GitInfo.cmake
142 # main code/game library
153 CreateSourceGroups(${code_SOURCE} ${platform_SOURCE})
155 add_dependencies(code
163 set(FS_BINARY "fs${BIN_SUFFIX}")
165 add_executable(${FS_BINARY}
171 CreateSourceGroups(${freespace_SOURCE})
173 target_link_libraries(
179 ${LIBWEBSOCKETS_LIBRARIES}
180 ${PLATFORM_LIBRARIES}
184 set_target_properties(${FS_BINARY} PROPERTIES LINK_FLAGS "-s USE_SDL=2 -s FULL_ES2=1 -s TOTAL_MEMORY=268435456 -s DISABLE_EXCEPTION_CATCHING=0 --preload-file game@/")
188 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
190 set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
198 set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
200 add_executable(${LAUNCHER_BINARY}
206 CreateSourceGroups(${launcher_SOURCE})
208 target_link_libraries(
213 ${wxWidgets_LIBRARIES}
214 ${PLATFORM_LIBRARIES}
217 set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
219 # wxWidgets appears to need c++11 for one or more headers
221 set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
225 # standalone server GUI
229 if(NOT FS1 OR NOT DEMO)
231 set(STANDALONE_BINARY fsstandalone)
233 set(STANDALONE_BINARY fs2standalone)
236 add_executable(${STANDALONE_BINARY}
239 ${standalone_HEADERS}
242 CreateSourceGroups(${standalone_SOURCE})
244 target_link_libraries(
247 ${wxWidgets_LIBRARIES}
248 ${LIBWEBSOCKETS_LIBRARIES}
249 ${PLATFORM_LIBRARIES}
252 set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
254 # wxWidgets appears to need c++11 for one or more headers
256 set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
261 # extra rule to make sure we cleanup all exe variants
264 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
266 fsdemo${CMAKE_EXECUTABLE_SUFFIX}
267 fsdemo${CMAKE_EXECUTABLE_SUFFIX}.mem
270 freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
272 fs${CMAKE_EXECUTABLE_SUFFIX}
273 fs${CMAKE_EXECUTABLE_SUFFIX}.mem
276 freespace${CMAKE_EXECUTABLE_SUFFIX}
278 fs2demo${CMAKE_EXECUTABLE_SUFFIX}
279 fs2demo${CMAKE_EXECUTABLE_SUFFIX}.mem
282 freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
284 fs2${CMAKE_EXECUTABLE_SUFFIX}
285 fs2${CMAKE_EXECUTABLE_SUFFIX}.mem
288 freespace2${CMAKE_EXECUTABLE_SUFFIX}
290 fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
291 fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
295 # ##############################################################################
297 # ##############################################################################
299 # toolset: targets for creating/modifying game assets
302 # don't build toolset unless it's a full build
315 CreateSourceGroups(${ac_SOURCE})
317 target_link_libraries(
323 ${LIBWEBSOCKETS_LIBRARIES}
324 ${PLATFORM_LIBRARIES}
328 # CFILEARCHIVER: to create VP file archives
331 add_executable(cfilearchiver
333 ${cfilearchiver_SOURCE}
336 CreateSourceGroups(${cfilearchiver_SOURCE})
339 # CRYPTSTRING: string encryption (for embedded cheat codes)
342 add_executable(cryptstring
344 ${cryptstring_SOURCE}
347 CreateSourceGroups(${cryptstring_SOURCE})
350 # NEBEDIT: FS1 style nebula editor/creator
353 add_executable(nebedit
359 CreateSourceGroups(${nebedit_SOURCE})
361 target_link_libraries(
367 ${wxWidgets_LIBRARIES}
368 ${LIBWEBSOCKETS_LIBRARIES}
369 ${PLATFORM_LIBRARIES}
372 # wxWidgets appears to need c++11 for one or more headers
374 set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
378 # POFVIEW: model viewer
381 add_executable(pofview
388 CreateSourceGroups(${pofview_SOURCE})
390 target_link_libraries(
396 ${wxWidgets_LIBRARIES}
397 ${LIBWEBSOCKETS_LIBRARIES}
398 ${PLATFORM_LIBRARIES}
401 # wxWidgets appears to need c++11 for one or more headers
403 set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
407 # SCRAMBLE: file-based encryption for TBLs
410 add_executable(scramble
416 CreateSourceGroups(${scramble_SOURCE})
419 # FONTTOOL: create font files / edit kerning data
422 add_executable(fonttool
428 CreateSourceGroups(${fonttool_SOURCE})
430 # background setup, to allow running from build location without installing
431 add_custom_command(TARGET fonttool
433 COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
434 COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
437 target_link_libraries(
443 ${LIBWEBSOCKETS_LIBRARIES}
444 ${PLATFORM_LIBRARIES}
448 # custom target to build all tools in one pass
451 add_custom_target(tools)
453 add_dependencies(tools
466 # ##############################################################################
468 endif(NOT EMSCRIPTEN)
470 # optionally include any dev/user preferred build commands and/or options
473 include(custom.cmake OPTIONAL)