You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.9 KiB

  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindFontconfig
  5. --------------
  6. .. versionadded:: 3.14
  7. Find Fontconfig headers and library.
  8. Imported Targets
  9. ^^^^^^^^^^^^^^^^
  10. ``Fontconfig::Fontconfig``
  11. The Fontconfig library, if found.
  12. Result Variables
  13. ^^^^^^^^^^^^^^^^
  14. This will define the following variables in your project:
  15. ``Fontconfig_FOUND``
  16. true if (the requested version of) Fontconfig is available.
  17. ``Fontconfig_VERSION``
  18. the version of Fontconfig.
  19. ``Fontconfig_LIBRARIES``
  20. the libraries to link against to use Fontconfig.
  21. ``Fontconfig_INCLUDE_DIRS``
  22. where to find the Fontconfig headers.
  23. ``Fontconfig_COMPILE_OPTIONS``
  24. this should be passed to target_compile_options(), if the
  25. target is not used for linking
  26. #]=======================================================================]
  27. # use pkg-config to get the directories and then use these values
  28. # in the FIND_PATH() and FIND_LIBRARY() calls
  29. find_package(PkgConfig QUIET)
  30. pkg_check_modules(PKG_FONTCONFIG QUIET fontconfig)
  31. set(Fontconfig_COMPILE_OPTIONS ${PKG_FONTCONFIG_CFLAGS_OTHER})
  32. set(Fontconfig_VERSION ${PKG_FONTCONFIG_VERSION})
  33. find_path( Fontconfig_INCLUDE_DIR
  34. NAMES
  35. fontconfig/fontconfig.h
  36. HINTS
  37. ${PKG_FONTCONFIG_INCLUDE_DIRS}
  38. /usr/X11/include
  39. )
  40. find_library( Fontconfig_LIBRARY
  41. NAMES
  42. fontconfig
  43. PATHS
  44. ${PKG_FONTCONFIG_LIBRARY_DIRS}
  45. )
  46. if (Fontconfig_INCLUDE_DIR AND NOT Fontconfig_VERSION)
  47. file(STRINGS ${Fontconfig_INCLUDE_DIR}/fontconfig/fontconfig.h _contents REGEX "^#define[ \t]+FC_[A-Z]+[ \t]+[0-9]+$")
  48. unset(Fontconfig_VERSION)
  49. foreach(VPART MAJOR MINOR REVISION)
  50. foreach(VLINE ${_contents})
  51. if(VLINE MATCHES "^#define[\t ]+FC_${VPART}[\t ]+([0-9]+)$")
  52. set(Fontconfig_VERSION_PART "${CMAKE_MATCH_1}")
  53. if(Fontconfig_VERSION)
  54. string(APPEND Fontconfig_VERSION ".${Fontconfig_VERSION_PART}")
  55. else()
  56. set(Fontconfig_VERSION "${Fontconfig_VERSION_PART}")
  57. endif()
  58. endif()
  59. endforeach()
  60. endforeach()
  61. endif ()
  62. include(FindPackageHandleStandardArgs)
  63. find_package_handle_standard_args(Fontconfig
  64. FOUND_VAR
  65. Fontconfig_FOUND
  66. REQUIRED_VARS
  67. Fontconfig_LIBRARY
  68. Fontconfig_INCLUDE_DIR
  69. VERSION_VAR
  70. Fontconfig_VERSION
  71. )
  72. if(Fontconfig_FOUND AND NOT TARGET Fontconfig::Fontconfig)
  73. add_library(Fontconfig::Fontconfig UNKNOWN IMPORTED)
  74. set_target_properties(Fontconfig::Fontconfig PROPERTIES
  75. IMPORTED_LOCATION "${Fontconfig_LIBRARY}"
  76. INTERFACE_COMPILE_OPTIONS "${Fontconfig_COMPILE_OPTIONS}"
  77. INTERFACE_INCLUDE_DIRECTORIES "${Fontconfig_INCLUDE_DIR}"
  78. )
  79. endif()
  80. mark_as_advanced(Fontconfig_LIBRARY Fontconfig_INCLUDE_DIR)
  81. if(Fontconfig_FOUND)
  82. set(Fontconfig_LIBRARIES ${Fontconfig_LIBRARY})
  83. set(Fontconfig_INCLUDE_DIRS ${Fontconfig_INCLUDE_DIR})
  84. endif()