Skip to content

Commit 1da9bec

Browse files
committedJun 14, 2015
Merge pull request libRocket#224 from i8degrees/bugfix-upstream/sdl2-sample
Fix build of SDL2 sample on OSX
2 parents af20162 + f4ffced commit 1da9bec

File tree

3 files changed

+294
-10
lines changed

3 files changed

+294
-10
lines changed
 

‎Build/CMakeLists.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ if(NOT DEFINED ENV{LUA_DIR})
9797
set(ENV{LUA_DIR} "${PROJECT_SOURCE_DIR}/../Dependencies")
9898
endif()
9999

100-
if(NOT DEFINED ENV{SDLDIR})
101-
set(ENV{SDLDIR} "${PROJECT_SOURCE_DIR}/../Dependencies")
100+
if(NOT DEFINED ENV{SDL2DIR})
101+
set(ENV{SDL2DIR} "${PROJECT_SOURCE_DIR}/../Dependencies")
102102
endif()
103103

104-
if(NOT DEFINED ENV{SDLIMAGEDIR})
105-
set(ENV{SDLIMAGEDIR} "${PROJECT_SOURCE_DIR}/../Dependencies")
104+
if(NOT DEFINED ENV{SDL2_IMAGE_DIR})
105+
set(ENV{SDL2_IMAGE_DIR} "${PROJECT_SOURCE_DIR}/../Dependencies")
106106
endif()
107107

108108
if(NOT DEFINED ENV{SFML_ROOT})
@@ -615,16 +615,16 @@ endif(NOT BUILD_FRAMEWORK)
615615
endif()
616616

617617
message("-- Can SDL2 sample be built")
618-
find_package(SDL)
619-
if(SDL_FOUND)
620-
find_package(SDL_image)
621-
if(SDL_IMAGE_FOUND)
618+
find_package(SDL2)
619+
if(SDL2_FOUND)
620+
find_package(SDL2_image)
621+
if(SDL2_IMAGE_FOUND)
622622
find_package(GLEW)
623623
if(GLEW_FOUND)
624624
message("-- Can SDL2 sample be built - yes")
625-
include_directories(${SDL_INCLUDE_DIR} ${GLEW_INCLUDE_DIR})
625+
include_directories(${SDL2_INCLUDE_DIR} ${GLEW_INCLUDE_DIR})
626626

