CMake: clean up HIDAPI build

This commit is contained in:
Michael Maltese 2017-04-24 20:06:39 -07:00
parent dd31a403db
commit 655ab9b4e2
8 changed files with 34 additions and 38 deletions

View File

@ -6,4 +6,12 @@ set(HIDAPI_INCLUDE_DIRS ${HIDAPI_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HIDAPI DEFAULT_MSG HIDAPI_LIBRARY HIDAPI_INCLUDE_DIR)
if(HIDAPI_FOUND AND NOT TARGET Hidapi::Hidapi)
add_library(Hidapi::Hidapi UNKNOWN IMPORTED)
set_target_properties(Hidapi::Hidapi PROPERTIES
IMPORTED_LOCATION ${HIDAPI_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${HIDAPI_INCLUDE_DIRS}
)
endif()
mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_LIBRARY)

View File

@ -752,39 +752,9 @@ list(APPEND LIBS ${ICONV_LIBRARIES})
if(NOT ANDROID)
find_package(HIDAPI)
if(HIDAPI_FOUND)
message(STATUS "Using shared ${HIDAPI_LIBRARIES} ${HIDAPI_VERSION}")
include_directories(${HIDAPI_INCLUDE_DIRS})
list(APPEND LIBS ${HIDAPI_LIBRARIES})
else()
set(HIDAPI_FOUND 1)
include_directories(Externals/hidapi/hidapi)
if(APPLE)
message(STATUS "Using static hidapi from Externals")
add_subdirectory(Externals/hidapi/mac)
list(APPEND LIBS hidapi)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
find_package(Libudev)
if(LIBUDEV_FOUND)
message(STATUS "Using static hidapi-hidraw from Externals")
add_subdirectory(Externals/hidapi/linux)
list(APPEND LIBS hidapi-hidraw udev)
else()
message(STATUS "Could not find udev, disabling hidapi")
set(HIDAPI_FOUND 0)
endif()
elseif(MSVC)
message(STATUS "Using static hidapi-hid from Externals")
add_subdirectory(Externals/hidapi/windows)
list(APPEND LIBS hidapi-hid)
else()
message(STATUS "Using static hidapi-libusb from Externals")
add_subdirectory(Externals/hidapi/libusb)
list(APPEND LIBS hidapi-libusb)
endif()
endif()
if(HIDAPI_FOUND)
add_definitions(-DHAVE_HIDAPI=1)
if(NOT HIDAPI_FOUND)
message(STATUS "Using static HIDAPI from Externals")
add_subdirectory(Externals/hidapi EXCLUDE_FROM_ALL)
endif()
endif()

20
Externals/hidapi/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,20 @@
project(hidapi)
add_library(hidapi STATIC hidapi/hidapi.h)
target_include_directories(hidapi PUBLIC hidapi)
if(APPLE)
target_sources(hidapi PRIVATE mac/hid.c)
elseif(MSVC)
target_sources(hidapi PRIVATE windows/hid.c)
else()
find_package(Libudev)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND LIBUDEV_FOUND)
target_sources(hidapi PRIVATE linux/hid.c)
target_link_libraries(hidapi PRIVATE udev)
else()
target_sources(hidapi PRIVATE libusb/hid.c)
endif()
endif()
add_library(Hidapi::Hidapi ALIAS hidapi)

View File

@ -1 +0,0 @@
add_library(hidapi-libusb hid.c)

View File

@ -1 +0,0 @@
add_library(hidapi-hidraw hid.c)

View File

@ -1 +0,0 @@
add_library(hidapi hid.c)

View File

@ -1 +0,0 @@
add_library(hidapi-hid hid.c)

View File

@ -339,8 +339,10 @@ else()
message(STATUS "BlueZ explicitly disabled, disabling bluetooth support")
endif()
if(HIDAPI_FOUND)
if(TARGET Hidapi::Hidapi)
set(SRCS ${SRCS} HW/WiimoteReal/IOhidapi.cpp)
list(APPEND LIBS Hidapi::Hidapi)
add_definitions(-DHAVE_HIDAPI=1)
endif()
if(PORTAUDIO_FOUND)