FindSDL_gfx.cmake 4.9 KB

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