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