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