]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
add test for existing instance of game (an error condition)
[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
14 find_package(SDL2 "2.0.1" REQUIRED)
15 find_package(OpenGL REQUIRED)
16 find_package(OpenAL REQUIRED)
17 find_package(LibWebSockets REQUIRED)
18
19 find_package(wxWidgets COMPONENTS core base gl net)
20 include(${wxWidgets_USE_FILE})
21
22
23 # ##############################################################################
24
25 option(FS1 "Build original FreeSpace" OFF)
26 option(DEMO "Create demo build" OFF)
27
28 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
29   message(STATUS "Setting build type to 'Debug' as none was specified.")
30   set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
31   # Set the possible values of build type for cmake-gui
32   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
33     "MinSizeRel" "RelWithDebInfo")
34 endif()
35
36
37 if(FS1)
38   add_definitions(-DMAKE_FS1)
39
40   if(DEMO)
41         add_definitions(-DDEMO -DFS1_DEMO)
42   endif()
43 else()
44   if(DEMO)
45         add_definitions(-DFS2_DEMO)
46   endif()
47 endif()
48
49 if(NOT WIN32)
50   set(PLATFORM_LIBRARIES "")
51
52   add_definitions(-DPLAT_UNIX)
53   add_definitions(-Wall)
54 # add_definitions(-Wno-format-y2k)
55 # add_definitions(-Wno-deprecated)
56   add_definitions(-fsigned-char)
57
58   set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG -g -O2")
59   set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG -Os")
60   set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
61   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
62 else()
63   set(PLATFORM_LIBRARIES
64         wsock32.lib
65         winmm.lib
66   )
67
68   add_definitions(/D _CRT_SECURE_NO_WARNINGS)
69   add_definitions(/W4)
70   add_definitions(/wd4100) # unreferenced parameter
71   add_definitions(/wd4127) # conditional expression is constant: do { } while (0)
72   add_definitions(/wd4996) # deprecated functions: fopen, fileno, ...
73 endif()
74
75
76 # ##############################################################################
77
78
79 include_directories(
80   ${PROJECT_SOURCE_DIR}/include
81   ${SDL2_INCLUDE_DIR}
82   ${OPENAL_INCLUDE_DIR}
83   ${LIBWEBSOCKETS_INCLUDE_DIR}
84   ${wxWidgets_INCLUDE_DIRS}
85 )
86
87
88 add_subdirectory(src)
89 add_subdirectory(include)
90
91
92 # ##############################################################################
93 #
94
95 #
96 # main code/game library
97 #
98
99 add_library(code
100   STATIC
101   ${code_SOURCE}
102   ${code_HEADERS}
103   ${platform_SOURCE}
104   ${platform_HEADERS}
105 )
106
107 #
108 # the game itself
109 #
110
111 if(FS1)
112   if(DEMO)
113     set(FS_BINARY freespace_demo)
114   else()
115     set(FS_BINARY freespace)
116   endif()
117 else()
118   if(DEMO)
119     set(FS_BINARY freespace2_demo)
120   else()
121         set(FS_BINARY freespace2)
122   endif()
123 endif()
124
125 add_executable(${FS_BINARY}
126   WIN32
127   ${freespace_SOURCE}
128   ${freespace_HEADERS}
129 )
130
131 target_link_libraries(
132   ${FS_BINARY}
133   code
134   ${SDL2_LIBRARY}
135   ${OPENGL_LIBRARIES}
136   ${OPENAL_LIBRARY}
137   ${LIBWEBSOCKETS_LIBRARIES}
138   ${PLATFORM_LIBRARIES}
139 )
140
141 #
142 # launcher
143 #
144
145 if(FS1)
146   set(LAUNCHER_BINARY fslaunch)
147 else()
148   set(LAUNCHER_BINARY fs2launch)
149 endif()
150
151 add_executable(${LAUNCHER_BINARY}
152   WIN32
153   ${launcher_SOURCE}
154   ${launcher_HEADERS}
155 )
156
157 target_link_libraries(
158   ${LAUNCHER_BINARY}
159   ${SDL2_LIBRARY}
160   ${OPENGL_LIBRARIES}
161   ${OPENAL_LIBRARY}
162   ${wxWidgets_LIBRARIES}
163   ${PLATFORM_LIBRARIES}
164 )
165
166 # wxWidgets appears to need c++11 for one or more headers
167 if(NOT WIN32)
168   set_target_properties(${LAUNCHER_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
169 endif()
170
171 #
172 # standalone server GUI
173 #
174
175 if(FS1)
176   set(STANDALONE_BINARY fsstandalone)
177 else()
178   set(STANDALONE_BINARY fs2standalone)
179 endif()
180
181 add_executable(${STANDALONE_BINARY}
182   EXCLUDE_FROM_ALL
183   WIN32
184   ${standalone_SOURCE}
185   ${standalone_HEADERS}
186 )
187
188 target_link_libraries(
189   ${STANDALONE_BINARY}
190   ${SDL2_LIBRARY}
191   ${wxWidgets_LIBRARIES}
192   ${LIBWEBSOCKETS_LIBRARIES}
193   ${PLATFORM_LIBRARIES}
194 )
195
196 # wxWidgets appears to need c++11 for one or more headers
197 if(NOT WIN32)
198   set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
199 endif()
200
201 #
202 # ##############################################################################
203
204 # ##############################################################################
205 #
206 # toolset: targets for creating/modifying game assets
207 #
208
209 #
210 # AC: anim converter
211 #
212
213 add_executable(ac
214   EXCLUDE_FROM_ALL
215   ${ac_SOURCE}
216   ${ac_HEADERS}
217 )
218
219 target_link_libraries(
220   ac
221   code
222   ${SDL2_LIBRARY}
223   ${OPENGL_LIBRARIES}
224   ${OPENAL_LIBRARY}
225   ${LIBWEBSOCKETS_LIBRARIES}
226   ${PLATFORM_LIBRARIES}
227 )
228
229 #
230 # CFILEARCHIVER: to create VP file archives
231 #
232
233 add_executable(cfilearchiver
234   EXCLUDE_FROM_ALL
235   ${cfilearchiver_SOURCE}
236 )
237
238 #
239 # CRYPTSTRING: string encryption (for embedded cheat codes)
240 #
241
242 add_executable(cryptstring
243   EXCLUDE_FROM_ALL
244   ${cryptstring_SOURCE}
245 )
246
247 #
248 # NEBEDIT: FS1 style nebula editor/creator
249 #
250
251 add_executable(nebedit
252   EXCLUDE_FROM_ALL
253   WIN32
254   ${nebedit_SOURCE}
255 )
256
257 target_link_libraries(
258   nebedit
259   code
260   ${SDL2_LIBRARY}
261   ${OPENGL_LIBRARIES}
262   ${OPENAL_LIBRARY}
263   ${wxWidgets_LIBRARIES}
264   ${LIBWEBSOCKETS_LIBRARIES}
265   ${PLATFORM_LIBRARIES}
266 )
267
268 # wxWidgets appears to need c++11 for one or more headers
269 if(NOT WIN32)
270   set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
271 endif()
272
273 #
274 # POFVIEW: model viewer
275 #
276
277 add_executable(pofview
278   EXCLUDE_FROM_ALL
279   WIN32
280   ${pofview_SOURCE}
281   ${pofview_HEADERS}
282 )
283
284 target_link_libraries(
285   pofview
286   code
287   ${SDL2_LIBRARY}
288   ${OPENGL_LIBRARIES}
289   ${OPENAL_LIBRARY}
290   ${wxWidgets_LIBRARIES}
291   ${LIBWEBSOCKETS_LIBRARIES}
292   ${PLATFORM_LIBRARIES}
293 )
294
295 # wxWidgets appears to need c++11 for one or more headers
296 if(NOT WIN32)
297   set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
298 endif()
299
300 #
301 # SCRAMBLE: file-based encryption for TBLs
302 #
303
304 add_executable(scramble
305   EXCLUDE_FROM_ALL
306   ${scramble_SOURCE}
307   ${scramble_HEADERS}
308 )
309
310 #
311 # FONTTOOL: create font files / edit kerning data
312 #
313
314 add_executable(fonttool
315   EXCLUDE_FROM_ALL
316   WIN32
317   ${fonttool_SOURCE}
318   ${fonttool_HEADERS}
319 )
320
321 # background setup, to allow running from build location without installing
322 add_custom_command(TARGET fonttool
323   POST_BUILD
324   COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
325   COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
326 )
327
328 target_link_libraries(
329   fonttool
330   code
331   ${SDL2_LIBRARY}
332   ${OPENGL_LIBRARIES}
333   ${OPENAL_LIBRARY}
334   ${LIBWEBSOCKETS_LIBRARIES}
335   ${PLATFORM_LIBRARIES}
336 )
337
338 #
339 # custom target to build all tools in one pass
340 #
341
342 add_custom_target(tools)
343
344 add_dependencies(tools
345   ac
346   cfilearchiver
347   cryptstring
348   nebedit
349   pofview
350   scramble
351   fonttool
352 )
353
354 #
355 # ##############################################################################
356
357 #
358 # optionally include any dev/user preferred build commands and/or options
359 #
360
361 include(custom.cmake OPTIONAL)