FindLibinput.cmake 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. FindLibinput
  5. ------------
  6. Find libinput headers and library.
  7. Imported Targets
  8. ^^^^^^^^^^^^^^^^
  9. ``Libinput::Libinput``
  10. The libinput library, if found.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. This will define the following variables in your project:
  14. ``Libinput_FOUND``
  15. true if (the requested version of) libinput is available.
  16. ``Libinput_VERSION``
  17. the version of libinput.
  18. ``Libinput_LIBRARIES``
  19. the libraries to link against to use libinput.
  20. ``Libinput_INCLUDE_DIRS``
  21. where to find the libinput headers.
  22. ``Libinput_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_Libinput QUIET libinput)
  30. set(Libinput_COMPILE_OPTIONS ${PKG_Libinput_CFLAGS_OTHER})
  31. set(Libinput_VERSION ${PKG_Libinput_VERSION})
  32. find_path(Libinput_INCLUDE_DIR
  33. NAMES
  34. libinput.h
  35. HINTS
  36. ${PKG_Libinput_INCLUDE_DIRS}
  37. )
  38. find_library(Libinput_LIBRARY
  39. NAMES
  40. input
  41. HINTS
  42. ${PKG_Libinput_LIBRARY_DIRS}
  43. )
  44. include(FindPackageHandleStandardArgs)
  45. find_package_handle_standard_args(Libinput
  46. FOUND_VAR
  47. Libinput_FOUND
  48. REQUIRED_VARS
  49. Libinput_LIBRARY
  50. Libinput_INCLUDE_DIR
  51. VERSION_VAR
  52. Libinput_VERSION
  53. )
  54. if(Libinput_FOUND AND NOT TARGET Libinput::Libinput)
  55. add_library(Libinput::Libinput UNKNOWN IMPORTED)
  56. set_target_properties(Libinput::Libinput PROPERTIES
  57. IMPORTED_LOCATION "${Libinput_LIBRARY}"
  58. INTERFACE_COMPILE_OPTIONS "${Libinput_COMPILE_OPTIONS}"
  59. INTERFACE_INCLUDE_DIRECTORIES "${Libinput_INCLUDE_DIR}"
  60. )
  61. endif()
  62. mark_as_advanced(Libinput_LIBRARY Libinput_INCLUDE_DIR)
  63. if(Libinput_FOUND)
  64. set(Libinput_LIBRARIES ${Libinput_LIBRARY})
  65. set(Libinput_INCLUDE_DIRS ${Libinput_INCLUDE_DIR})
  66. endif()