3 # SDL_LIBRARY, the name of the library to link against
4 # SDL_FOUND, if false, do not try to link to SDL
5 # SDL_INCLUDE_DIR, where to find SDL.h
6 # SDL_VERSION_STRING, human-readable string containing the version of SDL
8 # This module responds to the the flag:
10 # If this is defined, then no SDL_main will be linked in because
11 # only applications need main().
12 # Otherwise, it is assumed you are building an application and this
13 # module will attempt to locate and set the the proper link flags
14 # as part of the returned SDL_LIBRARY variable.
16 # Don't forget to include SDLmain.h and SDLmain.m your project for the
17 # OS X framework based version. (Other versions link to -lSDLmain which
18 # this module will try to find on your behalf.) Also for OS X, this
19 # module will automatically add the -framework Cocoa on your behalf.
22 # Additional Note: If you see an empty SDL_LIBRARY_TEMP in your configuration
23 # and no SDL_LIBRARY, it means CMake did not find your SDL library
24 # (SDL.dll, libsdl.so, SDL.framework, etc).
25 # Set SDL_LIBRARY_TEMP to point to your SDL library, and configure again.
26 # Similarly, if you see an empty SDLMAIN_LIBRARY, you should set this value
27 # as appropriate. These values are used to generate the final SDL_LIBRARY
28 # variable, but when these values are unset, SDL_LIBRARY does not get created.
31 # $SDLDIR is an environment variable that would
32 # correspond to the ./configure --prefix=$SDLDIR
33 # used in building SDL.
36 # Modified by Eric Wing.
37 # Added code to assist with automated building by using environmental variables
38 # and providing a more controlled/consistent search behavior.
39 # Added new modifications to recognize OS X frameworks and
40 # additional Unix paths (FreeBSD, etc).
41 # Also corrected the header search path to follow "proper" SDL guidelines.
42 # Added a search for SDLmain which is needed by some platforms.
43 # Added a search for threads which is needed by some platforms.
44 # Added needed compile switches for MinGW.
46 # On OSX, this will prefer the Framework version (if found) over others.
47 # People will have to manually change the cache values of
48 # SDL_LIBRARY to override this selection or set the CMake environment
49 # CMAKE_INCLUDE_PATH to modify the search paths.
51 # Note that the header path has changed from SDL/SDL.h to just SDL.h
52 # This needed to change because "proper" SDL convention
53 # is #include "SDL.h", not <SDL/SDL.h>. This is done for portability
54 # reasons because not all systems place things in SDL/ (see FreeBSD).
56 #=============================================================================
57 # Copyright 2003-2009 Kitware, Inc.
58 # Copyright 2012 Benjamin Eikel
60 # Distributed under the OSI-approved BSD License (the "License");
61 # see accompanying file Copyright.txt for details.
63 # This software is distributed WITHOUT ANY WARRANTY; without even the
64 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
65 # See the License for more information.
66 #=============================================================================
67 # (To distribute this file outside of CMake, substitute the full
68 # License text for the above reference.)
70 find_path(SDL_INCLUDE_DIR SDL.h
73 PATH_SUFFIXES include/SDL include/SDL12 include/SDL11 include
76 # SDL-1.1 is the name used by FreeBSD ports...
77 # don't confuse it for the version number.
78 find_library(SDL_LIBRARY_TEMP
85 if(NOT SDL_BUILDING_LIBRARY)
86 if(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework")
87 # Non-OS X framework versions expect you to also dynamically link to
88 # SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms
89 # seem to provide SDLmain for compatibility even though they don't
90 # necessarily need it.
91 find_library(SDLMAIN_LIBRARY
92 NAMES SDLmain SDLmain-1.1
105 # SDL may require threads on your system.
106 # The Apple build may not need an explicit flag because one of the
107 # frameworks may already provide it.
108 # But for non-OSX systems, I will use the CMake Threads package.
110 find_package(Threads)
113 # MinGW needs an additional library, mwindows
114 # It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows
115 # (Actually on second look, I think it only needs one of the m* libraries.)
117 set(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
122 if(SDLMAIN_LIBRARY AND NOT SDL_BUILDING_LIBRARY)
123 list(FIND SDL_LIBRARY_TEMP "${SDLMAIN_LIBRARY}" _SDL_MAIN_INDEX)
124 if(_SDL_MAIN_INDEX EQUAL -1)
125 list(APPEND SDL_LIBRARY_TEMP "${SDLMAIN_LIBRARY}")
127 unset(_SDL_MAIN_INDEX)
130 # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa.
131 # CMake doesn't display the -framework Cocoa string in the UI even
132 # though it actually is there if I modify a pre-used variable.
133 # I think it has something to do with the CACHE STRING.
134 # So I use a temporary variable until the end so I can set the
135 # "real" variable in one-shot.
137 set(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-framework Cocoa")
140 # For threads, as mentioned Apple doesn't need this.
141 # In fact, there seems to be a problem if I used the Threads package
142 # and try using this line, so I'm just skipping it entirely for OS X.
144 set(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
149 set(SDL_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL_LIBRARY_TEMP})
152 # Set the final string here so the GUI reflects the final state.
153 set(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found")
154 # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
155 set(SDL_LIBRARY_TEMP "${SDL_LIBRARY_TEMP}" CACHE INTERNAL "")
158 if(SDL_INCLUDE_DIR AND EXISTS "${SDL_INCLUDE_DIR}/SDL_version.h")
159 file(STRINGS "${SDL_INCLUDE_DIR}/SDL_version.h" SDL_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$")
160 file(STRINGS "${SDL_INCLUDE_DIR}/SDL_version.h" SDL_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$")
161 file(STRINGS "${SDL_INCLUDE_DIR}/SDL_version.h" SDL_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$")
162 string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MAJOR "${SDL_VERSION_MAJOR_LINE}")
163 string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MINOR "${SDL_VERSION_MINOR_LINE}")
164 string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_VERSION_PATCH "${SDL_VERSION_PATCH_LINE}")
165 set(SDL_VERSION_STRING ${SDL_VERSION_MAJOR}.${SDL_VERSION_MINOR}.${SDL_VERSION_PATCH})
166 unset(SDL_VERSION_MAJOR_LINE)
167 unset(SDL_VERSION_MINOR_LINE)
168 unset(SDL_VERSION_PATCH_LINE)
169 unset(SDL_VERSION_MAJOR)
170 unset(SDL_VERSION_MINOR)
171 unset(SDL_VERSION_PATCH)
174 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
176 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL
177 REQUIRED_VARS SDL_LIBRARY SDL_INCLUDE_DIR
178 VERSION_VAR SDL_VERSION_STRING)