Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FindLibudev: Link hidapi and libusb with libudev in static builds on Linux #12294

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmake/modules/FindLibUSB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ The following cache variables may also be set:

#]=======================================================================]

include(IsStaticLibrary)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(PC_LibUSB QUIET libusb-1.0)
Expand Down Expand Up @@ -87,5 +89,15 @@ if(LibUSB_FOUND)
INTERFACE_COMPILE_OPTIONS "${PC_LibUSB_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${LibUSB_INCLUDE_DIR}"
)

is_static_library(LibUSB_IS_STATIC LibUSB::LibUSB)
if(LibUSB_IS_STATIC)
find_package(Libudev)
if(Libudev_FOUND)
set_property(TARGET LibUSB::LibUSB APPEND PROPERTY INTERFACE_LINK_LIBRARIES
Libudev::Libudev
)
endif()
endif()
endif()
endif()
61 changes: 61 additions & 0 deletions cmake/modules/FindLibudev.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This file is part of Mixxx, Digital DJ'ing software.
# Copyright (C) 2001-2023 Mixxx Development Team
# Distributed under the GNU General Public Licence (GPL) version 2 or any later
# later version. See the LICENSE file for details.

#[=======================================================================[.rst:
FindLibudev
--------

Finds the libudev (userspace device manager) library.

Imported Targets
^^^^^^^^^^^^^^^^

This module provides the following imported targets, if found:

``Libudev::Libudev``
The libudev library

#]=======================================================================]

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(PC_Libudev QUIET libudev)
endif()

find_path(Libudev_INCLUDE_DIR
NAMES libudev.h
PATHS ${PC_Libudev_INCLUDE_DIRS}
DOC "The libudev include directory")
mark_as_advanced(Libudev_INCLUDE_DIR)

find_library(Libudev_LIBRARY
NAMES udev
PATH ${PC_Libudev_LIBRARY_DIRS}
DOC "The libudev library"
)
mark_as_advanced(Libudev_LIBRARY)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Libudev
REQUIRED_VARS Libudev_LIBRARY Libudev_INCLUDE_DIR
VERSION_VAR Libudev_VERSION
)

if(Libudev_FOUND)
set(Libudev_LIBRARIES "${Libudev_LIBRARY}")
set(Libudev_INCLUDE_DIRS "${Libudev_INCLUDE_DIR}")
set(Libudev_DEFINITIONS ${PC_Libudev_CFLAGS_OTHER})

if(NOT TARGET Libudev::Libudev)
add_library(Libudev::Libudev UNKNOWN IMPORTED)
set_target_properties(Libudev::Libudev
PROPERTIES
IMPORTED_LOCATION "${Libudev_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_Libudev_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Libudev_INCLUDE_DIR}"
)
endif()
endif()
19 changes: 19 additions & 0 deletions cmake/modules/Findhidapi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ The following cache variables may also be set:

#]=======================================================================]

include(IsStaticLibrary)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_search_module(PC_hidapi QUIET hidapi-libusb hidapi)
Expand Down Expand Up @@ -121,6 +123,23 @@ if(hidapi_FOUND)
INTERFACE_COMPILE_OPTIONS "${PC_hidapi_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${hidapi_INCLUDE_DIR}"
)

find_package(Libudev)
if(Libudev_FOUND)
is_static_library(hidapi_IS_STATIC hidapi::hidapi)
if(hidapi_IS_STATIC)
set_property(TARGET hidapi::hidapi APPEND PROPERTY INTERFACE_LINK_LIBRARIES
Libudev::Libudev
)
endif()

is_static_library(hidapi-hidraw_IS_STATIC hidapi::hidraw)
if(hidapi-hidraw_IS_STATIC)
set_property(TARGET hidapi::hidraw APPEND PROPERTY INTERFACE_LINK_LIBRARIES
Libudev::Libudev
)
endif()
endif()
endif()
endif()
endif()
Loading