FindSDL_gfx.cmake 4.8 KB

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