Mercurial > check-sdl-version
changeset 3:d3d9c758a0ee tip
Published version
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Thu, 21 Oct 2010 21:38:11 -0500 |
parents | 837f5d6c4a72 |
children | |
files | CMakeLists.txt src/main.c |
diffstat | 2 files changed, 129 insertions(+), 142 deletions(-) [+] |
line diff
1.1 --- a/CMakeLists.txt Thu Oct 14 00:43:26 2010 -0500 1.2 +++ b/CMakeLists.txt Thu Oct 21 21:38:11 2010 -0500 1.3 @@ -2,8 +2,23 @@ 1.4 # 1.5 # A generalized cmake file for developing cross-platform games. 1.6 # 1.7 -# (c) 2010 Sarah Eris Horsley Caffee 1.8 - 1.9 +# Copyright (c) 2010 Eris Caffee 1.10 +# Permission is hereby granted, free of charge, to any person obtaining a copy 1.11 +# of this software and associated documentation files (the "Software"), to deal 1.12 +# in the Software without restriction, including without limitation the rights 1.13 +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1.14 +# copies of the Software, and to permit persons to whom the Software is 1.15 +# furnished to do so, subject to the following conditions: 1.16 +# The above copyright notice and this permission notice shall be included in 1.17 +# all copies or substantial portions of the Software. 1.18 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.19 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.20 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1.21 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1.22 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1.23 +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1.24 +# THE SOFTWARE. 1.25 +# 1.26 # Instructions: 1.27 # This cmake file assumes that your source files are laid in out in the 1.28 # following manner: 1.29 @@ -21,16 +36,15 @@ 1.30 # and build-windows\ directories. 1.31 # 1.32 # Set the App_Name variable, below, to the name of your application and you 1.33 -# are ready to start. Run cmake, ccmake, or cmake-gui from within your build 1.34 -# directory, choose the options you need, such as enabling SDL or OGRE, 1.35 -# and you should be good to go. 1.36 +# are ready to start. Run ccmake, or cmake-gui from within your build 1.37 +# directory, choose the options you need, such as enabling SDL, and you 1.38 +# should be good to go. 1.39 # 1.40 -# You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON) command if you 1.41 +# You can uncomment the "SET (CMAKE_VERBOSE_MAKEFILE ON)" command if you 1.42 # need to debug the actual makefile that is generated. 1.43 # 1.44 -# On windows, you may need to modify some of the variables farther down in 1.45 -# this file so that cmake knows where SDL or other support libraries 1.46 -# and their header files can be found on the system. 1.47 +# On windows, you may need to set the SDLDIR environment variable to the location 1.48 +# of your SDL installation before you run cmake-gui. 1.49 # 1.50 # When writing path names on Windows, such as when manually specifiying a 1.51 # file or directory name, either use unix-style forward slashes '/' in the 1.52 @@ -42,7 +56,6 @@ 1.53 # strip out one of the slashes, so if there are two lev3els of cmake you 1.54 # need to write \\\, three levels requires \\\\, etc. 1.55 # 1.56 -# 1.57 # Note that some of the cmake support scripts that find libraries for you 1.58 # can be controlled by environment variables. For example, you can set the 1.59 # SDLDIR environment variable before running cmake in order to point to 1.60 @@ -50,42 +63,34 @@ 1.61 # for trying out cutting edge versions of libraries without installing them 1.62 # system wide. 1.63 1.64 - 1.65 - 1.66 -# Probably not needed, but it may save someone else a headache someday. 1.67 -CMAKE_MINIMUM_REQUIRED (VERSION 2.6) 1.68 - 1.69 - 1.70 +cmake_minimum_required (VERSION 2.6 FATAL_ERROR) 1.71 +#set (CMAKE_VERBOSE_MAKEFILE ON) 1.72 1.73 # Name your program! 1.74 -SET (App_Name "check-sdl-version") 1.75 -IF (App_Name STREQUAL "") 1.76 - MESSAGE (FATAL_ERROR "You must set the App_Name variable!") 1.77 -ENDIF () 1.78 - 1.79 - 1.80 -#SET (CMAKE_VERBOSE_MAKEFILE ON) 1.81 - 1.82 +set (App_Name "check-sdl-version") 1.83 +if (App_Name STREQUAL "") 1.84 + message (FATAL_ERROR "You must set the App_Name variable!") 1.85 +endif () 1.86 1.87 # Every project must have a name. 1.88 -PROJECT (${App_Name}) 1.89 +project (${App_Name}) 1.90 1.91 1.92 ################################################################################ 1.93 # Ensure that we are not building in our source directories. 1.94 1.95 -SET (Build_Dir_OK "TRUE") 1.96 -STRING (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR}) 1.97 -IF (In_Sub_Dir) 1.98 - STRING (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR}) 1.99 - IF (NOT In_Build_Dir) 1.100 - SET (Build_Dir_OK "FALSE") 1.101 - ENDIF () 1.102 -ENDIF () 1.103 +set (Build_Dir_OK "TRUE") 1.104 +string (REGEX MATCH "^${CMAKE_SOURCE_DIR}" In_Sub_Dir ${CMAKE_BINARY_DIR}) 1.105 +if (In_Sub_Dir) 1.106 + string (REGEX MATCH "^${CMAKE_SOURCE_DIR}/build" In_Build_Dir ${CMAKE_BINARY_DIR}) 1.107 + if (NOT In_Build_Dir) 1.108 + set (Build_Dir_OK "FALSE") 1.109 + endif () 1.110 +endif () 1.111 1.112 -IF (NOT Build_Dir_OK) 1.113 - 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.114 -ENDIF () 1.115 +if (NOT Build_Dir_OK) 1.116 + 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.117 +endif () 1.118 1.119 1.120 ################################################################################ 1.121 @@ -95,40 +100,49 @@ 1.122 # so we need to set the build type manually here, and we are setting it to the 1.123 # generally useful "Release with debug info" 1.124 1.125 -IF (CMAKE_BUILD_TYPE STREQUAL "") 1.126 +if (CMAKE_BUILD_TYPE STREQUAL "") 1.127 # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This messes up 1.128 # differentiation between debug and release builds. 1.129 - SET (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) 1.130 -ENDIF () 1.131 + set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) 1.132 +endif () 1.133 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 +file (GLOB SRCS src/*.c src/*.cpp) 1.142 +file (GLOB HDRS include/*.h include/*.hpp) 1.143 1.144 # The directories that contain the libraries we will be linking against. 1.145 # This must come before the ADD_EXECUTABLE directive. 1.146 -LINK_DIRECTORIES ( 1.147 -) 1.148 +link_directories ( 1.149 + ) 1.150 1.151 # The directories that contain the include files our programs use. 1.152 # This must come before the ADD_EXECUTABLE directive. 1.153 -INCLUDE_DIRECTORIES ( 1.154 - ${PROJECT_SOURCE_DIR}/include 1.155 -) 1.156 +include_directories ( 1.157 + ${CMAKE_SOURCE_DIR}/include 1.158 + ) 1.159 1.160 # Define the executable program file we are creating. We must list all of 1.161 -# the source files. 1.162 -ADD_EXECUTABLE (${App_Name} 1.163 - ${SRCS} 1.164 - ${HDRS} 1.165 -) 1.166 +# the source files. If we are copmiling on Windows, we set the executable 1.167 +# to have the WIN32 attribute, which makes it a Windows GUI program. Without 1.168 +# this attribute it would be compiled into a console application. 1.169 +if (WIN32) 1.170 + add_executable (${App_Name} WIN32 1.171 + ${SRCS} 1.172 + ${HDRS} 1.173 + ) 1.174 +else () 1.175 + add_executable (${App_Name} 1.176 + ${SRCS} 1.177 + ${HDRS} 1.178 + ) 1.179 +endif () 1.180 1.181 # Although we listed the library directories above, we also need to list the 1.182 # individual libraries we will be linking against. 1.183 -TARGET_LINK_LIBRARIES (${App_Name} 1.184 +target_link_libraries (${App_Name} 1.185 ) 1.186 1.187 1.188 @@ -142,103 +156,37 @@ 1.189 # to set the appropriate environment variables and rerun cmake. You will 1.190 # need to remove the CMake cache before doing so. 1.191 1.192 -OPTION (Option_SDL_Dev "Build an SDL application." OFF) 1.193 +# If you don't want to set actual environment variables before running 1.194 +# CMake, then uncomment the if block below and put in the actual 1.195 +# locations of your SDL installation. 1.196 1.197 -IF (Option_SDL_Dev) 1.198 +# if (WIN32) 1.199 +# set (ENV{SDLDIR} "c:\gamedev\deps\sdl\SDL-build") 1.200 +# else () 1.201 +# set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build") 1.202 +# endif () 1.203 + 1.204 +option(Option_SDL_Dev "Build an SDL application." OFF) 1.205 + 1.206 +if (Option_SDL_Dev) 1.207 1.208 # SDL base package 1.209 # To use a version of SDL other than your systems default, set the SDLDIR 1.210 # environment variable to the installation location of your preferred version. 1.211 - FIND_PACKAGE (SDL) 1.212 - IF (NOT SDL_FOUND) 1.213 - MESSAGE (FATAL_ERROR "SDL not found!") 1.214 - ENDIF (NOT SDL_FOUND) 1.215 - INCLUDE_DIRECTORIES( 1.216 + find_package (SDL) 1.217 + if (NOT SDL_FOUND) 1.218 + message (FATAL_ERROR "SDL not found!") 1.219 + endif (NOT SDL_FOUND) 1.220 + include_directories( 1.221 ${SDL_INCLUDE_DIR} 1.222 ${INCLUDE_DIRECTORIES} 1.223 ) 1.224 - TARGET_LINK_LIBRARIES(${App_Name} 1.225 + target_link_libraries(${App_Name} 1.226 ${SDL_LIBRARY} 1.227 ${TARGET_LINK_LIBRARIES} 1.228 ) 1.229 1.230 - # SDL_ttf 1.231 - # Environment variables SDLTTFDIR and SDLDIR will be checked in that order 1.232 - # and if set cmake will try to find SDL_ttf in the specified directory. 1.233 - OPTION(Option_SDL_Dev_SDL_ttf "Use SDL_ttf." OFF) 1.234 - IF (Option_SDL_Dev_SDL_ttf) 1.235 - FIND_PACKAGE (SDL_ttf) 1.236 - IF (NOT SDLTTF_FOUND) 1.237 - MESSAGE (FATAL_ERROR "SDL_ttf not found!") 1.238 - ENDIF (NOT SDLTTF_FOUND) 1.239 - INCLUDE_DIRECTORIES( 1.240 - ${SDLTTF_INCLUDE_DIR} 1.241 - ${INCLUDE_DIRECTORIES} 1.242 - ) 1.243 - TARGET_LINK_LIBRARIES(${App_Name} 1.244 - ${SDLTTF_LIBRARY} 1.245 - ${TARGET_LINK_LIBRARIES} 1.246 - ) 1.247 - ENDIF (Option_SDL_Dev_SDL_ttf) 1.248 - 1.249 - # SDL_image 1.250 - # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order 1.251 - # and if set cmake will try to find SDL_image in the specified directory. 1.252 - OPTION(Option_SDL_Dev_SDL_image "Use SDL_image." OFF) 1.253 - IF (Option_SDL_Dev_SDL_image) 1.254 - FIND_PACKAGE (SDL_image) 1.255 - IF (NOT SDLIMAGE_FOUND) 1.256 - MESSAGE (FATAL_ERROR "SDL_image not found!") 1.257 - ENDIF (NOT SDLIMAGE_FOUND) 1.258 - INCLUDE_DIRECTORIES( 1.259 - ${SDLIMAGE_INCLUDE_DIR} 1.260 - ${INCLUDE_DIRECTORIES} 1.261 - ) 1.262 - TARGET_LINK_LIBRARIES(${App_Name} 1.263 - ${SDLIMAGE_LIBRARY} 1.264 - ${TARGET_LINK_LIBRARIES} 1.265 - ) 1.266 - ENDIF (Option_SDL_Dev_SDL_image) 1.267 - 1.268 - # SDL_mixer 1.269 - # Environment variables SDLMIXERDIR and SDLDIR will be checked in that order 1.270 - # and if set cmake will try to find SDL_mixer in the specified directory. 1.271 - OPTION(Option_SDL_Dev_SDL_mixer "Use SDL_mixer." OFF) 1.272 - IF (Option_SDL_Dev_SDL_mixer) 1.273 - FIND_PACKAGE (SDL_mixer) 1.274 - IF (NOT SDLMIXER_FOUND) 1.275 - MESSAGE (FATAL_ERROR "SDL_mixer not found!") 1.276 - ENDIF (NOT SDLMIXER_FOUND) 1.277 - INCLUDE_DIRECTORIES( 1.278 - ${SDLMIXER_INCLUDE_DIR} 1.279 - ${INCLUDE_DIRECTORIES} 1.280 - ) 1.281 - TARGET_LINK_LIBRARIES(${App_Name} 1.282 - ${SDLMIXER_LIBRARY} 1.283 - ${TARGET_LINK_LIBRARIES} 1.284 - ) 1.285 - ENDIF (Option_SDL_Dev_SDL_mixer) 1.286 - 1.287 - # SDL_net 1.288 - # Environment variables SDLNETDIR and SDLDIR will be checked in that order 1.289 - # and if set cmake will try to find SDL_net in the specified directory. 1.290 - OPTION(Option_SDL_Dev_SDL_net "Use SDL_net." OFF) 1.291 - IF (Option_SDL_Dev_SDL_net) 1.292 - FIND_PACKAGE (SDL_net) 1.293 - IF (NOT SDLNET_FOUND) 1.294 - MESSAGE (FATAL_ERROR "SDL_net not found!") 1.295 - ENDIF (NOT SDLNET_FOUND) 1.296 - INCLUDE_DIRECTORIES( 1.297 - ${SDLNET_INCLUDE_DIR} 1.298 - ${INCLUDE_DIRECTORIES} 1.299 - ) 1.300 - TARGET_LINK_LIBRARIES(${App_Name} 1.301 - ${SDLNET_LIBRARY} 1.302 - ${TARGET_LINK_LIBRARIES} 1.303 - ) 1.304 - ENDIF (Option_SDL_Dev_SDL_net) 1.305 - 1.306 -ENDIF (Option_SDL_Dev) 1.307 +endif (Option_SDL_Dev) 1.308 1.309 1.310 ################################################################################
2.1 --- a/src/main.c Thu Oct 14 00:43:26 2010 -0500 2.2 +++ b/src/main.c Thu Oct 21 21:38:11 2010 -0500 2.3 @@ -1,27 +1,66 @@ 2.4 /****************************************************************************** 2.5 // 2.6 // check-sdl-version 2.7 -// Copyright (c) 2010 Sarah Eris Horsley Caffee 2.8 +// Copyright (c) 2010 Eris Caffee 2.9 +// Permission is hereby granted, free of charge, to any person obtaining a copy 2.10 +// of this software and associated documentation files (the "Software"), to deal 2.11 +// in the Software without restriction, including without limitation the rights 2.12 +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 2.13 +// copies of the Software, and to permit persons to whom the Software is 2.14 +// furnished to do so, subject to the following conditions: 2.15 +// The above copyright notice and this permission notice shall be included in 2.16 +// all copies or substantial portions of the Software. 2.17 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2.18 +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2.19 +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2.20 +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2.21 +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2.22 +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 2.23 +// THE SOFTWARE. 2.24 +// 2.25 // 2.26 // Just a quick test program to verify SDL installation and to use as an 2.27 // example for learning to use CMake. 2.28 -// 2.29 -// This program may be freely copied, distributed, and used for any purpose. 2.30 // 2.31 ******************************************************************************/ 2.32 2.33 #include <stdio.h> 2.34 #include <SDL.h> 2.35 2.36 + 2.37 +/* Redirect I/O on Windows to a file. We would not need to do this in a 2.38 + console app. */ 2.39 +#ifdef WIN32 2.40 +#include <windows.h> 2.41 +#include <io.h> 2.42 +void redirect_stdio(void) 2.43 + { 2.44 + /* We must freopen stderr to get it to have a valid fd before we can 2.45 + dup it to stdout. This creates a file on disk, which we then delete. */ 2.46 + freopen("stdout.txt", "w", stdout); 2.47 + freopen("stderr.txt", "w", stderr); 2.48 + if (_dup2(_fileno(stdout), _fileno(stderr)) != 0) 2.49 + fprintf(stdout, "_dup2 failed!\n"); 2.50 + DeleteFile("stderr.txt"); 2.51 + } 2.52 +#endif 2.53 + 2.54 int main(int argc, char **argv) 2.55 { 2.56 SDL_version compiled; 2.57 const SDL_version * linked; 2.58 2.59 +#ifdef WIN32 2.60 + redirect_stdio(); 2.61 +#endif 2.62 + 2.63 printf("\t\t\tCompiled\t\tLinked\n"); 2.64 2.65 SDL_VERSION(&compiled); 2.66 linked = SDL_Linked_Version(); 2.67 - printf("SDL version\t\t%d.%d.%d\t\t\t%d.%d.%d\n", compiled.major, compiled.minor, compiled.patch, 2.68 + printf("SDL version\t\t%d.%d.%d\t\t\t%d.%d.%d\n", 2.69 + compiled.major, compiled.minor, compiled.patch, 2.70 linked->major, linked->minor, linked->patch); 2.71 + 2.72 + return 0; 2.73 }