FindSDL2_image.cmake 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #[[
  2. Find module for SDL_image version 2 that matches the naming convention of the SDL2_imageConfig.cmake file
  3. provided in official distributions of the SDL2_image library.
  4. This is necessary on some distributions, including Ubuntu 20.04 and 22.04, because the libsdl2-image-dev package
  5. doesn't provide the config file. https://packages.ubuntu.com/focal/amd64/libsdl2-image-dev/filelist
  6. Furthermore, the CMake integrated find module is only compatible with the SDL1_image.
  7. Defines the imported CMake target:
  8. SDL2_image::SDL2_image
  9. In addition, the following CMake variables are defined according to normal conventions:
  10. SDL2_IMAGE_LIBRARIES
  11. SDL2_IMAGE_INCLUDE_DIRS
  12. SDL2_IMAGE_FOUND
  13. ]]
  14. # Prefer config mode.
  15. find_package(SDL2_image CONFIG QUIET)
  16. if(TARGET SDL2_image::SDL2_image)
  17. return()
  18. endif()
  19. # Not found in config mode, proceed as a normal find module.
  20. find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h
  21. HINTS ENV SDL2_IMAGE_DIR
  22. PATH_SUFFIXES SDL2
  23. )
  24. find_library(SDL2_IMAGE_LIBRARY
  25. NAMES SDL2_image
  26. HINTS ENV SDL2_IMAGE_DIR
  27. PATH_SUFFIXES lib
  28. )
  29. set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR})
  30. set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY})
  31. include(FindPackageHandleStandardArgs)
  32. find_package_handle_standard_args(SDL2_image
  33. REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS
  34. )
  35. mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)
  36. if(SDL2_IMAGE_FOUND)
  37. if(NOT TARGET SDL2_image::SDL2_image)
  38. add_library(SDL2_image::SDL2_image INTERFACE IMPORTED)
  39. set_target_properties(SDL2_image::SDL2_image PROPERTIES
  40. INTERFACE_INCLUDE_DIRECTORIES "${SDL2_IMAGE_INCLUDE_DIRS}"
  41. INTERFACE_LINK_LIBRARIES "${SDL2_IMAGE_LIBRARIES}"
  42. )
  43. endif()
  44. endif()