1# - Locate the SDL library
2# This module defines
3#  SDL_LIBRARY, 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# Don't forget to include SDLmain.h and SDLmain.m your project for the
8# OS X framework based version. (Other versions link to -lSDLmain which
9# this module will try to find on your behalf.) Also for OS X, this
10# module will automatically add the -framework Cocoa on your behalf.
11# $SDLDIR is an environment variable that would
12# correspond to the ./configure --prefix=$SDLDIR
13# used in building SDL.
14# l.e.galup  9-20-02
15#
16# Modified by Eric Wing.
17# Added new modifications to recognize OS X frameworks and
18# additional Unix paths (FreeBSD, etc).
19# Also corrected the header search path to follow "proper" SDL guidelines.
20# Added a search for SDLmain which is needed by some platforms.
21# Added a search for threads which is needed by some platforms.
22# Added needed compile switches for MinGW.
23#
24# On OSX, this will prefer the Framework version (if found) over others.
25# People will have to manually change the cache values of
26# SDL_LIBRARY to override this selection.
27#
28# Note that the header path has changed from SDL/SDL.h to just SDL.h
29# This needed to change because "proper" SDL convention
30# is #include "SDL.h", not <SDL/SDL.h>. This is done for portability
31# reasons because not all systems place things in SDL/ (see FreeBSD).
32FIND_PATH(SDL_INCLUDE_DIR SDL.h
33  $ENV{SDLDIR}/include
34  $ENV{SDLDIR}/include/SDL
35  ~/Library/Frameworks/SDL.framework/Headers
36  /Library/Frameworks/SDL.framework/Headers
37  /usr/local/include/SDL
38  /usr/include/SDL
39  /usr/local/include/SDL12
40  /usr/local/include/SDL11 # FreeBSD ports
41  /usr/include/SDL12
42  /usr/include/SDL11
43  /usr/local/include
44  /usr/include
45  /sw/include/SDL # Fink
46  /sw/include
47  /opt/local/include/SDL # DarwinPorts
48  /opt/local/include
49  /opt/csw/include/SDL # Blastwave
50  /opt/csw/include
51  /opt/include/SDL
52  /opt/include
53  )
54# I'm not sure if I should do a special casing for Apple. It is
55# unlikely that other Unix systems will find the framework path.
56# But if they do ([Next|Open|GNU]Step?),
57# do they want the -framework option also?
58IF(${SDL_INCLUDE_DIR} MATCHES ".framework")
59  # The Cocoa framework must be linked into SDL because SDL is Cocoa based.
60  # Remember that the OS X framework version expects you to drop in
61  # SDLmain.h and SDLmain.m directly into your project.
62  # (Cocoa link moved to bottom of this script.)
63  # SET (SDL_LIBRARY "-framework SDL -framework Cocoa" CACHE STRING "SDL framework for OSX")
64  # SET(SDL_LIBRARY "-framework SDL" CACHE STRING "SDL framework for OSX")
65  # Extract the path the framework resides in so we can use it for the -F flag
66  STRING(REGEX REPLACE "(.*)/.*\\.framework/.*" "\\1" SDL_FRAMEWORK_PATH_TEMP ${SDL_INCLUDE_DIR})
67  IF("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
68      OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
69      )
70    # String is in default search path, don't need to use -F
71    SET(SDL_LIBRARY_TEMP "-framework SDL")
72  ELSE("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
73      OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
74      )
75    # String is not /Library/Frameworks, need to use -F
76    SET(SDL_LIBRARY_TEMP "-F${SDL_FRAMEWORK_PATH_TEMP} -framework SDL")
77  ENDIF("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
78    OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
79    )
80  # Clear the temp variable so nobody can see it
81  SET(SDL_FRAMEWORK_PATH_TEMP "" CACHE INTERNAL "")
82
83ELSE(${SDL_INCLUDE_DIR} MATCHES ".framework")
84  # SDL-1.1 is the name used by FreeBSD ports...
85  # don't confuse it for the version number.
86  FIND_LIBRARY(SDL_LIBRARY_TEMP
87    NAMES SDL SDL-1.1
88    PATHS
89    $ENV{SDLDIR}/lib
90    /usr/local/lib
91    /usr/lib
92    /sw/lib
93    /opt/local/lib
94    /opt/csw/lib
95    /opt/lib
96    )
97  # Non-OS X framework versions expect you to also dynamically link to
98  # SDLmain. This is mainly for Windows and OS X. Other platforms
99  # seem to provide SDLmain for compatibility even though they don't
100  # necessarily need it.
101  FIND_LIBRARY(SDLMAIN_LIBRARY
102    NAMES SDLmain SDLmain-1.1
103    PATHS
104    $ENV{SDLDIR}/lib
105    /usr/local/lib
106    /usr/lib
107    /sw/lib
108    /opt/local/lib
109    /opt/csw/lib
110    /opt/lib
111    )
112ENDIF(${SDL_INCLUDE_DIR} MATCHES ".framework")
113
114# SDL may require threads on your system.
115# The Apple build may not need an explicit flag because one of the
116# frameworks may already provide it.
117# But for non-OSX systems, I will use the CMake Threads package.
118IF(NOT APPLE)
119  FIND_PACKAGE(Threads)
120ENDIF(NOT APPLE)
121
122# MinGW needs an additional library, mwindows
123# It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows
124# (Actually on second look, I think it only needs one of the m* libraries.)
125IF(MINGW)
126  SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
127ENDIF(MINGW)
128
129SET(SDL_FOUND "NO")
130IF(SDL_LIBRARY_TEMP)
131  # For SDLmain
132  IF(SDLMAIN_LIBRARY)
133    SET(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP})
134  ENDIF(SDLMAIN_LIBRARY)
135
136  # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa.
137  # CMake doesn't display the -framework Cocoa string in the UI even
138  # though it actually is there. I think it has something to do
139  # with the CACHE STRING. Maybe somebody else knows how to fix this.
140  # The problem is mainly cosmetic, and not a functional issue.
141  IF(APPLE)
142    SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-framework Cocoa")
143  ENDIF(APPLE)
144
145  # For threads, as mentioned Apple doesn't need this.
146  # In fact, there seems to be a problem if Find the threads package
147  # and try using this line, so I'm just skipping it entirely for OS X.
148  IF(NOT APPLE)
149    SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
150  ENDIF(NOT APPLE)
151
152  # For MinGW library
153  IF(MINGW)
154    SET(SDL_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL_LIBRARY_TEMP})
155  ENDIF(MINGW)
156
157  # Set the final string here so the GUI reflects the final state.
158  SET(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found")
159
160  SET(SDL_FOUND "YES")
161ENDIF(SDL_LIBRARY_TEMP)
162
163MARK_AS_ADVANCED(SDL_LIBRARY_TEMP)
164