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