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