view CMakeLists.txt @ 3:4f8b47ac2715

Aborted test of loading an MD2 model. The GLTools TriangleBatch class doesn't play nicely with MD2, as it erroneously marks vertices as duplicates of each other.
author Eris Caffee <discordia@eldalin.com>
date Sun, 28 Apr 2013 18:04:27 -0500
parents c24af3462002
children
line source
1 ###############################################################################
2 #
3 # A generalized cmake file for developing cross-platform games.
4 #
5 # Copyright (C) 2010 Sarah Eris Horsley Caffee
6 #
7 # This is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #
20 #
21 # Instructions:
22 # This cmake file assumes that your source files are laid in out in the
23 # following manner:
24 #
25 # project_dir\ Top level directory of the project.
26 # |---include\ Header files are here.
27 # |---src\ Source files are here.
28 # |---build\ Binaries/objects go here. Run cmake from here.
29 # !---cmake\
30 # | |---modules\ Custom cmake include files, if any, go here.
31 # |---CMakeLists.txt This file.
32 #
33 # You may have more directories, of course, but these are assumed. You probably
34 # want more than one build directory. I normally have build-linux\
35 # and build-windows\ directories.
36 #
37 # Set the App_Name variable, below, to the name of your application and you
38 # are ready to start. Run ccmake, or cmake-gui from within your build
39 # directory, choose the options you need, such as enabling SDL, and you
40 # should be good to go.
41 #
42 # You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON) command if you
43 # need to debug the actual makefile that is generated.
44 #
45 # On windows, you may need to set the SDLDIR environment variable to the location
46 # of your SDL installation before you run cmake-gui.
47 #
48 # When writing path names on Windows, such as when manually specifiying a
49 # file or directory name, either use unix-style forward slashes '/' in the
50 # path names or use double backslashes. If you use a single backslash as the
51 # path name seperator, then cmake will interpret it as an esacpe sequence.
52 # Thus, write "C:/source" or "C:\\source" instead of "C:\source". It's
53 # probably best to use forward slashes in case to ever have a situation
54 # where cmake needs to do recursive processing: each level of cmake will
55 # strip out one of the slashes, so if there are two lev3els of cmake you
56 # need to write \\\, three levels requires \\\\, etc.
57 #
58 # Note that some of the cmake support scripts that find libraries for you
59 # can be controlled by environment variables. For example, you can set the
60 # SDLDIR environment variable before running cmake in order to point to
61 # a different version of SDL than your systems default copy. This is useful
62 # for trying out cutting edge versions of libraries without installing them
63 # system wide.
65 cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
66 #set (CMAKE_VERBOSE_MAKEFILE ON)
68 # Name your program!
69 set (App_Name "solar-system")
70 if (App_Name STREQUAL "")
71 message (FATAL_ERROR "You must set the App_Name variable!")
72 endif ()
74 # Every project must have a name.
75 project (${App_Name})
78 ################################################################################
79 # Special options
82 ################################################################################
83 # Ensure that we are not building in our source directories.
85 set (Build_Dir_OK "TRUE")
86 string (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR})
87 if (In_Sub_Dir)
88 string (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR})
89 if (NOT In_Build_Dir)
90 set (Build_Dir_OK "FALSE")
91 endif ()
92 endif ()
94 if (NOT Build_Dir_OK)
95 message (FATAL_ERROR "You must run cmake from a directory that is not in your source tree, or that is in a special subdirectory of the tree whose name begins with 'build'.")
96 endif ()
99 ################################################################################
100 # Set up the basic build environment
101 # A build type defines which options are passed to the compiler, and there are
102 # several that CMake defines by default. It does not set one by default, though
103 # so we need to set the build type manually here, and we are setting it to the
104 # generally useful "Release with debug info"
106 if (CMAKE_BUILD_TYPE STREQUAL "")
107 # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This messes up
108 # differentiation between debug and release builds.
109 set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
110 endif ()
113 ################################################################################
114 # When using GCC turn on lots of warnings.
115 # Some other options to consider:
116 # C++ -Weffc++ -std=c++0x
117 # C -std=gnu99 -std=c99
119 if (CMAKE_COMPILER_IS_GNUCXX)
120 add_definitions( -Wall -std=c++0x)
121 endif ()
124 ################################################################################
126 option(Option_Profile_Program "Build for gprof profiling." OFF)
127 if (Option_Profile_Program)
128 add_definitions(-pg)
129 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
130 endif ()
133 ################################################################################
134 # The core project files
136 file (GLOB SRCS src/*.c src/*.cpp
137 /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/src/*
138 /home/eris/gamedev/projects/MD2/src/*
139 )
140 file (GLOB HDRS include/*.h include/*.hpp
141 /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/*
142 /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/GL/*
143 /home/eris/gamedev/projects/MD2/include/*
144 )
146 # The directories that contain the libraries we will be linking against.
147 # This must come before the ADD_EXECUTABLE directive.
148 link_directories (
149 )
151 # The directories that contain the include files our programs use.
152 # This must come before the ADD_EXECUTABLE directive.
153 include_directories (
154 ${CMAKE_SOURCE_DIR}/include
155 /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/
156 /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/GL
157 /home/eris/gamedev/projects/MD2/include
158 )
160 # Define the executable program file we are creating. We must list all of
161 # the source files.
162 if (WIN32)
163 add_executable (${App_Name} WIN32
164 ${SRCS}
165 ${HDRS}
166 )
167 else ()
168 # I should NOT have to define this symbol explictly. Why do I?
169 add_definitions(-Dlinux)
171 add_executable (${App_Name}
172 ${SRCS}
173 ${HDRS}
174 )
175 endif ()
177 # Although we listed the library directories above, we also need to list the
178 # individual libraries we will be linking against.
179 target_link_libraries (${App_Name}
180 )
183 # # An example for a unix library named utils with a test driver program.
185 # set (SRCS_utils
186 # src/utils.cpp
187 # include/utils.h
188 # )
190 # include_directories (
191 # ${PROJECT_SOURCE_DIR}/include
192 # )
194 # # Build both static and shared libraries
195 # # The target properties are needed because, by default, the output name
196 # # will be the name in the add_library command, and we need to have different
197 # # names in the two commands for the shared and static versions, even though
198 # # we want the final files to have the same names with different extensions.
199 # #
200 # # The prefix is needed mostly in case we build on windows, which has no prefix
201 # # by default.
202 # #
203 # # The clean_direct_output option makes sure that the two lib builds don't
204 # # clobber each others temp files since they are being built from the same
205 # # sources.
207 # add_library (utils SHARED
208 # ${SRCS_utils}
209 # )
210 # set_target_properties (utils PROPERTIES OUTPUT_NAME "utils")
211 # set_target_properties (utils PROPERTIES PREFIX "lib")
212 # set_target_properties (utils PROPERTIES CLEAN_DIRECT_OUTPUT 1)
214 # add_library (utils-static STATIC
215 # ${SRCS_utils}
216 # )
217 # set_target_properties (utils-static PROPERTIES OUTPUT_NAME "utils")
218 # set_target_properties (utils-static PROPERTIES PREFIX "lib")
219 # set_target_properties (utils-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
221 # # Build a test application.
223 # add_executable (test
224 # src/main.cpp
225 # )
227 # target_link_libraries (test
228 # utils
229 # )
232 ################################################################################
233 # X11
234 #
235 # Note that the FindX11.cmake package does _not_ include most X extensions
236 # in the X11_LIBRARIES variable, although it does pick up their header files
237 # in the X11_INCLUDE_DIR variable.
238 #
239 # To link a program with extensions, such as Xrandr, or Xv, you must manually
240 # update the target_link_libraries to include the appropriate library variable.
241 # ${X11_Xrandr_LIB} is an example. See the FindX11.cmake file for a complete
242 # list of availble variables.
243 #
245 option(Option_X11_Dev "Build an X11 Application." OFF)
247 if (Option_X11_Dev)
249 option(Option_Xrandr "Use Xrandr" OFF)
250 option(Option_Xinerama "Use Xinerama" OFF)
253 ########################################
254 find_package(X11)
255 if (NOT X11_FOUND)
256 message (FATAL_ERROR "X11 not found!")
257 endif ()
259 include_directories(
260 ${X11_INCLUDE_DIR}
261 ${INCLUDE_DIRECTORIES}
262 )
264 target_link_libraries(${App_Name}
265 ${X11_LIBRARIES}
266 ${TARGET_LINK_LIBRARIES}
267 )
269 ########################################
270 if (Option_Xrandr)
271 if (NOT X11_Xrandr_FOUND)
272 message (FATAL_ERRO "Xrandr not found!")
273 endif ()
274 target_link_libraries(${App_Name}
275 ${X11_Xrandr_LIB}
276 ${TARGET_LINK_LIBRARIES}
277 )
278 endif ()
280 ########################################
281 if (Option_Xinerama)
282 if (NOT X11_Xinerama_FOUND)
283 message (FATAL_ERRO "Xinerama not found!")
284 endif ()
285 target_link_libraries(${App_Name}
286 ${X11_Xinerama_LIB}
287 ${TARGET_LINK_LIBRARIES}
288 )
289 endif ()
291 endif ()
293 ################################################################################
294 # SDL
295 #
296 # Enabling SDL support enables several suboptions to make some common SDL
297 # extension libraries available as well.
298 #
299 # If any of the SDL libraries are not found automatically, you will need
300 # to set the appropriate environment variables and rerun cmake. You will
301 # need to remove the CMake cache before doing so.
303 # If you don't want to set actual environment variables before running
304 # CMake, then uncomment the if block below and put in the actual
305 # locations of your SDL installation.
307 option(Option_SDL_Dev "Build an SDL application." OFF)
309 if (Option_SDL_Dev)
311 # # Force SDL 1.3 only
312 # if (WIN32)
313 # set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-build")
314 # else ()
315 # set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build")
316 # endif ()
317 # add_definitions(-DSDL_NO_COMPAT)
319 # SDL base package
320 # To use a version of SDL other than your systems default, set the SDLDIR
321 # environment variable to the installation location of your preferred version.
322 find_package (SDL)
323 if (NOT SDL_FOUND)
324 message (FATAL_ERROR "SDL not found!")
325 endif (NOT SDL_FOUND)
326 include_directories(
327 ${SDL_INCLUDE_DIR}
328 ${INCLUDE_DIRECTORIES}
329 )
330 target_link_libraries(${App_Name}
331 ${SDL_LIBRARY}
332 ${TARGET_LINK_LIBRARIES}
333 )
335 # SDL_ttf
336 # Environment variables SDLTTFDIR and SDLDIR will be checked in that order
337 # and if set cmake will try to find SDL_ttf in the specified directory.
338 option(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF)
339 if (Option_SDL_Dev_SDL_ttf)
340 find_package (SDL_ttf)
341 if (NOT SDLTTF_FOUND)
342 message (FATAL_ERROR "SDL_ttf not found!")
343 endif (NOT SDLTTF_FOUND)
344 include_directories(
345 ${SDLTTF_INCLUDE_DIR}
346 ${INCLUDE_DIRECTORIES}
347 )
348 target_link_libraries(${App_Name}
349 ${SDLTTF_LIBRARY}
350 ${TARGET_LINK_LIBRARIES}
351 )
352 endif ()
354 # SDL_image
355 # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order
356 # and if set cmake will try to find SDL_image in the specified directory.
357 option(Option_SDL_Dev_SDL_image "Use SDL_image." OFF)
358 if (Option_SDL_Dev_SDL_image)
359 find_package (SDL_image)
360 if (NOT SDLIMAGE_FOUND)
361 message (FATAL_ERROR "SDL_image not found!")
362 endif (NOT SDLIMAGE_FOUND)
363 include_directories(
364 ${SDLIMAGE_INCLUDE_DIR}
365 ${INCLUDE_DIRECTORIES}
366 )
367 target_link_libraries(${App_Name}
368 ${SDLIMAGE_LIBRARY}
369 ${TARGET_LINK_LIBRARIES}
370 )
371 endif ()
373 # SDL_mixer
374 # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order
375 # and if set cmake will try to find SDL_mixer in the specified directory.
376 option(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF)
377 if (Option_SDL_Dev_SDL_mixer)
378 find_package (SDL_mixer)
379 if (NOT SDLMIXER_FOUND)
380 message (FATAL_ERROR "SDL_mixer not found!")
381 endif (NOT SDLMIXER_FOUND)
382 include_directories(
383 ${SDLMIXER_INCLUDE_DIR}
384 ${INCLUDE_DIRECTORIES}
385 )
386 target_link_libraries(${App_Name}
387 ${SDLMIXER_LIBRARY}
388 ${TARGET_LINK_LIBRARIES}
389 )
390 endif ()
392 # SDL_net
393 # Environment variables SDLNETDIR and SDLDIR will be checked in that order
394 # and if set cmake will try to find SDL_net in the specified directory.
395 option(Option_SDL_Dev_SDL_net "Use SDL_net." OFF)
396 if (Option_SDL_Dev_SDL_net)
397 find_package (SDL_net)
398 if (NOT SDLNET_FOUND)
399 message (FATAL_ERROR "SDL_net not found!")
400 endif (NOT SDLNET_FOUND)
401 include_directories(
402 ${SDLNET_INCLUDE_DIR}
403 ${INCLUDE_DIRECTORIES}
404 )
405 target_link_libraries(${App_Name}
406 ${SDLNET_LIBRARY}
407 ${TARGET_LINK_LIBRARIES}
408 )
409 endif ()
411 endif (Option_SDL_Dev)
414 ################################################################################
416 option(Option_OpenGL_Dev "Build an OpenGL Application." ON)
418 if (Option_OpenGL_Dev)
420 find_package(OpenGL)
421 if (NOT OPENGL_FOUND)
422 message (FATAL_ERROR "OpenGL not found!")
423 endif (NOT OPENGL_FOUND)
425 include_directories(
426 ${OPENGL_INCLUDE_DIR}
427 ${INCLUDE_DIRECTORIES}
428 )
430 target_link_libraries(${App_Name}
431 ${OPENGL_LIBRARIES}
432 ${TARGET_LINK_LIBRARIES}
433 )
435 option(Option_GLUT_Dev "Build a GLUT Application." ON)
437 if (Option_GLUT_Dev)
439 find_package(GLUT)
440 if (NOT GLUT_FOUND)
441 message (FATAL_ERROR "GLUT not found!")
442 endif()
444 include_directories(
445 ${GLUT_INCLUDE_DIR}
446 ${INCLUDE_DIRECTORIES}
447 )
449 target_link_libraries(${App_Name}
450 ${GLUT_LIBRARIES}
451 ${TARGET_LINK_LIBRARIES}
452 )
454 endif()
456 endif ()
458 ################################################################################
460 option(Option_OpenAL_Dev "Build an OpenAL Application." OFF)
462 if (Option_OpenAL_Dev)
464 find_package(OpenAL)
465 if (NOT OPENAL_FOUND)
466 message (FATAL_ERROR "OpenAL not found!")
467 endif (NOT OPENAL_FOUND)
469 include_directories(
470 ${OPENAL_INCLUDE_DIR}
471 ${INCLUDE_DIRECTORIES}
472 )
474 target_link_libraries(${App_Name}
475 ${OPENAL_LIBRARY}
476 ${TARGET_LINK_LIBRARIES}
477 )
479 endif ()
481 ################################################################################