view CMakeLists.txt @ 7:be3fa4df4b0b

Updated to include default Doxyfile.in file and have the project name and description automatically added by cmake.
author Eris Caffee <discordia@eldalin.com>
date Sun, 26 May 2013 16:36:48 -0500
parents ca3af0595d77
children 65c716ba7cda
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 "MYAPPNAME")
70 if (App_Name STREQUAL "MYAPPNAME")
71 message (FATAL_ERROR "You must set the App_Name variable!")
72 endif ()
74 # Every project must have a name.
75 project (${App_Name})
77 # You may specify an application description, too. This will be passed to
78 # Doxygen, if you use that.
79 set (App_Description "")
81 ################################################################################
82 # Special options
85 ################################################################################
86 # Ensure that we are not building in our source directories.
88 set (Build_Dir_OK "TRUE")
89 string (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR})
90 if (In_Sub_Dir)
91 string (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR})
92 if (NOT In_Build_Dir)
93 set (Build_Dir_OK "FALSE")
94 endif ()
95 endif ()
97 if (NOT Build_Dir_OK)
98 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'.")
99 endif ()
102 ################################################################################
103 # Set up the basic build environment
104 # A build type defines which options are passed to the compiler, and there are
105 # several that CMake defines by default. It does not set one by default, though
106 # so we need to set the build type manually here, and we are setting it to the
107 # generally useful "Release with debug info"
109 if (CMAKE_BUILD_TYPE STREQUAL "")
110 # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This messes up
111 # differentiation between debug and release builds.
112 set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
113 endif ()
116 ################################################################################
117 # When using GCC turn on lots of warnings.
118 # Some other options to consider:
119 # C++ -Weffc++
120 # C -std=gnu99 -std=c99
122 if (CMAKE_COMPILER_IS_GNUCXX)
123 add_definitions(-pedantic -Wall)
124 endif ()
127 ################################################################################
129 option(Option_Profile_Program "Build for gprof profiling." OFF)
130 if (Option_Profile_Program)
131 add_definitions(-pg)
132 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
133 endif ()
136 ################################################################################
137 # The core project files
139 file (GLOB SRCS src/*.c src/*.cpp)
140 file (GLOB HDRS include/*.h include/*.hpp)
142 # The directories that contain the libraries we will be linking against.
143 # This must come before the ADD_EXECUTABLE directive.
144 link_directories (
145 )
147 # The directories that contain the include files our programs use.
148 # This must come before the ADD_EXECUTABLE directive.
149 include_directories (
150 ${CMAKE_SOURCE_DIR}/include
151 )
153 # Define the executable program file we are creating. We must list all of
154 # the source files.
155 if (WIN32)
156 add_executable (${App_Name} WIN32
157 ${SRCS}
158 ${HDRS}
159 )
160 else ()
161 add_executable (${App_Name}
162 ${SRCS}
163 ${HDRS}
164 )
165 endif ()
167 # Although we listed the library directories above, we also need to list the
168 # individual libraries we will be linking against.
169 target_link_libraries (${App_Name}
170 )
173 # Example to build a linux library with a test driver.
175 # set (SRCS_${App_Name}
176 # src/.cpp
177 # include/.h
178 # )
180 # include_directories (
181 # ${PROJECT_SOURCE_DIR}/include
182 # )
184 # # Build both static and shared libraries
185 # # The target properties are needed because, by default, the output name
186 # # will be the name in the add_library command, and we need to have different
187 # # names in the two commands for the shared and static versions, even though
188 # # we want the final files to have the same names with different extensions.
189 # #
190 # # The prefix is needed mostly in case we build on windows, which has no prefix
191 # # by default.
192 # #
193 # # The clean_direct_output option makes sure that the two lib builds don't
194 # # clobber each others temp files since they are being built from the same
195 # # sources.
197 # add_library (${App_Name} SHARED
198 # ${SRCS_${App_Name}}
199 # )
200 # set_target_properties (${App_Name} PROPERTIES OUTPUT_NAME ${App_Name})
201 # set_target_properties (${App_Name} PROPERTIES PREFIX "lib")
202 # set_target_properties (${App_Name} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
204 # add_library (${App_Name}-static STATIC
205 # ${SRCS_${App_Name}}
206 # )
207 # set_target_properties (${App_Name}-static PROPERTIES OUTPUT_NAME ${App_Name})
208 # set_target_properties (${App_Name}-static PROPERTIES PREFIX "lib")
209 # set_target_properties (${App_Name}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
211 # # Build a test application.
213 # link_directories (
214 # )
216 # include_directories (
217 # ${CMAKE_SOURCE_DIR}/include
218 # )
220 # add_executable (${App_Name}-test
221 # src/main.cpp
222 # )
224 # target_link_libraries (${App_Name}-test
225 # ${App_Name}
226 # )
228 ################################################################################
229 # Doxygen documentation
230 #
231 # - Create a directory named docs to hold your Doxygen config and standalone
232 # (.dox) files.
233 # - Name your Doxyfile config as "docs/Doxyfile.in".
234 # - In that file, set the following variables as shown, adjusting INPUT as
235 # needed to reflect the actual location of the fiels you wnat processed.
236 #
237 # PROJECT_NAME = "@App_Name@"
238 # PROJECT_BRIEF = "@App_Description@"
239 # STRIP_FROM_PATH = @CMAKE_CURRENT_SOURCE_DIR@
240 # INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/ @CMAKE_CURRENT_SOURCE_DIR@/include/ @CMAKE_CURRENT_SOURCE_DIR@/docs/
241 #
242 # Then you can generate the docs with "make docs" and this will create a "docs" directory under your build directory.
243 #
245 option(Option_Doxygen "Generate Doxygen documentation." OFF)
247 if (Option_Doxygen)
249 find_package(Doxygen)
250 if (NOT DOXYGEN_FOUND)
251 message (FATAL_ERROR "Doxygen not found!")
252 endif ()
254 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile @ONLY)
256 add_custom_target(docs
257 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile
258 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
259 COMMENT "Generating API documentation with Doxygen" VERBATIM
260 )
262 endif ()
264 ################################################################################
265 # X11
266 #
267 # Note that the FindX11.cmake package does _not_ include most X extensions
268 # in the X11_LIBRARIES variable, although it does pick up their header files
269 # in the X11_INCLUDE_DIR variable.
270 #
271 # To link a program with extensions, such as Xrandr, or Xv, you must manually
272 # update the target_link_libraries to include the appropriate library variable.
273 # ${X11_Xrandr_LIB} is an example. See the FindX11.cmake file for a complete
274 # list of availble variables.
275 #
277 option(Option_X11_Dev "Build an X11 Application." OFF)
279 if (Option_X11_Dev)
281 option(Option_Xrandr "Use Xrandr" OFF)
282 option(Option_Xinerama "Use Xinerama" OFF)
285 ########################################
286 find_package(X11)
287 if (NOT X11_FOUND)
288 message (FATAL_ERROR "X11 not found!")
289 endif ()
291 include_directories(
292 ${X11_INCLUDE_DIR}
293 ${INCLUDE_DIRECTORIES}
294 )
296 target_link_libraries(${App_Name}
297 ${X11_LIBRARIES}
298 ${TARGET_LINK_LIBRARIES}
299 )
301 ########################################
302 if (Option_Xrandr)
303 if (NOT X11_Xrandr_FOUND)
304 message (FATAL_ERROR "Xrandr not found!")
305 endif ()
306 target_link_libraries(${App_Name}
307 ${X11_Xrandr_LIB}
308 ${TARGET_LINK_LIBRARIES}
309 )
310 endif ()
312 ########################################
313 if (Option_Xinerama)
314 if (NOT X11_Xinerama_FOUND)
315 message (FATAL_ERROR "Xinerama not found!")
316 endif ()
317 target_link_libraries(${App_Name}
318 ${X11_Xinerama_LIB}
319 ${TARGET_LINK_LIBRARIES}
320 )
321 endif ()
323 endif ()
325 ################################################################################
326 # SDL
327 #
328 # Enabling SDL support enables several suboptions to make some common SDL
329 # extension libraries available as well.
330 #
331 # If any of the SDL libraries are not found automatically, you will need
332 # to set the appropriate environment variables and rerun cmake. You will
333 # need to remove the CMake cache before doing so.
335 # If you don't want to set actual environment variables before running
336 # CMake, then uncomment the if block below and put in the actual
337 # locations of your SDL installation.
339 option(Option_SDL_Dev "Build an SDL application." OFF)
341 if (Option_SDL_Dev)
343 # # Force SDL 1.3 only
344 # if (WIN32)
345 # set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-build")
346 # else ()
347 # set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build")
348 # endif ()
349 # add_definitions(-DSDL_NO_COMPAT)
351 # SDL base package
352 # To use a version of SDL other than your systems default, set the SDLDIR
353 # environment variable to the installation location of your preferred version.
354 find_package (SDL)
355 if (NOT SDL_FOUND)
356 message (FATAL_ERROR "SDL not found!")
357 endif (NOT SDL_FOUND)
358 include_directories(
359 ${SDL_INCLUDE_DIR}
360 ${INCLUDE_DIRECTORIES}
361 )
362 target_link_libraries(${App_Name}
363 ${SDL_LIBRARY}
364 ${TARGET_LINK_LIBRARIES}
365 )
367 # SDL_ttf
368 # Environment variables SDLTTFDIR and SDLDIR will be checked in that order
369 # and if set cmake will try to find SDL_ttf in the specified directory.
370 option(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF)
371 if (Option_SDL_Dev_SDL_ttf)
372 find_package (SDL_ttf)
373 if (NOT SDLTTF_FOUND)
374 message (FATAL_ERROR "SDL_ttf not found!")
375 endif (NOT SDLTTF_FOUND)
376 include_directories(
377 ${SDLTTF_INCLUDE_DIR}
378 ${INCLUDE_DIRECTORIES}
379 )
380 target_link_libraries(${App_Name}
381 ${SDLTTF_LIBRARY}
382 ${TARGET_LINK_LIBRARIES}
383 )
384 endif ()
386 # SDL_image
387 # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order
388 # and if set cmake will try to find SDL_image in the specified directory.
389 option(Option_SDL_Dev_SDL_image "Use SDL_image." OFF)
390 if (Option_SDL_Dev_SDL_image)
391 find_package (SDL_image)
392 if (NOT SDLIMAGE_FOUND)
393 message (FATAL_ERROR "SDL_image not found!")
394 endif (NOT SDLIMAGE_FOUND)
395 include_directories(
396 ${SDLIMAGE_INCLUDE_DIR}
397 ${INCLUDE_DIRECTORIES}
398 )
399 target_link_libraries(${App_Name}
400 ${SDLIMAGE_LIBRARY}
401 ${TARGET_LINK_LIBRARIES}
402 )
403 endif ()
405 # SDL_mixer
406 # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order
407 # and if set cmake will try to find SDL_mixer in the specified directory.
408 option(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF)
409 if (Option_SDL_Dev_SDL_mixer)
410 find_package (SDL_mixer)
411 if (NOT SDLMIXER_FOUND)
412 message (FATAL_ERROR "SDL_mixer not found!")
413 endif (NOT SDLMIXER_FOUND)
414 include_directories(
415 ${SDLMIXER_INCLUDE_DIR}
416 ${INCLUDE_DIRECTORIES}
417 )
418 target_link_libraries(${App_Name}
419 ${SDLMIXER_LIBRARY}
420 ${TARGET_LINK_LIBRARIES}
421 )
422 endif ()
424 # SDL_net
425 # Environment variables SDLNETDIR and SDLDIR will be checked in that order
426 # and if set cmake will try to find SDL_net in the specified directory.
427 option(Option_SDL_Dev_SDL_net "Use SDL_net." OFF)
428 if (Option_SDL_Dev_SDL_net)
429 find_package (SDL_net)
430 if (NOT SDLNET_FOUND)
431 message (FATAL_ERROR "SDL_net not found!")
432 endif (NOT SDLNET_FOUND)
433 include_directories(
434 ${SDLNET_INCLUDE_DIR}
435 ${INCLUDE_DIRECTORIES}
436 )
437 target_link_libraries(${App_Name}
438 ${SDLNET_LIBRARY}
439 ${TARGET_LINK_LIBRARIES}
440 )
441 endif ()
443 endif (Option_SDL_Dev)
446 ################################################################################
448 option(Option_OpenGL_Dev "Build an OpenGL Application." OFF)
450 if (Option_OpenGL_Dev)
452 find_package(OpenGL)
453 if (NOT OPENGL_FOUND)
454 message (FATAL_ERROR "OpenGL not found!")
455 endif (NOT OPENGL_FOUND)
457 include_directories(
458 ${OPENGL_INCLUDE_DIR}
459 ${INCLUDE_DIRECTORIES}
460 )
462 target_link_libraries(${App_Name}
463 ${OPENGL_LIBRARIES}
464 ${TARGET_LINK_LIBRARIES}
465 )
467 option(Option_GLUT_Dev "Build a GLUT Application." OFF)
469 if (Option_GLUT_Dev)
471 find_package(GLUT)
472 if (NOT GLUT_FOUND)
473 message (FATAL_ERROR "GLUT not found!")
474 endif()
476 include_directories(
477 ${GLUT_INCLUDE_DIR}
478 ${INCLUDE_DIRECTORIES}
479 )
481 target_link_libraries(${App_Name}
482 ${GLUT_LIBRARIES}
483 ${TARGET_LINK_LIBRARIES}
484 )
486 endif()
488 endif ()
490 ################################################################################
492 option(Option_OpenAL_Dev "Build an OpenAL Application." OFF)
494 if (Option_OpenAL_Dev)
496 find_package(OpenAL)
497 if (NOT OPENAL_FOUND)
498 message (FATAL_ERROR "OpenAL not found!")
499 endif (NOT OPENAL_FOUND)
501 include_directories(
502 ${OPENAL_INCLUDE_DIR}
503 ${INCLUDE_DIRECTORIES}
504 )
506 target_link_libraries(${App_Name}
507 ${OPENAL_LIBRARY}
508 ${TARGET_LINK_LIBRARIES}
509 )
511 endif ()
513 ################################################################################