FindFreetype-v2fix.cmake 4.9 KB

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