FindFontconfig.cmake 2.9 KB

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