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