FindSDL.cmake 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. # Don't forget to include SDLmain.h and SDLmain.m your project for the
  8. # OS X framework based version. (Other versions link to -lSDLmain which
  9. # this module will try to find on your behalf.) Also for OS X, this
  10. # module will automatically add the -framework Cocoa on your behalf.
  11. #
  12. # $SDLDIR is an environment variable that would
  13. # correspond to the ./configure --prefix=$SDLDIR
  14. # used in building SDL.
  15. # l.e.galup 9-20-02
  16. #
  17. # Modified by Eric Wing.
  18. # Added new modifications to recognize OS X frameworks and
  19. # additional Unix paths (FreeBSD, etc).
  20. # Also corrected the header search path to follow "proper" SDL guidelines.
  21. # Added a search for SDLmain which is needed by some platforms.
  22. # Added a search for threads which is needed by some platforms.
  23. # Added needed compile switches for MinGW.
  24. #
  25. # On OSX, this will prefer the Framework version (if found) over others.
  26. # People will have to manually change the cache values of
  27. # SDL_LIBRARY to override this selection.
  28. #
  29. # Note that the header path has changed from SDL/SDL.h to just SDL.h
  30. # This needed to change because "proper" SDL convention
  31. # is #include "SDL.h", not <SDL/SDL.h>. This is done for portability
  32. # reasons because not all systems place things in SDL/ (see FreeBSD).
  33. FIND_PATH(SDL_INCLUDE_DIR SDL.h
  34. $ENV{SDLDIR}/include
  35. ~/Library/Frameworks/SDL.framework/Headers
  36. /Library/Frameworks/SDL.framework/Headers
  37. /usr/local/include/SDL
  38. /usr/include/SDL
  39. /usr/local/include/SDL12
  40. /usr/local/include/SDL11 # FreeBSD ports
  41. /usr/include/SDL12
  42. /usr/include/SDL11
  43. /usr/local/include
  44. /usr/include
  45. /sw/include/SDL # Fink
  46. /sw/include
  47. /opt/local/include/SDL # DarwinPorts
  48. /opt/local/include
  49. /opt/csw/include/SDL # Blastwave
  50. /opt/csw/include
  51. /opt/include/SDL
  52. /opt/include
  53. )
  54. # I'm not sure if I should do a special casing for Apple. It is
  55. # unlikely that other Unix systems will find the framework path.
  56. # But if they do ([Next|Open|GNU]Step?),
  57. # do they want the -framework option also?
  58. IF(${SDL_INCLUDE_DIR} MATCHES ".framework")
  59. # The Cocoa framework must be linked into SDL because SDL is Cocoa based.
  60. # Remember that the OS X framework version expects you to drop in
  61. # SDLmain.h and SDLmain.m directly into your project.
  62. # (Cocoa link moved to bottom of this script.)
  63. # SET (SDL_LIBRARY "-framework SDL -framework Cocoa" CACHE STRING "SDL framework for OSX")
  64. # SET(SDL_LIBRARY "-framework SDL" CACHE STRING "SDL framework for OSX")
  65. # Extract the path the framework resides in so we can use it for the -F flag
  66. STRING(REGEX REPLACE "(.*)/.*\\.framework/.*" "\\1" SDL_FRAMEWORK_PATH_TEMP ${SDL_INCLUDE_DIR})
  67. IF("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
  68. OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
  69. )
  70. # String is in default search path, don't need to use -F
  71. SET(SDL_LIBRARY_TEMP "-framework SDL")
  72. ELSE("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
  73. OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
  74. )
  75. # String is not /Library/Frameworks, need to use -F
  76. SET(SDL_LIBRARY_TEMP "-F${SDL_FRAMEWORK_PATH_TEMP} -framework SDL")
  77. ENDIF("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
  78. OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
  79. )
  80. # Clear the temp variable so nobody can see it
  81. SET(SDL_FRAMEWORK_PATH_TEMP "" CACHE INTERNAL "")
  82. ELSE(${SDL_INCLUDE_DIR} MATCHES ".framework")
  83. # SDL-1.1 is the name used by FreeBSD ports...
  84. # don't confuse it for the version number.
  85. FIND_LIBRARY(SDL_LIBRARY_TEMP
  86. NAMES SDL SDL-1.1
  87. PATHS
  88. $ENV{SDLDIR}/lib
  89. /usr/local/lib
  90. /usr/lib
  91. /sw/lib
  92. /opt/local/lib
  93. /opt/csw/lib
  94. /opt/lib
  95. )
  96. # Non-OS X framework versions expect you to also dynamically link to
  97. # SDLmain. This is mainly for Windows and OS X. Other platforms
  98. # seem to provide SDLmain for compatibility even though they don't
  99. # necessarily need it.
  100. FIND_LIBRARY(SDLMAIN_LIBRARY
  101. NAMES SDLmain SDLmain-1.1
  102. PATHS
  103. $ENV{SDLDIR}/lib
  104. /usr/local/lib
  105. /usr/lib
  106. /sw/lib
  107. /opt/local/lib
  108. /opt/csw/lib
  109. /opt/lib
  110. )
  111. ENDIF(${SDL_INCLUDE_DIR} MATCHES ".framework")
  112. # SDL may require threads on your system.
  113. # The Apple build may not need an explicit flag because one of the
  114. # frameworks may already provide it.
  115. # But for non-OSX systems, I will use the CMake Threads package.
  116. IF(NOT APPLE)
  117. FIND_PACKAGE(Threads)
  118. ENDIF(NOT APPLE)
  119. # MinGW needs an additional library, mwindows
  120. # It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows
  121. # (Actually on second look, I think it only needs one of the m* libraries.)
  122. IF(MINGW)
  123. SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
  124. ENDIF(MINGW)
  125. SET(SDL_FOUND "NO")
  126. IF(SDL_LIBRARY_TEMP)
  127. # For SDLmain
  128. IF(SDLMAIN_LIBRARY)
  129. SET(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP})
  130. ENDIF(SDLMAIN_LIBRARY)
  131. # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa.
  132. # CMake doesn't display the -framework Cocoa string in the UI even
  133. # though it actually is there. I think it has something to do
  134. # with the CACHE STRING. Maybe somebody else knows how to fix this.
  135. # The problem is mainly cosmetic, and not a functional issue.
  136. IF(APPLE)
  137. SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-framework Cocoa")
  138. ENDIF(APPLE)
  139. # For threads, as mentioned Apple doesn't need this.
  140. # In fact, there seems to be a problem if Find the threads package
  141. # and try using this line, so I'm just skipping it entirely for OS X.
  142. IF(NOT APPLE)
  143. SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
  144. ENDIF(NOT APPLE)
  145. # For MinGW library
  146. IF(MINGW)
  147. SET(SDL_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL_LIBRARY_TEMP})
  148. ENDIF(MINGW)
  149. # Set the final string here so the GUI reflects the final state.
  150. SET(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found")
  151. SET(SDL_FOUND "YES")
  152. ENDIF(SDL_LIBRARY_TEMP)