Debian Codegraph @

cmake/packages/FindFreeTypeSource.cmake

raw
1 # Distributed under the original FontForge BSD 3-clause license
2
3 #[=======================================================================[.rst:
4 FindFreeTypeSource
5 ------------------
6
7 Find the location to the FreeType source.
8
9 Imported Targets
10 ^^^^^^^^^^^^^^^^
11
12 This module defines the following :prop_tgt:`IMPORTED` target:
13
14 ``FreeTypeSource::FreeTypeSource``
15 The ``FreeType`` source library, if found
16
17 Result Variables
18 ^^^^^^^^^^^^^^^^
19
20 This module will set the following variables in your project:
21
22 ``FreeTypeSource_FOUND``
23 true if the FreeTypeSource headers and libraries were found
24 ``FreeTypeSource_INCLUDE_DIRS``
25 directories containing the FreeTypeSource headers.
26 ``FreeTypeSource_LIBRARIES``
27 the library to link against
28 ``FreeTypeSource_VERSION``
29 the version of FreeTypeSource found
30
31 #]=======================================================================]
32
33 find_path(FreeTypeSource_INCLUDE_DIR
34 NAMES ft2build.h
35 HINTS ${FreeTypeSource_ROOT}
36 ${FreeTypeSource_HINT}
37 PATH_SUFFIXES include
38 )
39
40 find_path(FreeTypeSource_FREETYPE_INCLUDE_DIR
41 NAMES freetype.h
42 HINTS ${FreeTypeSource_ROOT}
43 ${FreeTypeSource_HINT}
44 PATH_SUFFIXES include/freetype
45 )
46
47 find_path(FreeTypeSource_TRUETYPE_INCLUDE_DIR
48 NAMES tterrors.h
49 HINTS ${FreeTypeSource_ROOT}
50 ${FreeTypeSource_HINT}
51 PATH_SUFFIXES src/truetype
52 )
53
54 if(FreeTypeSource_INCLUDE_DIR AND FreeTypeSource_FREETYPE_INCLUDE_DIR AND FreeTypeSource_TRUETYPE_INCLUDE_DIR)
55 set (FreeTypeSource_INCLUDE_DIRS
56 ${FreeTypeSource_INCLUDE_DIR}
57 ${FreeTypeSource_FREETYPE_INCLUDE_DIR}
58 ${FreeTypeSource_TRUETYPE_INCLUDE_DIR}
59 CACHE INTERNAL "FreeType source include directories")
60
61 if(EXISTS "${FreeTypeSource_FREETYPE_INCLUDE_DIR}/freetype.h")
62 set(FREETYPE_H "${FreeTypeSource_FREETYPE_INCLUDE_DIR}/freetype.h")
63 elseif(EXISTS "${FreeTypeSource_INCLUDE_DIR}/freetype.h")
64 set(FREETYPE_H "${FreeTypeSource_INCLUDE_DIR}/freetype.h")
65 endif()
66
67 if(FREETYPE_H)
68 file(STRINGS "${FREETYPE_H}" freetype_version_str
69 REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")
70
71 unset(FreeTypeSource_VERSION)
72 foreach(VPART MAJOR MINOR PATCH)
73 foreach(VLINE ${freetype_version_str})
74 if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$")
75 set(FreeTypeSource_VERSION_PART "${CMAKE_MATCH_1}")
76 if(FreeTypeSource_VERSION)
77 string(APPEND FreeTypeSource_VERSION ".${FreeTypeSource_VERSION_PART}")
78 else ()
79 set(FreeTypeSource_VERSION "${FreeTypeSource_VERSION_PART}")
80 endif()
81 unset(FreeTypeSource_VERSION_PART)
82 endif()
83 endforeach()
84 endforeach()
85 endif()
86 endif()
87
88 include(FindPackageHandleStandardArgs)
89 find_package_handle_standard_args(
90 FreeTypeSource
91 REQUIRED_VARS
92 FreeTypeSource_INCLUDE_DIRS
93 VERSION_VAR
94 FreeTypeSource_VERSION
95 )
96
97 mark_as_advanced(FreeTypeSource_INCLUDE_DIRS)
98
99 if(FreeTypeSource_FOUND AND NOT TARGET FreeTypeSource::FreeTypeSource)
100 add_library(FreeTypeSource::FreeTypeSource INTERFACE IMPORTED)
101 set_property(TARGET FreeTypeSource::FreeTypeSource PROPERTY
102 INTERFACE_INCLUDE_DIRECTORIES "${FreeTypeSource_INCLUDE_DIRS}")
103 endif()