Browse Source

Merge topic 'find_libinput'

f76047f34a FindLibinput: Add module to find libinput

Acked-by: Kitware Robot <[email protected]>
Merge-request: !2420
Brad King 7 years ago
parent
commit
1cfe2442c4

+ 2 - 0
Copyright.txt

@@ -39,6 +39,7 @@ The following individuals and institutions are among the Contributors:
 * Alexander Neundorf <[email protected]>
 * Alexander Smorkalov <[email protected]>
 * Alexey Sokolov <[email protected]>
+* Alex Merry <[email protected]>
 * Alex Turbov <[email protected]>
 * Andreas Pakulat <[email protected]>
 * Andreas Schneider <[email protected]>
@@ -65,6 +66,7 @@ The following individuals and institutions are among the Contributors:
 * Kelly Thompson <[email protected]>
 * Konstantin Podsvirov <[email protected]>
 * Mario Bensi <[email protected]>
+* Martin Gräßlin <[email protected]>
 * Mathieu Malaterre <[email protected]>
 * Matthaeus G. Chajdas
 * Matthias Kretz <[email protected]>

+ 1 - 0
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

+ 1 - 0
Help/module/FindLibinput.rst

@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindLibinput.cmake

+ 6 - 0
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/

+ 83 - 0
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()

+ 4 - 0
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()

+ 10 - 0
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>
+  )

+ 14 - 0
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)

+ 13 - 0
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;
+}