FindFreetype.cmake 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # - Locate FreeType library
  2. # This module defines
  3. # FREETYPE_LIBRARIES, the library to link against
  4. # FREETYPE_FOUND, if false, do not try to link to FREETYPE
  5. # FREETYPE_INCLUDE_DIRS, where to find headers.
  6. # FREETYPE_VERSION_STRING, the version of freetype found (since CMake 2.8.8)
  7. # This is the concatenation of the paths:
  8. # FREETYPE_INCLUDE_DIR_ft2build
  9. # FREETYPE_INCLUDE_DIR_freetype2
  10. #
  11. # $FREETYPE_DIR is an environment variable that would
  12. # correspond to the ./configure --prefix=$FREETYPE_DIR
  13. # used in building FREETYPE.
  14. #=============================================================================
  15. # Copyright 2007-2009 Kitware, Inc.
  16. #
  17. # Distributed under the OSI-approved BSD License (the "License");
  18. # see accompanying file Copyright.txt for details.
  19. #
  20. # This software is distributed WITHOUT ANY WARRANTY; without even the
  21. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. # See the License for more information.
  23. #=============================================================================
  24. # (To distribute this file outside of CMake, substitute the full
  25. # License text for the above reference.)
  26. # Created by Eric Wing.
  27. # Modifications by Alexander Neundorf.
  28. # This file has been renamed to "FindFreetype.cmake" instead of the correct
  29. # "FindFreeType.cmake" in order to be compatible with the one from KDE4, Alex.
  30. # Ugh, FreeType seems to use some #include trickery which
  31. # makes this harder than it should be. It looks like they
  32. # put ft2build.h in a common/easier-to-find location which
  33. # then contains a #include to a more specific header in a
  34. # more specific location (#include <freetype/config/ftheader.h>).
  35. # Then from there, they need to set a bunch of #define's
  36. # so you can do something like:
  37. # #include FT_FREETYPE_H
  38. # Unfortunately, using CMake's mechanisms like include_directories()
  39. # wants explicit full paths and this trickery doesn't work too well.
  40. # I'm going to attempt to cut out the middleman and hope
  41. # everything still works.
  42. find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h
  43. HINTS
  44. ENV FREETYPE_DIR
  45. PATHS
  46. /usr/X11R6
  47. /usr/local/X11R6
  48. /usr/local/X11
  49. /usr/freeware
  50. PATH_SUFFIXES include/freetype2 include
  51. )
  52. find_path(FREETYPE_INCLUDE_DIR_freetype2 freetype/config/ftheader.h
  53. HINTS
  54. ENV FREETYPE_DIR
  55. PATHS
  56. /usr/X11R6
  57. /usr/local/X11R6
  58. /usr/local/X11
  59. /usr/freeware
  60. PATH_SUFFIXES include/freetype2 include
  61. )
  62. find_library(FREETYPE_LIBRARY
  63. NAMES freetype libfreetype freetype219
  64. HINTS
  65. ENV FREETYPE_DIR
  66. PATH_SUFFIXES lib
  67. PATHS
  68. /usr/X11R6
  69. /usr/local/X11R6
  70. /usr/local/X11
  71. /usr/freeware
  72. )
  73. # set the user variables
  74. if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2)
  75. set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}")
  76. endif()
  77. set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}")
  78. if(FREETYPE_INCLUDE_DIR_freetype2 AND EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
  79. file(STRINGS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h" freetype_version_str
  80. REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")
  81. unset(FREETYPE_VERSION_STRING)
  82. foreach(VPART MAJOR MINOR PATCH)
  83. foreach(VLINE ${freetype_version_str})
  84. if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}")
  85. string(REGEX REPLACE "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$" "\\1"
  86. FREETYPE_VERSION_PART "${VLINE}")
  87. if(FREETYPE_VERSION_STRING)
  88. set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_STRING}.${FREETYPE_VERSION_PART}")
  89. else()
  90. set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}")
  91. endif()
  92. unset(FREETYPE_VERSION_PART)
  93. endif()
  94. endforeach()
  95. endforeach()
  96. endif()
  97. # handle the QUIETLY and REQUIRED arguments and set FREETYPE_FOUND to TRUE if
  98. # all listed variables are TRUE
  99. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  100. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Freetype
  101. REQUIRED_VARS FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS
  102. VERSION_VAR FREETYPE_VERSION_STRING)
  103. mark_as_advanced(FREETYPE_LIBRARY FREETYPE_INCLUDE_DIR_freetype2 FREETYPE_INCLUDE_DIR_ft2build)