summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederik Gladhorn <gladhorn@kde.org>2018-09-27 07:41:02 (GMT)
committerBrad King <brad.king@kitware.com>2018-10-11 14:43:45 (GMT)
commitf76047f34a960272ca29518551fb23504c61ee7e (patch)
tree15df7d2424387bad3ee97e8f2af481e6a1dc54b3
parente2dd6ac9776e4f5a1995dfc606480b627fdbce72 (diff)
downloadCMake-f76047f34a960272ca29518551fb23504c61ee7e.zip
CMake-f76047f34a960272ca29518551fb23504c61ee7e.tar.gz
CMake-f76047f34a960272ca29518551fb23504c61ee7e.tar.bz2
FindLibinput: Add module to find libinput
This module is inspired by one from KDE's KWin.
-rw-r--r--Copyright.txt2
-rw-r--r--Help/manual/cmake-modules.7.rst1
-rw-r--r--Help/module/FindLibinput.rst1
-rw-r--r--Help/release/dev/find_libinput.rst6
-rw-r--r--Modules/FindLibinput.cmake83
-rw-r--r--Tests/CMakeLists.txt4
-rw-r--r--Tests/FindLibinput/CMakeLists.txt10
-rw-r--r--Tests/FindLibinput/Test/CMakeLists.txt14
-rw-r--r--Tests/FindLibinput/Test/main.c13
9 files changed, 134 insertions, 0 deletions
diff --git a/Copyright.txt b/Copyright.txt
index 743c634..0b0fbf1 100644
--- a/Copyright.txt
+++ b/Copyright.txt
@@ -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>
diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst
index af8e33f..f9b4afb 100644
--- a/Help/manual/cmake-modules.7.rst
+++ b/Help/manual/cmake-modules.7.rst
@@ -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
diff --git a/Help/module/FindLibinput.rst b/Help/module/FindLibinput.rst
new file mode 100644
index 0000000..a8ca0b0
--- /dev/null
+++ b/Help/module/FindLibinput.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLibinput.cmake
diff --git a/Help/release/dev/find_libinput.rst b/Help/release/dev/find_libinput.rst
new file mode 100644
index 0000000..ebb9e7a
--- /dev/null
+++ b/Help/release/dev/find_libinput.rst
@@ -0,0 +1,6 @@
+find_libinput
+-------------
+
+* The :module:`FindLibinput` module was added to find `libinput`_.
+
+.. _`libinput`: https://www.freedesktop.org/wiki/Software/libinput/
diff --git a/Modules/FindLibinput.cmake b/Modules/FindLibinput.cmake
new file mode 100644
index 0000000..df66cff
--- /dev/null
+++ b/Modules/FindLibinput.cmake
@@ -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()
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 0de6c41..9e192be 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -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()
diff --git a/Tests/FindLibinput/CMakeLists.txt b/Tests/FindLibinput/CMakeLists.txt
new file mode 100644
index 0000000..8538a55
--- /dev/null
+++ b/Tests/FindLibinput/CMakeLists.txt
@@ -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>
+ )
diff --git a/Tests/FindLibinput/Test/CMakeLists.txt b/Tests/FindLibinput/Test/CMakeLists.txt
new file mode 100644
index 0000000..1cc68d4
--- /dev/null
+++ b/Tests/FindLibinput/Test/CMakeLists.txt
@@ -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)
diff --git a/Tests/FindLibinput/Test/main.c b/Tests/FindLibinput/Test/main.c
new file mode 100644
index 0000000..3919962
--- /dev/null
+++ b/Tests/FindLibinput/Test/main.c
@@ -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;
+}