627-
bl_sample(sdl2 ${sample_LIBRARIES} ${SDL_LIBRARY} ${SDL_IMAGE_LIBRARY} ${GLEW_LIBRARY})
627+
bl_sample(sdl2 ${sample_LIBRARIES} ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY} ${GLEW_LIBRARY})
628628
# The samples always set this as their current working directory
629629
install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/sdl2)
630630
install(TARGETS sdl2

‎Build/cmake/FindSDL2.cmake

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
# Source: https://code.google.com/p/freerct/source/browse/trunk/CMake/FindSDL2.cmake
8+
#
9+
# This module responds to the the flag:
10+
# SDL2_BUILDING_LIBRARY
11+
# If this is defined, then no SDL2main will be linked in because
12+
# only applications need main().
13+
# Otherwise, it is assumed you are building an application and this
14+
# module will attempt to locate and set the the proper link flags
15+
# as part of the returned SDL2_LIBRARY variable.
16+
#
17+
# Don't forget to include SDLmain.h and SDLmain.m your project for the
18+
# OS X framework based version. (Other versions link to -lSDL2main which
19+
# this module will try to find on your behalf.) Also for OS X, this
20+
# module will automatically add the -framework Cocoa on your behalf.
21+
#
22+
#
23+
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
24+
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
25+
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
26+
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
27+
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
28+
# as appropriate. These values are used to generate the final SDL2_LIBRARY
29+
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
30+
#
31+
#
32+
# $SDL2DIR is an environment variable that would
33+
# correspond to the ./configure --prefix=$SDL2DIR
34+
# used in building SDL2.
35+
# l.e.galup 9-20-02
36+
#
37+
# Modified by Eric Wing.
38+
# Added code to assist with automated building by using environmental variables
39+
# and providing a more controlled/consistent search behavior.
40+
# Added new modifications to recognize OS X frameworks and
41+
# additional Unix paths (FreeBSD, etc).
42+
# Also corrected the header search path to follow "proper" SDL guidelines.
43+
# Added a search for SDL2main which is needed by some platforms.
44+
# Added a search for threads which is needed by some platforms.
45+
# Added needed compile switches for MinGW.
46+
#
47+
# On OSX, this will prefer the Framework version (if found) over others.
48+
# People will have to manually change the cache values of
49+
# SDL2_LIBRARY to override this selection or set the CMake environment
50+
# CMAKE_INCLUDE_PATH to modify the search paths.
51+
#
52+
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
53+
# This needed to change because "proper" SDL convention
54+
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
55+
# reasons because not all systems place things in SDL2/ (see FreeBSD).
56+
57+
#=============================================================================
58+
# Copyright 2003-2009 Kitware, Inc.
59+
#
60+
# Distributed under the OSI-approved BSD License (the "License");
61+
# see accompanying file Copyright.txt for details.
62+
#
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.)
69+
70+
SET(SDL2_SEARCH_PATHS
71+
~/Library/Frameworks
72+
/Library/Frameworks
73+
/usr/local
74+
/usr
75+
/sw # Fink
76+
/opt/local # DarwinPorts
77+
/opt/csw # Blastwave
78+
/opt
79+
)
80+
81+
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
82+
HINTS
83+
$ENV{SDL2DIR}
84+
PATH_SUFFIXES include/SDL2 include
85+
PATHS ${SDL2_SEARCH_PATHS}
86+
)
87+
88+
FIND_LIBRARY(SDL2_LIBRARY_TEMP
89+
NAMES SDL2
90+
HINTS
91+
$ENV{SDL2DIR}
92+
PATH_SUFFIXES lib64 lib
93+
PATHS ${SDL2_SEARCH_PATHS}
94+
)
95+
96+
IF(NOT SDL2_BUILDING_LIBRARY)
97+
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
98+
# Non-OS X framework versions expect you to also dynamically link to
99+
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
100+
# seem to provide SDL2main for compatibility even though they don't
101+
# necessarily need it.
102+
FIND_LIBRARY(SDL2MAIN_LIBRARY
103+
NAMES SDL2main
104+
HINTS
105+
$ENV{SDL2DIR}
106+
PATH_SUFFIXES lib64 lib
107+
PATHS ${SDL2_SEARCH_PATHS}
108+
)
109+
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
110+
ENDIF(NOT SDL2_BUILDING_LIBRARY)
111+
112+
# SDL2 may require threads on your system.
113+
# The Apple build may not need an explicit flag because one of the
114+
# frameworks may already provide it.
115+
# But for non-OSX systems, I will use the CMake Threads package.
116+
IF(NOT APPLE)
117+
FIND_PACKAGE(Threads)
118+
ENDIF(NOT APPLE)
119+
120+
# MinGW needs an additional library, mwindows
121+
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
122+
# (Actually on second look, I think it only needs one of the m* libraries.)
123+
IF(MINGW)
124+
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
125+
ENDIF(MINGW)
126+
127+
IF(SDL2_LIBRARY_TEMP)
128+
# For SDL2main
129+
IF(NOT SDL2_BUILDING_LIBRARY)
130+
IF(SDL2MAIN_LIBRARY)
131+
SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
132+
ENDIF(SDL2MAIN_LIBRARY)
133+
ENDIF(NOT SDL2_BUILDING_LIBRARY)
134+
135+
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
136+
# CMake doesn't display the -framework Cocoa string in the UI even
137+
# though it actually is there if I modify a pre-used variable.
138+
# I think it has something to do with the CACHE STRING.
139+
# So I use a temporary variable until the end so I can set the
140+
# "real" variable in one-shot.
141+
IF(APPLE)
142+
SET(SDL2_LIBRARY_TEMP ${SDL2_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 I used 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(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
150+
ENDIF(NOT APPLE)
151+
152+
# For MinGW library
153+
IF(MINGW)
154+
SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
155+
ENDIF(MINGW)
156+
157+
# Set the final string here so the GUI reflects the final state.
158+
SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
159+
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
160+
SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
161+
ENDIF(SDL2_LIBRARY_TEMP)
162+
163+
INCLUDE(FindPackageHandleStandardArgs)
164+
165+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)

‎Build/cmake/FindSDL2_image.cmake

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Locate SDL2_image library
2+
# This module defines
3+
# SDL2_IMAGE_LIBRARY, the name of the library to link against
4+
# SDL2_IMAGE_FOUND, if false, do not try to link to SDL2_image
5+
# SDL2_IMAGE_INCLUDE_DIR, where to find SDL.h
6+
#
7+
# Source: https://code.google.com/p/freerct/source/browse/trunk/CMake/FindSDL2_ttf.cmake
8+
#
9+
# $SDL2_IMAGE_DIR is an environment variable that would
10+
# correspond to the ./configure --prefix=$SDL2_IMAGE_DIR
11+
# used in building SDL2_image.
12+
# l.e.galup 9-20-02
13+
#
14+
# Modified by Eric Wing.
15+
# Added code to assist with automated building by using environmental variables
16+
# and providing a more controlled/consistent search behavior.
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 SDL2main 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+
# SDL2_LIBRARY to override this selection or set the CMake environment
27+
# CMAKE_INCLUDE_PATH to modify the search paths.
28+
#
29+
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
30+
# This needed to change because "proper" SDL convention
31+
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
32+
# reasons because not all systems place things in SDL2/ (see FreeBSD).
33+
34+
#=============================================================================
35+
# Copyright 2003-2009 Kitware, Inc.
36+
#
37+
# Distributed under the OSI-approved BSD License (the "License");
38+
# see accompanying file Copyright.txt for details.
39+
#
40+
# This software is distributed WITHOUT ANY WARRANTY; without even the
41+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
42+
# See the License for more information.
43+
#=============================================================================
44+
# (To distribute this file outside of CMake, substitute the full
45+
# License text for the above reference.)
46+
47+
SET(SDL2_IMAGE_SEARCH_PATHS
48+
~/Library/Frameworks
49+
/Library/Frameworks
50+
/usr/local
51+
/usr
52+
/sw # Fink
53+
/opt/local # DarwinPorts
54+
/opt/csw # Blastwave
55+
/opt
56+
)
57+
58+
FIND_PATH(SDL2_IMAGE_INCLUDE_DIR SDL_image.h
59+
HINTS
60+
$ENV{SDL2_IMAGE_DIR}
61+
PATH_SUFFIXES include/SDL2 include
62+
PATHS ${SDL2_IMAGE_SEARCH_PATHS}
63+
)
64+
65+
FIND_LIBRARY(SDL2_IMAGE_LIBRARY_TEMP
66+
NAMES SDL2_image
67+
HINTS
68+
$ENV{SDL2_IMAGE_DIR}
69+
PATH_SUFFIXES lib64 lib
70+
PATHS ${SDL2_IMAGE_SEARCH_PATHS}
71+
)
72+
73+
# SDL2_image may require threads on your system.
74+
# The Apple build may not need an explicit flag because one of the
75+
# frameworks may already provide it.
76+
# But for non-OSX systems, I will use the CMake Threads package.
77+
# IF(NOT APPLE)
78+
# FIND_PACKAGE(Threads)
79+
# ENDIF(NOT APPLE)
80+
81+
# MinGW needs an additional library, mwindows
82+
# It's total link flags should look like -lmingw32 -lSDL2_image -lmwindows
83+
# (Actually on second look, I think it only needs one of the m* libraries.)
84+
IF(MINGW)
85+
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
86+
ENDIF(MINGW)
87+
88+
IF(SDL2_IMAGE_LIBRARY_TEMP)
89+
# For OS X, SDL2_IMAGE uses Cocoa as a backend so it must link to Cocoa.
90+
# CMake doesn't display the -framework Cocoa string in the UI even
91+
# though it actually is there if I modify a pre-used variable.
92+
# I think it has something to do with the CACHE STRING.
93+
# So I use a temporary variable until the end so I can set the
94+
# "real" variable in one-shot.
95+
# IF(APPLE)
96+
# SET(SDL2_IMAGE_LIBRARY_TEMP ${SDL2_IMAGE_LIBRARY_TEMP} "-framework Cocoa")
97+
# ENDIF(APPLE)
98+
99+
# For threads, as mentioned Apple doesn't need this.
100+
# In fact, there seems to be a problem if I used the Threads package
101+
# and try using this line, so I'm just skipping it entirely for OS X.
102+
# IF(NOT APPLE)
103+
# SET(SDL2_IMAGE_LIBRARY_TEMP ${SDL2_IMAGE_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
104+
# ENDIF(NOT APPLE)
105+
106+
# For MinGW library
107+
# IF(MINGW)
108+
# SET(SDL2_IMAGE_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_IMAGE_LIBRARY_TEMP})
109+
# ENDIF(MINGW)
110+
111+
# Set the final string here so the GUI reflects the final state.
112+
SET(SDL2_IMAGE_LIBRARY ${SDL2_IMAGE_LIBRARY_TEMP} CACHE STRING "Where the SDL2_IMAGE Library can be found")
113+
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
114+
SET(SDL2_IMAGE_LIBRARY_TEMP "${SDL2_IMAGE_LIBRARY_TEMP}" CACHE INTERNAL "")
115+
ENDIF(SDL2_IMAGE_LIBRARY_TEMP)
116+
117+
INCLUDE(FindPackageHandleStandardArgs)
118+
119+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image REQUIRED_VARS SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)

0 commit comments

Comments
 (0)
Please sign in to comment.