]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
platform and pstypes cleanup:
[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(/wd4611) # non-portable interaction between setjmp() and C++ object destruction
67   add_definitions(/wd4996) # deprecated functions: fopen, fileno, ...
68 endif()
69
70
71 # ##############################################################################
72
73
74 include_directories(
75   ${PROJECT_SOURCE_DIR}/include
76   ${SDL2_INCLUDE_DIR}
77   ${OPENAL_INCLUDE_DIR}
78   ${wxWidgets_INCLUDE_DIRS}
79 )
80
81
82 add_subdirectory(src)
83 add_subdirectory(include)
84
85
86 # ##############################################################################
87 #
88
89 #
90 # main code/game library
91 #
92
93 add_library(code
94   STATIC
95   ${code_SOURCE}
96   ${code_HEADERS}
97   ${platform_SOURCE}
98   ${platform_HEADERS}
99 )
100
101 #
102 # the game itself
103 #
104
105 if(FS1)
106   if(DEMO)
107     set(FS_BINARY freespace_demo)
108   else()
109     set(FS_BINARY freespace)
110   endif()
111 else()
112   if(DEMO)
113     set(FS_BINARY freespace2_demo)
114   else()
115         set(FS_BINARY freespace2)
116   endif()
117 endif()
118
119 add_executable(${FS_BINARY}
120   WIN32
121   ${freespace_SOURCE}
122   ${freespace_HEADERS}
123 )
124
125 target_link_libraries(
126   ${FS_BINARY}
127   code
128   ${SDL2_LIBRARY}
129   ${OPENGL_LIBRARIES}
130   ${OPENAL_LIBRARY}
131   ${PLATFORM_LIBRARIES}
132 )
133
134 #
135 # ##############################################################################
136
137 # ##############################################################################
138 #
139 # toolset: targets for creating/modifying game assets
140 #
141
142 #
143 # AC: anim converter
144 #
145
146 add_executable(ac
147   EXCLUDE_FROM_ALL
148   ${ac_SOURCE}
149   ${ac_HEADERS}
150 )
151
152 target_link_libraries(
153   ac
154   code
155   ${SDL2_LIBRARY}
156   ${OPENGL_LIBRARIES}
157   ${OPENAL_LIBRARY}
158   ${PLATFORM_LIBRARIES}
159 )
160
161 #
162 # CFILEARCHIVER: to create VP file archives
163 #
164
165 add_executable(cfilearchiver
166   EXCLUDE_FROM_ALL
167   ${cfilearchiver_SOURCE}
168 )
169
170 #
171 # CRYPTSTRING: string encryption (for embedded cheat codes)
172 #
173
174 add_executable(cryptstring
175   EXCLUDE_FROM_ALL
176   ${cryptstring_SOURCE}
177 )
178
179 #
180 # NEBEDIT: FS1 style nebula editor/creator
181 #
182
183 add_executable(nebedit
184   EXCLUDE_FROM_ALL
185   WIN32
186   ${nebedit_SOURCE}
187 )
188
189 target_link_libraries(
190   nebedit
191   code
192   ${SDL2_LIBRARY}
193   ${OPENGL_LIBRARIES}
194   ${OPENAL_LIBRARY}
195   ${wxWidgets_LIBRARIES}
196   ${PLATFORM_LIBRARIES}
197 )
198
199 # wxWidgets appears to need c++11 for one or more headers
200 if(NOT WIN32)
201   set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
202 endif()
203
204 #
205 # POFVIEW: model viewer
206 #
207
208 add_executable(pofview
209   EXCLUDE_FROM_ALL
210   WIN32
211   ${pofview_SOURCE}
212   ${pofview_HEADERS}
213 )
214
215 target_link_libraries(
216   pofview
217   code
218   ${SDL2_LIBRARY}
219   ${OPENGL_LIBRARIES}
220   ${OPENAL_LIBRARY}
221   ${wxWidgets_LIBRARIES}
222   ${PLATFORM_LIBRARIES}
223 )
224
225 # wxWidgets appears to need c++11 for one or more headers
226 if(NOT WIN32)
227   set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
228 endif()
229
230 #
231 # SCRAMBLE: file-based encryption for TBLs
232 #
233
234 add_executable(scramble
235   EXCLUDE_FROM_ALL
236   ${scramble_SOURCE}
237   ${scramble_HEADERS}
238 )
239
240 #
241 # FONTTOOL: create font files / edit kerning data
242 #
243
244 add_executable(fonttool
245   EXCLUDE_FROM_ALL
246   WIN32
247   ${fonttool_SOURCE}
248   ${fonttool_HEADERS}
249 )
250
251 # background setup, to allow running from build location without installing
252 add_custom_command(TARGET fonttool
253   POST_BUILD
254   COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
255   COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
256 )
257
258 target_link_libraries(
259   fonttool
260   code
261   ${SDL2_LIBRARY}
262   ${OPENGL_LIBRARIES}
263   ${OPENAL_LIBRARY}
264   ${PLATFORM_LIBRARIES}
265 )
266
267 #
268 # custom target to build all tools in one pass
269 #
270
271 add_custom_target(tools)
272
273 add_dependencies(tools
274   ac
275   cfilearchiver
276   cryptstring
277   nebedit
278   pofview
279   scramble
280   fonttool
281 )
282
283 #
284 # ##############################################################################
285
286 #
287 # optionally include any dev/user preferred build commands and/or options
288 #
289
290 include(custom.cmake OPTIONAL)