1# Locate SDL library
2# This module defines
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#
7# This module responds to the the flag:
8# SDL_BUILDING_LIBRARY
9# If this is defined, then no SDL_main will be linked in because
10# only applications need main().
11# Otherwise, it is assumed you are building an application and this
12# module will attempt to locate and set the the proper link flags
13# as part of the returned SDL_LIBRARY variable.
14#
15# Don't forget to include SDLmain.h and SDLmain.m your project for the
16# OS X framework based version. (Other versions link to -lSDLmain which
17# this module will try to find on your behalf.) Also for OS X, this
18# module will automatically add the -framework Cocoa on your behalf.
19#
20#
21# Additional Note: If you see an empty SDL_LIBRARY_TEMP in your configuration
22# and no SDL_LIBRARY, it means CMake did not find your SDL library
23# (SDL.dll, libsdl.so, SDL.framework, etc).
24# Set SDL_LIBRARY_TEMP to point to your SDL library, and configure again.
25# Similarly, if you see an empty SDLMAIN_LIBRARY, you should set this value
26# as appropriate. These values are used to generate the final SDL_LIBRARY
27# variable, but when these values are unset, SDL_LIBRARY does not get created.
28#
29#
30# $SDLDIR is an environment variable that would
31# correspond to the ./configure --prefix=$SDLDIR
32# used in building SDL.
33# l.e.galup  9-20-02
34#
35# Modified by Eric Wing.
36# Added code to assist with automated building by using environmental variables
37# and providing a more controlled/consistent search behavior.
38# Added new modifications to recognize OS X frameworks and
39# additional Unix paths (FreeBSD, etc).
40# Also corrected the header search path to follow "proper" SDL guidelines.
41# Added a search for SDLmain which is needed by some platforms.
42# Added a search for threads which is needed by some platforms.
43# Added needed compile switches for MinGW.
44#
45# On OSX, this will prefer the Framework version (if found) over others.
46# People will have to manually change the cache values of
47# SDL_LIBRARY to override this selection or set the CMake environment
48# CMAKE_INCLUDE_PATH to modify the search paths.
49#
50# Note that the header path has changed from SDL/SDL.h to just SDL.h
51# This needed to change because "proper" SDL convention
52# is #include "SDL.h", not <SDL/SDL.h>. This is done for portability
53# reasons because not all systems place things in SDL/ (see FreeBSD).
54
55FIND_PATH(SDL_INCLUDE_DIR SDL.h
56  PATHS
57  $ENV{SDLDIR}
58  NO_DEFAULT_PATH
59  PATH_SUFFIXES include
60)
61
62FIND_PATH(SDL_INCLUDE_DIR SDL.h
63  PATHS
64  ~/Library/Frameworks
65  /Library/Frameworks
66  /usr/local/include/SDL
67  /usr/include/SDL
68  /usr/local/include/SDL12
69  /usr/local/include/SDL11 # FreeBSD ports
70  /usr/include/SDL12
71  /usr/include/SDL11
72  /usr/local/include
73  /usr/include
74  /sw/include/SDL # Fink
75  /sw/include
76  /opt/local/include/SDL # DarwinPorts
77  /opt/local/include
78  /opt/csw/include/SDL # Blastwave
79  /opt/csw/include
80  /opt/include/SDL
81  /opt/include
82)
83#MESSAGE("SDL_INCLUDE_DIR is ${SDL_INCLUDE_DIR}")
84
85# SDL-1.1 is the name used by FreeBSD ports...
86# don't confuse it for the version number.
87FIND_LIBRARY(SDL_LIBRARY_TEMP
88  NAMES SDL SDL-1.1
89  PATHS
90  $ENV{SDLDIR}
91  NO_DEFAULT_PATH
92    PATH_SUFFIXES lib64 lib
93)
94
95FIND_LIBRARY(SDL_LIBRARY_TEMP
96  NAMES SDL SDL-1.1
97  PATHS
98  /usr/local
99  /usr
100  /sw
101  /opt/local
102  /opt/csw
103  /opt
104    PATH_SUFFIXES lib64 lib
105)
106
107#MESSAGE("SDL_LIBRARY_TEMP is ${SDL_LIBRARY_TEMP}")
108
109IF(NOT SDL_BUILDING_LIBRARY)
110  IF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework")
111    # Non-OS X framework versions expect you to also dynamically link to
112    # SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms
113    # seem to provide SDLmain for compatibility even though they don't
114    # necessarily need it.
115    FIND_LIBRARY(SDLMAIN_LIBRARY
116      NAMES SDLmain SDLmain-1.1
117      PATHS
118      $ENV{SDLDIR}
119      NO_DEFAULT_PATH
120      PATH_SUFFIXES lib64 lib
121    )
122
123    FIND_LIBRARY(SDLMAIN_LIBRARY
124      NAMES SDLmain SDLmain-1.1
125      PATHS
126      /usr/local
127      /usr
128      /sw
129      /opt/local
130      /opt/csw
131      /opt
132      PATH_SUFFIXES lib64 lib
133    )
134  ENDIF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework")
135ENDIF(NOT SDL_BUILDING_LIBRARY)
136
137# SDL may require threads on your system.
138# The Apple build may not need an explicit flag because one of the
139# frameworks may already provide it.
140# But for non-OSX systems, I will use the CMake Threads package.
141IF(NOT APPLE)
142  FIND_PACKAGE(Threads)
143ENDIF(NOT APPLE)
144
145# MinGW needs an additional library, mwindows
146# It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows
147# (Actually on second look, I think it only needs one of the m* libraries.)
148IF(MINGW)
149  SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
150ENDIF(MINGW)
151
152SET(SDL_FOUND "NO")
153IF(SDL_LIBRARY_TEMP)
154  # For SDLmain
155  IF(NOT SDL_BUILDING_LIBRARY)
156    IF(SDLMAIN_LIBRARY)
157      SET(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP})
158    ENDIF(SDLMAIN_LIBRARY)
159  ENDIF(NOT SDL_BUILDING_LIBRARY)
160
161  # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa.
162  # CMake doesn't display the -framework Cocoa string in the UI even
163  # though it actually is there if I modify a pre-used variable.
164  # I think it has something to do with the CACHE STRING.
165  # So I use a temporary variable until the end so I can set the
166  # "real" variable in one-shot.
167  IF(APPLE)
168    SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-framework Cocoa")
169  ENDIF(APPLE)
170
171  # For threads, as mentioned Apple doesn't need this.
172  # In fact, there seems to be a problem if I used the Threads package
173  # and try using this line, so I'm just skipping it entirely for OS X.
174  IF(NOT APPLE)
175    SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
176  ENDIF(NOT APPLE)
177
178  # For MinGW library
179  IF(MINGW)
180    SET(SDL_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL_LIBRARY_TEMP})
181  ENDIF(MINGW)
182
183  # Set the final string here so the GUI reflects the final state.
184  SET(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found")
185  # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
186  SET(SDL_LIBRARY_TEMP "${SDL_LIBRARY_TEMP}" CACHE INTERNAL "")
187
188  SET(SDL_FOUND "YES")
189ENDIF(SDL_LIBRARY_TEMP)
190
191#MESSAGE("SDL_LIBRARY is ${SDL_LIBRARY}")
192
193