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