1 # Locate SDL2 library |
1 # Locate SDL2 library |
2 # This module defines |
2 # This module defines |
3 # SDL2_LIBRARY, the name of the library to link against |
3 # SDL2_LIBRARIES, the name of the library to link against |
4 # SDL2_FOUND, if false, do not try to link to SDL2 |
4 # SDL2_FOUND, if false, do not try to link to SDL2 |
5 # SDL2_INCLUDE_DIR, where to find SDL.h |
5 # SDL2_INCLUDE_DIR, where to find SDL.h |
6 # |
6 # |
7 # This module responds to the the flag: |
7 # This module responds to the the flag: |
8 # SDL2_BUILDING_LIBRARY |
8 # SDL2_BUILDING_LIBRARY |
9 # If this is defined, then no SDL2main will be linked in because |
9 # If this is defined, then no SDL2main will be linked in because |
10 # only applications need main(). |
10 # only applications need main(). |
11 # Otherwise, it is assumed you are building an application and this |
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 |
12 # module will attempt to locate and set the the proper link flags |
13 # as part of the returned SDL2_LIBRARY variable. |
13 # as part of the returned SDL2_LIBRARIES variable. |
14 # |
14 # |
15 # Don't forget to include SDLmain.h and SDLmain.m your project for the |
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 -lSDL2main which |
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 |
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. |
18 # module will automatically add the -framework Cocoa on your behalf. |
19 # |
19 # |
20 # |
20 # |
21 # Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration |
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 |
22 # and no SDL2_LIBRARIES, it means CMake did not find your SDL2 library |
23 # (SDL2.dll, libsdl2.so, SDL2.framework, etc). |
23 # (SDL2.dll, libsdl2.so, SDL2.framework, etc). |
24 # Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. |
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 |
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 |
26 # as appropriate. These values are used to generate the final SDL2_LIBRARIES |
27 # variable, but when these values are unset, SDL2_LIBRARY does not get created. |
27 # variable, but when these values are unset, SDL2_LIBRARIES does not get created. |
28 # |
28 # |
29 # |
29 # |
30 # $SDL2DIR is an environment variable that would |
30 # $SDL2DIR is an environment variable that would |
31 # correspond to the ./configure --prefix=$SDL2DIR |
31 # correspond to the ./configure --prefix=$SDL2DIR |
32 # used in building SDL2. |
32 # used in building SDL2. |
42 # Added a search for threads 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. |
43 # Added needed compile switches for MinGW. |
44 # |
44 # |
45 # On OSX, this will prefer the Framework version (if found) over others. |
45 # On OSX, this will prefer the Framework version (if found) over others. |
46 # People will have to manually change the cache values of |
46 # People will have to manually change the cache values of |
47 # SDL2_LIBRARY to override this selection or set the CMake environment |
47 # SDL2_LIBRARIES to override this selection or set the CMake environment |
48 # CMAKE_INCLUDE_PATH to modify the search paths. |
48 # CMAKE_INCLUDE_PATH to modify the search paths. |
49 # |
49 # |
50 # Note that the header path has changed from SDL2/SDL.h to just SDL.h |
50 # Note that the header path has changed from SDL2/SDL.h to just SDL.h |
51 # This needed to change because "proper" SDL convention |
51 # This needed to change because "proper" SDL convention |
52 # is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability |
52 # is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability |
90 PATH_SUFFIXES lib64 lib |
90 PATH_SUFFIXES lib64 lib |
91 PATHS ${SDL2_SEARCH_PATHS} |
91 PATHS ${SDL2_SEARCH_PATHS} |
92 ) |
92 ) |
93 |
93 |
94 IF(NOT SDL2_BUILDING_LIBRARY) |
94 IF(NOT SDL2_BUILDING_LIBRARY) |
95 IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") |
95 IF(NOT ${SDL2_INCLUDE_DIRS} MATCHES ".framework") |
96 # Non-OS X framework versions expect you to also dynamically link to |
96 # Non-OS X framework versions expect you to also dynamically link to |
97 # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms |
97 # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms |
98 # seem to provide SDL2main for compatibility even though they don't |
98 # seem to provide SDL2main for compatibility even though they don't |
99 # necessarily need it. |
99 # necessarily need it. |
100 FIND_LIBRARY(SDL2MAIN_LIBRARY |
100 FIND_LIBRARY(SDL2MAIN_LIBRARY |
102 HINTS |
102 HINTS |
103 $ENV{SDL2DIR} |
103 $ENV{SDL2DIR} |
104 PATH_SUFFIXES lib64 lib |
104 PATH_SUFFIXES lib64 lib |
105 PATHS ${SDL2_SEARCH_PATHS} |
105 PATHS ${SDL2_SEARCH_PATHS} |
106 ) |
106 ) |
107 ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") |
107 ENDIF(NOT ${SDL2_INCLUDE_DIRS} MATCHES ".framework") |
108 ENDIF(NOT SDL2_BUILDING_LIBRARY) |
108 ENDIF(NOT SDL2_BUILDING_LIBRARY) |
109 |
109 |
110 # SDL2 may require threads on your system. |
110 # SDL2 may require threads on your system. |
111 # The Apple build may not need an explicit flag because one of the |
111 # The Apple build may not need an explicit flag because one of the |
112 # frameworks may already provide it. |
112 # frameworks may already provide it. |
151 IF(MINGW) |
151 IF(MINGW) |
152 SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) |
152 SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) |
153 ENDIF(MINGW) |
153 ENDIF(MINGW) |
154 |
154 |
155 # Set the final string here so the GUI reflects the final state. |
155 # Set the final string here so the GUI reflects the final state. |
156 SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") |
156 SET(SDL2_LIBRARIES ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") |
157 # Set the temp variable to INTERNAL so it is not seen in the CMake GUI |
157 # Set the temp variable to INTERNAL so it is not seen in the CMake GUI |
158 SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") |
158 SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") |
159 ENDIF(SDL2_LIBRARY_TEMP) |
159 ENDIF(SDL2_LIBRARY_TEMP) |
160 |
160 |
161 if(BUILD_ENGINE_JS) |
161 if(BUILD_ENGINE_JS) |
162 set(SDL2_LIBRARY "sdl2_emscripten_internal" CACHE STRING "emscripten override" FORCE) |
162 set(SDL2_LIBRARIES "sdl2_emscripten_internal" CACHE STRING "emscripten override" FORCE) |
163 set(SDL2_INCLUDE_DIR "${CMAKE_SYSTEM_INCLUDE_PATH}/SDL" CACHE STRING "emscripten override" FORCE) |
163 set(SDL2_INCLUDE_DIRS "${CMAKE_SYSTEM_INCLUDE_PATH}/SDL" CACHE STRING "emscripten override" FORCE) |
164 endif() |
164 endif() |
165 |
165 |
166 INCLUDE(FindPackageHandleStandardArgs) |
166 INCLUDE(FindPackageHandleStandardArgs) |
167 |
167 |
168 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) |
168 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARIES SDL2_INCLUDE_DIRS) |
169 |
169 |