FindSDL2.cmake 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. # This module defines
  2. # SDL2_LIBRARY, the name of the library to link against
  3. # SDL2_FOUND, if false, do not try to link to SDL2
  4. # SDL2_INCLUDE_DIR, where to find SDL.h
  5. #
  6. # This module responds to the the flag:
  7. # SDL2_BUILDING_LIBRARY
  8. # If this is defined, then no SDL2main will be linked in because
  9. # only applications need main().
  10. # Otherwise, it is assumed you are building an application and this
  11. # module will attempt to locate and set the the proper link flags
  12. # as part of the returned SDL2_LIBRARY variable.
  13. #
  14. # Don't forget to include SDLmain.h and SDLmain.m your project for the
  15. # OS X framework based version. (Other versions link to -lSDL2main which
  16. # this module will try to find on your behalf.) Also for OS X, this
  17. # module will automatically add the -framework Cocoa on your behalf.
  18. #
  19. #
  20. # Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
  21. # and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
  22. # (SDL2.dll, libsdl2.so, SDL2.framework, etc).
  23. # Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
  24. # Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
  25. # as appropriate. These values are used to generate the final SDL2_LIBRARY
  26. # variable, but when these values are unset, SDL2_LIBRARY does not get created.
  27. #
  28. #
  29. # $SDL2DIR is an environment variable that would
  30. # correspond to the ./configure --prefix=$SDL2DIR
  31. # used in building SDL2.
  32. # l.e.galup 9-20-02
  33. #
  34. # Modified by Eric Wing.
  35. # Added code to assist with automated building by using environmental variables
  36. # and providing a more controlled/consistent search behavior.
  37. # Added new modifications to recognize OS X frameworks and
  38. # additional Unix paths (FreeBSD, etc).
  39. # Also corrected the header search path to follow "proper" SDL guidelines.
  40. # Added a search for SDL2main which is needed by some platforms.
  41. # Added a search for threads which is needed by some platforms.
  42. # Added needed compile switches for MinGW.
  43. #
  44. # On OSX, this will prefer the Framework version (if found) over others.
  45. # People will have to manually change the cache values of
  46. # SDL2_LIBRARY to override this selection or set the CMake environment
  47. # CMAKE_INCLUDE_PATH to modify the search paths.
  48. #
  49. # Note that the header path has changed from SDL2/SDL.h to just SDL.h
  50. # This needed to change because "proper" SDL convention
  51. # is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
  52. # reasons because not all systems place things in SDL2/ (see FreeBSD).
  53. #=============================================================================
  54. # Copyright 2003-2009 Kitware, Inc.
  55. #
  56. # Distributed under the OSI-approved BSD License (the "License").
  57. #
  58. # This software is distributed WITHOUT ANY WARRANTY; without even the
  59. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  60. # See the License for more information.
  61. #=============================================================================
  62. # CMake - Cross Platform Makefile Generator
  63. # Copyright 2000-2016 Kitware, Inc.
  64. # Copyright 2000-2011 Insight Software Consortium
  65. # All rights reserved.
  66. #
  67. # Redistribution and use in source and binary forms, with or without
  68. # modification, are permitted provided that the following conditions
  69. # are met:
  70. #
  71. # * Redistributions of source code must retain the above copyright
  72. # notice, this list of conditions and the following disclaimer.
  73. #
  74. # * Redistributions in binary form must reproduce the above copyright
  75. # notice, this list of conditions and the following disclaimer in the
  76. # documentation and/or other materials provided with the distribution.
  77. #
  78. # * Neither the names of Kitware, Inc., the Insight Software Consortium,
  79. # nor the names of their contributors may be used to endorse or promote
  80. # products derived from this software without specific prior written
  81. # permission.
  82. #
  83. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  84. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  85. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  86. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  87. # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  88. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  89. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  90. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  91. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  92. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  93. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  94. #
  95. # ------------------------------------------------------------------------------
  96. #
  97. # The above copyright and license notice applies to distributions of
  98. # CMake in source and binary form. Some source files contain additional
  99. # notices of original copyright by their contributors; see each source
  100. # for details. Third-party software packages supplied with CMake under
  101. # compatible licenses provide their own copyright notices documented in
  102. # corresponding subdirectories.
  103. #
  104. # ------------------------------------------------------------------------------
  105. #
  106. # CMake was initially developed by Kitware with the following sponsorship:
  107. #
  108. # * National Library of Medicine at the National Institutes of Health
  109. # as part of the Insight Segmentation and Registration Toolkit (ITK).
  110. #
  111. # * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel
  112. # Visualization Initiative.
  113. #
  114. # * National Alliance for Medical Image Computing (NAMIC) is funded by the
  115. # National Institutes of Health through the NIH Roadmap for Medical Research,
  116. # Grant U54 EB005149.
  117. #
  118. # * Kitware, Inc.
  119. #
  120. message("<FindSDL2.cmake>")
  121. SET(SDL2_SEARCH_PATHS
  122. ~/Library/Frameworks
  123. /Library/Frameworks
  124. /usr/local
  125. /usr
  126. /sw # Fink
  127. /opt/local # DarwinPorts
  128. /opt/csw # Blastwave
  129. /opt
  130. ${SDL2_PATH}
  131. )
  132. FIND_LIBRARY(SDL2_LIBRARY_TEMP
  133. NAMES SDL2
  134. HINTS
  135. $ENV{SDL2DIR}
  136. PATH_SUFFIXES lib64 lib
  137. PATHS ${SDL2_SEARCH_PATHS}
  138. )
  139. IF(SDL2_LIBRARY_TEMP)
  140. FIND_PATH(SDL2_INCLUDE_DIR SDL.h
  141. HINTS
  142. $ENV{SDL2DIR}
  143. PATH_SUFFIXES include/SDL2 include
  144. PATHS ${SDL2_SEARCH_PATHS}
  145. )
  146. IF(NOT SDL2_BUILDING_LIBRARY)
  147. IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
  148. # Non-OS X framework versions expect you to also dynamically link to
  149. # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
  150. # seem to provide SDL2main for compatibility even though they don't
  151. # necessarily need it.
  152. FIND_LIBRARY(SDL2MAIN_LIBRARY
  153. NAMES SDL2main
  154. HINTS
  155. $ENV{SDL2DIR}
  156. PATH_SUFFIXES lib64 lib
  157. PATHS ${SDL2_SEARCH_PATHS}
  158. )
  159. ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
  160. ENDIF(NOT SDL2_BUILDING_LIBRARY)
  161. # SDL2 may require threads on your system.
  162. # The Apple build may not need an explicit flag because one of the
  163. # frameworks may already provide it.
  164. # But for non-OSX systems, I will use the CMake Threads package.
  165. IF(NOT APPLE)
  166. FIND_PACKAGE(Threads)
  167. ENDIF(NOT APPLE)
  168. # MinGW needs an additional library, mwindows
  169. # It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
  170. # (Actually on second look, I think it only needs one of the m* libraries.)
  171. IF(MINGW)
  172. SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
  173. ENDIF(MINGW)
  174. # For SDL2main
  175. IF(NOT SDL2_BUILDING_LIBRARY)
  176. IF(SDL2MAIN_LIBRARY)
  177. SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
  178. ENDIF(SDL2MAIN_LIBRARY)
  179. ENDIF(NOT SDL2_BUILDING_LIBRARY)
  180. # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
  181. # CMake doesn't display the -framework Cocoa string in the UI even
  182. # though it actually is there if I modify a pre-used variable.
  183. # I think it has something to do with the CACHE STRING.
  184. # So I use a temporary variable until the end so I can set the
  185. # "real" variable in one-shot.
  186. IF(APPLE)
  187. SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
  188. ENDIF(APPLE)
  189. # For threads, as mentioned Apple doesn't need this.
  190. # In fact, there seems to be a problem if I used the Threads package
  191. # and try using this line, so I'm just skipping it entirely for OS X.
  192. IF(NOT APPLE)
  193. SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
  194. ENDIF(NOT APPLE)
  195. # For MinGW library
  196. IF(MINGW)
  197. SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
  198. ENDIF(MINGW)
  199. # Set the final string here so the GUI reflects the final state.
  200. SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
  201. # Unset the temp variable to INTERNAL so it is not seen in the CMake GUI
  202. UNSET(SDL2_LIBRARY_TEMP)
  203. ENDIF(SDL2_LIBRARY_TEMP)
  204. message("</FindSDL2.cmake>")
  205. INCLUDE(FindPackageHandleStandardArgs)
  206. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)