FindSDL_ttf.cmake 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_ttf
  5. -----------
  6. Locate SDL_ttf library
  7. This module defines:
  8. ::
  9. SDL_TTF_LIBRARIES, the name of the library to link against
  10. SDL_TTF_INCLUDE_DIRS, where to find the headers
  11. SDL_TTF_FOUND, if false, do not try to link against
  12. SDL_TTF_VERSION_STRING - human-readable string containing the version of SDL_ttf
  13. For backward compatibility the following variables are also set:
  14. ::
  15. SDLTTF_LIBRARY (same value as SDL_TTF_LIBRARIES)
  16. SDLTTF_INCLUDE_DIR (same value as SDL_TTF_INCLUDE_DIRS)
  17. SDLTTF_FOUND (same value as SDL_TTF_FOUND)
  18. $SDLDIR is an environment variable that would correspond to the
  19. ./configure --prefix=$SDLDIR used in building SDL.
  20. Created by Eric Wing. This was influenced by the FindSDL.cmake
  21. module, but with modifications to recognize OS X frameworks and
  22. additional Unix paths (FreeBSD, etc).
  23. #]=======================================================================]
  24. if(NOT SDL_TTF_INCLUDE_DIR AND SDLTTF_INCLUDE_DIR)
  25. set(SDL_TTF_INCLUDE_DIR ${SDLTTF_INCLUDE_DIR} CACHE PATH "directory cache
  26. entry initialized from old variable name")
  27. endif()
  28. find_path(SDL_TTF_INCLUDE_DIR SDL_ttf.h
  29. HINTS
  30. ENV SDLTTFDIR
  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. if(NOT SDL_TTF_LIBRARY AND SDLTTF_LIBRARY)
  42. set(SDL_TTF_LIBRARY ${SDLTTF_LIBRARY} CACHE FILEPATH "file cache entry
  43. initialized from old variable name")
  44. endif()
  45. find_library(SDL_TTF_LIBRARY
  46. NAMES SDL_ttf
  47. HINTS
  48. ENV SDLTTFDIR
  49. ENV SDLDIR
  50. PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
  51. )
  52. if(SDL_TTF_INCLUDE_DIR AND EXISTS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h")
  53. file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$")
  54. file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$")
  55. file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+[0-9]+$")
  56. string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_MAJOR "${SDL_TTF_VERSION_MAJOR_LINE}")
  57. string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_MINOR "${SDL_TTF_VERSION_MINOR_LINE}")
  58. string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_PATCH "${SDL_TTF_VERSION_PATCH_LINE}")
  59. set(SDL_TTF_VERSION_STRING ${SDL_TTF_VERSION_MAJOR}.${SDL_TTF_VERSION_MINOR}.${SDL_TTF_VERSION_PATCH})
  60. unset(SDL_TTF_VERSION_MAJOR_LINE)
  61. unset(SDL_TTF_VERSION_MINOR_LINE)
  62. unset(SDL_TTF_VERSION_PATCH_LINE)
  63. unset(SDL_TTF_VERSION_MAJOR)
  64. unset(SDL_TTF_VERSION_MINOR)
  65. unset(SDL_TTF_VERSION_PATCH)
  66. endif()
  67. set(SDL_TTF_LIBRARIES ${SDL_TTF_LIBRARY})
  68. set(SDL_TTF_INCLUDE_DIRS ${SDL_TTF_INCLUDE_DIR})
  69. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  70. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_ttf
  71. REQUIRED_VARS SDL_TTF_LIBRARIES SDL_TTF_INCLUDE_DIRS
  72. VERSION_VAR SDL_TTF_VERSION_STRING)
  73. # for backward compatibility
  74. set(SDLTTF_LIBRARY ${SDL_TTF_LIBRARIES})
  75. set(SDLTTF_INCLUDE_DIR ${SDL_TTF_INCLUDE_DIRS})
  76. set(SDLTTF_FOUND ${SDL_TTF_FOUND})
  77. mark_as_advanced(SDL_TTF_LIBRARY SDL_TTF_INCLUDE_DIR)