FindSDL_gfx.cmake 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindSDL_gfx
  5. -----------
  6. .. versionadded:: 3.25
  7. Locate SDL_gfx library
  8. This module defines:
  9. ::
  10. SDL::SDL_gfx, the name of the target to use with target_*() commands
  11. SDL_GFX_LIBRARIES, the name of the library to link against
  12. SDL_GFX_INCLUDE_DIRS, where to find the headers
  13. SDL_GFX_FOUND, if false, do not try to link against
  14. SDL_GFX_VERSION_STRING - human-readable string containing the
  15. version of SDL_gfx
  16. ``$SDLDIR`` is an environment variable that would correspond to the
  17. ``./configure --prefix=$SDLDIR`` used in building SDL.
  18. #]=======================================================================]
  19. cmake_policy(PUSH)
  20. cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
  21. find_path(SDL_GFX_INCLUDE_DIRS
  22. NAMES
  23. SDL_framerate.h
  24. SDL_gfxBlitFunc.h
  25. SDL_gfxPrimitives.h
  26. SDL_gfxPrimitives_font.h
  27. SDL_imageFilter.h
  28. SDL_rotozoom.h
  29. HINTS
  30. ENV SDLGFXDIR
  31. ENV SDLDIR
  32. PATH_SUFFIXES SDL
  33. # path suffixes to search inside ENV{SDLDIR}
  34. include/SDL include/SDL12 include/SDL11 include
  35. )
  36. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  37. set(VC_LIB_PATH_SUFFIX lib/x64)
  38. else()
  39. set(VC_LIB_PATH_SUFFIX lib/x86)
  40. endif()
  41. find_library(SDL_GFX_LIBRARIES
  42. NAMES SDL_gfx
  43. HINTS
  44. ENV SDLGFXDIR
  45. ENV SDLDIR
  46. PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
  47. )
  48. if(SDL_GFX_INCLUDE_DIRS AND EXISTS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h")
  49. file(STRINGS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MAJOR[ \t]+[0-9]+$")
  50. file(STRINGS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MINOR[ \t]+[0-9]+$")
  51. file(STRINGS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MICRO[ \t]+[0-9]+$")
  52. string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MAJOR[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MAJOR "${SDL_GFX_VERSION_MAJOR_LINE}")
  53. string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MINOR[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MINOR "${SDL_GFX_VERSION_MINOR_LINE}")
  54. string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MICRO[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_PATCH "${SDL_GFX_VERSION_PATCH_LINE}")
  55. set(SDL_GFX_VERSION_STRING ${SDL_GFX_VERSION_MAJOR}.${SDL_GFX_VERSION_MINOR}.${SDL_GFX_VERSION_PATCH})
  56. unset(SDL_GFX_VERSION_MAJOR_LINE)
  57. unset(SDL_GFX_VERSION_MINOR_LINE)
  58. unset(SDL_GFX_VERSION_PATCH_LINE)
  59. unset(SDL_GFX_VERSION_MAJOR)
  60. unset(SDL_GFX_VERSION_MINOR)
  61. unset(SDL_GFX_VERSION_PATCH)
  62. endif()
  63. include(FindPackageHandleStandardArgs)
  64. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_gfx
  65. REQUIRED_VARS SDL_GFX_LIBRARIES SDL_GFX_INCLUDE_DIRS
  66. VERSION_VAR SDL_GFX_VERSION_STRING)
  67. if(SDL_gfx_FOUND)
  68. if(NOT TARGET SDL::SDL_gfx)
  69. add_library(SDL::SDL_gfx INTERFACE IMPORTED)
  70. set_target_properties(SDL::SDL_gfx PROPERTIES
  71. INTERFACE_INCLUDE_DIRECTORIES "${SDL_GFX_INCLUDE_DIRS}"
  72. INTERFACE_LINK_LIBRARIES "${SDL_GFX_LIBRARIES}")
  73. endif()
  74. endif()
  75. cmake_policy(POP)