Commit f76047f3 authored by Frederik Gladhorn's avatar Frederik Gladhorn Committed by Brad King

FindLibinput: Add module to find libinput

This module is inspired by one from KDE's KWin.
parent e2dd6ac9
......@@ -39,6 +39,7 @@ The following individuals and institutions are among the Contributors:
* Alexander Neundorf <neundorf@kde.org>
* Alexander Smorkalov <alexander.smorkalov@itseez.com>
* Alexey Sokolov <sokolov@google.com>
* Alex Merry <alex.merry@kde.org>
* Alex Turbov <i.zaufi@gmail.com>
* Andreas Pakulat <apaku@gmx.de>
* Andreas Schneider <asn@cryptomilk.org>
......@@ -65,6 +66,7 @@ The following individuals and institutions are among the Contributors:
* Kelly Thompson <kgt@lanl.gov>
* Konstantin Podsvirov <konstantin@podsvirov.pro>
* Mario Bensi <mbensi@ipsquad.net>
* Martin Gräßlin <mgraesslin@kde.org>
* Mathieu Malaterre <mathieu.malaterre@gmail.com>
* Matthaeus G. Chajdas
* Matthias Kretz <kretz@kde.org>
......
......@@ -165,6 +165,7 @@ They are normally called through the :command:`find_package` command.
/module/FindLAPACK
/module/FindLATEX
/module/FindLibArchive
/module/FindLibinput
/module/FindLibLZMA
/module/FindLibXml2
/module/FindLibXslt
......
.. cmake-module:: ../../Modules/FindLibinput.cmake
find_libinput
-------------
* The :module:`FindLibinput` module was added to find `libinput`_.
.. _`libinput`: https://www.freedesktop.org/wiki/Software/libinput/
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindLibinput
------------
Find libinput headers and library.
Imported Targets
^^^^^^^^^^^^^^^^
``Libinput::Libinput``
The libinput library, if found.
Result Variables
^^^^^^^^^^^^^^^^
This will define the following variables in your project:
``Libinput_FOUND``
true if (the requested version of) libinput is available.
``Libinput_VERSION``
the version of libinput.
``Libinput_LIBRARIES``
the libraries to link against to use libinput.
``Libinput_INCLUDE_DIRS``
where to find the libinput headers.
``Libinput_DEFINITIONS``
this should be passed to target_compile_options(), if the
target is not used for linking
#]=======================================================================]
# Use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package(PkgConfig QUIET)
pkg_check_modules(PKG_Libinput QUIET libinput)
set(Libinput_DEFINITIONS ${PKG_Libinput_CFLAGS_OTHER})
set(Libinput_VERSION ${PKG_Libinput_VERSION})
find_path(Libinput_INCLUDE_DIR
NAMES
libinput.h
HINTS
${PKG_Libinput_INCLUDE_DIRS}
)
find_library(Libinput_LIBRARY
NAMES
input
HINTS
${PKG_Libinput_LIBRARY_DIRS}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libinput
FOUND_VAR
Libinput_FOUND
REQUIRED_VARS
Libinput_LIBRARY
Libinput_INCLUDE_DIR
VERSION_VAR
Libinput_VERSION
)
if(Libinput_FOUND AND NOT TARGET Libinput::Libinput)
add_library(Libinput::Libinput UNKNOWN IMPORTED)
set_target_properties(Libinput::Libinput PROPERTIES
IMPORTED_LOCATION "${Libinput_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${Libinput_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${Libinput_INCLUDE_DIR}"
)
endif()
mark_as_advanced(Libinput_LIBRARY Libinput_INCLUDE_DIR)
if(Libinput_FOUND)
set(Libinput_LIBRARIES ${Libinput_LIBRARY})
set(Libinput_INCLUDE_DIRS ${Libinput_INCLUDE_DIR})
set(Libinput_VERSION_STRING ${Libinput_VERSION})
endif()
......@@ -1409,6 +1409,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindLibRHash)
endif()
if(CMake_TEST_FindLibinput)
add_subdirectory(FindLibinput)
endif()
if(CMake_TEST_FindLibUV)
add_subdirectory(FindLibUV)
endif()
......
add_test(NAME FindLibinput.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindLibinput/Test"
"${CMake_BINARY_DIR}/Tests/FindLibinput/Test"
${build_generator_args}
--build-project TestFindLibinput
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
cmake_minimum_required(VERSION 3.10)
project(TestFindLibinput C)
include(CTest)
find_package(Libinput REQUIRED)
add_executable(test_tgt main.c)
target_link_libraries(test_tgt Libinput::Libinput)
add_test(NAME test_tgt COMMAND test_tgt)
add_executable(test_var main.c)
target_include_directories(test_var PRIVATE ${Libinput_INCLUDE_DIRS})
target_link_libraries(test_var PRIVATE ${Libinput_LIBRARIES})
add_test(NAME test_var COMMAND test_var)
#include <libinput.h>
#include <stdio.h>
int main()
{
struct libinput_interface interface;
interface.open_restricted = 0;
interface.close_restricted = 0;
struct libinput* li;
li = libinput_udev_create_context(&interface, NULL, NULL);
printf("Found Libinput.\n");
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment