FindSDL_gfx.cmake 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindSDL_gfx
  5. -----------
  6. .. versionadded:: 3.25
  7. Finds the SDL_gfx library that provides graphics support in SDL (Simple
  8. DirectMedia Layer) applications.
  9. .. note::
  10. This module is for SDL_gfx version 1. For version 2 or newer usage refer to
  11. the upstream documentation.
  12. Imported Targets
  13. ^^^^^^^^^^^^^^^^
  14. This module provides the following :ref:`Imported Targets`:
  15. ``SDL::SDL_gfx``
  16. Target encapsulating the SDL_gfx library usage requirements, available if
  17. SDL_gfx is found.
  18. Result Variables
  19. ^^^^^^^^^^^^^^^^
  20. This module defines the following variables:
  21. ``SDL_gfx_FOUND``
  22. Boolean indicating whether the (requested version of) SDL_gfx library is
  23. found. For backward compatibility, the ``SDL_GFX_FOUND`` variable is also set
  24. to the same value.
  25. ``SDL_GFX_VERSION_STRING``
  26. The human-readable string containing the version of SDL_gfx found.
  27. Cache Variables
  28. ^^^^^^^^^^^^^^^
  29. The following cache variables may also be set:
  30. ``SDL_GFX_INCLUDE_DIRS``
  31. The directory containing the headers needed to use SDL_gfx.
  32. ``SDL_GFX_LIBRARIES``
  33. The path to the SDL_gfx library needed to link against to use SDL_gfx.
  34. Hints
  35. ^^^^^
  36. This module accepts the following variables:
  37. ``SDLDIR``
  38. Environment variable that can be set to help locate an SDL library installed
  39. in a custom location. It should point to the installation destination that
  40. was used when configuring, building, and installing SDL library:
  41. ``./configure --prefix=$SDLDIR``.
  42. Examples
  43. ^^^^^^^^
  44. Finding SDL_gfx library and linking it to a project target:
  45. .. code-block:: cmake
  46. find_package(SDL_gfx)
  47. target_link_libraries(project_target PRIVATE SDL::SDL_gfx)
  48. See Also
  49. ^^^^^^^^
  50. * The :module:`FindSDL` module to find the main SDL library.
  51. #]=======================================================================]
  52. cmake_policy(PUSH)
  53. cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
  54. find_path(SDL_GFX_INCLUDE_DIRS
  55. NAMES
  56. SDL_framerate.h
  57. SDL_gfxBlitFunc.h
  58. SDL_gfxPrimitives.h
  59. SDL_gfxPrimitives_font.h
  60. SDL_imageFilter.h
  61. SDL_rotozoom.h
  62. HINTS
  63. ENV SDLGFXDIR
  64. ENV SDLDIR
  65. PATH_SUFFIXES SDL
  66. # path suffixes to search inside ENV{SDLDIR}
  67. include/SDL include/SDL12 include/SDL11 include
  68. )
  69. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  70. set(VC_LIB_PATH_SUFFIX lib/x64)
  71. else()
  72. set(VC_LIB_PATH_SUFFIX lib/x86)
  73. endif()
  74. find_library(SDL_GFX_LIBRARIES
  75. NAMES SDL_gfx
  76. HINTS
  77. ENV SDLGFXDIR
  78. ENV SDLDIR
  79. PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
  80. )
  81. if(SDL_GFX_INCLUDE_DIRS AND EXISTS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h")
  82. file(STRINGS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MAJOR[ \t]+[0-9]+$")
  83. file(STRINGS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MINOR[ \t]+[0-9]+$")
  84. file(STRINGS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MICRO[ \t]+[0-9]+$")
  85. string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MAJOR[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MAJOR "${SDL_GFX_VERSION_MAJOR_LINE}")
  86. string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MINOR[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MINOR "${SDL_GFX_VERSION_MINOR_LINE}")
  87. string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MICRO[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_PATCH "${SDL_GFX_VERSION_PATCH_LINE}")
  88. set(SDL_GFX_VERSION_STRING ${SDL_GFX_VERSION_MAJOR}.${SDL_GFX_VERSION_MINOR}.${SDL_GFX_VERSION_PATCH})
  89. unset(SDL_GFX_VERSION_MAJOR_LINE)
  90. unset(SDL_GFX_VERSION_MINOR_LINE)
  91. unset(SDL_GFX_VERSION_PATCH_LINE)
  92. unset(SDL_GFX_VERSION_MAJOR)
  93. unset(SDL_GFX_VERSION_MINOR)
  94. unset(SDL_GFX_VERSION_PATCH)
  95. endif()
  96. include(FindPackageHandleStandardArgs)
  97. find_package_handle_standard_args(SDL_gfx
  98. REQUIRED_VARS SDL_GFX_LIBRARIES SDL_GFX_INCLUDE_DIRS
  99. VERSION_VAR SDL_GFX_VERSION_STRING)
  100. if(SDL_gfx_FOUND)
  101. if(NOT TARGET SDL::SDL_gfx)
  102. add_library(SDL::SDL_gfx INTERFACE IMPORTED)
  103. set_target_properties(SDL::SDL_gfx PROPERTIES
  104. INTERFACE_INCLUDE_DIRECTORIES "${SDL_GFX_INCLUDE_DIRS}"
  105. INTERFACE_LINK_LIBRARIES "${SDL_GFX_LIBRARIES}")
  106. endif()
  107. endif()
  108. cmake_policy(POP)