view CMakeLists.txt @ 19:4634ca3fc308

Renamed src to test Began refactoring test program to use Google Test framework
author Eris Caffee <discordia@eldalin.com>
date Mon, 15 Sep 2014 01:02:04 -0500
parents f9fb659509e1
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 # |---test\ Test 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 "Math")
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 # You may specify an application description, too. This will be passed to
80 # Doxygen, if you use that.
81 set (App_Description "3D math library for games.")
84 ################################################################################
85 # Special options
88 ################################################################################
89 # Ensure that we are not building in our source directories.
91 set (Build_Dir_OK "TRUE")
92 string (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR})
93 if (In_Sub_Dir)
94 string (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR})
95 if (NOT In_Build_Dir)
96 set (Build_Dir_OK "FALSE")
97 endif ()
98 endif ()
100 if (NOT Build_Dir_OK)
101 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'.")
102 endif ()
105 ################################################################################
106 # Set up the basic build environment
107 # A build type defines which options are passed to the compiler, and there are
108 # several that CMake defines by default. It does not set one by default, though
109 # so we need to set the build type manually here, and we are setting it to the
110 # generally useful "Release with debug info"
112 if (CMAKE_BUILD_TYPE STREQUAL "")
113 # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This messes up
114 # differentiation between debug and release builds.
115 set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
116 endif ()
119 ################################################################################
120 # When using GCC turn on lots of warnings.
121 # Some other options to consider:
122 # C++ -Weffc++
123 # C -std=gnu99 -std=c99
125 if (CMAKE_COMPILER_IS_GNUCXX)
126 add_definitions( -std=gnu++11 )
127 # add_definitions(-pedantic -Wall)
128 endif ()
130 ################################################################################
131 # Other miscellaneous compiler options
133 #if (CMAKE_COMPILER_IS_GNUCXX)
134 # # Allow anonymous structs
135 # add_definitions(-fms-extensions)
136 #endif ()
138 ################################################################################
139 # Build for profiling.
141 option(Option_Profile_Program "Build for gprof profiling." OFF)
142 if (Option_Profile_Program)
143 add_definitions(-pg)
144 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
145 endif ()
148 ################################################################################
149 # The core project files
152 # Not GLOBing here so that I can explicitly list main.cpp later as part of the
153 # test driver. Also, it just seems good practice to explicitly list things since
154 # it avoids accidental inclusion of things that ought not to be included.
155 set (SRCS_${App_Name}
156 include/Math.h
157 include/Vector.h
158 include/Matrix.h
159 )
161 include_directories (
162 ${PROJECT_SOURCE_DIR}/include
163 )
165 # Build both static and shared libraries
166 # The target properties are needed because, by default, the output name
167 # will be the name in the add_library command, and we need to have different
168 # names in the two commands for the shared and static versions, even though
169 # we want the final files to have the same names with different extensions.
170 #
171 # The prefix is needed mostly in case we build on windows, which has no prefix
172 # by default.
173 #
174 # The clean_direct_output option makes sure that the two lib builds don't
175 # clobber each others temp files since they are being built from the same
176 # sources.
178 #add_library (${App_Name} SHARED
179 # ${SRCS_${App_Name}}
180 #)
181 #set_target_properties (${App_Name} PROPERTIES OUTPUT_NAME ${App_Name})
182 #set_target_properties (${App_Name} PROPERTIES PREFIX "lib")
183 #set_target_properties (${App_Name} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
184 #
185 #add_library (${App_Name}-static STATIC
186 # ${SRCS_${App_Name}}
187 #)
188 #set_target_properties (${App_Name}-static PROPERTIES OUTPUT_NAME ${App_Name})
189 #set_target_properties (${App_Name}-static PROPERTIES PREFIX "lib")
190 #set_target_properties (${App_Name}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
192 # Build a test application.
193 set (GTEST_INCLUDE_DIR "/home/eris/gamedev/deps/gtest/current/include")
194 set (GTEST_LIB_DIR "/home/eris/gamedev/deps/gtest/current/build")
196 link_directories (
197 ${GTEST_LIB_DIR}
198 )
200 include_directories (
201 ${CMAKE_SOURCE_DIR}/include
202 ${GTEST_INCLUDE_DIR}
203 )
205 add_executable (${App_Name}-test
206 test/main.cpp
207 )
209 target_link_libraries (${App_Name}-test
210 libgtest.a
211 pthread
212 )
214 ################################################################################
215 # Doxygen documentation
216 #
217 # - Create a directory named docs to hold your Doxygen config and standalone
218 # (.dox) files.
219 # - Name your Doxyfile config as "docs/Doxyfile.in".
220 # - In that file, set the following variables as shown, adjusting INPUT as
221 # needed to reflect the actual location of the fiels you wnat processed.
222 #
223 # PROJECT_NAME = "@App_Name@"
224 # PROJECT_BRIEF = "@App_Description@"
225 # STRIP_FROM_PATH = @CMAKE_CURRENT_SOURCE_DIR@
226 # INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/ @CMAKE_CURRENT_SOURCE_DIR@/include/ @CMAKE_CURRENT_SOURCE_DIR@/docs/
227 #
228 # Then you can generate the docs with "make docs" and this will create a "docs" directory under your build directory.
229 #
231 option(Option_Doxygen "Generate Doxygen documentation." ON)
233 if (Option_Doxygen)
235 find_package(Doxygen)
236 if (NOT DOXYGEN_FOUND)
237 message (FATAL_ERROR "Doxygen not found!")
238 endif ()
240 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile @ONLY)
242 add_custom_target(docs
243 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile
244 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
245 COMMENT "Generating API documentation with Doxygen" VERBATIM
246 )
248 endif ()
250 ################################################################################
251 # Google Test C++ Unit testing framework
253 option (Option_GTEST "Google Test" ON)
255 if (Option_GTEST)
256 set (GTEST_INCLUDE_DIR "/home/eris/gamedev/deps/gtest/current/include")
257 set (GTEST_LIB_DIR "/home/eris/gamedev/deps/gtest/current/build")
258 endif ()