# HG changeset patch # User Eris Caffee # Date 1287715091 18000 # Node ID d3d9c758a0ee4bb341e231a6088be10bb2044643 # Parent 837f5d6c4a72af04e0992fd1f713a70d9a3a2598 Published version diff -r 837f5d6c4a72 -r d3d9c758a0ee CMakeLists.txt --- a/CMakeLists.txt Thu Oct 14 00:43:26 2010 -0500 +++ b/CMakeLists.txt Thu Oct 21 21:38:11 2010 -0500 @@ -2,8 +2,23 @@ # # A generalized cmake file for developing cross-platform games. # -# (c) 2010 Sarah Eris Horsley Caffee - +# Copyright (c) 2010 Eris Caffee +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# # Instructions: # This cmake file assumes that your source files are laid in out in the # following manner: @@ -21,16 +36,15 @@ # and build-windows\ directories. # # Set the App_Name variable, below, to the name of your application and you -# are ready to start. Run cmake, ccmake, or cmake-gui from within your build -# directory, choose the options you need, such as enabling SDL or OGRE, -# and you should be good to go. +# 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 +# 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 modify some of the variables farther down in -# this file so that cmake knows where SDL or other support libraries -# and their header files can be found on the system. +# 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 @@ -42,7 +56,6 @@ # 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 @@ -50,42 +63,34 @@ # for trying out cutting edge versions of libraries without installing them # system wide. - - -# Probably not needed, but it may save someone else a headache someday. -CMAKE_MINIMUM_REQUIRED (VERSION 2.6) - - +cmake_minimum_required (VERSION 2.6 FATAL_ERROR) +#set (CMAKE_VERBOSE_MAKEFILE ON) # Name your program! -SET (App_Name "check-sdl-version") -IF (App_Name STREQUAL "") - MESSAGE (FATAL_ERROR "You must set the App_Name variable!") -ENDIF () - - -#SET (CMAKE_VERBOSE_MAKEFILE ON) - +set (App_Name "check-sdl-version") +if (App_Name STREQUAL "") + message (FATAL_ERROR "You must set the App_Name variable!") +endif () # Every project must have a name. -PROJECT (${App_Name}) +project (${App_Name}) ################################################################################ # 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 () +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 () +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 () ################################################################################ @@ -95,40 +100,49 @@ # 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 "") +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 () + set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) +endif () - + ################################################################################ # The core project files -FILE (GLOB SRCS src/*.c src/*.cpp) -FILE (GLOB HDRS include/*.h include/*.hpp) +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 ( -) +link_directories ( + ) # The directories that contain the include files our programs use. # This must come before the ADD_EXECUTABLE directive. -INCLUDE_DIRECTORIES ( - ${PROJECT_SOURCE_DIR}/include -) +include_directories ( + ${CMAKE_SOURCE_DIR}/include + ) # Define the executable program file we are creating. We must list all of -# the source files. -ADD_EXECUTABLE (${App_Name} - ${SRCS} - ${HDRS} -) +# the source files. If we are copmiling on Windows, we set the executable +# to have the WIN32 attribute, which makes it a Windows GUI program. Without +# this attribute it would be compiled into a console application. +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} +target_link_libraries (${App_Name} ) @@ -142,103 +156,37 @@ # to set the appropriate environment variables and rerun cmake. You will # need to remove the CMake cache before doing so. -OPTION (Option_SDL_Dev "Build an SDL application." OFF) +# 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. -IF (Option_SDL_Dev) +# if (WIN32) +# set (ENV{SDLDIR} "c:\gamedev\deps\sdl\SDL-build") +# else () +# set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build") +# endif () + +option(Option_SDL_Dev "Build an SDL application." OFF) + +if (Option_SDL_Dev) # 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( + 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} + 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 (Option_SDL_Dev_SDL_ttf) - - # 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 (Option_SDL_Dev_SDL_image) - - # 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 (Option_SDL_Dev_SDL_mixer) - - # 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 (Option_SDL_Dev_SDL_net) - -ENDIF (Option_SDL_Dev) +endif (Option_SDL_Dev) ################################################################################ diff -r 837f5d6c4a72 -r d3d9c758a0ee src/main.c --- a/src/main.c Thu Oct 14 00:43:26 2010 -0500 +++ b/src/main.c Thu Oct 21 21:38:11 2010 -0500 @@ -1,27 +1,66 @@ /****************************************************************************** // // check-sdl-version -// Copyright (c) 2010 Sarah Eris Horsley Caffee +// Copyright (c) 2010 Eris Caffee +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// // // Just a quick test program to verify SDL installation and to use as an // example for learning to use CMake. -// -// This program may be freely copied, distributed, and used for any purpose. // ******************************************************************************/ #include #include + +/* Redirect I/O on Windows to a file. We would not need to do this in a + console app. */ +#ifdef WIN32 +#include +#include +void redirect_stdio(void) + { + /* We must freopen stderr to get it to have a valid fd before we can + dup it to stdout. This creates a file on disk, which we then delete. */ + freopen("stdout.txt", "w", stdout); + freopen("stderr.txt", "w", stderr); + if (_dup2(_fileno(stdout), _fileno(stderr)) != 0) + fprintf(stdout, "_dup2 failed!\n"); + DeleteFile("stderr.txt"); + } +#endif + int main(int argc, char **argv) { SDL_version compiled; const SDL_version * linked; +#ifdef WIN32 + redirect_stdio(); +#endif + printf("\t\t\tCompiled\t\tLinked\n"); SDL_VERSION(&compiled); linked = SDL_Linked_Version(); - printf("SDL version\t\t%d.%d.%d\t\t\t%d.%d.%d\n", compiled.major, compiled.minor, compiled.patch, + printf("SDL version\t\t%d.%d.%d\t\t\t%d.%d.%d\n", + compiled.major, compiled.minor, compiled.patch, linked->major, linked->minor, linked->patch); + + return 0; }