Skip to content
Closed
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
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2605,9 +2605,8 @@ find_package(LibUSB)
# USB HID controller support
option(HID "USB HID controller support" ON)
if(HID)
find_package(hidapi)
Comment thread
uklotzde marked this conversation as resolved.
# 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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated to the fix and can be reverted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not unrelated. find_package(hidapi 0.10.1) creates the error message hinting the version is too old.

find_package(hidapi 0.10.1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was wrong with this expression above?
Find_package(hidapi 0.10.1) succeeds on Ubuntu Bionic, because it is no version number set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, why does CMake let this succeed...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this by adding hidapi_VERSION to the find_package_handle_standard_args call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error makes it clear what is happening:

-- Could NOT find hidapi (missing: hidapi_VERSION) (Required is at least version "0.10.1")
-- Linking internal libhidapi statically

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)
Comment thread
Be-ing marked this conversation as resolved.
Expand Down
24 changes: 14 additions & 10 deletions cmake/modules/Findhidapi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ 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)
Expand All @@ -80,10 +72,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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the hidapi_VERSION version required to "find" the package which is an issue because the code above does not work for versions < 0.10.0. We can make it work by using the version from the PC file or just stick with the original solution.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give a hint what you prefer and I will prepare a PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. We require 0.10.1, so if there is no hidapi_VERSION it is too old anyway.

)

if(hidapi_FOUND)
set(hidapi_LIBRARIES "${hidapi_LIBRARY}")
Expand Down