]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
add first stages of GUI for standalone
[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)
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   ${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   ${PLATFORM_LIBRARIES}
225 )
226
227 #
228 # CFILEARCHIVER: to create VP file archives
229 #
230
231 add_executable(cfilearchiver
232   EXCLUDE_FROM_ALL
233   ${cfilearchiver_SOURCE}
234 )
235
236 #
237 # CRYPTSTRING: string encryption (for embedded cheat codes)
238 #
239
240 add_executable(cryptstring
241   EXCLUDE_FROM_ALL
242   ${cryptstring_SOURCE}
243 )
244
245 #
246 # NEBEDIT: FS1 style nebula editor/creator
247 #
248
249 add_executable(nebedit
250   EXCLUDE_FROM_ALL
251   WIN32
252   ${nebedit_SOURCE}
253 )
254
255 target_link_libraries(
256   nebedit
257   code
258   ${SDL2_LIBRARY}
259   ${OPENGL_LIBRARIES}
260   ${OPENAL_LIBRARY}
261   ${wxWidgets_LIBRARIES}
262   ${PLATFORM_LIBRARIES}
263 )
264
265 # wxWidgets appears to need c++11 for one or more headers
266 if(NOT WIN32)
267   set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
268 endif()
269
270 #
271 # POFVIEW: model viewer
272 #
273
274 add_executable(pofview
275   EXCLUDE_FROM_ALL
276   WIN32
277   ${pofview_SOURCE}
278   ${pofview_HEADERS}
279 )
280
281 target_link_libraries(
282   pofview
283   code
284   ${SDL2_LIBRARY}
285   ${OPENGL_LIBRARIES}
286   ${OPENAL_LIBRARY}
287   ${wxWidgets_LIBRARIES}
288   ${PLATFORM_LIBRARIES}
289 )
290
291 # wxWidgets appears to need c++11 for one or more headers
292 if(NOT WIN32)
293   set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
294 endif()
295
296 #
297 # SCRAMBLE: file-based encryption for TBLs
298 #
299
300 add_executable(scramble
301   EXCLUDE_FROM_ALL
302   ${scramble_SOURCE}
303   ${scramble_HEADERS}
304 )
305
306 #
307 # FONTTOOL: create font files / edit kerning data
308 #
309
310 add_executable(fonttool
311   EXCLUDE_FROM_ALL
312   WIN32
313   ${fonttool_SOURCE}
314   ${fonttool_HEADERS}
315 )
316
317 # background setup, to allow running from build location without installing
318 add_custom_command(TARGET fonttool
319   POST_BUILD
320   COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
321   COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
322 )
323
324 target_link_libraries(
325   fonttool
326   code
327   ${SDL2_LIBRARY}
328   ${OPENGL_LIBRARIES}
329   ${OPENAL_LIBRARY}
330   ${PLATFORM_LIBRARIES}
331 )
332
333 #
334 # custom target to build all tools in one pass
335 #
336
337 add_custom_target(tools)
338
339 add_dependencies(tools
340   ac
341   cfilearchiver
342   cryptstring
343   nebedit
344   pofview
345   scramble
346   fonttool
347 )
348
349 #
350 # ##############################################################################
351
352 #
353 # optionally include any dev/user preferred build commands and/or options
354 #
355
356 include(custom.cmake OPTIONAL)