view CMakeLists.txt @ 3:d3d9c758a0ee

Published version
author Eris Caffee <discordia@eldalin.com>
date Thu, 21 Oct 2010 21:38:11 -0500
parents 0aaa058b0994
children
line source
1 ###############################################################################
2 #
3 # A generalized cmake file for developing cross-platform games.
4 #
5 # Copyright (c) 2010 Eris Caffee
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 # THE SOFTWARE.
21 #
22 # Instructions:
23 # This cmake file assumes that your source files are laid in out in the
24 # following manner:
25 #
26 # project_dir\ Top level directory of the project.
27 # |---include\ Header files are here.
28 # |---src\ Source files are here.
29 # |---build\ Binaries/objects go here. Run cmake from here.
30 # !---cmake\
31 # | |---modules\ Custom cmake include files, if any, go here.
32 # |---CMakeLists.txt This file.
33 #
34 # You may have more directories, of course, but these are assumed. You probably
35 # want more than one build directory. I normally have build-linux\
36 # and build-windows\ directories.
37 #
38 # Set the App_Name variable, below, to the name of your application and you
39 # are ready to start. Run ccmake, or cmake-gui from within your build
40 # directory, choose the options you need, such as enabling SDL, and you
41 # should be good to go.
42 #
43 # You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON)" command if you
44 # need to debug the actual makefile that is generated.
45 #
46 # On windows, you may need to set the SDLDIR environment variable to the location
47 # of your SDL installation before you run cmake-gui.
48 #
49 # When writing path names on Windows, such as when manually specifiying a
50 # file or directory name, either use unix-style forward slashes '/' in the
51 # path names or use double backslashes. If you use a single backslash as the
52 # path name seperator, then cmake will interpret it as an esacpe sequence.
53 # Thus, write "C:/source" or "C:\\source" instead of "C:\source". It's
54 # probably best to use forward slashes in case to ever have a situation
55 # where cmake needs to do recursive processing: each level of cmake will
56 # strip out one of the slashes, so if there are two lev3els of cmake you
57 # need to write \\\, three levels requires \\\\, etc.
58 #
59 # Note that some of the cmake support scripts that find libraries for you
60 # can be controlled by environment variables. For example, you can set the
61 # SDLDIR environment variable before running cmake in order to point to
62 # a different version of SDL than your systems default copy. This is useful
63 # for trying out cutting edge versions of libraries without installing them
64 # system wide.
66 cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
67 #set (CMAKE_VERBOSE_MAKEFILE ON)
69 # Name your program!
70 set (App_Name "check-sdl-version")
71 if (App_Name STREQUAL "")
72 message (FATAL_ERROR "You must set the App_Name variable!")
73 endif ()
75 # Every project must have a name.
76 project (${App_Name})
79 ################################################################################
80 # Ensure that we are not building in our source directories.
82 set (Build_Dir_OK "TRUE")
83 string (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR})
84 if (In_Sub_Dir)
85 string (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR})
86 if (NOT In_Build_Dir)
87 set (Build_Dir_OK "FALSE")
88 endif ()
89 endif ()
91 if (NOT Build_Dir_OK)
92 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'.")
93 endif ()
96 ################################################################################
97 # Set up the basic build environment
98 # A build type defines which options are passed to the compiler, and there are
99 # several that CMake defines by default. It does not set one by default, though
100 # so we need to set the build type manually here, and we are setting it to the
101 # generally useful "Release with debug info"
103 if (CMAKE_BUILD_TYPE STREQUAL "")
104 # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This messes up
105 # differentiation between debug and release builds.
106 set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
107 endif ()
110 ################################################################################
111 # The core project files
113 file (GLOB SRCS src/*.c src/*.cpp)
114 file (GLOB HDRS include/*.h include/*.hpp)
116 # The directories that contain the libraries we will be linking against.
117 # This must come before the ADD_EXECUTABLE directive.
118 link_directories (
119 )
121 # The directories that contain the include files our programs use.
122 # This must come before the ADD_EXECUTABLE directive.
123 include_directories (
124 ${CMAKE_SOURCE_DIR}/include
125 )
127 # Define the executable program file we are creating. We must list all of
128 # the source files. If we are copmiling on Windows, we set the executable
129 # to have the WIN32 attribute, which makes it a Windows GUI program. Without
130 # this attribute it would be compiled into a console application.
131 if (WIN32)
132 add_executable (${App_Name} WIN32
133 ${SRCS}
134 ${HDRS}
135 )
136 else ()
137 add_executable (${App_Name}
138 ${SRCS}
139 ${HDRS}
140 )
141 endif ()
143 # Although we listed the library directories above, we also need to list the
144 # individual libraries we will be linking against.
145 target_link_libraries (${App_Name}
146 )
149 ################################################################################
150 # SDL Support
151 #
152 # Enabling SDL support enables several suboptions to make some common SDL
153 # extension libraries available as well.
154 #
155 # If any of the SDL libraries are not found automatically, you will need
156 # to set the appropriate environment variables and rerun cmake. You will
157 # need to remove the CMake cache before doing so.
159 # If you don't want to set actual environment variables before running
160 # CMake, then uncomment the if block below and put in the actual
161 # locations of your SDL installation.
163 # if (WIN32)
164 # set (ENV{SDLDIR} "c:\gamedev\deps\sdl\SDL-build")
165 # else ()
166 # set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build")
167 # endif ()
169 option(Option_SDL_Dev "Build an SDL application." OFF)
171 if (Option_SDL_Dev)
173 # SDL base package
174 # To use a version of SDL other than your systems default, set the SDLDIR
175 # environment variable to the installation location of your preferred version.
176 find_package (SDL)
177 if (NOT SDL_FOUND)
178 message (FATAL_ERROR "SDL not found!")
179 endif (NOT SDL_FOUND)
180 include_directories(
181 ${SDL_INCLUDE_DIR}
182 ${INCLUDE_DIRECTORIES}
183 )
184 target_link_libraries(${App_Name}
185 ${SDL_LIBRARY}
186 ${TARGET_LINK_LIBRARIES}
187 )
189 endif (Option_SDL_Dev)
192 ################################################################################