1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
8 Find Fontconfig headers and library.
13 ``Fontconfig::Fontconfig``
14 The Fontconfig library, if found.
19 This will define the following variables in your project:
22 true if (the requested version of) Fontconfig is available.
23 ``Fontconfig_VERSION``
24 the version of Fontconfig.
25 ``Fontconfig_LIBRARIES``
26 the libraries to link against to use Fontconfig.
27 ``Fontconfig_INCLUDE_DIRS``
28 where to find the Fontconfig headers.
29 ``Fontconfig_COMPILE_OPTIONS``
30 this should be passed to target_compile_options(), if the
31 target is not used for linking
33 #]=======================================================================]
36 # use pkg-config to get the directories and then use these values
37 # in the FIND_PATH() and FIND_LIBRARY() calls
38 find_package(PkgConfig QUIET)
39 pkg_check_modules(PKG_FONTCONFIG QUIET fontconfig)
40 set(Fontconfig_COMPILE_OPTIONS ${PKG_FONTCONFIG_CFLAGS_OTHER})
41 set(Fontconfig_VERSION ${PKG_FONTCONFIG_VERSION})
43 find_path( Fontconfig_INCLUDE_DIR
45 fontconfig/fontconfig.h
47 ${PKG_FONTCONFIG_INCLUDE_DIRS}
51 find_library( Fontconfig_LIBRARY
55 ${PKG_FONTCONFIG_LIBRARY_DIRS}
58 if(Fontconfig_INCLUDE_DIR AND NOT Fontconfig_VERSION)
59 file(STRINGS ${Fontconfig_INCLUDE_DIR}/fontconfig/fontconfig.h _contents REGEX "^#define[ \t]+FC_[A-Z]+[ \t]+[0-9]+$")
60 unset(Fontconfig_VERSION)
61 foreach(VPART MAJOR MINOR REVISION)
62 foreach(VLINE ${_contents})
63 if(VLINE MATCHES "^#define[\t ]+FC_${VPART}[\t ]+([0-9]+)$")
64 set(Fontconfig_VERSION_PART "${CMAKE_MATCH_1}")
65 if(Fontconfig_VERSION)
66 string(APPEND Fontconfig_VERSION ".${Fontconfig_VERSION_PART}")
68 set(Fontconfig_VERSION "${Fontconfig_VERSION_PART}")
75 include(FindPackageHandleStandardArgs)
76 find_package_handle_standard_args(Fontconfig
81 Fontconfig_INCLUDE_DIR
87 if(Fontconfig_FOUND AND NOT TARGET Fontconfig::Fontconfig)
88 add_library(Fontconfig::Fontconfig UNKNOWN IMPORTED)
89 set_target_properties(Fontconfig::Fontconfig PROPERTIES
90 IMPORTED_LOCATION "${Fontconfig_LIBRARY}"
91 INTERFACE_COMPILE_OPTIONS "${Fontconfig_COMPILE_OPTIONS}"
92 INTERFACE_INCLUDE_DIRECTORIES "${Fontconfig_INCLUDE_DIR}"
96 mark_as_advanced(Fontconfig_LIBRARY Fontconfig_INCLUDE_DIR)
99 set(Fontconfig_LIBRARIES ${Fontconfig_LIBRARY})
100 set(Fontconfig_INCLUDE_DIRS ${Fontconfig_INCLUDE_DIR})