FindSDL2_image.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Locate SDL2_image library
  2. # This module defines
  3. # SDL2_IMAGE_LIBRARY, the name of the library to link against
  4. # SDL2_IMAGE_FOUND, if false, do not try to link to SDL2_image
  5. # SDL2_IMAGE_INCLUDE_DIR, where to find SDL.h
  6. #
  7. # Source: https://code.google.com/p/freerct/source/browse/trunk/CMake/FindSDL2_ttf.cmake
  8. #
  9. # $SDL2_IMAGE_DIR is an environment variable that would
  10. # correspond to the ./configure --prefix=$SDL2_IMAGE_DIR
  11. # used in building SDL2_image.
  12. # l.e.galup 9-20-02
  13. #
  14. # Modified by Eric Wing.
  15. # Added code to assist with automated building by using environmental variables
  16. # and providing a more controlled/consistent search behavior.
  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 SDL2main 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. # SDL2_LIBRARY to override this selection or set the CMake environment
  27. # CMAKE_INCLUDE_PATH to modify the search paths.
  28. #
  29. # Note that the header path has changed from SDL2/SDL.h to just SDL.h
  30. # This needed to change because "proper" SDL convention
  31. # is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
  32. # reasons because not all systems place things in SDL2/ (see FreeBSD).
  33. #=============================================================================
  34. # Copyright 2003-2009 Kitware, Inc.
  35. #
  36. # Distributed under the OSI-approved BSD License (the "License");
  37. # see accompanying file Copyright.txt for details.
  38. #
  39. # This software is distributed WITHOUT ANY WARRANTY; without even the
  40. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  41. # See the License for more information.
  42. #=============================================================================
  43. # (To distribute this file outside of CMake, substitute the full
  44. # License text for the above reference.)
  45. SET(SDL2_IMAGE_SEARCH_PATHS
  46. ~/Library/Frameworks
  47. /Library/Frameworks
  48. /usr/local
  49. /usr
  50. /sw # Fink
  51. /opt/local # DarwinPorts
  52. /opt/csw # Blastwave
  53. /opt
  54. )
  55. FIND_PATH(SDL2_IMAGE_INCLUDE_DIR SDL_image.h
  56. HINTS
  57. $ENV{SDL2_IMAGE_DIR}
  58. PATH_SUFFIXES include/SDL2 include
  59. PATHS ${SDL2_IMAGE_SEARCH_PATHS}
  60. )
  61. FIND_LIBRARY(SDL2_IMAGE_LIBRARY_TEMP
  62. NAMES SDL2_image
  63. HINTS
  64. $ENV{SDL2_IMAGE_DIR}
  65. PATH_SUFFIXES lib64 lib
  66. PATHS ${SDL2_IMAGE_SEARCH_PATHS}
  67. )
  68. # SDL2_image may require threads on your system.
  69. # The Apple build may not need an explicit flag because one of the
  70. # frameworks may already provide it.
  71. # But for non-OSX systems, I will use the CMake Threads package.
  72. # IF(NOT APPLE)
  73. # FIND_PACKAGE(Threads)
  74. # ENDIF(NOT APPLE)
  75. # MinGW needs an additional library, mwindows
  76. # It's total link flags should look like -lmingw32 -lSDL2_image -lmwindows
  77. # (Actually on second look, I think it only needs one of the m* libraries.)
  78. IF(MINGW)
  79. SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
  80. ENDIF(MINGW)
  81. IF(SDL2_IMAGE_LIBRARY_TEMP)
  82. # For OS X, SDL2_IMAGE uses Cocoa as a backend so it must link to Cocoa.
  83. # CMake doesn't display the -framework Cocoa string in the UI even
  84. # though it actually is there if I modify a pre-used variable.
  85. # I think it has something to do with the CACHE STRING.
  86. # So I use a temporary variable until the end so I can set the
  87. # "real" variable in one-shot.
  88. # IF(APPLE)
  89. # SET(SDL2_IMAGE_LIBRARY_TEMP ${SDL2_IMAGE_LIBRARY_TEMP} "-framework Cocoa")
  90. # ENDIF(APPLE)
  91. # For threads, as mentioned Apple doesn't need this.
  92. # In fact, there seems to be a problem if I used the Threads package
  93. # and try using this line, so I'm just skipping it entirely for OS X.
  94. # IF(NOT APPLE)
  95. # SET(SDL2_IMAGE_LIBRARY_TEMP ${SDL2_IMAGE_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
  96. # ENDIF(NOT APPLE)
  97. # For MinGW library
  98. # IF(MINGW)
  99. # SET(SDL2_IMAGE_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_IMAGE_LIBRARY_TEMP})
  100. # ENDIF(MINGW)
  101. # Set the final string here so the GUI reflects the final state.
  102. SET(SDL2_IMAGE_LIBRARY ${SDL2_IMAGE_LIBRARY_TEMP} CACHE STRING "Where the SDL2_IMAGE Library can be found")
  103. # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
  104. SET(SDL2_IMAGE_LIBRARY_TEMP "${SDL2_IMAGE_LIBRARY_TEMP}" CACHE INTERNAL "")
  105. ENDIF(SDL2_IMAGE_LIBRARY_TEMP)
  106. INCLUDE(FindPackageHandleStandardArgs)
  107. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image REQUIRED_VARS SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)