1+ #https://raw.githubusercontent.com/freeorion/freeorion/master/cmake/FindSDL.cmake
2+ #.rst:
3+ # FindSDL
4+ # -------
5+ #
6+ # Find the native SDL includes and library.
7+ #
8+ # IMPORTED Targets
9+ # ^^^^^^^^^^^^^^^^
10+ #
11+ # This module defines :prop_tgt:`IMPORTED` targets
12+ #
13+ # ::
14+ #
15+ # ``SDL::SDL`` - The SDL library.
16+ # ``SDL::main`` - The SDLmain library.
17+ #
18+ # Result Variables
19+ # ^^^^^^^^^^^^^^^^
20+ #
21+ # This module defines the following variables:
22+ #
23+ # ::
24+ #
25+ # SDL_INCLUDE_DIRS - where to find SDL.h, etc.
26+ # SDL_LIBRARIES - List of librarie when using SDL
27+ # SDL_VERSION - SDL version from SDL_version.hpp
28+ # SDL_MAJOR_VERSION - SDL major version number (X in X.y.z)
29+ # SDL_MINOR_VERSION - SDL minor version number (Y in x.Y.z)
30+ # SDL_PATCH_VERSION - SDL patch version number (Z in x.y.Z)
31+ # SDL_FOUND - True if SDL found.
32+ #
33+ # Controls
34+ # ^^^^^^^^
35+ #
36+ # ::
37+ #
38+ # SDL_NO_MAIN - If set to true the SDLmain library is skipped
39+ # from the SDL_LIBRARIES to let the application
40+ # handle the various entry point variants used
41+ # by different operating systems.
42+ #
43+ # Hints
44+ # ^^^^^
45+ #
46+ # A user may set ``SDL_ROOT`` to a SDL installation root to tell this
47+ # module where to look.
48+ #
49+ # On OSX, this will prefer the Framework version (if found) over others.
50+ # People will have to manually change the cache values of SDL2_LIBRARY to
51+ # override this selection or set the CMake environment
52+ # CMAKE_INCLUDE_PATH to modify the search paths.
53+
54+ #=============================================================================
55+ # Copyright 2003-2009 Kitware, Inc.
56+ # Copyright 2012 Benjamin Eikel
57+ #
58+ # Distributed under the OSI-approved BSD License (the "License");
59+ # see accompanying file Copyright.txt for details.
60+ #
61+ # This software is distributed WITHOUT ANY WARRANTY; without even the
62+ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
63+ # See the License for more information.
64+ #=============================================================================
65+ # (To distribute this file outside of CMake, substitute the full
66+ # License text for the above reference.)
67+
68+
69+ set (_SDL_SEARCHES)
70+
71+ # Search SDL_ROOT first when is set.
72+ if (SDL_ROOT)
73+ set (_SDL_SEARCH_ROOT PATH ${SDL_ROOT} NO_DEFAULT_PATH)
74+ list (APPEND _SDL_SEARCHES _OGG_SEARCH_ROOT)
75+ endif ()
76+
77+ # Normal search.
78+ set (_SDL_SEARCH_NORMAL
79+ PATH ""
80+ )
81+ list (APPEND _SDL_SEARCHES _SDL_SEARCH_NORMAL)
82+
83+ foreach (search ${_SDL_SEARCHES} )
84+ find_path (SDL_INCLUDE_DIR NAMES SDL.h ${${search} } PATH_SUFFIXES SDL2)
85+ endforeach ()
86+
87+ if (SDL_INCLUDE_DIR)
88+ file (STRINGS "${SDL_INCLUDE_DIR} /SDL_version.h" _SDL_VERSION_HPP_CONTENTS REGEX "#define SDL_((MAJOR|MINOR)_VERSION|PATCHLEVEL)" )
89+ foreach (v MAJOR_VERSION MINOR_VERSION PATCHLEVEL)
90+ if ("${_SDL_VERSION_HPP_CONTENTS} " MATCHES "#define SDL_${v} +([0-9]+)" )
91+ set (SDL_${v} "${CMAKE_MATCH_1} " )
92+ endif ()
93+ endforeach ()
94+ set (SDL_PATCH_VERSION ${SDL_PATCHLEVEL} )
95+ unset (SDL_PATCHLEVEL)
96+ set (SDL_VERSION "${SDL_MAJOR_VERSION} .${SDL_MINOR_VERSION} .${SDL_PATCH_VERSION} " )
97+ endif ()
98+
99+ # Allow SDL_LIBRARY to be set manually, as the location of the
100+ # SDL library
101+ if (NOT SDL_LIBRARY)
102+ foreach (search ${_SDL_SEARCHES} )
103+ find_library (SDL_LIBRARY NAMES SDL2 ${${search} } PATH_SUFFIXES lib64 lib)
104+ endforeach ()
105+ endif ()
106+
107+ if (NOT SDL_NO_MAIN AND NOT ${SDL_INCLUDE_DIR} MATCHES ".framework" )
108+ foreach (search ${_SDL_SEARCHES} )
109+ # Non-OS X framework versions expect you to also dynamically link to
110+ # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
111+ # seem to provide SDL2main for compatibility even though they don't
112+ # necessarily need it.
113+ find_library (SDL_MAIN_LIBRARY NAMES SDL2main ${${search} } PATH_SUFFIXES lib64 lib)
114+ endforeach ()
115+ endif ()
116+
117+ include (FindPackageHandleStandardArgs)
118+ find_package_handle_standard_args(SDL REQUIRED_VARS SDL_LIBRARY SDL_INCLUDE_DIR
119+ VERSION_VAR SDL_VERSION)
120+
121+ if (SDL_FOUND)
122+ set (SDL_INCLUDE_DIRS ${SDL_INCLUDE_DIRS} )
123+
124+ if (NOT SDL_LIBRARIES)
125+ set (SDL_LIBRARIES ${SDL_LIBRARY} )
126+
127+ # For SDL2main
128+ if (NOT SDL_NO_MAIN AND SDL_MAIN_LIBRARY)
129+ set (SDL_LIBRARIES ${SDL_MAIN_LIBRARY} ${SDL_LIBRARIES} )
130+ endif ()
131+
132+ if (APPLE )
133+ # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
134+ set (SDL_LIBRARIES ${SDL_LIBRARIES} "-framework Cocoa" )
135+ endif ()
136+ endif ()
137+
138+ if (NOT TARGET SDL::SDL)
139+ add_library (SDL::SDL UNKNOWN IMPORTED )
140+ set_target_properties (SDL::SDL PROPERTIES
141+ INTERFACE_INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIRS} " )
142+
143+ if (SDL_LIBRARY)
144+ set_property (TARGET SDL::SDL APPEND PROPERTY
145+ IMPORTED_LOCATION "${SDL_LIBRARY} " )
146+ endif ()
147+ endif ()
148+
149+ if (NOT TARGET SDL::main AND SDL_MAIN_LIBRARY)
150+ add_library (SDL::main UNKNOWN IMPORTED )
151+
152+ if (SDL_MAIN_LIBRARY)
153+ set_property (TARGET SDL::main APPEND PROPERTY
154+ IMPORTED_LOCATION "${SDL_MAIN_LIBRARY} " )
155+ endif ()
156+
157+
158+ add_dependencies (SDL::SDL SDL::main)
159+ endif ()
160+ endif ()
0 commit comments