FindSDL.cmake 4.7 KB

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