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