FindSDL.cmake 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # Locate SDL library
  2. # This module defines
  3. # SDL_LIBRARY, the name of the library to link against
  4. # SDL_FOUND, if false, do not try to link to SDL
  5. # SDL_INCLUDE_DIR, where to find SDL.h
  6. #
  7. # This module responds to the the flag:
  8. # SDL_BUILDING_LIBRARY
  9. # If this is defined, then no SDL_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 SDL_LIBRARY variable.
  14. #
  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 -lSDLmain 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 SDL_LIBRARY_TEMP in your configuration
  22. # and no SDL_LIBRARY, it means CMake did not find your SDL library
  23. # (SDL.dll, libsdl.so, SDL.framework, etc).
  24. # Set SDL_LIBRARY_TEMP to point to your SDL library, and configure again.
  25. # Similarly, if you see an empty SDLMAIN_LIBRARY, you should set this value
  26. # as appropriate. These values are used to generate the final SDL_LIBRARY
  27. # variable, but when these values are unset, SDL_LIBRARY does not get created.
  28. #
  29. #
  30. # $SDLDIR is an environment variable that would
  31. # correspond to the ./configure --prefix=$SDLDIR
  32. # used in building SDL.
  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" SDL guidelines.
  41. # Added a search for SDLmain 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. # SDL_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 SDL/SDL.h to just SDL.h
  51. # This needed to change because "proper" SDL convention
  52. # is #include "SDL.h", not <SDL/SDL.h>. This is done for portability
  53. # reasons because not all systems place things in SDL/ (see FreeBSD).
  54. #=============================================================================
  55. # Copyright 2003-2009 Kitware, Inc.
  56. #
  57. # Distributed under the OSI-approved BSD License (the "License");
  58. # see accompanying file Copyright.txt for details.
  59. #
  60. # This software is distributed WITHOUT ANY WARRANTY; without even the
  61. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  62. # See the License for more information.
  63. #=============================================================================
  64. # (To distribute this file outside of CMake, substitute the full
  65. # License text for the above reference.)
  66. find_path(SDL_INCLUDE_DIR SDL.h
  67. HINTS
  68. $ENV{SDLDIR}
  69. PATH_SUFFIXES include/SDL include
  70. PATHS
  71. ~/Library/Frameworks
  72. /Library/Frameworks
  73. /usr/local/include/SDL12
  74. /usr/local/include/SDL11 # FreeBSD ports
  75. /usr/include/SDL12
  76. /usr/include/SDL11
  77. /sw # Fink
  78. /opt/local # DarwinPorts
  79. /opt/csw # Blastwave
  80. /opt
  81. )
  82. # SDL-1.1 is the name used by FreeBSD ports...
  83. # don't confuse it for the version number.
  84. find_library(SDL_LIBRARY_TEMP
  85. NAMES SDL SDL-1.1
  86. HINTS
  87. $ENV{SDLDIR}
  88. PATH_SUFFIXES lib64 lib
  89. PATHS
  90. /sw
  91. /opt/local
  92. /opt/csw
  93. /opt
  94. )
  95. if(NOT SDL_BUILDING_LIBRARY)
  96. if(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework")
  97. # Non-OS X framework versions expect you to also dynamically link to
  98. # SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms
  99. # seem to provide SDLmain for compatibility even though they don't
  100. # necessarily need it.
  101. find_library(SDLMAIN_LIBRARY
  102. NAMES SDLmain SDLmain-1.1
  103. HINTS
  104. $ENV{SDLDIR}
  105. PATH_SUFFIXES lib64 lib
  106. PATHS
  107. /sw
  108. /opt/local
  109. /opt/csw
  110. /opt
  111. )
  112. endif()
  113. endif()
  114. # SDL may require threads on your system.
  115. # The Apple build may not need an explicit flag because one of the
  116. # frameworks may already provide it.
  117. # But for non-OSX systems, I will use the CMake Threads package.
  118. if(NOT APPLE)
  119. find_package(Threads)
  120. endif()
  121. # MinGW needs an additional library, mwindows
  122. # It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows
  123. # (Actually on second look, I think it only needs one of the m* libraries.)
  124. if(MINGW)
  125. set(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
  126. endif()
  127. if(SDL_LIBRARY_TEMP)
  128. # For SDLmain
  129. if(NOT SDL_BUILDING_LIBRARY)
  130. if(SDLMAIN_LIBRARY)
  131. set(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP})
  132. endif()
  133. endif()
  134. # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa.
  135. # CMake doesn't display the -framework Cocoa string in the UI even
  136. # though it actually is there if I modify a pre-used variable.
  137. # I think it has something to do with the CACHE STRING.
  138. # So I use a temporary variable until the end so I can set the
  139. # "real" variable in one-shot.
  140. if(APPLE)
  141. set(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-framework Cocoa")
  142. endif()
  143. # For threads, as mentioned Apple doesn't need this.
  144. # In fact, there seems to be a problem if I used the Threads package
  145. # and try using this line, so I'm just skipping it entirely for OS X.
  146. if(NOT APPLE)
  147. set(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
  148. endif()
  149. # For MinGW library
  150. if(MINGW)
  151. set(SDL_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL_LIBRARY_TEMP})
  152. endif()
  153. # Set the final string here so the GUI reflects the final state.
  154. set(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found")
  155. # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
  156. set(SDL_LIBRARY_TEMP "${SDL_LIBRARY_TEMP}" CACHE INTERNAL "")
  157. endif()
  158. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  159. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL
  160. REQUIRED_VARS SDL_LIBRARY SDL_INCLUDE_DIR)