view CMakeLists.txt @ 4:416399d055e9

Added option for Doxygen
author Eris Caffee <discordia@eldalin.com>
date Sun, 07 Apr 2013 00:38:06 -0500
parents acb4b5af3dfa
children 2d4c97813e03
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})
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 ()
124 ################################################################################
126 option(Option_Profile_Program "Build for gprof profiling." OFF)
127 if (Option_Profile_Program)
128 add_definitions(-pg)
129 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
130 endif ()
133 ################################################################################
134 # The core project files
136 file (GLOB SRCS src/*.c src/*.cpp)
137 file (GLOB HDRS include/*.h include/*.hpp)
139 # The directories that contain the libraries we will be linking against.
140 # This must come before the ADD_EXECUTABLE directive.
141 link_directories (
142 )
144 # The directories that contain the include files our programs use.
145 # This must come before the ADD_EXECUTABLE directive.
146 include_directories (
147 ${CMAKE_SOURCE_DIR}/include
148 )
150 # Define the executable program file we are creating. We must list all of
151 # the source files.
152 if (WIN32)
153 add_executable (${App_Name} WIN32
154 ${SRCS}
155 ${HDRS}
156 )
157 else ()
158 add_executable (${App_Name}
159 ${SRCS}
160 ${HDRS}
161 )
162 endif ()
164 # Although we listed the library directories above, we also need to list the
165 # individual libraries we will be linking against.
166 target_link_libraries (${App_Name}
167 )
170 # Example to build a linux library with a test driver.
172 # set (SRCS_${App_Name}
173 # src/.cpp
174 # include/.h
175 # )
177 # include_directories (
178 # ${PROJECT_SOURCE_DIR}/include
179 # )
181 # # Build both static and shared libraries
182 # # The target properties are needed because, by default, the output name
183 # # will be the name in the add_library command, and we need to have different
184 # # names in the two commands for the shared and static versions, even though
185 # # we want the final files to have the same names with different extensions.
186 # #
187 # # The prefix is needed mostly in case we build on windows, which has no prefix
188 # # by default.
189 # #
190 # # The clean_direct_output option makes sure that the two lib builds don't
191 # # clobber each others temp files since they are being built from the same
192 # # sources.
194 # add_library (${App_Name} SHARED
195 # ${SRCS_${App_Name}}
196 # )
197 # set_target_properties (${App_Name} PROPERTIES OUTPUT_NAME ${App_Name})
198 # set_target_properties (${App_Name} PROPERTIES PREFIX "lib")
199 # set_target_properties (${App_Name} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
201 # add_library (${App_Name}-static STATIC
202 # ${SRCS_${App_Name}}
203 # )
204 # set_target_properties (${App_Name}-static PROPERTIES OUTPUT_NAME ${App_Name})
205 # set_target_properties (${App_Name}-static PROPERTIES PREFIX "lib")
206 # set_target_properties (${App_Name}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
208 # # Build a test application.
210 # link_directories (
211 # )
213 # include_directories (
214 # ${CMAKE_SOURCE_DIR}/include
215 # )
217 # add_executable (${App_Name}-test
218 # src/main.cpp
219 # )
221 # target_link_libraries (${App_Name}-test
222 # ${App_Name}
223 # )
225 ################################################################################
226 # Doxygen documentation
227 #
228 # - Create a directory named docs to hold your Doxygen config and standalone (.dox) files.
229 # - Name you Doxyfile config as "Doxyfile.in".
230 # - In that file, prepend "@CMAKE_CURRENT_SOURCE_DIR@/" to all of the files and directorys listed in the INPUT setting.
231 # - Set STRIP_FROM_PATH to "@CMAKE_CURRENT_SOURCE_DIR@"
232 #
233 # Then you can generate the docs with "make docs" and this will create a "docs" directory under your build directory.
234 #
236 option(Option_Doxygen "Generate Doxygen documentation." OFF)
238 if (Option_Doxygen)
240 find_package(Doxygen)
241 if (NOT DOXYGEN_FOUND)
242 message (FATAL_ERROR "Doxygen not found!")
243 endif ()
245 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile @ONLY)
247 add_custom_target(docs
248 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile
249 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
250 COMMENT "Generating API documentation with Doxygen" VERBATIM
251 )
253 endif ()
255 ################################################################################
256 # X11
257 #
258 # Note that the FindX11.cmake package does _not_ include most X extensions
259 # in the X11_LIBRARIES variable, although it does pick up their header files
260 # in the X11_INCLUDE_DIR variable.
261 #
262 # To link a program with extensions, such as Xrandr, or Xv, you must manually
263 # update the target_link_libraries to include the appropriate library variable.
264 # ${X11_Xrandr_LIB} is an example. See the FindX11.cmake file for a complete
265 # list of availble variables.
266 #
268 option(Option_X11_Dev "Build an X11 Application." OFF)
270 if (Option_X11_Dev)
272 option(Option_Xrandr "Use Xrandr" OFF)
273 option(Option_Xinerama "Use Xinerama" OFF)
276 ########################################
277 find_package(X11)
278 if (NOT X11_FOUND)
279 message (FATAL_ERROR "X11 not found!")
280 endif ()
282 include_directories(
283 ${X11_INCLUDE_DIR}
284 ${INCLUDE_DIRECTORIES}
285 )
287 target_link_libraries(${App_Name}
288 ${X11_LIBRARIES}
289 ${TARGET_LINK_LIBRARIES}
290 )
292 ########################################
293 if (Option_Xrandr)
294 if (NOT X11_Xrandr_FOUND)
295 message (FATAL_ERRO "Xrandr not found!")
296 endif ()
297 target_link_libraries(${App_Name}
298 ${X11_Xrandr_LIB}
299 ${TARGET_LINK_LIBRARIES}
300 )
301 endif ()
303 ########################################
304 if (Option_Xinerama)
305 if (NOT X11_Xinerama_FOUND)
306 message (FATAL_ERRO "Xinerama not found!")
307 endif ()
308 target_link_libraries(${App_Name}
309 ${X11_Xinerama_LIB}
310 ${TARGET_LINK_LIBRARIES}
311 )
312 endif ()
314 endif ()
316 ################################################################################
317 # SDL
318 #
319 # Enabling SDL support enables several suboptions to make some common SDL
320 # extension libraries available as well.
321 #
322 # If any of the SDL libraries are not found automatically, you will need
323 # to set the appropriate environment variables and rerun cmake. You will
324 # need to remove the CMake cache before doing so.
326 # If you don't want to set actual environment variables before running
327 # CMake, then uncomment the if block below and put in the actual
328 # locations of your SDL installation.
330 option(Option_SDL_Dev "Build an SDL application." OFF)
332 if (Option_SDL_Dev)
334 # # Force SDL 1.3 only
335 # if (WIN32)
336 # set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-build")
337 # else ()
338 # set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build")
339 # endif ()
340 # add_definitions(-DSDL_NO_COMPAT)
342 # SDL base package
343 # To use a version of SDL other than your systems default, set the SDLDIR
344 # environment variable to the installation location of your preferred version.
345 find_package (SDL)
346 if (NOT SDL_FOUND)
347 message (FATAL_ERROR "SDL not found!")
348 endif (NOT SDL_FOUND)
349 include_directories(
350 ${SDL_INCLUDE_DIR}
351 ${INCLUDE_DIRECTORIES}
352 )
353 target_link_libraries(${App_Name}
354 ${SDL_LIBRARY}
355 ${TARGET_LINK_LIBRARIES}
356 )
358 # SDL_ttf
359 # Environment variables SDLTTFDIR and SDLDIR will be checked in that order
360 # and if set cmake will try to find SDL_ttf in the specified directory.
361 option(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF)
362 if (Option_SDL_Dev_SDL_ttf)
363 find_package (SDL_ttf)
364 if (NOT SDLTTF_FOUND)
365 message (FATAL_ERROR "SDL_ttf not found!")
366 endif (NOT SDLTTF_FOUND)
367 include_directories(
368 ${SDLTTF_INCLUDE_DIR}
369 ${INCLUDE_DIRECTORIES}
370 )
371 target_link_libraries(${App_Name}
372 ${SDLTTF_LIBRARY}
373 ${TARGET_LINK_LIBRARIES}
374 )
375 endif ()
377 # SDL_image
378 # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order
379 # and if set cmake will try to find SDL_image in the specified directory.
380 option(Option_SDL_Dev_SDL_image "Use SDL_image." OFF)
381 if (Option_SDL_Dev_SDL_image)
382 find_package (SDL_image)
383 if (NOT SDLIMAGE_FOUND)
384 message (FATAL_ERROR "SDL_image not found!")
385 endif (NOT SDLIMAGE_FOUND)
386 include_directories(
387 ${SDLIMAGE_INCLUDE_DIR}
388 ${INCLUDE_DIRECTORIES}
389 )
390 target_link_libraries(${App_Name}
391 ${SDLIMAGE_LIBRARY}
392 ${TARGET_LINK_LIBRARIES}
393 )
394 endif ()
396 # SDL_mixer
397 # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order
398 # and if set cmake will try to find SDL_mixer in the specified directory.
399 option(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF)
400 if (Option_SDL_Dev_SDL_mixer)
401 find_package (SDL_mixer)
402 if (NOT SDLMIXER_FOUND)
403 message (FATAL_ERROR "SDL_mixer not found!")
404 endif (NOT SDLMIXER_FOUND)
405 include_directories(
406 ${SDLMIXER_INCLUDE_DIR}
407 ${INCLUDE_DIRECTORIES}
408 )
409 target_link_libraries(${App_Name}
410 ${SDLMIXER_LIBRARY}
411 ${TARGET_LINK_LIBRARIES}
412 )
413 endif ()
415 # SDL_net
416 # Environment variables SDLNETDIR and SDLDIR will be checked in that order
417 # and if set cmake will try to find SDL_net in the specified directory.
418 option(Option_SDL_Dev_SDL_net "Use SDL_net." OFF)
419 if (Option_SDL_Dev_SDL_net)
420 find_package (SDL_net)
421 if (NOT SDLNET_FOUND)
422 message (FATAL_ERROR "SDL_net not found!")
423 endif (NOT SDLNET_FOUND)
424 include_directories(
425 ${SDLNET_INCLUDE_DIR}
426 ${INCLUDE_DIRECTORIES}
427 )
428 target_link_libraries(${App_Name}
429 ${SDLNET_LIBRARY}
430 ${TARGET_LINK_LIBRARIES}
431 )
432 endif ()
434 endif (Option_SDL_Dev)
437 ################################################################################
439 option(Option_OpenGL_Dev "Build an OpenGL Application." OFF)
441 if (Option_OpenGL_Dev)
443 find_package(OpenGL)
444 if (NOT OPENGL_FOUND)
445 message (FATAL_ERROR "OpenGL not found!")
446 endif (NOT OPENGL_FOUND)
448 include_directories(
449 ${OPENGL_INCLUDE_DIR}
450 ${INCLUDE_DIRECTORIES}
451 )
453 target_link_libraries(${App_Name}
454 ${OPENGL_LIBRARIES}
455 ${TARGET_LINK_LIBRARIES}
456 )
458 option(Option_GLUT_Dev "Build a GLUT Application." OFF)
460 if (Option_GLUT_Dev)
462 find_package(GLUT)
463 if (NOT GLUT_FOUND)
464 message (FATAL_ERROR "GLUT not found!")
465 endif()
467 include_directories(
468 ${GLUT_INCLUDE_DIR}
469 ${INCLUDE_DIRECTORIES}
470 )
472 target_link_libraries(${App_Name}
473 ${GLUT_LIBRARIES}
474 ${TARGET_LINK_LIBRARIES}
475 )
477 endif()
479 endif ()
481 ################################################################################
483 option(Option_OpenAL_Dev "Build an OpenAL Application." OFF)
485 if (Option_OpenAL_Dev)
487 find_package(OpenAL)
488 if (NOT OPENAL_FOUND)
489 message (FATAL_ERROR "OpenAL not found!")
490 endif (NOT OPENAL_FOUND)
492 include_directories(
493 ${OPENAL_INCLUDE_DIR}
494 ${INCLUDE_DIRECTORIES}
495 )
497 target_link_libraries(${App_Name}
498 ${OPENAL_LIBRARY}
499 ${TARGET_LINK_LIBRARIES}
500 )
502 endif ()
504 ################################################################################