]> icculus.org git repositories - taylor/freespace2.git/blob - CMakeLists.txt
first pass at a real cleanup of cmake files
[taylor/freespace2.git] / CMakeLists.txt
1
2 project(freespace2)
3
4 cmake_minimum_required(VERSION 2.6)
5
6
7 include(CheckCXXCompilerFlag)
8 include(CheckCXXSourceCompiles)
9 include(CheckTypeSize)
10 include(FindPkgConfig)
11
12 pkg_search_module(SDL2 REQUIRED sdl2 >= 2.0.1)
13
14 find_package(OpenGL)
15 find_package(OpenAL)
16 find_package(wxWidgets COMPONENTS core base gl)
17
18 include(${wxWidgets_USE_FILE})
19
20
21 # ##############################################################################
22
23 option(FS1 "Build original FreeSpace" OFF)
24 option(DEMO "Create demo build" OFF)
25
26 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
27   message(STATUS "Setting build type to 'Debug' as none was specified.")
28   set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
29   # Set the possible values of build type for cmake-gui
30   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
31     "MinSizeRel" "RelWithDebInfo")
32 endif()
33
34
35 if(FS1)
36   add_definitions(-DMAKE_FS1)
37
38   if(DEMO)
39         add_definitions(-DDEMO -DFS1_DEMO)
40   endif()
41 else()
42   if(DEMO)
43         add_definitions(-DFS2_DEMO)
44   endif()
45 endif()
46
47 if(NOT WIN32)
48   add_definitions(-DPLAT_UNIX)
49   add_definitions(-Wall -Wno-format-y2k -Wno-deprecated)
50   add_definitions(-fsigned-char)
51
52   set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG -g -O2")
53   set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG -Os")
54   set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
55   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
56 endif()
57
58 # ##############################################################################
59
60
61 include_directories(
62   ${PROJECT_SOURCE_DIR}/include
63   ${SDL2_INCLUDE_DIRS}
64   ${OPENAL_INCLUDE_DIR}
65   ${wxWidgets_INCLUDE_DIRS}
66 )
67
68
69 add_subdirectory(src)
70 add_subdirectory(include)
71
72
73 # ##############################################################################
74 #
75
76 #
77 # main code/game library
78 #
79
80 add_library(code
81   STATIC
82   ${code_SOURCE}
83   ${code_HEADERS}
84 )
85
86 #
87 # the game itself
88 #
89
90 if(FS1)
91   if(DEMO)
92     set(FS_BINARY freespace_demo)
93   else()
94     set(FS_BINARY freespace)
95   endif()
96 else()
97   if(DEMO)
98     set(FS_BINARY freespace2_demo)
99   else()
100         set(FS_BINARY freespace2)
101   endif()
102 endif()
103
104 add_executable(${FS_BINARY}
105   ${freespace_SOURCE}
106   ${freespace_HEADERS}
107 )
108
109 target_link_libraries(
110   ${FS_BINARY}
111   code
112   ${SDL2_LIBRARIES}
113   ${OPENGL_LIBRARIES}
114   ${OPENAL_LIBRARY}
115 )
116
117 #
118 # ##############################################################################
119
120 # ##############################################################################
121 #
122 # toolset: targets for creating/modifying game assets
123 #
124
125 #
126 # AC: anim converter
127 #
128
129 add_executable(ac
130   EXCLUDE_FROM_ALL
131   ${ac_SOURCE}
132   ${ac_HEADERS}
133 )
134
135 target_link_libraries(
136   ac
137   code
138   ${SDL2_LIBRARIES}
139   ${OPENGL_LIBRARIES}
140   ${OPENAL_LIBRARY}
141 )
142
143 #
144 # CFILEARCHIVER: to create VP file archives
145 #
146
147 add_executable(cfilearchiver
148   EXCLUDE_FROM_ALL
149   ${cfilearchiver_SOURCE}
150 )
151
152 #
153 # CRYPTSTRING: string encryption (for embedded cheat codes)
154 #
155
156 add_executable(cryptstring
157   EXCLUDE_FROM_ALL
158   ${cryptstring_SOURCE}
159 )
160
161 #
162 # NEBEDIT: FS1 style nebula editor/creator
163 #
164
165 add_executable(nebedit
166   EXCLUDE_FROM_ALL
167   ${nebedit_SOURCE}
168 )
169
170 target_link_libraries(
171   nebedit
172   code
173   ${SDL2_LIBRARIES}
174   ${OPENGL_LIBRARIES}
175   ${OPENAL_LIBRARY}
176   ${wxWidgets_LIBRARIES}
177 )
178
179 #
180 # POFVIEW: model viewer
181 #
182
183 add_executable(pofview
184   EXCLUDE_FROM_ALL
185   ${pofview_SOURCE}
186   ${pofview_HEADERS}
187 )
188
189 target_link_libraries(
190   pofview
191   code
192   ${SDL2_LIBRARIES}
193   ${OPENGL_LIBRARIES}
194   ${OPENAL_LIBRARY}
195   ${wxWidgets_LIBRARIES}
196 )
197
198 # wxWidgets appears to need c++11 for one or more headers
199 if(NOT WIN32)
200   set_target_properties(pofview PROPERTIES COMPILE_FLAGS -std=c++11)
201 endif()
202
203 #
204 # SCRAMBLE: file-based encryption for TBLs
205 #
206
207 add_executable(scramble
208   EXCLUDE_FROM_ALL
209   ${scramble_SOURCE}
210   ${scramble_HEADERS}
211 )
212
213 #
214 # FONTTOOL: create font files / edit kerning data
215 #
216
217 add_executable(fonttool
218   EXCLUDE_FROM_ALL
219   ${fonttool_SOURCE}
220   ${fonttool_HEADERS}
221 )
222
223 # background setup, to allow running from build location without installing
224 add_custom_command(TARGET fonttool
225   POST_BUILD
226   COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
227   COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/src/fonttool/fonttool.pcx" "${CMAKE_CURRENT_BINARY_DIR}/src/fonttool"
228 )
229
230 target_link_libraries(
231   fonttool
232   code
233   ${SDL2_LIBRARIES}
234   ${OPENGL_LIBRARIES}
235   ${OPENAL_LIBRARY}
236 )
237
238 #
239 # custom target to build all tools in one pass
240 #
241
242 add_custom_target(tools)
243
244 add_dependencies(tools
245   ac
246   cfilearchiver
247   cryptstring
248   nebedit
249   pofview
250   scramble
251   fonttool
252 )
253
254 #
255 # ##############################################################################
256
257 #
258 # optionally include any dev/user preferred build commands and/or options
259 #
260
261 include(custom.cmake OPTIONAL)