FindFreetype.cmake 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/local/X11R6/include
  47. /usr/local/X11/include
  48. /usr/freeware/include
  49. )
  50. find_path(FREETYPE_INCLUDE_DIR_freetype2 freetype/config/ftheader.h
  51. HINTS
  52. $ENV{FREETYPE_DIR}/include/freetype2
  53. PATHS
  54. /usr/local/X11R6/include
  55. /usr/local/X11/include
  56. /usr/freeware/include
  57. PATH_SUFFIXES freetype2
  58. )
  59. find_library(FREETYPE_LIBRARY
  60. NAMES freetype libfreetype freetype219
  61. HINTS
  62. $ENV{FREETYPE_DIR}
  63. PATH_SUFFIXES lib64 lib
  64. PATHS
  65. /usr/local/X11R6
  66. /usr/local/X11
  67. /usr/freeware
  68. )
  69. # set the user variables
  70. if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2)
  71. set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}")
  72. endif()
  73. set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}")
  74. if(FREETYPE_INCLUDE_DIR_freetype2 AND EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
  75. file(STRINGS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h" freetype_version_str
  76. REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")
  77. unset(FREETYPE_VERSION_STRING)
  78. foreach(VPART MAJOR MINOR PATCH)
  79. foreach(VLINE ${freetype_version_str})
  80. if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}")
  81. string(REGEX REPLACE "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$" "\\1"
  82. FREETYPE_VERSION_PART "${VLINE}")
  83. if(FREETYPE_VERSION_STRING)
  84. set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_STRING}.${FREETYPE_VERSION_PART}")
  85. else()
  86. set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}")
  87. endif()
  88. unset(FREETYPE_VERSION_PART)
  89. endif()
  90. endforeach()
  91. endforeach()
  92. endif()
  93. # handle the QUIETLY and REQUIRED arguments and set FREETYPE_FOUND to TRUE if
  94. # all listed variables are TRUE
  95. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  96. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Freetype
  97. REQUIRED_VARS FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS
  98. VERSION_VAR FREETYPE_VERSION_STRING)
  99. mark_as_advanced(FREETYPE_LIBRARY FREETYPE_INCLUDE_DIR_freetype2 FREETYPE_INCLUDE_DIR_ft2build)