]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
only show Warning()'s on debug builds
[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 # ##############################################################################
140
141 # ##############################################################################
142 #
143 # toolset: targets for creating/modifying game assets
144 #
145
146 #
147 # AC: anim converter
148 #
149
150 add_executable(ac
151   EXCLUDE_FROM_ALL
152   ${ac_SOURCE}
153   ${ac_HEADERS}
154 )
155
156 target_link_libraries(
157   ac
158   code
159   ${SDL2_LIBRARY}
160   ${OPENGL_LIBRARIES}
161   ${OPENAL_LIBRARY}
162   ${PLATFORM_LIBRARIES}
163 )
164
165 #
166 # CFILEARCHIVER: to create VP file archives
167 #
168
169 add_executable(cfilearchiver
170   EXCLUDE_FROM_ALL
171   ${cfilearchiver_SOURCE}
172 )
173
174 #
175 # CRYPTSTRING: string encryption (for embedded cheat codes)
176 #
177
178 add_executable(cryptstring
179   EXCLUDE_FROM_ALL
180   ${cryptstring_SOURCE}
181 )
182
183 #
184 # NEBEDIT: FS1 style nebula editor/creator
185 #
186
187 add_executable(nebedit
188   EXCLUDE_FROM_ALL
189   WIN32
190   ${nebedit_SOURCE}
191 )
192
193 target_link_libraries(
194   nebedit
195   code
196   ${SDL2_LIBRARY}
197   ${OPENGL_LIBRARIES}
198   ${OPENAL_LIBRARY}
199   ${wxWidgets_LIBRARIES}
200   ${PLATFORM_LIBRARIES}
201 )
202
203 # wxWidgets appears to need c++11 for one or more headers
204 if(NOT WIN32)
205   set_target_properties(nebedit PROPERTIES COMPILE_FLAGS -std=c++11)
206 endif()
207
208 #
209 # POFVIEW: model viewer
210 #
211
212 add_executable(pofview
213   EXCLUDE_FROM_ALL
214   WIN32
215   ${pofview_SOURCE}
216   ${pofview_HEADERS}
217 )
218
219 target_link_libraries(
220   pofview
221   code
222   ${SDL2_LIBRARY}
223   ${OPENGL_LIBRARIES}
224   ${OPENAL_LIBRARY}
225   ${wxWidgets_LIBRARIES}
226   ${PLATFORM_LIBRARIES}
227 )
228
229 # wxWidgets appears to need c++11 for one or more headers
230 if(NOT WIN32)
231   set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
232 endif()
233
234 #
235 # SCRAMBLE: file-based encryption for TBLs
236 #
237
238 add_executable(scramble
239   EXCLUDE_FROM_ALL
240   ${scramble_SOURCE}
241   ${scramble_HEADERS}
242 )
243
244 #
245 # FONTTOOL: create font files / edit kerning data
246 #
247
248 add_executable(fonttool
249   EXCLUDE_FROM_ALL
250   WIN32
251   ${fonttool_SOURCE}
252   ${fonttool_HEADERS}
253 )
254
255 # background setup, to allow running from build location without installing
256 add_custom_command(TARGET fonttool
257   POST_BUILD
258   COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
259   COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
260 )
261
262 target_link_libraries(
263   fonttool
264   code
265   ${SDL2_LIBRARY}
266   ${OPENGL_LIBRARIES}
267   ${OPENAL_LIBRARY}
268   ${PLATFORM_LIBRARIES}
269 )
270
271 #
272 # custom target to build all tools in one pass
273 #
274
275 add_custom_target(tools)
276
277 add_dependencies(tools
278   ac
279   cfilearchiver
280   cryptstring
281   nebedit
282   pofview
283   scramble
284   fonttool
285 )
286
287 #
288 # ##############################################################################
289
290 #
291 # optionally include any dev/user preferred build commands and/or options
292 #
293
294 include(custom.cmake OPTIONAL)