FindLibinput.cmake 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindLibinput
  5. ------------
  6. .. versionadded:: 3.14
  7. Finds the libinput library which handles input devices in Wayland compositors
  8. and provides a generic X.Org input driver:
  9. .. code-block:: cmake
  10. find_package(Libinput [<version>] [...])
  11. Imported Targets
  12. ^^^^^^^^^^^^^^^^
  13. This module provides the following :ref:`Imported Targets`:
  14. ``Libinput::Libinput``
  15. Target encapsulating the libinput library usage requirements, available only
  16. if library is found.
  17. Result Variables
  18. ^^^^^^^^^^^^^^^^
  19. This module defines the following variables:
  20. ``Libinput_FOUND``
  21. Boolean indicating whether the (requested version of) libinput library is
  22. found.
  23. ``Libinput_VERSION``
  24. The version of the libinput found.
  25. ``Libinput_LIBRARIES``
  26. The libraries to link against to use the libinput library.
  27. ``Libinput_INCLUDE_DIRS``
  28. The include directories containing headers needed to use the libinput library.
  29. ``Libinput_COMPILE_OPTIONS``
  30. Compile options needed to use the libinput library. These can be passed to
  31. the :command:`target_compile_options` command, when not using the
  32. ``Libinput::Libinput`` imported target.
  33. Examples
  34. ^^^^^^^^
  35. Finding the libinput library and linking it to a project target:
  36. .. code-block:: cmake
  37. find_package(Libinput)
  38. target_link_libraries(project_target PRIVATE Libinput::Libinput)
  39. #]=======================================================================]
  40. # Use pkg-config to get the directories and then use these values
  41. # in the FIND_PATH() and FIND_LIBRARY() calls
  42. find_package(PkgConfig QUIET)
  43. if(PkgConfig_FOUND)
  44. pkg_check_modules(PKG_Libinput QUIET libinput)
  45. endif()
  46. set(Libinput_COMPILE_OPTIONS ${PKG_Libinput_CFLAGS_OTHER})
  47. set(Libinput_VERSION ${PKG_Libinput_VERSION})
  48. find_path(Libinput_INCLUDE_DIR
  49. NAMES
  50. libinput.h
  51. HINTS
  52. ${PKG_Libinput_INCLUDE_DIRS}
  53. )
  54. find_library(Libinput_LIBRARY
  55. NAMES
  56. input
  57. HINTS
  58. ${PKG_Libinput_LIBRARY_DIRS}
  59. )
  60. include(FindPackageHandleStandardArgs)
  61. find_package_handle_standard_args(Libinput
  62. REQUIRED_VARS
  63. Libinput_LIBRARY
  64. Libinput_INCLUDE_DIR
  65. VERSION_VAR
  66. Libinput_VERSION
  67. )
  68. if(Libinput_FOUND AND NOT TARGET Libinput::Libinput)
  69. add_library(Libinput::Libinput UNKNOWN IMPORTED)
  70. set_target_properties(Libinput::Libinput PROPERTIES
  71. IMPORTED_LOCATION "${Libinput_LIBRARY}"
  72. INTERFACE_COMPILE_OPTIONS "${Libinput_COMPILE_OPTIONS}"
  73. INTERFACE_INCLUDE_DIRECTORIES "${Libinput_INCLUDE_DIR}"
  74. )
  75. endif()
  76. mark_as_advanced(Libinput_LIBRARY Libinput_INCLUDE_DIR)
  77. if(Libinput_FOUND)
  78. set(Libinput_LIBRARIES ${Libinput_LIBRARY})
  79. set(Libinput_INCLUDE_DIRS ${Libinput_INCLUDE_DIR})
  80. endif()