view CMakeLists.txt @ 0:bacb3b7b582e

initial import
author Eris Caffee <discordia@eldalin.com>
date Sat, 09 Oct 2010 02:35:16 -0500
parents
children 0aaa058b0994
line source
1 ###############################################################################
2 #
3 # A generalized cmake file for developing cross-platform games.
4 #
5 # (c) 2010 Sarah Eris Horsley Caffee
7 # Instructions:
8 # This cmake file assumes that your source files are laid in out in the
9 # following manner:
10 #
11 # project_dir\ Top level directory of the project.
12 # |---include\ Header files are here.
13 # |---src\ Source files are here.
14 # |---build\ Binaries/objects go here. Run cmake from here.
15 # !---cmake\
16 # | |---modules\ Custom cmake include files, if any, go here.
17 # |---CMakeLists.txt This file.
18 #
19 # You may have more directories, of course, but these are assumed. You probably
20 # want more than one build directory. I normally have build-linux\
21 # and build-windows\ directories.
22 #
23 # Set the App_Name variable, below, to the name of your application and you
24 # are ready to start. Run cmake, ccmake, or cmake-gui from within your build
25 # directory, choose the options you need, such as enabling SDL or OGRE,
26 # and you should be good to go.
27 #
28 # You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON) command if you
29 # need to debug the actual makefile that is generated.
30 #
31 # On windows, you may need to modify some of the variables farther down in
32 # this file so that cmake knows where SDL or other support libraries
33 # and their header files can be found on the system.
34 #
35 # When writing path names on Windows, such as when manually specifiying a
36 # file or directory name, either use unix-style forward slashes '/' in the
37 # path names or use double backslashes. If you use a single backslash as the
38 # path name seperator, then cmake will interpret it as an esacpe sequence.
39 # Thus, write "C:/source" or "C:\\source" instead of "C:\source". It's
40 # probably best to use forward slashes in case to ever have a situation
41 # where cmake needs to do recursive processing: each level of cmake will
42 # strip out one of the slashes, so if there are two lev3els of cmake you
43 # need to write \\\, three levels requires \\\\, etc.
44 #
45 #
46 # Note that some of the cmake support scripts that find libraries for you
47 # can be controlled by environment variables. For example, you can set the
48 # SDLDIR environment variable before running cmake in order to point to
49 # a different version of SDL than your systems default copy. This is useful
50 # for trying out cutting edge versions of libraries without installing them
51 # system wide.
54 CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
57 SET (App_Name "check-sdl-version")
58 IF (App_Name STREQUAL "")
59 MESSAGE (FATAL_ERROR "You must set the App_Name variable!")
60 ENDIF ()
63 #SET (CMAKE_VERBOSE_MAKEFILE ON)
66 PROJECT (${App_Name})
69 ################################################################################
70 # Ensure that we are not building in our source directories.
72 SET (Build_Dir_OK "TRUE")
73 STRING (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR})
74 IF (In_Sub_Dir)
75 STRING (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR})
76 IF (NOT In_Build_Dir)
77 SET (Build_Dir_OK "FALSE")
78 ENDIF ()
79 ENDIF ()
81 IF (NOT Build_Dir_OK)
82 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'.")
83 ENDIF ()
86 ###############################################################################
87 # If you have your own custom cmake modules that you want to include, put them
88 # in the the cmake/modules subdirectory of your project.
90 SET (CMAKE_MODULE_PATH ${${App_Name}_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
93 ################################################################################
94 # Set up the basic build environment
96 IF (CMAKE_BUILD_TYPE STREQUAL "")
97 # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
98 # differentiation between debug and release builds.
99 SET (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
100 ENDIF ()
103 ################################################################################
104 # The core project files
106 FILE (GLOB SRCS src/*.c src/*.cpp)
107 FILE (GLOB HDRS include/*.h include/*.hpp)
109 LINK_DIRECTORIES (
110 )
112 INCLUDE_DIRECTORIES (
113 ${PROJECT_SOURCE_DIR}/include
114 )
116 ADD_EXECUTABLE (${App_Name}
117 ${SRCS}
118 ${HDRS}
119 )
121 TARGET_LINK_LIBRARIES (${App_Name}
122 )
125 # # An example for a unix library named utils with a test driver program.
127 # set (SRCS_utils
128 # src/utils.cpp
129 # include/utils.h
130 # )
132 # INCLUDE_DIRECTORIES (
133 # ${PROJECT_SOURCE_DIR}/include
134 # )
136 # # Build both static and shared libraries
137 # # The target properties are needed because, by default, the output name
138 # # will be the name in the add_library command, and we need to have different
139 # # names in the two commands for the shared and static versions, even though
140 # # we want the final files to have the same names with different extensions.
141 # #
142 # # The prefix is needed mostly in case we build on windows, which has no prefix
143 # # by default.
144 # #
145 # # The clean_direct_output option makes sure that the two lib builds don't
146 # # clobber each others temp files since they are being built from the same
147 # # sources.
149 # ADD_LIBRARY (utils SHARED
150 # ${SRCS_utils}
151 # )
152 # SET_TARGET_PROPERTIES (utils PROPERTIES OUTPUT_NAME "utils")
153 # SET_TARGET_PROPERTIES (utils PROPERTIES PREFIX "lib")
154 # SET_TARGET_PROPERTIES (utils PROPERTIES CLEAN_DIRECT_OUTPUT 1)
156 # ADD_LIBRARY (utils-static STATIC
157 # ${SRCS_utils}
158 # )
159 # SET_TARGET_PROPERTIES (utils-static PROPERTIES OUTPUT_NAME "utils")
160 # SET_TARGET_PROPERTIES (utils-static PROPERTIES PREFIX "lib")
161 # SET_TARGET_PROPERTIES (utils-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
165 # # Build a test application.
167 # ADD_EXECUTABLE (test
168 # src/main.cpp
169 # )
171 # TARGET_LINK_LIBRARIES (test
172 # utils
173 # )
176 ################################################################################
177 # SDL Support
178 #
179 # Enabling SDL support enables several suboptions to make some common SDL
180 # extension libraries available as well. On Windows, you will need to
181 # specify the path of the directory where you have installed the headers and
182 # libraries. See below.
184 OPTION (Option_SDL_Dev "Build an SDL application." OFF)
186 IF (Option_SDL_Dev)
188 IF (WIN32)
190 # Windows has no standard locations for include files and libraries,
191 # so you need to specify them by hand. Each of the SDLDIR environment
192 # variables below is used by the corresponding FIND_PACAKGE script
193 # to locate the needed include files and libraries. Set each variable
194 # to the directory containing the files.
196 # Some of the sdl packages do not provide built in support for MinGW
197 # compilation, and you will need to install the files appropriately by hand.
198 # Each one needs 3 subdirectories under its top level: bin, include, and lib.
199 # The bin directory is where you put the dll files, the include directory
200 # holds the header files, and the lib directory holds the libSDL*.a files
201 # needed by the mingw linker. Note that the dll's are not actually needed
202 # for compilation, while the libs are, yet are run time the dlls are needed.
203 # You will need to manually copy the dll's into an appropriate location, such
204 # as the installation directory of your program.
206 SET (ENV{SDLDIR} "C:/deps/SDL-1.2.14")
207 SET (ENV{SDLTTFDIR} "C:/deps/SDL_ttf-2.0.10")
208 SET (ENV{SDLIMAGEDIR} "C:/deps/SDL_image-1.2.10")
209 SET (ENV{SDLMIXERDIR} "C:/deps/SDL_mixer-1.2.11")
210 SET (ENV{SDLNETDIR} "C:/deps/SDL_net-1.2.7")
211 ENDIF (WIN32)
213 # SDL base package
214 # To use a version of SDL other than your systems default, set the SDLDIR
215 # environment variable to the installation location of your preferred version.
216 FIND_PACKAGE (SDL)
217 IF (NOT SDL_FOUND)
218 MESSAGE (FATAL_ERROR "SDL not found!")
219 ENDIF (NOT SDL_FOUND)
220 INCLUDE_DIRECTORIES(
221 ${SDL_INCLUDE_DIR}
222 ${INCLUDE_DIRECTORIES}
223 )
224 TARGET_LINK_LIBRARIES(${App_Name}
225 ${SDL_LIBRARY}
226 ${TARGET_LINK_LIBRARIES}
227 )
229 # SDL_ttf
230 # Environment variables SDLTTFDIR and SDLDIR will be checked in that order
231 # and if set cmake will try to find SDL_ttf in the specified directory.
232 OPTION(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF)
233 IF (Option_SDL_Dev_SDL_ttf)
234 FIND_PACKAGE (SDL_ttf)
235 IF (NOT SDLTTF_FOUND)
236 MESSAGE (FATAL_ERROR "SDL_ttf not found!")
237 ENDIF (NOT SDLTTF_FOUND)
238 INCLUDE_DIRECTORIES(
239 ${SDLTTF_INCLUDE_DIR}
240 ${INCLUDE_DIRECTORIES}
241 )
242 TARGET_LINK_LIBRARIES(${App_Name}
243 ${SDLTTF_LIBRARY}
244 ${TARGET_LINK_LIBRARIES}
245 )
246 ENDIF (Option_SDL_Dev_SDL_ttf)
248 # SDL_image
249 # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order
250 # and if set cmake will try to find SDL_image in the specified directory.
251 OPTION(Option_SDL_Dev_SDL_image "Use SDL_image." OFF)
252 IF (Option_SDL_Dev_SDL_image)
253 FIND_PACKAGE (SDL_image)
254 IF (NOT SDLIMAGE_FOUND)
255 MESSAGE (FATAL_ERROR "SDL_image not found!")
256 ENDIF (NOT SDLIMAGE_FOUND)
257 INCLUDE_DIRECTORIES(
258 ${SDLIMAGE_INCLUDE_DIR}
259 ${INCLUDE_DIRECTORIES}
260 )
261 TARGET_LINK_LIBRARIES(${App_Name}
262 ${SDLIMAGE_LIBRARY}
263 ${TARGET_LINK_LIBRARIES}
264 )
265 ENDIF (Option_SDL_Dev_SDL_image)
267 # SDL_mixer
268 # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order
269 # and if set cmake will try to find SDL_mixer in the specified directory.
270 OPTION(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF)
271 IF (Option_SDL_Dev_SDL_mixer)
272 FIND_PACKAGE (SDL_mixer)
273 IF (NOT SDLMIXER_FOUND)
274 MESSAGE (FATAL_ERROR "SDL_mixer not found!")
275 ENDIF (NOT SDLMIXER_FOUND)
276 INCLUDE_DIRECTORIES(
277 ${SDLMIXER_INCLUDE_DIR}
278 ${INCLUDE_DIRECTORIES}
279 )
280 TARGET_LINK_LIBRARIES(${App_Name}
281 ${SDLMIXER_LIBRARY}
282 ${TARGET_LINK_LIBRARIES}
283 )
284 ENDIF (Option_SDL_Dev_SDL_mixer)
286 # SDL_net
287 # Environment variables SDLNETDIR and SDLDIR will be checked in that order
288 # and if set cmake will try to find SDL_net in the specified directory.
289 OPTION(Option_SDL_Dev_SDL_net "Use SDL_net." OFF)
290 IF (Option_SDL_Dev_SDL_net)
291 FIND_PACKAGE (SDL_net)
292 IF (NOT SDLNET_FOUND)
293 MESSAGE (FATAL_ERROR "SDL_net not found!")
294 ENDIF (NOT SDLNET_FOUND)
295 INCLUDE_DIRECTORIES(
296 ${SDLNET_INCLUDE_DIR}
297 ${INCLUDE_DIRECTORIES}
298 )
299 TARGET_LINK_LIBRARIES(${App_Name}
300 ${SDLNET_LIBRARY}
301 ${TARGET_LINK_LIBRARIES}
302 )
303 ENDIF (Option_SDL_Dev_SDL_net)
305 ENDIF (Option_SDL_Dev)
308 ################################################################################
310 OPTION(Option_OGRE_Dev "Build with OGRE/OIS application." OFF)
312 IF (Option_OGRE_Dev)
313 set(CMAKE_MODULE_PATH
314 /usr/local/lib/OGRE/cmake
315 ${CMAKE_MODULE_PATH}
316 )
318 FIND_PACKAGE(OGRE)
319 FIND_PACKAGE(OIS)
320 INCLUDE_DIRECTORIES(
321 ${INCLUDE_DIRECTORIES}
322 ${OGRE_INCLUDE_DIRS}
323 ${OGRE_CEGUIRenderer_INCLUDE_DIRS}
324 ${OIS_INCLUDE_DIRS}
325 )
327 TARGET_LINK_LIBRARIES(${App_Name}
328 ${TARGET_LINK_LIBRARIES}
329 ${OGRE_LIBRARIES}
330 ${OIS_LIBRARIES}
331 ${TARGET_LINK_LIBRARIES}
332 )
333 ENDIF (Option_OGRE_Dev)
336 ################################################################################
337 # ${OGRE_CEGUIRenderer_LIBRARIES}
341 ################################################################################
343 OPTION(Option_OpenAL_Dev "Build an OpenAL Application." OFF)
345 IF (Option_OpenAL_Dev)
346 FIND_PACKAGE(OpenAL)
348 INCLUDE_DIRECTORIES(
349 ${OpenAL_INCLUDE_DIR}
350 ${INCLUDE_DIRECTORIES}
351 )
353 TARGET_LINK_LIBRARIES(${App_Name}
354 ${OpenAL_LIBRARIES}
355 ${TARGET_LINK_LIBRARIES}
356 )
358 ENDIF (Option_OpenAL_Dev)
362 ################################################################################
364 OPTION(Option_OpenGL_Dev "Build an OpenGL Application." OFF)
366 IF (Option_OpenGL_Dev)
368 FIND_PACKAGE(OpenGL)
370 INCLUDE_DIRECTORIES(
371 ${OpenGL_INCLUDE_DIR}
372 ${INCLUDE_DIRECTORIES}
373 )
375 TARGET_LINK_LIBRARIES(${App_Name}
376 ${OpenGL_LIBRARIES}
377 ${TARGET_LINK_LIBRARIES}
378 )
380 ENDIF (Option_OpenGL_Dev)
382 ################################################################################