view CMakeLists.txt @ 1:0aaa058b0994

Version with sdl and sdl_ttf functions.
author Eris Caffee <discordia@eldalin.com>
date Thu, 14 Oct 2010 00:42:55 -0500
parents bacb3b7b582e
children d3d9c758a0ee
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.
55 # Probably not needed, but it may save someone else a headache someday.
56 CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
60 # Name your program!
61 SET (App_Name "check-sdl-version")
62 IF (App_Name STREQUAL "")
63 MESSAGE (FATAL_ERROR "You must set the App_Name variable!")
64 ENDIF ()
67 #SET (CMAKE_VERBOSE_MAKEFILE ON)
70 # Every project must have a name.
71 PROJECT (${App_Name})
74 ################################################################################
75 # Ensure that we are not building in our source directories.
77 SET (Build_Dir_OK "TRUE")
78 STRING (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR})
79 IF (In_Sub_Dir)
80 STRING (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR})
81 IF (NOT In_Build_Dir)
82 SET (Build_Dir_OK "FALSE")
83 ENDIF ()
84 ENDIF ()
86 IF (NOT Build_Dir_OK)
87 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'.")
88 ENDIF ()
91 ################################################################################
92 # Set up the basic build environment
93 # A build type defines which options are passed to the compiler, and there are
94 # several that CMake defines by default. It does not set one by default, though
95 # so we need to set the build type manually here, and we are setting it to the
96 # generally useful "Release with debug info"
98 IF (CMAKE_BUILD_TYPE STREQUAL "")
99 # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This messes up
100 # differentiation between debug and release builds.
101 SET (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
102 ENDIF ()
105 ################################################################################
106 # The core project files
108 FILE (GLOB SRCS src/*.c src/*.cpp)
109 FILE (GLOB HDRS include/*.h include/*.hpp)
111 # The directories that contain the libraries we will be linking against.
112 # This must come before the ADD_EXECUTABLE directive.
113 LINK_DIRECTORIES (
114 )
116 # The directories that contain the include files our programs use.
117 # This must come before the ADD_EXECUTABLE directive.
118 INCLUDE_DIRECTORIES (
119 ${PROJECT_SOURCE_DIR}/include
120 )
122 # Define the executable program file we are creating. We must list all of
123 # the source files.
124 ADD_EXECUTABLE (${App_Name}
125 ${SRCS}
126 ${HDRS}
127 )
129 # Although we listed the library directories above, we also need to list the
130 # individual libraries we will be linking against.
131 TARGET_LINK_LIBRARIES (${App_Name}
132 )
135 ################################################################################
136 # SDL Support
137 #
138 # Enabling SDL support enables several suboptions to make some common SDL
139 # extension libraries available as well.
140 #
141 # If any of the SDL libraries are not found automatically, you will need
142 # to set the appropriate environment variables and rerun cmake. You will
143 # need to remove the CMake cache before doing so.
145 OPTION (Option_SDL_Dev "Build an SDL application." OFF)
147 IF (Option_SDL_Dev)
149 # SDL base package
150 # To use a version of SDL other than your systems default, set the SDLDIR
151 # environment variable to the installation location of your preferred version.
152 FIND_PACKAGE (SDL)
153 IF (NOT SDL_FOUND)
154 MESSAGE (FATAL_ERROR "SDL not found!")
155 ENDIF (NOT SDL_FOUND)
156 INCLUDE_DIRECTORIES(
157 ${SDL_INCLUDE_DIR}
158 ${INCLUDE_DIRECTORIES}
159 )
160 TARGET_LINK_LIBRARIES(${App_Name}
161 ${SDL_LIBRARY}
162 ${TARGET_LINK_LIBRARIES}
163 )
165 # SDL_ttf
166 # Environment variables SDLTTFDIR and SDLDIR will be checked in that order
167 # and if set cmake will try to find SDL_ttf in the specified directory.
168 OPTION(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF)
169 IF (Option_SDL_Dev_SDL_ttf)
170 FIND_PACKAGE (SDL_ttf)
171 IF (NOT SDLTTF_FOUND)
172 MESSAGE (FATAL_ERROR "SDL_ttf not found!")
173 ENDIF (NOT SDLTTF_FOUND)
174 INCLUDE_DIRECTORIES(
175 ${SDLTTF_INCLUDE_DIR}
176 ${INCLUDE_DIRECTORIES}
177 )
178 TARGET_LINK_LIBRARIES(${App_Name}
179 ${SDLTTF_LIBRARY}
180 ${TARGET_LINK_LIBRARIES}
181 )
182 ENDIF (Option_SDL_Dev_SDL_ttf)
184 # SDL_image
185 # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order
186 # and if set cmake will try to find SDL_image in the specified directory.
187 OPTION(Option_SDL_Dev_SDL_image "Use SDL_image." OFF)
188 IF (Option_SDL_Dev_SDL_image)
189 FIND_PACKAGE (SDL_image)
190 IF (NOT SDLIMAGE_FOUND)
191 MESSAGE (FATAL_ERROR "SDL_image not found!")
192 ENDIF (NOT SDLIMAGE_FOUND)
193 INCLUDE_DIRECTORIES(
194 ${SDLIMAGE_INCLUDE_DIR}
195 ${INCLUDE_DIRECTORIES}
196 )
197 TARGET_LINK_LIBRARIES(${App_Name}
198 ${SDLIMAGE_LIBRARY}
199 ${TARGET_LINK_LIBRARIES}
200 )
201 ENDIF (Option_SDL_Dev_SDL_image)
203 # SDL_mixer
204 # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order
205 # and if set cmake will try to find SDL_mixer in the specified directory.
206 OPTION(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF)
207 IF (Option_SDL_Dev_SDL_mixer)
208 FIND_PACKAGE (SDL_mixer)
209 IF (NOT SDLMIXER_FOUND)
210 MESSAGE (FATAL_ERROR "SDL_mixer not found!")
211 ENDIF (NOT SDLMIXER_FOUND)
212 INCLUDE_DIRECTORIES(
213 ${SDLMIXER_INCLUDE_DIR}
214 ${INCLUDE_DIRECTORIES}
215 )
216 TARGET_LINK_LIBRARIES(${App_Name}
217 ${SDLMIXER_LIBRARY}
218 ${TARGET_LINK_LIBRARIES}
219 )
220 ENDIF (Option_SDL_Dev_SDL_mixer)
222 # SDL_net
223 # Environment variables SDLNETDIR and SDLDIR will be checked in that order
224 # and if set cmake will try to find SDL_net in the specified directory.
225 OPTION(Option_SDL_Dev_SDL_net "Use SDL_net." OFF)
226 IF (Option_SDL_Dev_SDL_net)
227 FIND_PACKAGE (SDL_net)
228 IF (NOT SDLNET_FOUND)
229 MESSAGE (FATAL_ERROR "SDL_net not found!")
230 ENDIF (NOT SDLNET_FOUND)
231 INCLUDE_DIRECTORIES(
232 ${SDLNET_INCLUDE_DIR}
233 ${INCLUDE_DIRECTORIES}
234 )
235 TARGET_LINK_LIBRARIES(${App_Name}
236 ${SDLNET_LIBRARY}
237 ${TARGET_LINK_LIBRARIES}
238 )
239 ENDIF (Option_SDL_Dev_SDL_net)
241 ENDIF (Option_SDL_Dev)
244 ################################################################################