view CMakeLists.txt @ 9:81d2aa42a860

Matrix22 working, but a few methods not yet written. I started thinking about refactoring again t omake things even cleaner in design, with less repetition.
author Eris Caffee <discordia@eldalin.com>
date Fri, 07 Oct 2011 11:08:38 -0500
parents 378862555189
children f9fb659509e1
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 "Math")
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++
117 # C -std=gnu99 -std=c99
119 if (CMAKE_COMPILER_IS_GNUCXX)
120 add_definitions(-pedantic -Wall)
121 endif ()
123 ################################################################################
124 # Other miscellaneous compiler options
126 #if (CMAKE_COMPILER_IS_GNUCXX)
127 # # Allow anonymous structs
128 # add_definitions(-fms-extensions)
129 #endif ()
131 ################################################################################
132 # Build for profiling.
134 option(Option_Profile_Program "Build for gprof profiling." OFF)
135 if (Option_Profile_Program)
136 add_definitions(-pg)
137 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
138 endif ()
141 ################################################################################
142 # The core project files
145 # Not GLOBing here so that I can explicitly list main.cpp later as part of the
146 # test driver. Also, it just seems good practice to explicitly list things since
147 # it avoids accidental inclusion of things that ought not to be included.
148 set (SRCS_${App_Name}
149 include/Math.h
150 include/Vector.h
151 include/Matrix.h
152 )
154 include_directories (
155 ${PROJECT_SOURCE_DIR}/include
156 )
158 # Build both static and shared libraries
159 # The target properties are needed because, by default, the output name
160 # will be the name in the add_library command, and we need to have different
161 # names in the two commands for the shared and static versions, even though
162 # we want the final files to have the same names with different extensions.
163 #
164 # The prefix is needed mostly in case we build on windows, which has no prefix
165 # by default.
166 #
167 # The clean_direct_output option makes sure that the two lib builds don't
168 # clobber each others temp files since they are being built from the same
169 # sources.
171 #add_library (${App_Name} SHARED
172 # ${SRCS_${App_Name}}
173 #)
174 #set_target_properties (${App_Name} PROPERTIES OUTPUT_NAME ${App_Name})
175 #set_target_properties (${App_Name} PROPERTIES PREFIX "lib")
176 #set_target_properties (${App_Name} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
177 #
178 #add_library (${App_Name}-static STATIC
179 # ${SRCS_${App_Name}}
180 #)
181 #set_target_properties (${App_Name}-static PROPERTIES OUTPUT_NAME ${App_Name})
182 #set_target_properties (${App_Name}-static PROPERTIES PREFIX "lib")
183 #set_target_properties (${App_Name}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
185 # Build a test application.
187 link_directories (
188 )
190 include_directories (
191 ${CMAKE_SOURCE_DIR}/include
192 )
194 add_executable (${App_Name}-test
195 src/main.cpp
196 )
198 target_link_libraries (${App_Name}-test
199 # ${App_Name}
200 )