FindSDL.cmake 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. FIND_PATH(SDL_INCLUDE_DIR SDL.h
  55. PATHS
  56. $ENV{SDLDIR}
  57. NO_DEFAULT_PATH
  58. PATH_SUFFIXES include
  59. )
  60. FIND_PATH(SDL_INCLUDE_DIR SDL.h
  61. PATHS ${CMAKE_PREFIX_PATH} # Unofficial: We are proposing this.
  62. NO_DEFAULT_PATH
  63. PATH_SUFFIXES include
  64. )
  65. FIND_PATH(SDL_INCLUDE_DIR SDL.h
  66. PATHS
  67. ~/Library/Frameworks
  68. /Library/Frameworks
  69. /usr/local/include/SDL
  70. /usr/include/SDL
  71. /usr/local/include/SDL12
  72. /usr/local/include/SDL11 # FreeBSD ports
  73. /usr/include/SDL12
  74. /usr/include/SDL11
  75. /usr/local/include
  76. /usr/include
  77. /sw/include/SDL # Fink
  78. /sw/include
  79. /opt/local/include/SDL # DarwinPorts
  80. /opt/local/include
  81. /opt/csw/include/SDL # Blastwave
  82. /opt/csw/include
  83. /opt/include/SDL
  84. /opt/include
  85. )
  86. #MESSAGE("SDL_INCLUDE_DIR is ${SDL_INCLUDE_DIR}")
  87. # SDL-1.1 is the name used by FreeBSD ports...
  88. # don't confuse it for the version number.
  89. FIND_LIBRARY(SDL_LIBRARY_TEMP
  90. NAMES SDL SDL-1.1
  91. PATHS
  92. $ENV{SDLDIR}
  93. NO_DEFAULT_PATH
  94. PATH_SUFFIXES lib64 lib
  95. )
  96. FIND_LIBRARY(SDL_LIBRARY_TEMP
  97. NAMES SDL SDL-1.1
  98. PATHS ${CMAKE_PREFIX_PATH} # Unofficial: We are proposing this.
  99. NO_DEFAULT_PATH
  100. PATH_SUFFIXES lib64 lib
  101. )
  102. FIND_LIBRARY(SDL_LIBRARY_TEMP
  103. NAMES SDL SDL-1.1
  104. PATHS
  105. /usr/local
  106. /usr
  107. /sw
  108. /opt/local
  109. /opt/csw
  110. /opt
  111. PATH_SUFFIXES lib64 lib
  112. )
  113. #MESSAGE("SDL_LIBRARY_TEMP is ${SDL_LIBRARY_TEMP}")
  114. IF(NOT SDL_BUILDING_LIBRARY)
  115. IF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework")
  116. # Non-OS X framework versions expect you to also dynamically link to
  117. # SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms
  118. # seem to provide SDLmain for compatibility even though they don't
  119. # necessarily need it.
  120. FIND_LIBRARY(SDLMAIN_LIBRARY
  121. NAMES SDLmain SDLmain-1.1
  122. PATHS
  123. $ENV{SDLDIR}
  124. NO_DEFAULT_PATH
  125. PATH_SUFFIXES lib64 lib
  126. )
  127. FIND_LIBRARY(SDLMAIN_LIBRARY
  128. NAMES SDLmain SDLmain-1.1
  129. PATHS ${CMAKE_PREFIX_PATH} # Unofficial: We are proposing this.
  130. NO_DEFAULT_PATH
  131. PATH_SUFFIXES lib64 lib
  132. )
  133. FIND_LIBRARY(SDLMAIN_LIBRARY
  134. NAMES SDLmain SDLmain-1.1
  135. PATHS
  136. /usr/local
  137. /usr
  138. /sw
  139. /opt/local
  140. /opt/csw
  141. /opt
  142. PATH_SUFFIXES lib64 lib
  143. )
  144. ENDIF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework")
  145. ENDIF(NOT SDL_BUILDING_LIBRARY)
  146. # SDL may require threads on your system.
  147. # The Apple build may not need an explicit flag because one of the
  148. # frameworks may already provide it.
  149. # But for non-OSX systems, I will use the CMake Threads package.
  150. IF(NOT APPLE)
  151. FIND_PACKAGE(Threads)
  152. ENDIF(NOT APPLE)
  153. # MinGW needs an additional library, mwindows
  154. # It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows
  155. # (Actually on second look, I think it only needs one of the m* libraries.)
  156. IF(MINGW)
  157. SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
  158. ENDIF(MINGW)
  159. SET(SDL_FOUND "NO")
  160. IF(SDL_LIBRARY_TEMP)
  161. # For SDLmain
  162. IF(NOT SDL_BUILDING_LIBRARY)
  163. IF(SDLMAIN_LIBRARY)
  164. SET(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP})
  165. ENDIF(SDLMAIN_LIBRARY)
  166. ENDIF(NOT SDL_BUILDING_LIBRARY)
  167. # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa.
  168. # CMake doesn't display the -framework Cocoa string in the UI even
  169. # though it actually is there if I modify a pre-used variable.
  170. # I think it has something to do with the CACHE STRING.
  171. # So I use a temporary variable until the end so I can set the
  172. # "real" variable in one-shot.
  173. IF(APPLE)
  174. SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-framework Cocoa")
  175. ENDIF(APPLE)
  176. # For threads, as mentioned Apple doesn't need this.
  177. # In fact, there seems to be a problem if I used the Threads package
  178. # and try using this line, so I'm just skipping it entirely for OS X.
  179. IF(NOT APPLE)
  180. SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
  181. ENDIF(NOT APPLE)
  182. # For MinGW library
  183. IF(MINGW)
  184. SET(SDL_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL_LIBRARY_TEMP})
  185. ENDIF(MINGW)
  186. # Set the final string here so the GUI reflects the final state.
  187. SET(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found")
  188. # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
  189. SET(SDL_LIBRARY_TEMP "" CACHE INTERNAL "")
  190. SET(SDL_FOUND "YES")
  191. ENDIF(SDL_LIBRARY_TEMP)
  192. #MESSAGE("SDL_LIBRARY is ${SDL_LIBRARY}")