summary refs log tree commit diff stats
path: root/cmake/FindSDL2.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/FindSDL2.cmake')
-rw-r--r--cmake/FindSDL2.cmake254
1 files changed, 254 insertions, 0 deletions
diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake new file mode 100644 index 0000000..f9ebcf3 --- /dev/null +++ b/cmake/FindSDL2.cmake
@@ -0,0 +1,254 @@
1# Locate SDL2 library
2# This module defines
3# SDL2_LIBRARY, the name of the library to link against
4# SDL2_FOUND, if false, do not try to link to SDL2
5# SDL2_INCLUDE_DIR, where to find SDL.h
6#
7# This module responds to the the flag:
8# SDL2_BUILDING_LIBRARY
9# If this is defined, then no SDL2_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 SDL2_LIBRARY variable.
14#
15# Don't forget to include SDL2main.h and SDL2main.m your project for the
16# OS X framework based version. (Other versions link to -lSDL2main 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 SDL2_LIBRARY_TEMP in your configuration
22# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
23# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
24# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
25# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
26# as appropriate. These values are used to generate the final SDL2_LIBRARY
27# variable, but when these values are unset, SDL2_LIBRARY does not get created.
28#
29#
30# $SDL2 is an environment variable that would
31# correspond to the ./configure --prefix=$SDL2
32# used in building SDL2.
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" SDL2 guidelines.
41# Added a search for SDL2main 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# SDL2_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 SDL2/SDL.h to just SDL.h
51# This needed to change because "proper" SDL2 convention
52# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
53# reasons because not all systems place things in SDL2/ (see FreeBSD).
54#
55# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake
56# module with the minor edit of changing "SDL" to "SDL2" where necessary. This
57# was not created for redistribution, and exists temporarily pending official
58# SDL2 CMake modules.
59#
60# Note that on windows this will only search for the 32bit libraries, to search
61# for 64bit change x86/i686-w64 to x64/x86_64-w64
62
63#=============================================================================
64# Copyright 2003-2009 Kitware, Inc.
65#
66# CMake - Cross Platform Makefile Generator
67# Copyright 2000-2014 Kitware, Inc.
68# Copyright 2000-2011 Insight Software Consortium
69# All rights reserved.
70#
71# Redistribution and use in source and binary forms, with or without
72# modification, are permitted provided that the following conditions
73# are met:
74#
75# * Redistributions of source code must retain the above copyright
76# notice, this list of conditions and the following disclaimer.
77#
78# * Redistributions in binary form must reproduce the above copyright
79# notice, this list of conditions and the following disclaimer in the
80# documentation and/or other materials provided with the distribution.
81#
82# * Neither the names of Kitware, Inc., the Insight Software Consortium,
83# nor the names of their contributors may be used to endorse or promote
84# products derived from this software without specific prior written
85# permission.
86#
87# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
88# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
89# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
90# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
91# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
92# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
93# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
94# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
95# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
96# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
97# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98#
99# This software is distributed WITHOUT ANY WARRANTY; without even the
100# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
101# See the License for more information.
102#=============================================================================
103# (To distribute this file outside of CMake, substitute the full
104# License text for the above reference.)
105
106FIND_PATH(SDL2_INCLUDE_DIR SDL.h
107 HINTS
108 ${SDL2}
109 $ENV{SDL2}
110 PATH_SUFFIXES include/SDL2 include SDL2
111 i686-w64-mingw32/include/SDL2
112 x86_64-w64-mingw32/include/SDL2
113 PATHS
114 ~/Library/Frameworks
115 /Library/Frameworks
116 /usr/local/include/SDL2
117 /usr/include/SDL2
118 /sw # Fink
119 /opt/local # DarwinPorts
120 /opt/csw # Blastwave
121 /opt
122)
123
124# Lookup the 64 bit libs on x64
125IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
126 FIND_LIBRARY(SDL2_LIBRARY_TEMP SDL2
127 HINTS
128 ${SDL2}
129 $ENV{SDL2}
130 PATH_SUFFIXES lib64 lib
131 lib/x64
132 x86_64-w64-mingw32/lib
133 PATHS
134 /sw
135 /opt/local
136 /opt/csw
137 /opt
138 )
139# On 32bit build find the 32bit libs
140ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8)
141 FIND_LIBRARY(SDL2_LIBRARY_TEMP SDL2
142 HINTS
143 ${SDL2}
144 $ENV{SDL2}
145 PATH_SUFFIXES lib
146 lib/x86
147 i686-w64-mingw32/lib
148 PATHS
149 /sw
150 /opt/local
151 /opt/csw
152 /opt
153 )
154ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8)
155
156IF(NOT SDL2_BUILDING_LIBRARY)
157 IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
158 # Non-OS X framework versions expect you to also dynamically link to
159 # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
160 # seem to provide SDL2main for compatibility even though they don't
161 # necessarily need it.
162 # Lookup the 64 bit libs on x64
163 IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
164 FIND_LIBRARY(SDL2MAIN_LIBRARY
165 NAMES SDL2main
166 HINTS
167 ${SDL2}
168 $ENV{SDL2}
169 PATH_SUFFIXES lib64 lib
170 lib/x64
171 x86_64-w64-mingw32/lib
172 PATHS
173 /sw
174 /opt/local
175 /opt/csw
176 /opt
177 )
178 # On 32bit build find the 32bit libs
179 ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8)
180 FIND_LIBRARY(SDL2MAIN_LIBRARY
181 NAMES SDL2main
182 HINTS
183 ${SDL2}
184 $ENV{SDL2}
185 PATH_SUFFIXES lib
186 lib/x86
187 i686-w64-mingw32/lib
188 PATHS
189 /sw
190 /opt/local
191 /opt/csw
192 /opt
193 )
194 ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8)
195 ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
196ENDIF(NOT SDL2_BUILDING_LIBRARY)
197
198# SDL2 may require threads on your system.
199# The Apple build may not need an explicit flag because one of the
200# frameworks may already provide it.
201# But for non-OSX systems, I will use the CMake Threads package.
202IF(NOT APPLE)
203 FIND_PACKAGE(Threads)
204ENDIF(NOT APPLE)
205
206# MinGW needs an additional library, mwindows
207# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
208# (Actually on second look, I think it only needs one of the m* libraries.)
209IF(MINGW)
210 SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
211ENDIF(MINGW)
212
213SET(SDL2_FOUND "NO")
214 IF(SDL2_LIBRARY_TEMP)
215 # For SDL2main
216 IF(NOT SDL2_BUILDING_LIBRARY)
217 IF(SDL2MAIN_LIBRARY)
218 SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
219 ENDIF(SDL2MAIN_LIBRARY)
220 ENDIF(NOT SDL2_BUILDING_LIBRARY)
221
222 # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
223 # CMake doesn't display the -framework Cocoa string in the UI even
224 # though it actually is there if I modify a pre-used variable.
225 # I think it has something to do with the CACHE STRING.
226 # So I use a temporary variable until the end so I can set the
227 # "real" variable in one-shot.
228 IF(APPLE)
229 SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
230 ENDIF(APPLE)
231
232 # For threads, as mentioned Apple doesn't need this.
233 # In fact, there seems to be a problem if I used the Threads package
234 # and try using this line, so I'm just skipping it entirely for OS X.
235 IF(NOT APPLE)
236 SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
237 ENDIF(NOT APPLE)
238
239 # For MinGW library
240 IF(MINGW)
241 SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
242 ENDIF(MINGW)
243
244 # Set the final string here so the GUI reflects the final state.
245 SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
246 # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
247 SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
248
249 SET(SDL2_FOUND "YES")
250ENDIF(SDL2_LIBRARY_TEMP)
251
252INCLUDE(FindPackageHandleStandardArgs)
253
254FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)