From 863f50f1284978d30e204d825273acb49633b418 Mon Sep 17 00:00:00 2001 From: jcm <6864788+jcm93@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:17:38 -0600 Subject: [PATCH] build: Add missing Linux drivers --- cmake/CMakeLists.txt | 2 + cmake/common/compiler_common.cmake | 2 +- cmake/finders/FindOSS.cmake | 1 - cmake/finders/FindPulseAudio.cmake | 26 ++++++++- cmake/finders/Findudev.cmake | 90 ++++++++++++++++++++++++++++++ cmake/finders/Finduhid.cmake | 67 ++++++++++++++++++++++ ruby/cmake/os-linux.cmake | 25 ++++++++- 7 files changed, 208 insertions(+), 5 deletions(-) create mode 100644 cmake/finders/Findudev.cmake create mode 100644 cmake/finders/Finduhid.cmake diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 4262e565c0..073b80b3dd 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -20,6 +20,8 @@ target_sources( finders/FindAO.cmake finders/FindOSS.cmake finders/FindPulseAudio.cmake + finders/Findudev.cmake + finders/Finduhid.cmake macos/dependencies.cmake macos/compilerconfig.cmake macos/defaults.cmake diff --git a/cmake/common/compiler_common.cmake b/cmake/common/compiler_common.cmake index 73d8dfc270..9d29b1a286 100644 --- a/cmake/common/compiler_common.cmake +++ b/cmake/common/compiler_common.cmake @@ -5,7 +5,7 @@ include_guard(GLOBAL) option(ARES_COMPILE_DEPRECATION_AS_WARNING "Downgrade deprecation warnings to actual warnings" FALSE) mark_as_advanced(ARES_COMPILE_DEPRECATION_AS_WARNING) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION $<$:TRUE>) # Set C and C++ language standards to C17 and C++17 set(CMAKE_C_STANDARD 17) diff --git a/cmake/finders/FindOSS.cmake b/cmake/finders/FindOSS.cmake index 0fb2692992..52826c79cd 100644 --- a/cmake/finders/FindOSS.cmake +++ b/cmake/finders/FindOSS.cmake @@ -30,7 +30,6 @@ include(FindPackageHandleStandardArgs) find_path( OSS_INCLUDE_DIR NAMES sys/soundcard.h - HINTS ${PC_OSS_INCLUDE_DIRS} PATHS /usr/include /usr/local/include DOC "OSS include directory" ) diff --git a/cmake/finders/FindPulseAudio.cmake b/cmake/finders/FindPulseAudio.cmake index 177604617d..2bc5160928 100644 --- a/cmake/finders/FindPulseAudio.cmake +++ b/cmake/finders/FindPulseAudio.cmake @@ -21,13 +21,21 @@ find_library( DOC "PulseAudio location" ) +find_library( + PulseAudioSimple_LIBRARY + NAMES pulse-simple + HINTS ${PC_PulseAudio_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "PulseAudioSimple location" +) + set(PulseAudio_VERSION ${PC_PulseAudio_VERSION}) find_package_handle_standard_args( PulseAudio - REQUIRED_VARS PulseAudio_INCLUDE_DIR PulseAudio_LIBRARY + REQUIRED_VARS PulseAudio_INCLUDE_DIR PulseAudio_LIBRARY PulseAudioSimple_LIBRARY VERSION_VAR PulseAudio_VERSION - REASON_FAILURE_MESSAGE "Ensure that PulseAudio is available in local library paths." + REASON_FAILURE_MESSAGE "Ensure that PulseAudio and PulseAudioSimple are available in local library paths." ) mark_as_advanced(PulseAudio_INCLUDE_DIR PulseAudio_LIBRARY) @@ -40,6 +48,13 @@ if(PulseAudio_FOUND) add_library(PulseAudio::PulseAudio INTERFACE IMPORTED) set_property(TARGET PulseAudio::PulseAudio PROPERTY IMPORTED_LIBNAME "${PulseAudio_LIBRARY}") endif() + if(IS_ABSOLUTE "${PulseAudioSimple_LIBRARY}") + add_library(PulseAudio::PulseAudioSimple UNKNOWN IMPORTED) + set_property(TARGET PulseAudio::PulseAudioSimple PROPERTY IMPORTED_LOCATION "${PulseAudioSimple_LIBRARY}") + else() + add_library(PulseAudio::PulseAudioSimple INTERFACE IMPORTED) + set_property(TARGET PulseAudio::PulseAudioSimple PROPERTY IMPORTED_LIBNAME "${PulseAudioSimple_LIBRARY}") + endif() set_target_properties( PulseAudio::PulseAudio @@ -48,6 +63,13 @@ if(PulseAudio_FOUND) INTERFACE_INCLUDE_DIRECTORIES "${PulseAudio_INCLUDE_DIR}" VERSION ${PulseAudio_VERSION} ) + set_target_properties( + PulseAudio::PulseAudioSimple + PROPERTIES + INTERFACE_COMPILE_OPTIONS "${PC_PulseAudio_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${PulseAudio_INCLUDE_DIR}" + VERSION ${PulseAudio_VERSION} + ) endif() endif() diff --git a/cmake/finders/Findudev.cmake b/cmake/finders/Findudev.cmake new file mode 100644 index 0000000000..7ef8526c0f --- /dev/null +++ b/cmake/finders/Findudev.cmake @@ -0,0 +1,90 @@ +#[=======================================================================[.rst: +Findudev +------- + +Finds the udev library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``udev::udev`` + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``udev_FOUND`` + True if the system has udev. +``udev_VERSION`` + The version of udev which was found. +``udev_INCLUDE_DIR`` + Include directories needed to use udev. +``udev_LIBRARIES`` + Libraries needed to link to udev. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: +. +``GTK_LIBRARY`` + The path to the udev library. + +#]=======================================================================] + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_udev QUIET udev) +endif() + +find_path( + udev_INCLUDE_DIR + NAMES libudev.h + HINTS ${PC_udev_INCLUDE_DIRS} + PATHS /usr/include /usr/local/include + DOC "udev include directory" +) + +find_library( + udev_LIBRARIES + NAMES udev + HINTS ${PC_udev_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "udev location" +) + +set(udev_VERSION ${PC_udev_VERSION}) +set(udev_ERROR_REASON "Ensure udev libraries are available in local library paths.") + +find_package_handle_standard_args( + udev + REQUIRED_VARS udev_LIBRARIES udev_INCLUDE_DIR + REASON_FAILURE_MESSAGE "${udev_ERROR_REASON}" +) +mark_as_advanced(udev_INCLUDE_DIR udev_LIBRARIES) +unset(udev_ERROR_REASON) + +if(udev_FOUND) + if(NOT TARGET udev::udev) + add_library(udev::udev UNKNOWN IMPORTED) + set_property(TARGET udev::udev PROPERTY IMPORTED_LOCATION "${udev_LIBRARIES}") + + message(AUTHOR_WARNING "udev libraries are ${udev_LIBRARIES}") + set_target_properties( + udev::udev + PROPERTIES + INTERFACE_COMPILE_OPTIONS "${PC_udev_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${PC_udev_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${udev_LIBRARIES}" + VERSION "${udev_VERSION}" + ) + endif() +endif() + +include(FeatureSummary) +set_package_properties(udev PROPERTIES URL "https://www.freedesktop.org/software/systemd/man/latest/libudev.html" DESCRIPTION "libudev.h provides an API to introspect and enumerate devices on the local system.") diff --git a/cmake/finders/Finduhid.cmake b/cmake/finders/Finduhid.cmake new file mode 100644 index 0000000000..53fe8791d1 --- /dev/null +++ b/cmake/finders/Finduhid.cmake @@ -0,0 +1,67 @@ +#[=======================================================================[.rst: +Finduhid +------- + +Finds the usbhid library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``uhid::uhid`` + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``uhid_FOUND`` + True if the system has uhid. +``uhid_LIBRARIES`` + The location of the usbhid library. +``uhid_INCLUDE_DIR`` + Include directories needed to use uhid. + +#]=======================================================================] + +include(FindPackageHandleStandardArgs) + +find_path( + uhid_INCLUDE_DIR + NAMES usbhid.h /dev/usb/usbhid.h + PATHS /usr/include /usr/local/include + DOC "uhid include directory" +) + +find_library( + uhid_LIBRARIES + NAMES usbhid + PATHS /usr/lib /usr/local/lib + DOC "uhid location" +) + +set(uhid_VERSION ${CMAKE_HOST_SYSTEM_VERSION}) + +find_package_handle_standard_args( + uhid + REQUIRED_VARS uhid_INCLUDE_DIR uhid_LIBRARIES + VERSION_VAR uhid_VERSION + REASON_FAILURE_MESSAGE "Ensure that uhid is installed on the system." +) +mark_as_advanced(uhid_INCLUDE_DIR uhid_LIBRARY) + +if(uhid_FOUND) + if(NOT TARGET uhid::uhid) + add_library(uhid::uhid MODULE IMPORTED) + set_property(TARGET uhid::uhid PROPERTY IMPORTED_LOCATION "${uhid_LIBRARIES}") + + set_target_properties( + uhid::uhid + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${uhid_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${uhid_LIBRARIES}" + VERSION ${uhid_VERSION} + ) + endif() +endif() diff --git a/ruby/cmake/os-linux.cmake b/ruby/cmake/os-linux.cmake index 15d6ccc552..67ec6beebe 100644 --- a/ruby/cmake/os-linux.cmake +++ b/ruby/cmake/os-linux.cmake @@ -92,7 +92,7 @@ if(ARES_ENABLE_PULSEAUDIO) find_package(PulseAudio) endif() if(PulseAudio_FOUND) - target_enable_feature(ruby "PulseAudio audio driver" AUDIO_PULSEAUDIO) + target_enable_feature(ruby "PulseAudio audio driver" AUDIO_PULSEAUDIO AUDIO_PULSEAUDIOSIMPLE) else() target_disable_feature(ruby "PulseAudio audio driver") endif() @@ -107,6 +107,26 @@ else() target_disable_feature(ruby "AO audio driver") endif() +option(ARES_ENABLE_UDEV "Enable the udev input driver" ON) +if(ARES_ENABLE_UDEV) + find_package(udev) +endif() +if(udev_FOUND) + target_enable_feature(ruby "udev input driver" INPUT_UDEV) +else() + target_disable_feature(ruby "udev input driver") +endif() + +option(ARES_ENABLE_UHID "Enable the uhid input driver" ON) +if(ARES_ENABLE_UHID) + find_package(uhid) +endif() +if(uhid_FOUND) + target_enable_feature(ruby "uhid input driver" INPUT_UHID) +else() + target_disable_feature(ruby "uhid input driver") +endif() + target_link_libraries( ruby PRIVATE @@ -116,5 +136,8 @@ target_link_libraries( $<$:OSS::OSS> $<$:ALSA::ALSA> $<$:PulseAudio::PulseAudio> + $<$:PulseAudio::PulseAudioSimple> $<$:AO::AO> + $<$:udev::udev> + $<$:uhid::uhid> )