]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
merge new standalone server and client
[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   WIN32
183   ${standalone_SOURCE}
184   ${standalone_HEADERS}
185 )
186
187 target_link_libraries(
188   ${STANDALONE_BINARY}
189   ${SDL2_LIBRARY}
190   ${wxWidgets_LIBRARIES}
191   ${LIBWEBSOCKETS_LIBRARIES}
192   ${PLATFORM_LIBRARIES}
193 )
194
195 # wxWidgets appears to need c++11 for one or more headers
196 if(NOT WIN32)
197   set_target_properties(${STANDALONE_BINARY} PROPERTIES COMPILE_FLAGS -std=c++11)
198 endif()
199
200 #
201 # ##############################################################################
202
203 # ##############################################################################
204 #
205 # toolset: targets for creating/modifying game assets
206 #
207
208 #
209 # AC: anim converter
210 #
211
212 add_executable(ac
213   EXCLUDE_FROM_ALL
214   ${ac_SOURCE}
215   ${ac_HEADERS}
216 )
217
218 target_link_libraries(
219   ac
220   code
221   ${SDL2_LIBRARY}
222   ${OPENGL_LIBRARIES}
223   ${OPENAL_LIBRARY}
224   ${LIBWEBSOCKETS_LIBRARIES}
225   ${PLATFORM_LIBRARIES}
226 )
227
228 #
229 # CFILEARCHIVER: to create VP file archives
230 #
231
232 add_executable(cfilearchiver
233   EXCLUDE_FROM_ALL
234   ${cfilearchiver_SOURCE}
235 )
236
237 #
238 # CRYPTSTRING: string encryption (for embedded cheat codes)
239 #
240
241 add_executable(cryptstring
242   EXCLUDE_FROM_ALL
243   ${cryptstring_SOURCE}
244 )
245
246 #
247 # NEBEDIT: FS1 style nebula editor/creator
248 #
249
250 add_executable(nebedit
251   EXCLUDE_FROM_ALL
252   WIN32
253   ${nebedit_SOURCE}
254 )
255
256 target_link_libraries(
257   nebedit
258   code
259   ${SDL2_LIBRARY}
260   ${OPENGL_LIBRARIES}
261   ${OPENAL_LIBRARY}
262   ${wxWidgets_LIBRARIES}
263   ${LIBWEBSOCKETS_LIBRARIES}
264   ${PLATFORM_LIBRARIES}
265 )
266
267 # wxWidgets appears to need c++11 for one or more headers
268 if(NOT WIN32)
269   set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
270 endif()
271
272 #
273 # POFVIEW: model viewer
274 #
275
276 add_executable(pofview
277   EXCLUDE_FROM_ALL
278   WIN32
279   ${pofview_SOURCE}
280   ${pofview_HEADERS}
281 )
282
283 target_link_libraries(
284   pofview
285   code
286   ${SDL2_LIBRARY}
287   ${OPENGL_LIBRARIES}
288   ${OPENAL_LIBRARY}
289   ${wxWidgets_LIBRARIES}
290   ${LIBWEBSOCKETS_LIBRARIES}
291   ${PLATFORM_LIBRARIES}
292 )
293
294 # wxWidgets appears to need c++11 for one or more headers
295 if(NOT WIN32)
296   set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
297 endif()
298
299 #
300 # SCRAMBLE: file-based encryption for TBLs
301 #
302
303 add_executable(scramble
304   EXCLUDE_FROM_ALL
305   ${scramble_SOURCE}
306   ${scramble_HEADERS}
307 )
308
309 #
310 # FONTTOOL: create font files / edit kerning data
311 #
312
313 add_executable(fonttool
314   EXCLUDE_FROM_ALL
315   WIN32
316   ${fonttool_SOURCE}
317   ${fonttool_HEADERS}
318 )
319
320 # background setup, to allow running from build location without installing
321 add_custom_command(TARGET fonttool
322   POST_BUILD
323   COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
324   COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
325 )
326
327 target_link_libraries(
328   fonttool
329   code
330   ${SDL2_LIBRARY}
331   ${OPENGL_LIBRARIES}
332   ${OPENAL_LIBRARY}
333   ${LIBWEBSOCKETS_LIBRARIES}
334   ${PLATFORM_LIBRARIES}
335 )
336
337 #
338 # custom target to build all tools in one pass
339 #
340
341 add_custom_target(tools)
342
343 add_dependencies(tools
344   ac
345   cfilearchiver
346   cryptstring
347   nebedit
348   pofview
349   scramble
350   fonttool
351 )
352
353 #
354 # ##############################################################################
355
356 #
357 # optionally include any dev/user preferred build commands and/or options
358 #
359
360 include(custom.cmake OPTIONAL)