annotate CMakeLists.txt @ 1:9c54994a2635

Fixed OpenGL and OpenAL variable names
author Eris Caffee <discordia@eldalin.com>
date Tue, 29 Mar 2011 00:27:15 -0500
parents 6b163267bd3e
children c24af3462002
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@0 69 set (App_Name "")
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@0 115 # Some other options to consider:
discordia@0 116 # C++ -Weffc++
discordia@0 117 # C -std=gnu99 -std=c99
discordia@0 118
discordia@0 119 if (CMAKE_COMPILER_IS_GNUCXX)
discordia@0 120 add_definitions(-pedantic -Wall)
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@0 136 file (GLOB SRCS src/*.c src/*.cpp)
discordia@0 137 file (GLOB HDRS include/*.h include/*.hpp)
discordia@0 138
discordia@0 139 # The directories that contain the libraries we will be linking against.
discordia@0 140 # This must come before the ADD_EXECUTABLE directive.
discordia@0 141 link_directories (
discordia@0 142 )
discordia@0 143
discordia@0 144 # The directories that contain the include files our programs use.
discordia@0 145 # This must come before the ADD_EXECUTABLE directive.
discordia@0 146 include_directories (
discordia@0 147 ${CMAKE_SOURCE_DIR}/include
discordia@0 148 )
discordia@0 149
discordia@0 150 # Define the executable program file we are creating. We must list all of
discordia@0 151 # the source files.
discordia@0 152 if (WIN32)
discordia@0 153 add_executable (${App_Name} WIN32
discordia@0 154 ${SRCS}
discordia@0 155 ${HDRS}
discordia@0 156 )
discordia@0 157 else ()
discordia@0 158 add_executable (${App_Name}
discordia@0 159 ${SRCS}
discordia@0 160 ${HDRS}
discordia@0 161 )
discordia@0 162 endif ()
discordia@0 163
discordia@0 164 # Although we listed the library directories above, we also need to list the
discordia@0 165 # individual libraries we will be linking against.
discordia@0 166 target_link_libraries (${App_Name}
discordia@0 167 )
discordia@0 168
discordia@0 169
discordia@0 170 # # An example for a unix library named utils with a test driver program.
discordia@0 171
discordia@0 172 # set (SRCS_utils
discordia@0 173 # src/utils.cpp
discordia@0 174 # include/utils.h
discordia@0 175 # )
discordia@0 176
discordia@0 177 # include_directories (
discordia@0 178 # ${PROJECT_SOURCE_DIR}/include
discordia@0 179 # )
discordia@0 180
discordia@0 181 # # Build both static and shared libraries
discordia@0 182 # # The target properties are needed because, by default, the output name
discordia@0 183 # # will be the name in the add_library command, and we need to have different
discordia@0 184 # # names in the two commands for the shared and static versions, even though
discordia@0 185 # # we want the final files to have the same names with different extensions.
discordia@0 186 # #
discordia@0 187 # # The prefix is needed mostly in case we build on windows, which has no prefix
discordia@0 188 # # by default.
discordia@0 189 # #
discordia@0 190 # # The clean_direct_output option makes sure that the two lib builds don't
discordia@0 191 # # clobber each others temp files since they are being built from the same
discordia@0 192 # # sources.
discordia@0 193
discordia@0 194 # add_library (utils SHARED
discordia@0 195 # ${SRCS_utils}
discordia@0 196 # )
discordia@0 197 # set_target_properties (utils PROPERTIES OUTPUT_NAME "utils")
discordia@0 198 # set_target_properties (utils PROPERTIES PREFIX "lib")
discordia@0 199 # set_target_properties (utils PROPERTIES CLEAN_DIRECT_OUTPUT 1)
discordia@0 200
discordia@0 201 # add_library (utils-static STATIC
discordia@0 202 # ${SRCS_utils}
discordia@0 203 # )
discordia@0 204 # set_target_properties (utils-static PROPERTIES OUTPUT_NAME "utils")
discordia@0 205 # set_target_properties (utils-static PROPERTIES PREFIX "lib")
discordia@0 206 # set_target_properties (utils-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
discordia@0 207
discordia@0 208 # # Build a test application.
discordia@0 209
discordia@0 210 # add_executable (test
discordia@0 211 # src/main.cpp
discordia@0 212 # )
discordia@0 213
discordia@0 214 # target_link_libraries (test
discordia@0 215 # utils
discordia@0 216 # )
discordia@0 217
discordia@0 218
discordia@0 219 ################################################################################
discordia@0 220 # X11
discordia@0 221 #
discordia@0 222 # Note that the FindX11.cmake package does _not_ include most X extensions
discordia@0 223 # in the X11_LIBRARIES variable, although it does pick up their header files
discordia@0 224 # in the X11_INCLUDE_DIR variable.
discordia@0 225 #
discordia@0 226 # To link a program with extensions, such as Xrandr, or Xv, you must manually
discordia@0 227 # update the target_link_libraries to include the appropriate library variable.
discordia@0 228 # ${X11_Xrandr_LIB} is an example. See the FindX11.cmake file for a complete
discordia@0 229 # list of availble variables.
discordia@0 230 #
discordia@0 231
discordia@0 232 option(Option_X11_Dev "Build an X11 Application." OFF)
discordia@0 233
discordia@0 234 if (Option_X11_Dev)
discordia@0 235
discordia@0 236 option(Option_Xrandr "Use Xrandr" OFF)
discordia@0 237 option(Option_Xinerama "Use Xinerama" OFF)
discordia@0 238
discordia@0 239
discordia@0 240 ########################################
discordia@0 241 find_package(X11)
discordia@0 242 if (NOT X11_FOUND)
discordia@0 243 message (FATAL_ERROR "X11 not found!")
discordia@0 244 endif ()
discordia@0 245
discordia@0 246 include_directories(
discordia@0 247 ${X11_INCLUDE_DIR}
discordia@0 248 ${INCLUDE_DIRECTORIES}
discordia@0 249 )
discordia@0 250
discordia@0 251 target_link_libraries(${App_Name}
discordia@0 252 ${X11_LIBRARIES}
discordia@0 253 ${TARGET_LINK_LIBRARIES}
discordia@0 254 )
discordia@0 255
discordia@0 256 ########################################
discordia@0 257 if (Option_Xrandr)
discordia@0 258 if (NOT X11_Xrandr_FOUND)
discordia@0 259 message (FATAL_ERRO "Xrandr not found!")
discordia@0 260 endif ()
discordia@0 261 target_link_libraries(${App_Name}
discordia@0 262 ${X11_Xrandr_LIB}
discordia@0 263 ${TARGET_LINK_LIBRARIES}
discordia@0 264 )
discordia@0 265 endif ()
discordia@0 266
discordia@0 267 ########################################
discordia@0 268 if (Option_Xinerama)
discordia@0 269 if (NOT X11_Xinerama_FOUND)
discordia@0 270 message (FATAL_ERRO "Xinerama not found!")
discordia@0 271 endif ()
discordia@0 272 target_link_libraries(${App_Name}
discordia@0 273 ${X11_Xinerama_LIB}
discordia@0 274 ${TARGET_LINK_LIBRARIES}
discordia@0 275 )
discordia@0 276 endif ()
discordia@0 277
discordia@0 278 endif ()
discordia@0 279
discordia@0 280 ################################################################################
discordia@0 281 # SDL
discordia@0 282 #
discordia@0 283 # Enabling SDL support enables several suboptions to make some common SDL
discordia@0 284 # extension libraries available as well.
discordia@0 285 #
discordia@0 286 # If any of the SDL libraries are not found automatically, you will need
discordia@0 287 # to set the appropriate environment variables and rerun cmake. You will
discordia@0 288 # need to remove the CMake cache before doing so.
discordia@0 289
discordia@0 290 # If you don't want to set actual environment variables before running
discordia@0 291 # CMake, then uncomment the if block below and put in the actual
discordia@0 292 # locations of your SDL installation.
discordia@0 293
discordia@0 294 option(Option_SDL_Dev "Build an SDL application." OFF)
discordia@0 295
discordia@0 296 if (Option_SDL_Dev)
discordia@0 297
discordia@0 298 # # Force SDL 1.3 only
discordia@0 299 # if (WIN32)
discordia@0 300 # set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-build")
discordia@0 301 # else ()
discordia@0 302 # set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build")
discordia@0 303 # endif ()
discordia@0 304 # add_definitions(-DSDL_NO_COMPAT)
discordia@0 305
discordia@0 306 # SDL base package
discordia@0 307 # To use a version of SDL other than your systems default, set the SDLDIR
discordia@0 308 # environment variable to the installation location of your preferred version.
discordia@0 309 find_package (SDL)
discordia@0 310 if (NOT SDL_FOUND)
discordia@0 311 message (FATAL_ERROR "SDL not found!")
discordia@0 312 endif (NOT SDL_FOUND)
discordia@0 313 include_directories(
discordia@0 314 ${SDL_INCLUDE_DIR}
discordia@0 315 ${INCLUDE_DIRECTORIES}
discordia@0 316 )
discordia@0 317 target_link_libraries(${App_Name}
discordia@0 318 ${SDL_LIBRARY}
discordia@0 319 ${TARGET_LINK_LIBRARIES}
discordia@0 320 )
discordia@0 321
discordia@0 322 # SDL_ttf
discordia@0 323 # Environment variables SDLTTFDIR and SDLDIR will be checked in that order
discordia@0 324 # and if set cmake will try to find SDL_ttf in the specified directory.
discordia@0 325 option(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF)
discordia@0 326 if (Option_SDL_Dev_SDL_ttf)
discordia@0 327 find_package (SDL_ttf)
discordia@0 328 if (NOT SDLTTF_FOUND)
discordia@0 329 message (FATAL_ERROR "SDL_ttf not found!")
discordia@0 330 endif (NOT SDLTTF_FOUND)
discordia@0 331 include_directories(
discordia@0 332 ${SDLTTF_INCLUDE_DIR}
discordia@0 333 ${INCLUDE_DIRECTORIES}
discordia@0 334 )
discordia@0 335 target_link_libraries(${App_Name}
discordia@0 336 ${SDLTTF_LIBRARY}
discordia@0 337 ${TARGET_LINK_LIBRARIES}
discordia@0 338 )
discordia@0 339 endif ()
discordia@0 340
discordia@0 341 # SDL_image
discordia@0 342 # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order
discordia@0 343 # and if set cmake will try to find SDL_image in the specified directory.
discordia@0 344 option(Option_SDL_Dev_SDL_image "Use SDL_image." OFF)
discordia@0 345 if (Option_SDL_Dev_SDL_image)
discordia@0 346 find_package (SDL_image)
discordia@0 347 if (NOT SDLIMAGE_FOUND)
discordia@0 348 message (FATAL_ERROR "SDL_image not found!")
discordia@0 349 endif (NOT SDLIMAGE_FOUND)
discordia@0 350 include_directories(
discordia@0 351 ${SDLIMAGE_INCLUDE_DIR}
discordia@0 352 ${INCLUDE_DIRECTORIES}
discordia@0 353 )
discordia@0 354 target_link_libraries(${App_Name}
discordia@0 355 ${SDLIMAGE_LIBRARY}
discordia@0 356 ${TARGET_LINK_LIBRARIES}
discordia@0 357 )
discordia@0 358 endif ()
discordia@0 359
discordia@0 360 # SDL_mixer
discordia@0 361 # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order
discordia@0 362 # and if set cmake will try to find SDL_mixer in the specified directory.
discordia@0 363 option(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF)
discordia@0 364 if (Option_SDL_Dev_SDL_mixer)
discordia@0 365 find_package (SDL_mixer)
discordia@0 366 if (NOT SDLMIXER_FOUND)
discordia@0 367 message (FATAL_ERROR "SDL_mixer not found!")
discordia@0 368 endif (NOT SDLMIXER_FOUND)
discordia@0 369 include_directories(
discordia@0 370 ${SDLMIXER_INCLUDE_DIR}
discordia@0 371 ${INCLUDE_DIRECTORIES}
discordia@0 372 )
discordia@0 373 target_link_libraries(${App_Name}
discordia@0 374 ${SDLMIXER_LIBRARY}
discordia@0 375 ${TARGET_LINK_LIBRARIES}
discordia@0 376 )
discordia@0 377 endif ()
discordia@0 378
discordia@0 379 # SDL_net
discordia@0 380 # Environment variables SDLNETDIR and SDLDIR will be checked in that order
discordia@0 381 # and if set cmake will try to find SDL_net in the specified directory.
discordia@0 382 option(Option_SDL_Dev_SDL_net "Use SDL_net." OFF)
discordia@0 383 if (Option_SDL_Dev_SDL_net)
discordia@0 384 find_package (SDL_net)
discordia@0 385 if (NOT SDLNET_FOUND)
discordia@0 386 message (FATAL_ERROR "SDL_net not found!")
discordia@0 387 endif (NOT SDLNET_FOUND)
discordia@0 388 include_directories(
discordia@0 389 ${SDLNET_INCLUDE_DIR}
discordia@0 390 ${INCLUDE_DIRECTORIES}
discordia@0 391 )
discordia@0 392 target_link_libraries(${App_Name}
discordia@0 393 ${SDLNET_LIBRARY}
discordia@0 394 ${TARGET_LINK_LIBRARIES}
discordia@0 395 )
discordia@0 396 endif ()
discordia@0 397
discordia@0 398 endif (Option_SDL_Dev)
discordia@0 399
discordia@0 400
discordia@0 401 ################################################################################
discordia@0 402
discordia@0 403 option(Option_OpenGL_Dev "Build an OpenGL Application." OFF)
discordia@0 404
discordia@0 405 if (Option_OpenGL_Dev)
discordia@0 406
discordia@0 407 find_package(OpenGL)
discordia@1 408 if (NOT OPEN_FOUND)
discordia@1 409 message (FATAL_ERROR "OpenGL not found!")
discordia@1 410 endif (NOT OPEN_FOUND)
discordia@0 411
discordia@0 412 include_directories(
discordia@1 413 ${OPENGL_INCLUDE_DIR}
discordia@0 414 ${INCLUDE_DIRECTORIES}
discordia@0 415 )
discordia@0 416
discordia@0 417 target_link_libraries(${App_Name}
discordia@1 418 ${OPENGL_LIBRARIES}
discordia@0 419 ${TARGET_LINK_LIBRARIES}
discordia@0 420 )
discordia@0 421
discordia@0 422 endif ()
discordia@0 423
discordia@0 424 ################################################################################
discordia@0 425
discordia@0 426 option(Option_OpenAL_Dev "Build an OpenAL Application." OFF)
discordia@0 427
discordia@0 428 if (Option_OpenAL_Dev)
discordia@1 429
discordia@0 430 find_package(OpenAL)
discordia@1 431 if (NOT OPENAL_FOUND)
discordia@1 432 message (FATAL_ERROR "OpenAL not found!")
discordia@1 433 endif (NOT OPENAL_FOUND)
discordia@0 434
discordia@0 435 include_directories(
discordia@1 436 ${OPENAL_INCLUDE_DIR}
discordia@0 437 ${INCLUDE_DIRECTORIES}
discordia@0 438 )
discordia@0 439
discordia@0 440 target_link_libraries(${App_Name}
discordia@1 441 ${OPENAL_LIBRARY}
discordia@0 442 ${TARGET_LINK_LIBRARIES}
discordia@0 443 )
discordia@0 444
discordia@0 445 endif ()
discordia@0 446
discordia@0 447 ################################################################################