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

Fix version detection in Findhidapi.cmake #4215

Merged
merged 5 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2608,7 +2608,14 @@ 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)
message(STATUS "Linking internal libhidapi statically")
if(hidapi_FOUND)
if(hidapi_VERSION)
message(STATUS "Found libhidapi version: ${hidapi_VERSION}")
else()
message(STATUS "Found libhidapi version < 0.10.0")
endif()
endif()
message(STATUS "Linking internal libhidapi 0.10.1 statically")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is error prone. I do not anticipate that anyone would remember to update this line when updating the vendored library.

add_library(mixxx-hidapi STATIC EXCLUDE_FROM_ALL)
target_include_directories(mixxx-hidapi SYSTEM PUBLIC lib/hidapi/hidapi)
if(WIN32)
Expand All @@ -2630,10 +2637,6 @@ if(HID)
endif()
target_link_libraries(mixxx-lib PRIVATE mixxx-hidapi)
else()
message(STATUS "Linking libhidapi dynamically")
if(NOT HIDAPI_FOUND)
message(FATAL_ERROR "USB HID controller support requires libhidapi-libusb and its development headers.")
endif()
target_link_libraries(mixxx-lib PRIVATE hidapi::hidapi)
endif()
target_sources(mixxx-lib PRIVATE
Expand Down
5 changes: 4 additions & 1 deletion cmake/modules/Findhidapi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ 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 ()
Expand Down