From a6bb14efb870cc15da57b30c8fb4caa6bde53fc9 Mon Sep 17 00:00:00 2001 From: Be Date: Sat, 14 Aug 2021 16:31:56 -0500 Subject: [PATCH] CMake: fix detection of hidapi and #include paths --- CMakeLists.txt | 8 +++---- cmake/modules/Findhidapi.cmake | 31 +++++++++++++++------------ src/controllers/hid/hidcontroller.h | 2 +- src/controllers/hid/hidenumerator.cpp | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a41d30d513fb..e6cd54903c85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2605,12 +2605,12 @@ find_package(LibUSB) # USB HID controller support option(HID "USB HID controller support" ON) if(HID) - find_package(hidapi) - # hidapi_VERSION is only available starting with 0.10.0 - if(NOT hidapi_FOUND OR NOT hidapi_VERSION OR hidapi_VERSION VERSION_LESS 0.10.1) + find_package(hidapi 0.10.1) + if(NOT hidapi_FOUND) message(STATUS "Linking internal libhidapi statically") add_library(mixxx-hidapi STATIC EXCLUDE_FROM_ALL) - target_include_directories(mixxx-hidapi SYSTEM PUBLIC lib/hidapi/hidapi) + target_include_directories(mixxx-hidapi SYSTEM PRIVATE lib/hidapi/hidapi) + target_include_directories(mixxx-lib PRIVATE lib/hidapi) if(WIN32) target_sources(mixxx-hidapi PRIVATE lib/hidapi/windows/hid.c) find_library(Setupapi_LIBRARY Setupapi REQUIRED) diff --git a/cmake/modules/Findhidapi.cmake b/cmake/modules/Findhidapi.cmake index b4a7b282dd77..2db521a33a6c 100644 --- a/cmake/modules/Findhidapi.cmake +++ b/cmake/modules/Findhidapi.cmake @@ -49,9 +49,8 @@ if(PkgConfig_FOUND) endif() find_path(hidapi_INCLUDE_DIR - NAMES hidapi.h + NAMES hidapi/hidapi.h PATHS ${PC_hidapi_INCLUDE_DIRS} - PATH_SUFFIXES hidapi DOC "hidapi include directory") mark_as_advanced(hidapi_INCLUDE_DIR) @@ -62,17 +61,9 @@ find_library(hidapi_LIBRARY ) mark_as_advanced(hidapi_LIBRARY) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - hidapi - DEFAULT_MSG - hidapi_LIBRARY - hidapi_INCLUDE_DIR -) - # Version detection -if (EXISTS "${hidapi_INCLUDE_DIR}/hidapi.h") - file(READ "${hidapi_INCLUDE_DIR}/hidapi.h" hidapi_H_CONTENTS) +if (EXISTS "${hidapi_INCLUDE_DIR}/hidapi/hidapi.h") + file(READ "${hidapi_INCLUDE_DIR}/hidapi/hidapi.h" hidapi_H_CONTENTS) string(REGEX MATCH "#define HID_API_VERSION_MAJOR ([0-9]+)" _dummy "${hidapi_H_CONTENTS}") set(hidapi_VERSION_MAJOR "${CMAKE_MATCH_1}") string(REGEX MATCH "#define HID_API_VERSION_MINOR ([0-9]+)" _dummy "${hidapi_H_CONTENTS}") @@ -80,10 +71,22 @@ if (EXISTS "${hidapi_INCLUDE_DIR}/hidapi.h") string(REGEX MATCH "#define HID_API_VERSION_PATCH ([0-9]+)" _dummy "${hidapi_H_CONTENTS}") set(hidapi_VERSION_PATCH "${CMAKE_MATCH_1}") # hidapi_VERSION is only available starting with 0.10.0 - if (hidapi_VERSION_MAJOR AND hidapi_VERSION_MINOR AND hidapi_VERSION_PATCH) + # Simply using if(NOT) does not work because 0 is a valid value, so compare to empty string. + if (NOT hidapi_VERSION_MAJOR STREQUAL "" AND + NOT hidapi_VERSION_MINOR STREQUAL "" AND + NOT hidapi_VERSION_PATCH STREQUAL "") set(hidapi_VERSION "${hidapi_VERSION_MAJOR}.${hidapi_VERSION_MINOR}.${hidapi_VERSION_PATCH}") endif() -endif () +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + hidapi + DEFAULT_MSG + hidapi_LIBRARY + hidapi_INCLUDE_DIR + hidapi_VERSION +) if(hidapi_FOUND) set(hidapi_LIBRARIES "${hidapi_LIBRARY}") diff --git a/src/controllers/hid/hidcontroller.h b/src/controllers/hid/hidcontroller.h index ff2f786af231..4bf00d2cf148 100644 --- a/src/controllers/hid/hidcontroller.h +++ b/src/controllers/hid/hidcontroller.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/src/controllers/hid/hidenumerator.cpp b/src/controllers/hid/hidenumerator.cpp index d88b4baebbfa..b5749bd92842 100644 --- a/src/controllers/hid/hidenumerator.cpp +++ b/src/controllers/hid/hidenumerator.cpp @@ -1,6 +1,6 @@ #include "controllers/hid/hidenumerator.h" -#include +#include #include "controllers/hid/hidcontroller.h" #include "controllers/hid/hiddenylist.h"