FindFreetype.cmake 4.6 KB

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