FindFreetype.cmake
Go to the documentation of this file.
1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3 
4 # XXX: Copied from CMake, but includes vtkDetectLibraryType.
5 # See https://gitlab.kitware.com/cmake/cmake/-/issues/18564
6 
7 #[=======================================================================[.rst:
8 FindFreetype
9 ------------
10 
11 Find the FreeType font renderer includes and library.
12 
13 Imported Targets
14 ^^^^^^^^^^^^^^^^
15 
16 This module defines the following :prop_tgt:`IMPORTED` target:
17 
18 ``Freetype::Freetype``
19  The Freetype ``freetype`` library, if found
20 
21 Result Variables
22 ^^^^^^^^^^^^^^^^
23 
24 This module will set the following variables in your project:
25 
26 ``FREETYPE_FOUND``
27  true if the Freetype headers and libraries were found
28 ``FREETYPE_INCLUDE_DIRS``
29  directories containing the Freetype headers. This is the
30  concatenation of the variables:
31 
32  ``FREETYPE_INCLUDE_DIR_ft2build``
33  directory holding the main Freetype API configuration header
34  ``FREETYPE_INCLUDE_DIR_freetype2``
35  directory holding Freetype public headers
36 ``FREETYPE_LIBRARIES``
37  the library to link against
38 ``FREETYPE_VERSION_STRING``
39  the version of freetype found (since CMake 2.8.8)
40 
41 Hints
42 ^^^^^
43 
44 The user may set the environment variable ``FREETYPE_DIR`` to the root
45 directory of a Freetype installation.
46 #]=======================================================================]
47 
48 # Created by Eric Wing.
49 # Modifications by Alexander Neundorf.
50 # This file has been renamed to "FindFreetype.cmake" instead of the correct
51 # "FindFreeType.cmake" in order to be compatible with the one from KDE4, Alex.
52 
53 # Ugh, FreeType seems to use some #include trickery which
54 # makes this harder than it should be. It looks like they
55 # put ft2build.h in a common/easier-to-find location which
56 # then contains a #include to a more specific header in a
57 # more specific location (#include <freetype/config/ftheader.h>).
58 # Then from there, they need to set a bunch of #define's
59 # so you can do something like:
60 # #include FT_FREETYPE_H
61 # Unfortunately, using CMake's mechanisms like include_directories()
62 # wants explicit full paths and this trickery doesn't work too well.
63 # I'm going to attempt to cut out the middleman and hope
64 # everything still works.
65 
66 set(FREETYPE_FIND_ARGS
67  HINTS
68  ENV FREETYPE_DIR
69  PATHS
70  ENV GTKMM_BASEPATH
71  [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]
72  [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]
73 )
74 
75 find_path(
76  FREETYPE_INCLUDE_DIR_ft2build
77  ft2build.h
78  ${FREETYPE_FIND_ARGS}
79  PATH_SUFFIXES
80  include/freetype2
81  include
82  freetype2
83 )
84 
85 find_path(
86  FREETYPE_INCLUDE_DIR_freetype2
87  NAMES
88  freetype/config/ftheader.h
89  config/ftheader.h
90  ${FREETYPE_FIND_ARGS}
91  PATH_SUFFIXES
92  include/freetype2
93  include
94  freetype2
95 )
96 
97 if(NOT FREETYPE_LIBRARY)
98  find_library(FREETYPE_LIBRARY_RELEASE
99  NAMES
100  freetype
101  libfreetype
102  freetype219
103  ${FREETYPE_FIND_ARGS}
104  PATH_SUFFIXES
105  lib
106  )
107  find_library(FREETYPE_LIBRARY_DEBUG
108  NAMES
109  freetyped
110  libfreetyped
111  freetype219d
112  ${FREETYPE_FIND_ARGS}
113  PATH_SUFFIXES
114  lib
115  )
116  include(SelectLibraryConfigurations)
117  select_library_configurations(FREETYPE)
118 else()
119  # on Windows, ensure paths are in canonical format (forward slahes):
120  file(TO_CMAKE_PATH "${FREETYPE_LIBRARY}" FREETYPE_LIBRARY)
121 endif()
122 
123 unset(FREETYPE_FIND_ARGS)
124 
125 # set the user variables
126 if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2)
127  set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}")
128  list(REMOVE_DUPLICATES FREETYPE_INCLUDE_DIRS)
129 endif()
130 set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}")
131 
132 if(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
133  set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h")
134 elseif(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
135  set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h")
136 endif()
137 
138 if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H)
139  file(STRINGS "${FREETYPE_H}" freetype_version_str
140  REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")
141 
142  unset(FREETYPE_VERSION_STRING)
143  foreach(VPART MAJOR MINOR PATCH)
144  foreach(VLINE ${freetype_version_str})
145  if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$")
146  set(FREETYPE_VERSION_PART "${CMAKE_MATCH_1}")
147  if(FREETYPE_VERSION_STRING)
148  string(APPEND FREETYPE_VERSION_STRING ".${FREETYPE_VERSION_PART}")
149  else()
150  set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}")
151  endif()
152  unset(FREETYPE_VERSION_PART)
153  endif()
154  endforeach()
155  endforeach()
156 endif()
157 
158 include(FindPackageHandleStandardArgs)
159 
160 find_package_handle_standard_args(
161  Freetype
162  REQUIRED_VARS
163  FREETYPE_LIBRARY
164  FREETYPE_INCLUDE_DIRS
165  VERSION_VAR
166  FREETYPE_VERSION_STRING
167 )
168 
169 mark_as_advanced(
170  FREETYPE_INCLUDE_DIR_freetype2
171  FREETYPE_INCLUDE_DIR_ft2build
172 )
173 
174 if(Freetype_FOUND)
175  if(NOT TARGET Freetype::Freetype)
176  include(vtkDetectLibraryType)
177  set(freetype_library_type UNKNOWN)
178  if (FREETYPE_LIBRARY_RELEASE)
179  vtk_detect_library_type(freetype_release_library_type
180  PATH "${FREETYPE_LIBRARY_RELEASE}")
181  endif ()
182  if (FREETYPE_LIBRARY_DEBUG)
183  vtk_detect_library_type(freetype_debug_library_type
184  PATH "${FREETYPE_LIBRARY_DEBUG}")
185  endif ()
186  if (freetype_release_library_type AND freetype_debug_library_type)
187  if (freetype_release_library_type STREQUAL freetype_debug_library_type)
188  set(freetype_library_type "${freetype_release_library_type}")
189  endif ()
190  elseif (freetype_release_library_type)
191  set(freetype_library_type "${freetype_release_library_type}")
192  elseif (freetype_debug_library_type)
193  set(freetype_library_type "${freetype_debug_library_type}")
194  endif ()
195  add_library(Freetype::Freetype "${freetype_library_type}" IMPORTED)
196  unset(freetype_release_library_type)
197  unset(freetype_debug_library_type)
198  unset(freetype_library_type)
199  set_target_properties(Freetype::Freetype PROPERTIES
200  INTERFACE_INCLUDE_DIRECTORIES "${FREETYPE_INCLUDE_DIRS}")
201 
202  if(FREETYPE_LIBRARY_RELEASE)
203  set_property(TARGET Freetype::Freetype APPEND PROPERTY
204  IMPORTED_CONFIGURATIONS RELEASE)
205  set_target_properties(Freetype::Freetype PROPERTIES
206  IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
207  IMPORTED_LOCATION_RELEASE "${FREETYPE_LIBRARY_RELEASE}"
208  IMPORTED_IMPLIB_RELEASE "${FREETYPE_LIBRARY_RELEASE}")
209  endif()
210 
211  if(FREETYPE_LIBRARY_DEBUG)
212  set_property(TARGET Freetype::Freetype APPEND PROPERTY
213  IMPORTED_CONFIGURATIONS DEBUG)
214  set_target_properties(Freetype::Freetype PROPERTIES
215  IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
216  IMPORTED_LOCATION_DEBUG "${FREETYPE_LIBRARY_DEBUG}"
217  IMPORTED_IMPLIB_DEBUG "${FREETYPE_LIBRARY_DEBUG}")
218  endif()
219 
220  if(NOT FREETYPE_LIBRARY_RELEASE AND NOT FREETYPE_LIBRARY_DEBUG)
221  set_target_properties(Freetype::Freetype PROPERTIES
222  IMPORTED_LINK_INTERFACE_LANGUAGES "C"
223  IMPORTED_LOCATION "${FREETYPE_LIBRARY}"
224  IMPORTED_IMPLIB "${FREETYPE_LIBRARY}")
225  endif()
226  endif()
227 endif()
boost::graph_traits< vtkGraph *>::vertex_descriptor target(boost::graph_traits< vtkGraph *>::edge_descriptor e, vtkGraph *)
version