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