diff CMakeLists.txt @ 0:6b163267bd3e

Initial import
author Eris Caffee <discordia@eldalin.com>
date Wed, 29 Dec 2010 02:43:17 -0600
parents
children 9c54994a2635
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/CMakeLists.txt	Wed Dec 29 02:43:17 2010 -0600
     1.3 @@ -0,0 +1,440 @@
     1.4 +###############################################################################
     1.5 +#
     1.6 +# A generalized cmake file for developing cross-platform games.
     1.7 +#
     1.8 +# Copyright (C) 2010 Sarah Eris Horsley Caffee
     1.9 +#
    1.10 +# This is free software: you can redistribute it and/or modify
    1.11 +# it under the terms of the GNU General Public License as published by
    1.12 +# the Free Software Foundation, either version 3 of the License, or
    1.13 +# (at your option) any later version.
    1.14 +#
    1.15 +# This program is distributed in the hope that it will be useful,
    1.16 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.18 +# GNU General Public License for more details.
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License
    1.21 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 +#
    1.23 +#
    1.24 +# Instructions:
    1.25 +# This cmake file assumes that your source files are laid in out in the 
    1.26 +# following manner:
    1.27 +#
    1.28 +#   project_dir\		Top level directory of the project.
    1.29 +#     |---include\		Header files are here.
    1.30 +#     |---src\			Source files are here.
    1.31 +#     |---build\		Binaries/objects go here.  Run cmake from here.
    1.32 +#     !---cmake\
    1.33 +#     |     |---modules\        Custom cmake include files, if any, go here.
    1.34 +#     |---CMakeLists.txt	This file.
    1.35 +#
    1.36 +# You may have more directories, of course, but these are assumed.  You probably
    1.37 +# want more than one build directory.  I normally have build-linux\ 
    1.38 +# and build-windows\ directories.
    1.39 +#
    1.40 +# Set the App_Name variable, below, to the name of your application and you
    1.41 +# are ready to start.  Run ccmake, or cmake-gui from within your build
    1.42 +# directory, choose the options you need, such as enabling SDL, and you 
    1.43 +# should be good to go.
    1.44 +#
    1.45 +# You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON) command if you
    1.46 +# need to debug the actual makefile that is generated.
    1.47 +#
    1.48 +# On windows, you may need to set the SDLDIR environment variable to the location
    1.49 +# of your SDL installation before you run cmake-gui.
    1.50 +#
    1.51 +# When writing path names on Windows, such as when manually specifiying a 
    1.52 +# file or directory name, either use unix-style forward slashes '/' in the
    1.53 +# path names or use double backslashes. If you use a single backslash as the
    1.54 +# path name seperator, then cmake will interpret  it as an esacpe sequence.
    1.55 +# Thus, write "C:/source" or "C:\\source" instead of "C:\source".  It's
    1.56 +# probably best to use forward slashes in case to ever have a situation
    1.57 +# where cmake needs to do recursive processing: each level of cmake will
    1.58 +# strip out one of the slashes, so if there are two lev3els of cmake you
    1.59 +# need to write \\\, three levels requires \\\\, etc.
    1.60 +#
    1.61 +# Note that some of the cmake support scripts that find libraries for you
    1.62 +# can be controlled by environment variables.  For example, you can set the
    1.63 +# SDLDIR environment variable before running cmake in order to point to
    1.64 +# a different version of SDL than your systems default copy. This is useful
    1.65 +# for trying out cutting edge versions of libraries without installing them
    1.66 +# system wide.
    1.67 +
    1.68 +cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
    1.69 +#set (CMAKE_VERBOSE_MAKEFILE ON)
    1.70 +
    1.71 +# Name your program!
    1.72 +set (App_Name "")
    1.73 +if (App_Name STREQUAL "") 
    1.74 +  message (FATAL_ERROR "You must set the App_Name variable!")
    1.75 +endif ()
    1.76 +
    1.77 +# Every project must have a name.
    1.78 +project (${App_Name})
    1.79 +
    1.80 +
    1.81 +################################################################################
    1.82 +# Special options
    1.83 +
    1.84 +
    1.85 +################################################################################
    1.86 +# Ensure that we are not building in our source directories.
    1.87 +
    1.88 +set (Build_Dir_OK "TRUE")
    1.89 +string (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR})
    1.90 +if (In_Sub_Dir)
    1.91 +  string (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR})
    1.92 +  if (NOT In_Build_Dir)
    1.93 +    set (Build_Dir_OK "FALSE")
    1.94 +  endif ()
    1.95 +endif ()
    1.96 +
    1.97 +if (NOT Build_Dir_OK)
    1.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'.")
    1.99 +endif ()
   1.100 +
   1.101 +
   1.102 +################################################################################
   1.103 +# Set up the basic build environment
   1.104 +# A build type defines which options are passed to the compiler, and there are
   1.105 +# several that CMake defines by default. It does not set one by default, though
   1.106 +# so we need to set the build type manually here, and we are setting it to the
   1.107 +# generally useful "Release with debug info"
   1.108 +
   1.109 +if (CMAKE_BUILD_TYPE STREQUAL "")
   1.110 +  # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This messes up
   1.111 +  # differentiation between debug and release builds.               
   1.112 +  set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
   1.113 +endif ()
   1.114 +
   1.115 +
   1.116 +################################################################################
   1.117 +# When using GCC turn on lots of warnings.
   1.118 +# Some other options to consider:
   1.119 +#   C++  -Weffc++
   1.120 +#   C    -std=gnu99 -std=c99
   1.121 +
   1.122 +if (CMAKE_COMPILER_IS_GNUCXX)
   1.123 +  add_definitions(-pedantic -Wall)
   1.124 +endif ()
   1.125 +
   1.126 +
   1.127 +################################################################################
   1.128 +
   1.129 +option(Option_Profile_Program "Build for gprof profiling." OFF)
   1.130 +if (Option_Profile_Program)
   1.131 +  add_definitions(-pg)
   1.132 +  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
   1.133 +endif ()
   1.134 +
   1.135 +
   1.136 +################################################################################
   1.137 +# The core project files 
   1.138 +
   1.139 +file (GLOB SRCS src/*.c src/*.cpp)
   1.140 +file (GLOB HDRS include/*.h include/*.hpp)
   1.141 +
   1.142 +# The directories that contain the libraries we will be linking against.
   1.143 +# This must come before the ADD_EXECUTABLE directive.
   1.144 +link_directories (
   1.145 +  )
   1.146 +
   1.147 +# The directories that contain the include files our programs use.
   1.148 +# This must come before the ADD_EXECUTABLE directive.
   1.149 +include_directories (
   1.150 +  ${CMAKE_SOURCE_DIR}/include
   1.151 +  )
   1.152 +
   1.153 +# Define the executable program file we are creating.  We must list all of
   1.154 +# the source files.
   1.155 +if (WIN32)
   1.156 +  add_executable (${App_Name} WIN32
   1.157 +    ${SRCS}
   1.158 +    ${HDRS}
   1.159 +    )
   1.160 +else ()
   1.161 +  add_executable (${App_Name}
   1.162 +    ${SRCS}
   1.163 +    ${HDRS}
   1.164 +    )
   1.165 +endif ()
   1.166 +
   1.167 +# Although we listed the library  directories above, we also need to list the
   1.168 +# individual libraries we will be linking against.
   1.169 +target_link_libraries (${App_Name}
   1.170 +)
   1.171 +
   1.172 +
   1.173 +# # An example for a unix library named utils with a test driver program.
   1.174 +
   1.175 +# set (SRCS_utils
   1.176 +#   src/utils.cpp
   1.177 +#   include/utils.h
   1.178 +# )
   1.179 +
   1.180 +# include_directories (
   1.181 +#   ${PROJECT_SOURCE_DIR}/include
   1.182 +# )
   1.183 +
   1.184 +# # Build both static and shared libraries
   1.185 +# # The target properties are needed because, by default, the output name
   1.186 +# # will be the name in the add_library command, and we need to have different
   1.187 +# # names in the two commands for the shared and static versions, even though
   1.188 +# # we want the final files to have the same names with different extensions.
   1.189 +# #
   1.190 +# # The prefix is needed mostly in case we build on windows, which has no prefix
   1.191 +# # by default.
   1.192 +# # 
   1.193 +# # The clean_direct_output option makes sure that the two lib builds don't
   1.194 +# # clobber each others temp files since they are being built from the same
   1.195 +# # sources.
   1.196 +
   1.197 +# add_library (utils SHARED
   1.198 +#   ${SRCS_utils}
   1.199 +# )
   1.200 +# set_target_properties (utils PROPERTIES OUTPUT_NAME "utils")
   1.201 +# set_target_properties (utils PROPERTIES PREFIX "lib")
   1.202 +# set_target_properties (utils PROPERTIES CLEAN_DIRECT_OUTPUT 1)
   1.203 +
   1.204 +# add_library (utils-static STATIC
   1.205 +#   ${SRCS_utils}
   1.206 +# )
   1.207 +# set_target_properties (utils-static PROPERTIES OUTPUT_NAME "utils")
   1.208 +# set_target_properties (utils-static PROPERTIES PREFIX "lib")
   1.209 +# set_target_properties (utils-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
   1.210 +
   1.211 +# # Build a test application.
   1.212 +
   1.213 +# add_executable (test
   1.214 +#   src/main.cpp
   1.215 +# )
   1.216 +
   1.217 +# target_link_libraries (test
   1.218 +#   utils
   1.219 +# )
   1.220 +
   1.221 +
   1.222 +################################################################################
   1.223 +# X11
   1.224 +#
   1.225 +# Note that the FindX11.cmake package does _not_ include most X extensions
   1.226 +# in the X11_LIBRARIES variable, although it does pick up their header files
   1.227 +# in the X11_INCLUDE_DIR variable.
   1.228 +#
   1.229 +# To link a program with extensions, such as Xrandr, or Xv, you must manually
   1.230 +# update the target_link_libraries to include the appropriate library variable.
   1.231 +# ${X11_Xrandr_LIB} is an example.  See the FindX11.cmake file for a complete
   1.232 +# list of availble variables.
   1.233 +#
   1.234 +
   1.235 +option(Option_X11_Dev "Build an X11 Application." OFF)
   1.236 +
   1.237 +if (Option_X11_Dev)
   1.238 +
   1.239 +  option(Option_Xrandr "Use Xrandr" OFF)
   1.240 +  option(Option_Xinerama "Use Xinerama" OFF)
   1.241 +
   1.242 +
   1.243 +  ########################################
   1.244 +  find_package(X11)
   1.245 +  if (NOT X11_FOUND)
   1.246 +    message (FATAL_ERROR "X11 not found!")
   1.247 +  endif ()
   1.248 +
   1.249 +  include_directories(
   1.250 +    ${X11_INCLUDE_DIR}
   1.251 +    ${INCLUDE_DIRECTORIES}
   1.252 +    )
   1.253 +
   1.254 +  target_link_libraries(${App_Name}
   1.255 +    ${X11_LIBRARIES}
   1.256 +    ${TARGET_LINK_LIBRARIES}
   1.257 +    )
   1.258 +
   1.259 +  ########################################
   1.260 +  if (Option_Xrandr)
   1.261 +    if (NOT X11_Xrandr_FOUND)
   1.262 +      message (FATAL_ERRO "Xrandr not found!")
   1.263 +    endif ()
   1.264 +    target_link_libraries(${App_Name}
   1.265 +      ${X11_Xrandr_LIB}
   1.266 +      ${TARGET_LINK_LIBRARIES}
   1.267 +      )
   1.268 +  endif ()
   1.269 +
   1.270 +  ########################################
   1.271 +  if (Option_Xinerama)
   1.272 +    if (NOT X11_Xinerama_FOUND)
   1.273 +      message (FATAL_ERRO "Xinerama not found!")
   1.274 +    endif ()
   1.275 +    target_link_libraries(${App_Name}
   1.276 +      ${X11_Xinerama_LIB}
   1.277 +      ${TARGET_LINK_LIBRARIES}
   1.278 +      )
   1.279 +  endif ()
   1.280 +
   1.281 +endif ()
   1.282 +
   1.283 +################################################################################
   1.284 +# SDL
   1.285 +#
   1.286 +# Enabling SDL support enables several suboptions to make some common SDL
   1.287 +# extension libraries available as well. 
   1.288 +#
   1.289 +# If any of the SDL libraries are not found automatically, you will need
   1.290 +# to set the appropriate environment variables and rerun cmake.  You will
   1.291 +# need to remove the CMake cache before doing so.
   1.292 +
   1.293 +# If you don't want to set actual environment variables before running
   1.294 +# CMake, then uncomment the if block below and put in the actual
   1.295 +# locations of your SDL installation.
   1.296 +
   1.297 +option(Option_SDL_Dev "Build an SDL application." OFF)
   1.298 +
   1.299 +if (Option_SDL_Dev)
   1.300 +
   1.301 +  # # Force SDL 1.3 only
   1.302 +  # if (WIN32)
   1.303 +  #   set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-build")
   1.304 +  # else ()
   1.305 +  #   set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build")
   1.306 +  # endif ()
   1.307 +  # add_definitions(-DSDL_NO_COMPAT)
   1.308 +
   1.309 +  # SDL base package
   1.310 +  # To use a version of SDL other than your systems default, set the SDLDIR
   1.311 +  # environment variable to the installation location of your preferred version.
   1.312 +  find_package (SDL)
   1.313 +  if (NOT SDL_FOUND)
   1.314 +    message (FATAL_ERROR "SDL not found!")
   1.315 +  endif (NOT SDL_FOUND)
   1.316 +  include_directories(
   1.317 +    ${SDL_INCLUDE_DIR}
   1.318 +    ${INCLUDE_DIRECTORIES}
   1.319 +    )
   1.320 +  target_link_libraries(${App_Name}
   1.321 +    ${SDL_LIBRARY}
   1.322 +    ${TARGET_LINK_LIBRARIES}
   1.323 +    )
   1.324 +
   1.325 +  # SDL_ttf
   1.326 +  # Environment variables SDLTTFDIR and SDLDIR will be checked in that order
   1.327 +  # and if set cmake will try to find SDL_ttf in the specified directory.
   1.328 +  option(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF)
   1.329 +  if (Option_SDL_Dev_SDL_ttf)
   1.330 +    find_package (SDL_ttf)
   1.331 +    if (NOT SDLTTF_FOUND)
   1.332 +      message (FATAL_ERROR "SDL_ttf not found!")
   1.333 +    endif (NOT SDLTTF_FOUND)
   1.334 +    include_directories(
   1.335 +      ${SDLTTF_INCLUDE_DIR}
   1.336 +      ${INCLUDE_DIRECTORIES}
   1.337 +      )
   1.338 +    target_link_libraries(${App_Name}
   1.339 +      ${SDLTTF_LIBRARY}
   1.340 +      ${TARGET_LINK_LIBRARIES}
   1.341 +      )
   1.342 +  endif ()
   1.343 +
   1.344 +  # SDL_image
   1.345 +  # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order
   1.346 +  # and if set cmake will try to find SDL_image in the specified directory.
   1.347 +  option(Option_SDL_Dev_SDL_image "Use SDL_image." OFF)
   1.348 +  if (Option_SDL_Dev_SDL_image)
   1.349 +    find_package (SDL_image)
   1.350 +    if (NOT SDLIMAGE_FOUND)
   1.351 +      message (FATAL_ERROR "SDL_image not found!")
   1.352 +    endif (NOT SDLIMAGE_FOUND)
   1.353 +    include_directories(
   1.354 +      ${SDLIMAGE_INCLUDE_DIR}
   1.355 +      ${INCLUDE_DIRECTORIES}
   1.356 +      )
   1.357 +    target_link_libraries(${App_Name}
   1.358 +      ${SDLIMAGE_LIBRARY}
   1.359 +      ${TARGET_LINK_LIBRARIES}
   1.360 +      )
   1.361 +  endif ()
   1.362 +
   1.363 +  # SDL_mixer
   1.364 +  # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order
   1.365 +  # and if set cmake will try to find SDL_mixer in the specified directory.
   1.366 +  option(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF)
   1.367 +  if (Option_SDL_Dev_SDL_mixer)
   1.368 +    find_package (SDL_mixer)
   1.369 +    if (NOT SDLMIXER_FOUND)
   1.370 +      message (FATAL_ERROR "SDL_mixer not found!")
   1.371 +    endif (NOT SDLMIXER_FOUND)
   1.372 +    include_directories(
   1.373 +      ${SDLMIXER_INCLUDE_DIR}
   1.374 +      ${INCLUDE_DIRECTORIES}
   1.375 +      )
   1.376 +    target_link_libraries(${App_Name}
   1.377 +      ${SDLMIXER_LIBRARY}
   1.378 +      ${TARGET_LINK_LIBRARIES}
   1.379 +      )
   1.380 +  endif ()
   1.381 +
   1.382 +  # SDL_net
   1.383 +  # Environment variables SDLNETDIR and SDLDIR will be checked in that order
   1.384 +  # and if set cmake will try to find SDL_net in the specified directory.
   1.385 +  option(Option_SDL_Dev_SDL_net "Use SDL_net." OFF)
   1.386 +  if (Option_SDL_Dev_SDL_net)
   1.387 +    find_package (SDL_net)
   1.388 +    if (NOT SDLNET_FOUND)
   1.389 +      message (FATAL_ERROR "SDL_net not found!")
   1.390 +    endif (NOT SDLNET_FOUND)
   1.391 +    include_directories(
   1.392 +      ${SDLNET_INCLUDE_DIR}
   1.393 +      ${INCLUDE_DIRECTORIES}
   1.394 +      )
   1.395 +    target_link_libraries(${App_Name}
   1.396 +      ${SDLNET_LIBRARY}
   1.397 +      ${TARGET_LINK_LIBRARIES}
   1.398 +      )
   1.399 +  endif ()
   1.400 +
   1.401 +endif (Option_SDL_Dev)
   1.402 +
   1.403 +
   1.404 +################################################################################
   1.405 +
   1.406 +option(Option_OpenGL_Dev "Build an OpenGL Application." OFF)
   1.407 +
   1.408 +if (Option_OpenGL_Dev)
   1.409 +
   1.410 +  find_package(OpenGL)
   1.411 +
   1.412 +  include_directories(
   1.413 +    ${OpenGL_INCLUDE_DIR}
   1.414 +    ${INCLUDE_DIRECTORIES}
   1.415 +    )
   1.416 +
   1.417 +  target_link_libraries(${App_Name}
   1.418 +    ${OpenGL_LIBRARIES}
   1.419 +    ${TARGET_LINK_LIBRARIES}
   1.420 +    )
   1.421 +
   1.422 +endif ()
   1.423 +
   1.424 +################################################################################
   1.425 +
   1.426 +option(Option_OpenAL_Dev "Build an OpenAL Application." OFF)
   1.427 +
   1.428 +if (Option_OpenAL_Dev)
   1.429 +  find_package(OpenAL)
   1.430 +
   1.431 +  include_directories(
   1.432 +    ${OpenAL_INCLUDE_DIR}
   1.433 +    ${INCLUDE_DIRECTORIES}
   1.434 +    )
   1.435 +
   1.436 +  target_link_libraries(${App_Name}
   1.437 +    ${OpenAL_LIBRARIES}
   1.438 +    ${TARGET_LINK_LIBRARIES}
   1.439 +    )
   1.440 +
   1.441 +endif ()
   1.442 +
   1.443 +################################################################################