# HG changeset patch # User Eris Caffee # Date 1293612197 21600 # Node ID 6b163267bd3ee1de5db1a0b51014716d833a57f8 Initial import diff -r 000000000000 -r 6b163267bd3e .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Wed Dec 29 02:43:17 2010 -0600 @@ -0,0 +1,5 @@ +syntax: glob + +build*/* +*~ + diff -r 000000000000 -r 6b163267bd3e CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CMakeLists.txt Wed Dec 29 02:43:17 2010 -0600 @@ -0,0 +1,440 @@ +############################################################################### +# +# A generalized cmake file for developing cross-platform games. +# +# Copyright (C) 2010 Sarah Eris Horsley Caffee +# +# This is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# +# Instructions: +# This cmake file assumes that your source files are laid in out in the +# following manner: +# +# project_dir\ Top level directory of the project. +# |---include\ Header files are here. +# |---src\ Source files are here. +# |---build\ Binaries/objects go here. Run cmake from here. +# !---cmake\ +# | |---modules\ Custom cmake include files, if any, go here. +# |---CMakeLists.txt This file. +# +# You may have more directories, of course, but these are assumed. You probably +# want more than one build directory. I normally have build-linux\ +# and build-windows\ directories. +# +# Set the App_Name variable, below, to the name of your application and you +# are ready to start. Run ccmake, or cmake-gui from within your build +# directory, choose the options you need, such as enabling SDL, and you +# should be good to go. +# +# You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON) command if you +# need to debug the actual makefile that is generated. +# +# On windows, you may need to set the SDLDIR environment variable to the location +# of your SDL installation before you run cmake-gui. +# +# When writing path names on Windows, such as when manually specifiying a +# file or directory name, either use unix-style forward slashes '/' in the +# path names or use double backslashes. If you use a single backslash as the +# path name seperator, then cmake will interpret it as an esacpe sequence. +# Thus, write "C:/source" or "C:\\source" instead of "C:\source". It's +# probably best to use forward slashes in case to ever have a situation +# where cmake needs to do recursive processing: each level of cmake will +# strip out one of the slashes, so if there are two lev3els of cmake you +# need to write \\\, three levels requires \\\\, etc. +# +# Note that some of the cmake support scripts that find libraries for you +# can be controlled by environment variables. For example, you can set the +# SDLDIR environment variable before running cmake in order to point to +# a different version of SDL than your systems default copy. This is useful +# for trying out cutting edge versions of libraries without installing them +# system wide. + +cmake_minimum_required (VERSION 2.6 FATAL_ERROR) +#set (CMAKE_VERBOSE_MAKEFILE ON) + +# Name your program! +set (App_Name "") +if (App_Name STREQUAL "") + message (FATAL_ERROR "You must set the App_Name variable!") +endif () + +# Every project must have a name. +project (${App_Name}) + + +################################################################################ +# Special options + + +################################################################################ +# Ensure that we are not building in our source directories. + +set (Build_Dir_OK "TRUE") +string (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR}) +if (In_Sub_Dir) + string (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR}) + if (NOT In_Build_Dir) + set (Build_Dir_OK "FALSE") + endif () +endif () + +if (NOT Build_Dir_OK) + 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'.") +endif () + + +################################################################################ +# Set up the basic build environment +# A build type defines which options are passed to the compiler, and there are +# several that CMake defines by default. It does not set one by default, though +# so we need to set the build type manually here, and we are setting it to the +# generally useful "Release with debug info" + +if (CMAKE_BUILD_TYPE STREQUAL "") + # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This messes up + # differentiation between debug and release builds. + set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) +endif () + + +################################################################################ +# When using GCC turn on lots of warnings. +# Some other options to consider: +# C++ -Weffc++ +# C -std=gnu99 -std=c99 + +if (CMAKE_COMPILER_IS_GNUCXX) + add_definitions(-pedantic -Wall) +endif () + + +################################################################################ + +option(Option_Profile_Program "Build for gprof profiling." OFF) +if (Option_Profile_Program) + add_definitions(-pg) + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") +endif () + + +################################################################################ +# The core project files + +file (GLOB SRCS src/*.c src/*.cpp) +file (GLOB HDRS include/*.h include/*.hpp) + +# The directories that contain the libraries we will be linking against. +# This must come before the ADD_EXECUTABLE directive. +link_directories ( + ) + +# The directories that contain the include files our programs use. +# This must come before the ADD_EXECUTABLE directive. +include_directories ( + ${CMAKE_SOURCE_DIR}/include + ) + +# Define the executable program file we are creating. We must list all of +# the source files. +if (WIN32) + add_executable (${App_Name} WIN32 + ${SRCS} + ${HDRS} + ) +else () + add_executable (${App_Name} + ${SRCS} + ${HDRS} + ) +endif () + +# Although we listed the library directories above, we also need to list the +# individual libraries we will be linking against. +target_link_libraries (${App_Name} +) + + +# # An example for a unix library named utils with a test driver program. + +# set (SRCS_utils +# src/utils.cpp +# include/utils.h +# ) + +# include_directories ( +# ${PROJECT_SOURCE_DIR}/include +# ) + +# # Build both static and shared libraries +# # The target properties are needed because, by default, the output name +# # will be the name in the add_library command, and we need to have different +# # names in the two commands for the shared and static versions, even though +# # we want the final files to have the same names with different extensions. +# # +# # The prefix is needed mostly in case we build on windows, which has no prefix +# # by default. +# # +# # The clean_direct_output option makes sure that the two lib builds don't +# # clobber each others temp files since they are being built from the same +# # sources. + +# add_library (utils SHARED +# ${SRCS_utils} +# ) +# set_target_properties (utils PROPERTIES OUTPUT_NAME "utils") +# set_target_properties (utils PROPERTIES PREFIX "lib") +# set_target_properties (utils PROPERTIES CLEAN_DIRECT_OUTPUT 1) + +# add_library (utils-static STATIC +# ${SRCS_utils} +# ) +# set_target_properties (utils-static PROPERTIES OUTPUT_NAME "utils") +# set_target_properties (utils-static PROPERTIES PREFIX "lib") +# set_target_properties (utils-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) + +# # Build a test application. + +# add_executable (test +# src/main.cpp +# ) + +# target_link_libraries (test +# utils +# ) + + +################################################################################ +# X11 +# +# Note that the FindX11.cmake package does _not_ include most X extensions +# in the X11_LIBRARIES variable, although it does pick up their header files +# in the X11_INCLUDE_DIR variable. +# +# To link a program with extensions, such as Xrandr, or Xv, you must manually +# update the target_link_libraries to include the appropriate library variable. +# ${X11_Xrandr_LIB} is an example. See the FindX11.cmake file for a complete +# list of availble variables. +# + +option(Option_X11_Dev "Build an X11 Application." OFF) + +if (Option_X11_Dev) + + option(Option_Xrandr "Use Xrandr" OFF) + option(Option_Xinerama "Use Xinerama" OFF) + + + ######################################## + find_package(X11) + if (NOT X11_FOUND) + message (FATAL_ERROR "X11 not found!") + endif () + + include_directories( + ${X11_INCLUDE_DIR} + ${INCLUDE_DIRECTORIES} + ) + + target_link_libraries(${App_Name} + ${X11_LIBRARIES} + ${TARGET_LINK_LIBRARIES} + ) + + ######################################## + if (Option_Xrandr) + if (NOT X11_Xrandr_FOUND) + message (FATAL_ERRO "Xrandr not found!") + endif () + target_link_libraries(${App_Name} + ${X11_Xrandr_LIB} + ${TARGET_LINK_LIBRARIES} + ) + endif () + + ######################################## + if (Option_Xinerama) + if (NOT X11_Xinerama_FOUND) + message (FATAL_ERRO "Xinerama not found!") + endif () + target_link_libraries(${App_Name} + ${X11_Xinerama_LIB} + ${TARGET_LINK_LIBRARIES} + ) + endif () + +endif () + +################################################################################ +# SDL +# +# Enabling SDL support enables several suboptions to make some common SDL +# extension libraries available as well. +# +# If any of the SDL libraries are not found automatically, you will need +# to set the appropriate environment variables and rerun cmake. You will +# need to remove the CMake cache before doing so. + +# If you don't want to set actual environment variables before running +# CMake, then uncomment the if block below and put in the actual +# locations of your SDL installation. + +option(Option_SDL_Dev "Build an SDL application." OFF) + +if (Option_SDL_Dev) + + # # Force SDL 1.3 only + # if (WIN32) + # set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-build") + # else () + # set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build") + # endif () + # add_definitions(-DSDL_NO_COMPAT) + + # SDL base package + # To use a version of SDL other than your systems default, set the SDLDIR + # environment variable to the installation location of your preferred version. + find_package (SDL) + if (NOT SDL_FOUND) + message (FATAL_ERROR "SDL not found!") + endif (NOT SDL_FOUND) + include_directories( + ${SDL_INCLUDE_DIR} + ${INCLUDE_DIRECTORIES} + ) + target_link_libraries(${App_Name} + ${SDL_LIBRARY} + ${TARGET_LINK_LIBRARIES} + ) + + # SDL_ttf + # Environment variables SDLTTFDIR and SDLDIR will be checked in that order + # and if set cmake will try to find SDL_ttf in the specified directory. + option(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF) + if (Option_SDL_Dev_SDL_ttf) + find_package (SDL_ttf) + if (NOT SDLTTF_FOUND) + message (FATAL_ERROR "SDL_ttf not found!") + endif (NOT SDLTTF_FOUND) + include_directories( + ${SDLTTF_INCLUDE_DIR} + ${INCLUDE_DIRECTORIES} + ) + target_link_libraries(${App_Name} + ${SDLTTF_LIBRARY} + ${TARGET_LINK_LIBRARIES} + ) + endif () + + # SDL_image + # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order + # and if set cmake will try to find SDL_image in the specified directory. + option(Option_SDL_Dev_SDL_image "Use SDL_image." OFF) + if (Option_SDL_Dev_SDL_image) + find_package (SDL_image) + if (NOT SDLIMAGE_FOUND) + message (FATAL_ERROR "SDL_image not found!") + endif (NOT SDLIMAGE_FOUND) + include_directories( + ${SDLIMAGE_INCLUDE_DIR} + ${INCLUDE_DIRECTORIES} + ) + target_link_libraries(${App_Name} + ${SDLIMAGE_LIBRARY} + ${TARGET_LINK_LIBRARIES} + ) + endif () + + # SDL_mixer + # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order + # and if set cmake will try to find SDL_mixer in the specified directory. + option(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF) + if (Option_SDL_Dev_SDL_mixer) + find_package (SDL_mixer) + if (NOT SDLMIXER_FOUND) + message (FATAL_ERROR "SDL_mixer not found!") + endif (NOT SDLMIXER_FOUND) + include_directories( + ${SDLMIXER_INCLUDE_DIR} + ${INCLUDE_DIRECTORIES} + ) + target_link_libraries(${App_Name} + ${SDLMIXER_LIBRARY} + ${TARGET_LINK_LIBRARIES} + ) + endif () + + # SDL_net + # Environment variables SDLNETDIR and SDLDIR will be checked in that order + # and if set cmake will try to find SDL_net in the specified directory. + option(Option_SDL_Dev_SDL_net "Use SDL_net." OFF) + if (Option_SDL_Dev_SDL_net) + find_package (SDL_net) + if (NOT SDLNET_FOUND) + message (FATAL_ERROR "SDL_net not found!") + endif (NOT SDLNET_FOUND) + include_directories( + ${SDLNET_INCLUDE_DIR} + ${INCLUDE_DIRECTORIES} + ) + target_link_libraries(${App_Name} + ${SDLNET_LIBRARY} + ${TARGET_LINK_LIBRARIES} + ) + endif () + +endif (Option_SDL_Dev) + + +################################################################################ + +option(Option_OpenGL_Dev "Build an OpenGL Application." OFF) + +if (Option_OpenGL_Dev) + + find_package(OpenGL) + + include_directories( + ${OpenGL_INCLUDE_DIR} + ${INCLUDE_DIRECTORIES} + ) + + target_link_libraries(${App_Name} + ${OpenGL_LIBRARIES} + ${TARGET_LINK_LIBRARIES} + ) + +endif () + +################################################################################ + +option(Option_OpenAL_Dev "Build an OpenAL Application." OFF) + +if (Option_OpenAL_Dev) + find_package(OpenAL) + + include_directories( + ${OpenAL_INCLUDE_DIR} + ${INCLUDE_DIRECTORIES} + ) + + target_link_libraries(${App_Name} + ${OpenAL_LIBRARIES} + ${TARGET_LINK_LIBRARIES} + ) + +endif () + +################################################################################