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