FindFreetype.cmake 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. # Try find freetype for our arch in external folder
  40. #todo: fix location of freetype includes for linux android on cocos prebuilt repo
  41. #i.e we should not need to include an extra dir of /freetype2
  42. # Try pkg-config first (because it provided deps info)
  43. if(NOT FREETYPE_FOUND)
  44. find_package(PkgConfig)
  45. pkg_search_module(FREETYPE freetype2)
  46. endif()
  47. if(NOT FREETYPE_FOUND)
  48. # Ugh, FreeType seems to use some #include trickery which
  49. # makes this harder than it should be. It looks like they
  50. # put ft2build.h in a common/easier-to-find location which
  51. # then contains a #include to a more specific header in a
  52. # more specific location (#include <freetype/config/ftheader.h>).
  53. # Then from there, they need to set a bunch of #define's
  54. # so you can do something like:
  55. # #include FT_FREETYPE_H
  56. # Unfortunately, using CMake's mechanisms like include_directories()
  57. # wants explicit full paths and this trickery doesn't work too well.
  58. # I'm going to attempt to cut out the middleman and hope
  59. # everything still works.
  60. find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h
  61. HINTS
  62. ENV FREETYPE_DIR
  63. PATHS
  64. ~/Library/Frameworks
  65. /Library/Frameworks
  66. /usr/local
  67. /usr
  68. /usr/X11R6
  69. /usr/local/X11R6
  70. /usr/local/X11
  71. /usr/freeware
  72. ENV GTKMM_BASEPATH
  73. [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
  74. [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
  75. PATH_SUFFIXES include/freetype2 include
  76. )
  77. find_path(FREETYPE_INCLUDE_DIR_freetype2
  78. NAMES
  79. freetype/config/ftheader.h
  80. config/ftheader.h
  81. HINTS
  82. ENV FREETYPE_DIR
  83. PATHS
  84. ~/Library/Frameworks
  85. /Library/Frameworks
  86. /usr/local
  87. /usr
  88. /usr/X11R6
  89. /usr/local/X11R6
  90. /usr/local/X11
  91. /usr/freeware
  92. ENV GTKMM_BASEPATH
  93. [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
  94. [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
  95. PATH_SUFFIXES include/freetype2 include
  96. )
  97. find_library(FREETYPE_LIBRARY
  98. NAMES freetype libfreetype freetype219
  99. HINTS
  100. ENV FREETYPE_DIR
  101. PATH_SUFFIXES lib
  102. PATHS
  103. ~/Library/Frameworks
  104. /Library/Frameworks
  105. /usr/local
  106. /usr
  107. /usr/X11R6
  108. /usr/local/X11R6
  109. /usr/local/X11
  110. /usr/freeware
  111. ENV GTKMM_BASEPATH
  112. [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
  113. [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
  114. )
  115. # set the user variables
  116. if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2)
  117. set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}")
  118. list(REMOVE_DUPLICATES FREETYPE_INCLUDE_DIRS)
  119. endif()
  120. set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}")
  121. if(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
  122. set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
  123. elseif(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
  124. set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
  125. endif()
  126. if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H)
  127. file(STRINGS "${FREETYPE_H}" freetype_version_str
  128. REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")
  129. unset(FREETYPE_VERSION_STRING)
  130. foreach(VPART MAJOR MINOR PATCH)
  131. foreach(VLINE ${freetype_version_str})
  132. if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}")
  133. string(REGEX REPLACE "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$" "\\1"
  134. FREETYPE_VERSION_PART "${VLINE}")
  135. if(FREETYPE_VERSION_STRING)
  136. set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_STRING}.${FREETYPE_VERSION_PART}")
  137. else()
  138. set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}")
  139. endif()
  140. unset(FREETYPE_VERSION_PART)
  141. endif()
  142. endforeach()
  143. endforeach()
  144. endif()
  145. set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY})
  146. # handle the QUIETLY and REQUIRED arguments and set FREETYPE_FOUND to TRUE if
  147. # all listed variables are TRUE
  148. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  149. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Freetype
  150. REQUIRED_VARS FREETYPE_LIBRARIES FREETYPE_INCLUDE_DIRS
  151. VERSION_VAR FREETYPE_VERSION_STRING)
  152. endif(NOT FREETYPE_FOUND)
  153. mark_as_advanced(FREETYPE_LIBRARY FREETYPE_INCLUDE_DIR_freetype2 FREETYPE_INCLUDE_DIR_ft2build)