1
0

FindSDL.cmake 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 NAMES SDL.h
  33. PATH_SUFFIXES SDL SDL12 SDL11
  34. PATHS
  35. $ENV{SDLDIR}/include
  36. ~/Library/Frameworks/SDL.framework/Headers
  37. /Library/Frameworks/SDL.framework/Headers
  38. )
  39. # I'm not sure if I should do a special casing for Apple. It is
  40. # unlikely that other Unix systems will find the framework path.
  41. # But if they do ([Next|Open|GNU]Step?),
  42. # do they want the -framework option also?
  43. IF(${SDL_INCLUDE_DIR} MATCHES ".framework")
  44. # The Cocoa framework must be linked into SDL because SDL is Cocoa based.
  45. # Remember that the OS X framework version expects you to drop in
  46. # SDLmain.h and SDLmain.m directly into your project.
  47. # (Cocoa link moved to bottom of this script.)
  48. # SET (SDL_LIBRARY "-framework SDL -framework Cocoa" CACHE STRING "SDL framework for OSX")
  49. # SET(SDL_LIBRARY "-framework SDL" CACHE STRING "SDL framework for OSX")
  50. # Extract the path the framework resides in so we can use it for the -F flag
  51. STRING(REGEX REPLACE "(.*)/.*\\.framework/.*" "\\1" SDL_FRAMEWORK_PATH_TEMP ${SDL_INCLUDE_DIR})
  52. IF("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
  53. OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
  54. )
  55. # String is in default search path, don't need to use -F
  56. SET(SDL_LIBRARY_TEMP "-framework SDL")
  57. ELSE("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
  58. OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
  59. )
  60. # String is not /Library/Frameworks, need to use -F
  61. SET(SDL_LIBRARY_TEMP "-F${SDL_FRAMEWORK_PATH_TEMP} -framework SDL")
  62. ENDIF("${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/Library/Frameworks"
  63. OR "${SDL_FRAMEWORK_PATH_TEMP}" STREQUAL "/System/Library/Frameworks"
  64. )
  65. # Clear the temp variable so nobody can see it
  66. SET(SDL_FRAMEWORK_PATH_TEMP "" CACHE INTERNAL "")
  67. ELSE(${SDL_INCLUDE_DIR} MATCHES ".framework")
  68. # SDL-1.1 is the name used by FreeBSD ports...
  69. # don't confuse it for the version number.
  70. FIND_LIBRARY(SDL_LIBRARY_TEMP
  71. NAMES SDL SDL-1.1
  72. PATHS
  73. $ENV{SDLDIR}/lib
  74. )
  75. # Non-OS X framework versions expect you to also dynamically link to
  76. # SDLmain. This is mainly for Windows and OS X. Other platforms
  77. # seem to provide SDLmain for compatibility even though they don't
  78. # necessarily need it.
  79. FIND_LIBRARY(SDLMAIN_LIBRARY
  80. NAMES SDLmain SDLmain-1.1
  81. PATHS
  82. $ENV{SDLDIR}/lib
  83. )
  84. ENDIF(${SDL_INCLUDE_DIR} MATCHES ".framework")
  85. # SDL may require threads on your system.
  86. # The Apple build may not need an explicit flag because one of the
  87. # frameworks may already provide it.
  88. # But for non-OSX systems, I will use the CMake Threads package.
  89. IF(NOT APPLE)
  90. FIND_PACKAGE(Threads)
  91. ENDIF(NOT APPLE)
  92. # MinGW needs an additional library, mwindows
  93. # It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows
  94. # (Actually on second look, I think it only needs one of the m* libraries.)
  95. IF(MINGW)
  96. SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
  97. ENDIF(MINGW)
  98. IF(SDL_LIBRARY_TEMP)
  99. # For SDLmain
  100. IF(SDLMAIN_LIBRARY)
  101. SET(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP})
  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_TEMP ${SDL_LIBRARY_TEMP} "-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_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
  116. ENDIF(NOT APPLE)
  117. # For MinGW library
  118. IF(MINGW)
  119. SET(SDL_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL_LIBRARY_TEMP})
  120. ENDIF(MINGW)
  121. # Set the final string here so the GUI reflects the final state.
  122. SET(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found")
  123. ENDIF(SDL_LIBRARY_TEMP)
  124. # handle the QUIETLY and REQUIRED arguments and set SDL_FOUND to TRUE if
  125. # all listed variables are TRUE
  126. INCLUDE(FindPackageHandleStandardArgs)
  127. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL DEFAULT_MSG SDL_LIBRARY_TEMP)
  128. MARK_AS_ADVANCED(SDL_LIBRARY_TEMP)