]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
set RelWithDebInfo as default build type
[taylor/freespace2.git] / CMakeLists.txt
1
2 project(freespace2)
3
4 cmake_minimum_required(VERSION 2.8)
5 cmake_policy(VERSION 2.8)
6
7 if(POLICY CMP0043)
8   cmake_policy(SET CMP0043 OLD)
9 endif()
10
11 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
12
13 include(CreateSourceGroups)
14
15
16 # ##############################################################################
17
18 option(FS1 "Build original FreeSpace" OFF)
19 option(DEMO "Create demo build" OFF)
20
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")
26 endif()
27
28
29 if(FS1)
30   add_definitions(-DMAKE_FS1)
31
32   if(DEMO)
33         add_definitions(-DDEMO -DFS1_DEMO)
34   endif()
35 else()
36   if(DEMO)
37         add_definitions(-DFS2_DEMO)
38   endif()
39 endif()
40
41 if(EMSCRIPTEN)
42   add_definitions(-s USE_SDL=2)
43   add_definitions(-s FULL_ES2=1)
44   add_definitions(-s DISABLE_EXCEPTION_CATCHING=0)
45
46   set(CMAKE_EXECUTABLE_SUFFIX ".html")
47 endif()
48
49 if(NOT EMSCRIPTEN)
50   add_definitions(-DLEGACY_GL)
51 endif()
52
53 if(NOT WIN32)
54   set(PLATFORM_LIBRARIES "")
55
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)
62
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 -O2")
66   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
67 else()
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")
73
74   set(PLATFORM_LIBRARIES
75         ws2_32.lib
76         ${ANGLEDIR}/lib/libEGL.lib
77         ${ANGLEDIR}/lib/libGLESv2.lib
78   )
79
80   add_definitions(/D _CRT_SECURE_NO_WARNINGS)
81   add_definitions(/W4)
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, ...
85 endif()
86
87 set(BIN_SUFFIX "")
88
89 if(NOT FS1)
90         set(BIN_SUFFIX "2")
91 endif()
92
93 if(DEMO)
94         set(BIN_SUFFIX "${BIN_SUFFIX}demo")
95 endif()
96
97 find_package(SDL2 "2.0.5" REQUIRED)
98 find_package(OpenGL REQUIRED)
99 find_package(OpenAL REQUIRED)
100
101 if(NOT EMSCRIPTEN)
102   find_package(LibWebSockets REQUIRED)
103
104   find_package(wxWidgets COMPONENTS core base gl net)
105   include(${wxWidgets_USE_FILE})
106 endif()
107
108 # ##############################################################################
109
110
111 include_directories(
112   ${PROJECT_SOURCE_DIR}/include
113   ${CMAKE_BINARY_DIR}/include
114   ${SDL2_INCLUDE_DIR}
115   ${OPENAL_INCLUDE_DIR}
116   ${LIBWEBSOCKETS_INCLUDE_DIR}
117   ${wxWidgets_INCLUDE_DIRS}
118 )
119
120
121 add_subdirectory(src)
122 add_subdirectory(include)
123
124
125 # ##############################################################################
126 #
127
128 #
129 # custom target for source tree version info
130 #
131
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
139 )
140
141 #
142 # main code/game library
143 #
144
145 add_library(code
146   STATIC
147   ${code_SOURCE}
148   ${code_HEADERS}
149   ${platform_SOURCE}
150   ${platform_HEADERS}
151 )
152
153 CreateSourceGroups(${code_SOURCE} ${platform_SOURCE})
154
155 add_dependencies(code
156   buildver
157 )
158
159 #
160 # the game itself
161 #
162
163 set(FS_BINARY "fs${BIN_SUFFIX}")
164
165 add_executable(${FS_BINARY}
166   WIN32
167   ${freespace_SOURCE}
168   ${freespace_HEADERS}
169 )
170
171 CreateSourceGroups(${freespace_SOURCE})
172
173 target_link_libraries(
174   ${FS_BINARY}
175   code
176   ${SDL2_LIBRARY}
177   ${OPENGL_LIBRARIES}
178   ${OPENAL_LIBRARY}
179   ${LIBWEBSOCKETS_LIBRARIES}
180   ${PLATFORM_LIBRARIES}
181 )
182
183 if (EMSCRIPTEN)
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@/")
185 endif()
186
187 if(FS1)
188   set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace")
189 else()
190   set_target_properties(${FS_BINARY} PROPERTIES PROJECT_LABEL "Freespace2")
191 endif()
192
193 if(NOT EMSCRIPTEN)
194 #
195 # launcher
196 #
197
198 set(LAUNCHER_BINARY "freespace${BIN_SUFFIX}")
199
200 add_executable(${LAUNCHER_BINARY}
201   WIN32
202   ${launcher_SOURCE}
203   ${launcher_HEADERS}
204 )
205
206 CreateSourceGroups(${launcher_SOURCE})
207
208 target_link_libraries(
209   ${LAUNCHER_BINARY}
210   ${SDL2_LIBRARY}
211   ${OPENGL_LIBRARIES}
212   ${OPENAL_LIBRARY}
213   ${wxWidgets_LIBRARIES}
214   ${PLATFORM_LIBRARIES}
215 )
216
217 set_target_properties(${LAUNCHER_BINARY} PROPERTIES PROJECT_LABEL "Launcher")
218
219 # wxWidgets appears to need c++11 for one or more headers
220 if(NOT WIN32)
221   set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
222 endif()
223
224 #
225 # standalone server GUI
226 #
227
228 # Not for FS1 Demo
229 if(NOT FS1 OR NOT DEMO)
230         if(FS1)
231           set(STANDALONE_BINARY fsstandalone)
232         else()
233           set(STANDALONE_BINARY fs2standalone)
234         endif()
235
236         add_executable(${STANDALONE_BINARY}
237           WIN32
238           ${standalone_SOURCE}
239           ${standalone_HEADERS}
240         )
241
242         CreateSourceGroups(${standalone_SOURCE})
243
244         target_link_libraries(
245           ${STANDALONE_BINARY}
246           ${SDL2_LIBRARY}
247           ${wxWidgets_LIBRARIES}
248           ${LIBWEBSOCKETS_LIBRARIES}
249           ${PLATFORM_LIBRARIES}
250         )
251
252         set_target_properties(${STANDALONE_BINARY} PROPERTIES PROJECT_LABEL "Standalone")
253
254         # wxWidgets appears to need c++11 for one or more headers
255         if(NOT WIN32)
256           set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
257         endif()
258 endif()
259
260 #
261 # extra rule to make sure we cleanup all exe variants
262 #
263
264 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
265   # FS1 demo
266   fsdemo${CMAKE_EXECUTABLE_SUFFIX}
267   fsdemo${CMAKE_EXECUTABLE_SUFFIX}.mem
268   fsdemo.js
269   fsdemo.data
270   freespacedemo${CMAKE_EXECUTABLE_SUFFIX}
271   # FS1
272   fs${CMAKE_EXECUTABLE_SUFFIX}
273   fs${CMAKE_EXECUTABLE_SUFFIX}.mem
274   fs.js
275   fs.data
276   freespace${CMAKE_EXECUTABLE_SUFFIX}
277   # FS2 demo
278   fs2demo${CMAKE_EXECUTABLE_SUFFIX}
279   fs2demo${CMAKE_EXECUTABLE_SUFFIX}.mem
280   fs2demo.js
281   fs2demo.data
282   freespace2demo${CMAKE_EXECUTABLE_SUFFIX}
283   # FS2
284   fs2${CMAKE_EXECUTABLE_SUFFIX}
285   fs2${CMAKE_EXECUTABLE_SUFFIX}.mem
286   fs2.js
287   fs2.data
288   freespace2${CMAKE_EXECUTABLE_SUFFIX}
289   # standalone GUI
290   fsstandalone${CMAKE_EXECUTABLE_SUFFIX}
291   fs2standalone${CMAKE_EXECUTABLE_SUFFIX}
292 )
293
294 #
295 # ##############################################################################
296
297 # ##############################################################################
298 #
299 # toolset: targets for creating/modifying game assets
300 #
301
302 # don't build toolset unless it's a full build
303 if(NOT DEMO)
304
305         #
306         # AC: anim converter
307         #
308
309         add_executable(ac
310           EXCLUDE_FROM_ALL
311           ${ac_SOURCE}
312           ${ac_HEADERS}
313         )
314
315         CreateSourceGroups(${ac_SOURCE})
316
317         target_link_libraries(
318           ac
319           code
320           ${SDL2_LIBRARY}
321           ${OPENGL_LIBRARIES}
322           ${OPENAL_LIBRARY}
323           ${LIBWEBSOCKETS_LIBRARIES}
324           ${PLATFORM_LIBRARIES}
325         )
326
327         #
328         # CFILEARCHIVER: to create VP file archives
329         #
330
331         add_executable(cfilearchiver
332           EXCLUDE_FROM_ALL
333           ${cfilearchiver_SOURCE}
334         )
335
336         CreateSourceGroups(${cfilearchiver_SOURCE})
337
338         #
339         # CRYPTSTRING: string encryption (for embedded cheat codes)
340         #
341
342         add_executable(cryptstring
343           EXCLUDE_FROM_ALL
344           ${cryptstring_SOURCE}
345         )
346
347         CreateSourceGroups(${cryptstring_SOURCE})
348
349         #
350         # NEBEDIT: FS1 style nebula editor/creator
351         #
352
353         add_executable(nebedit
354           EXCLUDE_FROM_ALL
355           WIN32
356           ${nebedit_SOURCE}
357         )
358
359         CreateSourceGroups(${nebedit_SOURCE})
360
361         target_link_libraries(
362           nebedit
363           code
364           ${SDL2_LIBRARY}
365           ${OPENGL_LIBRARIES}
366           ${OPENAL_LIBRARY}
367           ${wxWidgets_LIBRARIES}
368           ${LIBWEBSOCKETS_LIBRARIES}
369           ${PLATFORM_LIBRARIES}
370         )
371
372         # wxWidgets appears to need c++11 for one or more headers
373         if(NOT WIN32)
374           set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
375         endif()
376
377         #
378         # POFVIEW: model viewer
379         #
380
381         add_executable(pofview
382           EXCLUDE_FROM_ALL
383           WIN32
384           ${pofview_SOURCE}
385           ${pofview_HEADERS}
386         )
387
388         CreateSourceGroups(${pofview_SOURCE})
389
390         target_link_libraries(
391           pofview
392           code
393           ${SDL2_LIBRARY}
394           ${OPENGL_LIBRARIES}
395           ${OPENAL_LIBRARY}
396           ${wxWidgets_LIBRARIES}
397           ${LIBWEBSOCKETS_LIBRARIES}
398           ${PLATFORM_LIBRARIES}
399         )
400
401         # wxWidgets appears to need c++11 for one or more headers
402         if(NOT WIN32)
403           set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
404         endif()
405
406         #
407         # SCRAMBLE: file-based encryption for TBLs
408         #
409
410         add_executable(scramble
411           EXCLUDE_FROM_ALL
412           ${scramble_SOURCE}
413           ${scramble_HEADERS}
414         )
415
416         CreateSourceGroups(${scramble_SOURCE})
417
418         #
419         # FONTTOOL: create font files / edit kerning data
420         #
421
422         add_executable(fonttool
423           EXCLUDE_FROM_ALL
424           ${fonttool_SOURCE}
425           ${fonttool_HEADERS}
426         )
427
428         CreateSourceGroups(${fonttool_SOURCE})
429
430         # background setup, to allow running from build location without installing
431         add_custom_command(TARGET fonttool
432           POST_BUILD
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"
435         )
436
437         target_link_libraries(
438           fonttool
439           code
440           ${SDL2_LIBRARY}
441           ${OPENGL_LIBRARIES}
442           ${OPENAL_LIBRARY}
443           ${LIBWEBSOCKETS_LIBRARIES}
444           ${PLATFORM_LIBRARIES}
445         )
446
447         #
448         # custom target to build all tools in one pass
449         #
450
451         add_custom_target(tools)
452
453         add_dependencies(tools
454           ac
455           cfilearchiver
456           cryptstring
457           nebedit
458           pofview
459           scramble
460           fonttool
461         )
462
463 endif(NOT DEMO)
464
465 #
466 # ##############################################################################
467
468 endif(NOT EMSCRIPTEN)
469 #
470 # optionally include any dev/user preferred build commands and/or options
471 #
472
473 include(custom.cmake OPTIONAL)