FindSDL.cmake 6.1 KB

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