annotate CMakeLists.txt @ 2:c24af3462002

initial commit
author Eris Caffee <discordia@eldalin.com>
date Sat, 27 Apr 2013 13:22:17 -0500
parents 9c54994a2635
children 4f8b47ac2715 7ae4ee5c27f8
rev   line source
discordia@0 1 ###############################################################################
discordia@0 2 #
discordia@0 3 # A generalized cmake file for developing cross-platform games.
discordia@0 4 #
discordia@0 5 # Copyright (C) 2010 Sarah Eris Horsley Caffee
discordia@0 6 #
discordia@0 7 # This is free software: you can redistribute it and/or modify
discordia@0 8 # it under the terms of the GNU General Public License as published by
discordia@0 9 # the Free Software Foundation, either version 3 of the License, or
discordia@0 10 # (at your option) any later version.
discordia@0 11 #
discordia@0 12 # This program is distributed in the hope that it will be useful,
discordia@0 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
discordia@0 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
discordia@0 15 # GNU General Public License for more details.
discordia@0 16 #
discordia@0 17 # You should have received a copy of the GNU General Public License
discordia@0 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
discordia@0 19 #
discordia@0 20 #
discordia@0 21 # Instructions:
discordia@0 22 # This cmake file assumes that your source files are laid in out in the
discordia@0 23 # following manner:
discordia@0 24 #
discordia@0 25 # project_dir\ Top level directory of the project.
discordia@0 26 # |---include\ Header files are here.
discordia@0 27 # |---src\ Source files are here.
discordia@0 28 # |---build\ Binaries/objects go here. Run cmake from here.
discordia@0 29 # !---cmake\
discordia@0 30 # | |---modules\ Custom cmake include files, if any, go here.
discordia@0 31 # |---CMakeLists.txt This file.
discordia@0 32 #
discordia@0 33 # You may have more directories, of course, but these are assumed. You probably
discordia@0 34 # want more than one build directory. I normally have build-linux\
discordia@0 35 # and build-windows\ directories.
discordia@0 36 #
discordia@0 37 # Set the App_Name variable, below, to the name of your application and you
discordia@0 38 # are ready to start. Run ccmake, or cmake-gui from within your build
discordia@0 39 # directory, choose the options you need, such as enabling SDL, and you
discordia@0 40 # should be good to go.
discordia@0 41 #
discordia@0 42 # You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON) command if you
discordia@0 43 # need to debug the actual makefile that is generated.
discordia@0 44 #
discordia@0 45 # On windows, you may need to set the SDLDIR environment variable to the location
discordia@0 46 # of your SDL installation before you run cmake-gui.
discordia@0 47 #
discordia@0 48 # When writing path names on Windows, such as when manually specifiying a
discordia@0 49 # file or directory name, either use unix-style forward slashes '/' in the
discordia@0 50 # path names or use double backslashes. If you use a single backslash as the
discordia@0 51 # path name seperator, then cmake will interpret it as an esacpe sequence.
discordia@0 52 # Thus, write "C:/source" or "C:\\source" instead of "C:\source". It's
discordia@0 53 # probably best to use forward slashes in case to ever have a situation
discordia@0 54 # where cmake needs to do recursive processing: each level of cmake will
discordia@0 55 # strip out one of the slashes, so if there are two lev3els of cmake you
discordia@0 56 # need to write \\\, three levels requires \\\\, etc.
discordia@0 57 #
discordia@0 58 # Note that some of the cmake support scripts that find libraries for you
discordia@0 59 # can be controlled by environment variables. For example, you can set the
discordia@0 60 # SDLDIR environment variable before running cmake in order to point to
discordia@0 61 # a different version of SDL than your systems default copy. This is useful
discordia@0 62 # for trying out cutting edge versions of libraries without installing them
discordia@0 63 # system wide.
discordia@0 64
discordia@0 65 cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
discordia@0 66 #set (CMAKE_VERBOSE_MAKEFILE ON)
discordia@0 67
discordia@0 68 # Name your program!
discordia@2 69 set (App_Name "solar-system")
discordia@0 70 if (App_Name STREQUAL "")
discordia@0 71 message (FATAL_ERROR "You must set the App_Name variable!")
discordia@0 72 endif ()
discordia@0 73
discordia@0 74 # Every project must have a name.
discordia@0 75 project (${App_Name})
discordia@0 76
discordia@0 77
discordia@0 78 ################################################################################
discordia@0 79 # Special options
discordia@0 80
discordia@0 81
discordia@0 82 ################################################################################
discordia@0 83 # Ensure that we are not building in our source directories.
discordia@0 84
discordia@0 85 set (Build_Dir_OK "TRUE")
discordia@0 86 string (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR})
discordia@0 87 if (In_Sub_Dir)
discordia@0 88 string (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR})
discordia@0 89 if (NOT In_Build_Dir)
discordia@0 90 set (Build_Dir_OK "FALSE")
discordia@0 91 endif ()
discordia@0 92 endif ()
discordia@0 93
discordia@0 94 if (NOT Build_Dir_OK)
discordia@0 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'.")
discordia@0 96 endif ()
discordia@0 97
discordia@0 98
discordia@0 99 ################################################################################
discordia@0 100 # Set up the basic build environment
discordia@0 101 # A build type defines which options are passed to the compiler, and there are
discordia@0 102 # several that CMake defines by default. It does not set one by default, though
discordia@0 103 # so we need to set the build type manually here, and we are setting it to the
discordia@0 104 # generally useful "Release with debug info"
discordia@0 105
discordia@0 106 if (CMAKE_BUILD_TYPE STREQUAL "")
discordia@0 107 # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This messes up
discordia@0 108 # differentiation between debug and release builds.
discordia@0 109 set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
discordia@0 110 endif ()
discordia@0 111
discordia@0 112
discordia@0 113 ################################################################################
discordia@0 114 # When using GCC turn on lots of warnings.
discordia@2 115 # Some other options to consider:
discordia@2 116 # C++ -Weffc++ -std=c++0x
discordia@0 117 # C -std=gnu99 -std=c99
discordia@0 118
discordia@0 119 if (CMAKE_COMPILER_IS_GNUCXX)
discordia@2 120 add_definitions(-pedantic -Wall -std=c++0x)
discordia@0 121 endif ()
discordia@0 122
discordia@0 123
discordia@0 124 ################################################################################
discordia@0 125
discordia@0 126 option(Option_Profile_Program "Build for gprof profiling." OFF)
discordia@0 127 if (Option_Profile_Program)
discordia@0 128 add_definitions(-pg)
discordia@0 129 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
discordia@0 130 endif ()
discordia@0 131
discordia@0 132
discordia@0 133 ################################################################################
discordia@0 134 # The core project files
discordia@0 135
discordia@2 136 file (GLOB SRCS src/*.c src/*.cpp
discordia@2 137 /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/src/*
discordia@2 138 )
discordia@2 139 file (GLOB HDRS include/*.h include/*.hpp
discordia@2 140 /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/*
discordia@2 141 /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/GL/*
discordia@2 142
discordia@2 143 )
discordia@0 144
discordia@0 145 # The directories that contain the libraries we will be linking against.
discordia@0 146 # This must come before the ADD_EXECUTABLE directive.
discordia@0 147 link_directories (
discordia@0 148 )
discordia@0 149
discordia@0 150 # The directories that contain the include files our programs use.
discordia@0 151 # This must come before the ADD_EXECUTABLE directive.
discordia@0 152 include_directories (
discordia@0 153 ${CMAKE_SOURCE_DIR}/include
discordia@2 154 /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/
discordia@2 155 /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/GL
discordia@0 156 )
discordia@0 157
discordia@0 158 # Define the executable program file we are creating. We must list all of
discordia@0 159 # the source files.
discordia@0 160 if (WIN32)
discordia@0 161 add_executable (${App_Name} WIN32
discordia@0 162 ${SRCS}
discordia@0 163 ${HDRS}
discordia@0 164 )
discordia@0 165 else ()
discordia@2 166 # I should NOT have to define this symbol explictly. Why do I?
discordia@2 167 add_definitions(-Dlinux)
discordia@2 168
discordia@0 169 add_executable (${App_Name}
discordia@0 170 ${SRCS}
discordia@0 171 ${HDRS}
discordia@0 172 )
discordia@0 173 endif ()
discordia@0 174
discordia@0 175 # Although we listed the library directories above, we also need to list the
discordia@0 176 # individual libraries we will be linking against.
discordia@0 177 target_link_libraries (${App_Name}
discordia@0 178 )
discordia@0 179
discordia@0 180
discordia@0 181 # # An example for a unix library named utils with a test driver program.
discordia@0 182
discordia@0 183 # set (SRCS_utils
discordia@0 184 # src/utils.cpp
discordia@0 185 # include/utils.h
discordia@0 186 # )
discordia@0 187
discordia@0 188 # include_directories (
discordia@0 189 # ${PROJECT_SOURCE_DIR}/include
discordia@0 190 # )
discordia@0 191
discordia@0 192 # # Build both static and shared libraries
discordia@0 193 # # The target properties are needed because, by default, the output name
discordia@0 194 # # will be the name in the add_library command, and we need to have different
discordia@0 195 # # names in the two commands for the shared and static versions, even though
discordia@0 196 # # we want the final files to have the same names with different extensions.
discordia@0 197 # #
discordia@0 198 # # The prefix is needed mostly in case we build on windows, which has no prefix
discordia@0 199 # # by default.
discordia@0 200 # #
discordia@0 201 # # The clean_direct_output option makes sure that the two lib builds don't
discordia@0 202 # # clobber each others temp files since they are being built from the same
discordia@0 203 # # sources.
discordia@0 204
discordia@0 205 # add_library (utils SHARED
discordia@0 206 # ${SRCS_utils}
discordia@0 207 # )
discordia@0 208 # set_target_properties (utils PROPERTIES OUTPUT_NAME "utils")
discordia@0 209 # set_target_properties (utils PROPERTIES PREFIX "lib")
discordia@0 210 # set_target_properties (utils PROPERTIES CLEAN_DIRECT_OUTPUT 1)
discordia@0 211
discordia@0 212 # add_library (utils-static STATIC
discordia@0 213 # ${SRCS_utils}
discordia@0 214 # )
discordia@0 215 # set_target_properties (utils-static PROPERTIES OUTPUT_NAME "utils")
discordia@0 216 # set_target_properties (utils-static PROPERTIES PREFIX "lib")
discordia@0 217 # set_target_properties (utils-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
discordia@0 218
discordia@0 219 # # Build a test application.
discordia@0 220
discordia@0 221 # add_executable (test
discordia@0 222 # src/main.cpp
discordia@0 223 # )
discordia@0 224
discordia@0 225 # target_link_libraries (test
discordia@0 226 # utils
discordia@0 227 # )
discordia@0 228
discordia@0 229
discordia@0 230 ################################################################################
discordia@0 231 # X11
discordia@0 232 #
discordia@0 233 # Note that the FindX11.cmake package does _not_ include most X extensions
discordia@0 234 # in the X11_LIBRARIES variable, although it does pick up their header files
discordia@0 235 # in the X11_INCLUDE_DIR variable.
discordia@0 236 #
discordia@0 237 # To link a program with extensions, such as Xrandr, or Xv, you must manually
discordia@0 238 # update the target_link_libraries to include the appropriate library variable.
discordia@0 239 # ${X11_Xrandr_LIB} is an example. See the FindX11.cmake file for a complete
discordia@0 240 # list of availble variables.
discordia@0 241 #
discordia@0 242
discordia@0 243 option(Option_X11_Dev "Build an X11 Application." OFF)
discordia@0 244
discordia@0 245 if (Option_X11_Dev)
discordia@0 246
discordia@0 247 option(Option_Xrandr "Use Xrandr" OFF)
discordia@0 248 option(Option_Xinerama "Use Xinerama" OFF)
discordia@0 249
discordia@0 250
discordia@0 251 ########################################
discordia@0 252 find_package(X11)
discordia@0 253 if (NOT X11_FOUND)
discordia@0 254 message (FATAL_ERROR "X11 not found!")
discordia@0 255 endif ()
discordia@0 256
discordia@0 257 include_directories(
discordia@0 258 ${X11_INCLUDE_DIR}
discordia@0 259 ${INCLUDE_DIRECTORIES}
discordia@0 260 )
discordia@0 261
discordia@0 262 target_link_libraries(${App_Name}
discordia@0 263 ${X11_LIBRARIES}
discordia@0 264 ${TARGET_LINK_LIBRARIES}
discordia@0 265 )
discordia@0 266
discordia@0 267 ########################################
discordia@0 268 if (Option_Xrandr)
discordia@0 269 if (NOT X11_Xrandr_FOUND)
discordia@0 270 message (FATAL_ERRO "Xrandr not found!")
discordia@0 271 endif ()
discordia@0 272 target_link_libraries(${App_Name}
discordia@0 273 ${X11_Xrandr_LIB}
discordia@0 274 ${TARGET_LINK_LIBRARIES}
discordia@0 275 )
discordia@0 276 endif ()
discordia@0 277
discordia@0 278 ########################################
discordia@0 279 if (Option_Xinerama)
discordia@0 280 if (NOT X11_Xinerama_FOUND)
discordia@0 281 message (FATAL_ERRO "Xinerama not found!")
discordia@0 282 endif ()
discordia@0 283 target_link_libraries(${App_Name}
discordia@0 284 ${X11_Xinerama_LIB}
discordia@0 285 ${TARGET_LINK_LIBRARIES}
discordia@0 286 )
discordia@0 287 endif ()
discordia@0 288
discordia@0 289 endif ()
discordia@0 290
discordia@0 291 ################################################################################
discordia@0 292 # SDL
discordia@0 293 #
discordia@0 294 # Enabling SDL support enables several suboptions to make some common SDL
discordia@0 295 # extension libraries available as well.
discordia@0 296 #
discordia@0 297 # If any of the SDL libraries are not found automatically, you will need
discordia@0 298 # to set the appropriate environment variables and rerun cmake. You will
discordia@0 299 # need to remove the CMake cache before doing so.
discordia@0 300
discordia@0 301 # If you don't want to set actual environment variables before running
discordia@0 302 # CMake, then uncomment the if block below and put in the actual
discordia@0 303 # locations of your SDL installation.
discordia@0 304
discordia@0 305 option(Option_SDL_Dev "Build an SDL application." OFF)
discordia@0 306
discordia@0 307 if (Option_SDL_Dev)
discordia@0 308
discordia@0 309 # # Force SDL 1.3 only
discordia@0 310 # if (WIN32)
discordia@0 311 # set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-build")
discordia@0 312 # else ()
discordia@0 313 # set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build")
discordia@0 314 # endif ()
discordia@0 315 # add_definitions(-DSDL_NO_COMPAT)
discordia@0 316
discordia@0 317 # SDL base package
discordia@0 318 # To use a version of SDL other than your systems default, set the SDLDIR
discordia@0 319 # environment variable to the installation location of your preferred version.
discordia@0 320 find_package (SDL)
discordia@0 321 if (NOT SDL_FOUND)
discordia@0 322 message (FATAL_ERROR "SDL not found!")
discordia@0 323 endif (NOT SDL_FOUND)
discordia@0 324 include_directories(
discordia@0 325 ${SDL_INCLUDE_DIR}
discordia@0 326 ${INCLUDE_DIRECTORIES}
discordia@0 327 )
discordia@0 328 target_link_libraries(${App_Name}
discordia@0 329 ${SDL_LIBRARY}
discordia@0 330 ${TARGET_LINK_LIBRARIES}
discordia@0 331 )
discordia@0 332
discordia@0 333 # SDL_ttf
discordia@0 334 # Environment variables SDLTTFDIR and SDLDIR will be checked in that order
discordia@0 335 # and if set cmake will try to find SDL_ttf in the specified directory.
discordia@0 336 option(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF)
discordia@0 337 if (Option_SDL_Dev_SDL_ttf)
discordia@0 338 find_package (SDL_ttf)
discordia@0 339 if (NOT SDLTTF_FOUND)
discordia@0 340 message (FATAL_ERROR "SDL_ttf not found!")
discordia@0 341 endif (NOT SDLTTF_FOUND)
discordia@0 342 include_directories(
discordia@0 343 ${SDLTTF_INCLUDE_DIR}
discordia@0 344 ${INCLUDE_DIRECTORIES}
discordia@0 345 )
discordia@0 346 target_link_libraries(${App_Name}
discordia@0 347 ${SDLTTF_LIBRARY}
discordia@0 348 ${TARGET_LINK_LIBRARIES}
discordia@0 349 )
discordia@0 350 endif ()
discordia@0 351
discordia@0 352 # SDL_image
discordia@0 353 # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order
discordia@0 354 # and if set cmake will try to find SDL_image in the specified directory.
discordia@0 355 option(Option_SDL_Dev_SDL_image "Use SDL_image." OFF)
discordia@0 356 if (Option_SDL_Dev_SDL_image)
discordia@0 357 find_package (SDL_image)
discordia@0 358 if (NOT SDLIMAGE_FOUND)
discordia@0 359 message (FATAL_ERROR "SDL_image not found!")
discordia@0 360 endif (NOT SDLIMAGE_FOUND)
discordia@0 361 include_directories(
discordia@0 362 ${SDLIMAGE_INCLUDE_DIR}
discordia@0 363 ${INCLUDE_DIRECTORIES}
discordia@0 364 )
discordia@0 365 target_link_libraries(${App_Name}
discordia@0 366 ${SDLIMAGE_LIBRARY}
discordia@0 367 ${TARGET_LINK_LIBRARIES}
discordia@0 368 )
discordia@0 369 endif ()
discordia@0 370
discordia@0 371 # SDL_mixer
discordia@0 372 # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order
discordia@0 373 # and if set cmake will try to find SDL_mixer in the specified directory.
discordia@0 374 option(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF)
discordia@0 375 if (Option_SDL_Dev_SDL_mixer)
discordia@0 376 find_package (SDL_mixer)
discordia@0 377 if (NOT SDLMIXER_FOUND)
discordia@0 378 message (FATAL_ERROR "SDL_mixer not found!")
discordia@0 379 endif (NOT SDLMIXER_FOUND)
discordia@0 380 include_directories(
discordia@0 381 ${SDLMIXER_INCLUDE_DIR}
discordia@0 382 ${INCLUDE_DIRECTORIES}
discordia@0 383 )
discordia@0 384 target_link_libraries(${App_Name}
discordia@0 385 ${SDLMIXER_LIBRARY}
discordia@0 386 ${TARGET_LINK_LIBRARIES}
discordia@0 387 )
discordia@0 388 endif ()
discordia@0 389
discordia@0 390 # SDL_net
discordia@0 391 # Environment variables SDLNETDIR and SDLDIR will be checked in that order
discordia@0 392 # and if set cmake will try to find SDL_net in the specified directory.
discordia@0 393 option(Option_SDL_Dev_SDL_net "Use SDL_net." OFF)
discordia@0 394 if (Option_SDL_Dev_SDL_net)
discordia@0 395 find_package (SDL_net)
discordia@0 396 if (NOT SDLNET_FOUND)
discordia@0 397 message (FATAL_ERROR "SDL_net not found!")
discordia@0 398 endif (NOT SDLNET_FOUND)
discordia@0 399 include_directories(
discordia@0 400 ${SDLNET_INCLUDE_DIR}
discordia@0 401 ${INCLUDE_DIRECTORIES}
discordia@0 402 )
discordia@0 403 target_link_libraries(${App_Name}
discordia@0 404 ${SDLNET_LIBRARY}
discordia@0 405 ${TARGET_LINK_LIBRARIES}
discordia@0 406 )
discordia@0 407 endif ()
discordia@0 408
discordia@0 409 endif (Option_SDL_Dev)
discordia@0 410
discordia@0 411
discordia@0 412 ################################################################################
discordia@0 413
discordia@2 414 option(Option_OpenGL_Dev "Build an OpenGL Application." ON)
discordia@0 415
discordia@0 416 if (Option_OpenGL_Dev)
discordia@0 417
discordia@0 418 find_package(OpenGL)
discordia@2 419 if (NOT OPENGL_FOUND)
discordia@1 420 message (FATAL_ERROR "OpenGL not found!")
discordia@2 421 endif (NOT OPENGL_FOUND)
discordia@0 422
discordia@0 423 include_directories(
discordia@1 424 ${OPENGL_INCLUDE_DIR}
discordia@0 425 ${INCLUDE_DIRECTORIES}
discordia@0 426 )
discordia@0 427
discordia@0 428 target_link_libraries(${App_Name}
discordia@1 429 ${OPENGL_LIBRARIES}
discordia@0 430 ${TARGET_LINK_LIBRARIES}
discordia@0 431 )
discordia@0 432
discordia@2 433 option(Option_GLUT_Dev "Build a GLUT Application." ON)
discordia@2 434
discordia@2 435 if (Option_GLUT_Dev)
discordia@2 436
discordia@2 437 find_package(GLUT)
discordia@2 438 if (NOT GLUT_FOUND)
discordia@2 439 message (FATAL_ERROR "GLUT not found!")
discordia@2 440 endif()
discordia@2 441
discordia@2 442 include_directories(
discordia@2 443 ${GLUT_INCLUDE_DIR}
discordia@2 444 ${INCLUDE_DIRECTORIES}
discordia@2 445 )
discordia@2 446
discordia@2 447 target_link_libraries(${App_Name}
discordia@2 448 ${GLUT_LIBRARIES}
discordia@2 449 ${TARGET_LINK_LIBRARIES}
discordia@2 450 )
discordia@2 451
discordia@2 452 endif()
discordia@2 453
discordia@0 454 endif ()
discordia@0 455
discordia@0 456 ################################################################################
discordia@0 457
discordia@0 458 option(Option_OpenAL_Dev "Build an OpenAL Application." OFF)
discordia@0 459
discordia@0 460 if (Option_OpenAL_Dev)
discordia@1 461
discordia@0 462 find_package(OpenAL)
discordia@1 463 if (NOT OPENAL_FOUND)
discordia@1 464 message (FATAL_ERROR "OpenAL not found!")
discordia@1 465 endif (NOT OPENAL_FOUND)
discordia@0 466
discordia@0 467 include_directories(
discordia@1 468 ${OPENAL_INCLUDE_DIR}
discordia@0 469 ${INCLUDE_DIRECTORIES}
discordia@0 470 )
discordia@0 471
discordia@0 472 target_link_libraries(${App_Name}
discordia@1 473 ${OPENAL_LIBRARY}
discordia@0 474 ${TARGET_LINK_LIBRARIES}
discordia@0 475 )
discordia@0 476
discordia@0 477 endif ()
discordia@0 478
discordia@0 479 ################################################################################
discordia@2 480