mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 02:39:48 -06:00
FindLibinput: Add module to find libinput
This module is inspired by one from KDE's KWin.
This commit is contained in:
committed by
Brad King
parent
e2dd6ac977
commit
f76047f34a
@@ -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
|
||||
|
||||
1
Help/module/FindLibinput.rst
Normal file
1
Help/module/FindLibinput.rst
Normal file
@@ -0,0 +1 @@
|
||||
.. cmake-module:: ../../Modules/FindLibinput.cmake
|
||||
6
Help/release/dev/find_libinput.rst
Normal file
6
Help/release/dev/find_libinput.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
find_libinput
|
||||
-------------
|
||||
|
||||
* The :module:`FindLibinput` module was added to find `libinput`_.
|
||||
|
||||
.. _`libinput`: https://www.freedesktop.org/wiki/Software/libinput/
|
||||
83
Modules/FindLibinput.cmake
Normal file
83
Modules/FindLibinput.cmake
Normal file
@@ -0,0 +1,83 @@
|
||||
# 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()
|
||||
|
||||
10
Tests/FindLibinput/CMakeLists.txt
Normal file
10
Tests/FindLibinput/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
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>
|
||||
)
|
||||
14
Tests/FindLibinput/Test/CMakeLists.txt
Normal file
14
Tests/FindLibinput/Test/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
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)
|
||||
13
Tests/FindLibinput/Test/main.c
Normal file
13
Tests/FindLibinput/Test/main.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user