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