Skip to content

Commit

Permalink
CMake: clean up HIDAPI build
Browse files Browse the repository at this point in the history
  • Loading branch information
ligfx committed Apr 25, 2017
1 parent dd31a40 commit 4748766
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
8 changes: 8 additions & 0 deletions CMake/FindHIDAPI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
36 changes: 3 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
24 changes: 24 additions & 0 deletions Externals/hidapi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
project(hidapi)

set(SRCS)
set(LIBS)

if(APPLE)
list(APPEND SRCS mac/hid.c)
elseif(MSVC)
list(APPEND SRCS windows/hid.c)
else()
find_package(Libudev)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND LIBUDEV_FOUND)
list(APPEND SRCS linux/hid.c)
list(APPEND LIBS udev)
else()
list(APPEND SRCS libusb/hid.c)
endif()
endif()

add_library(hidapi ${SRCS})
target_link_libraries(hidapi PRIVATE ${LIBS})
target_include_directories(hidapi PUBLIC hidapi)

add_library(Hidapi::Hidapi ALIAS hidapi)
1 change: 0 additions & 1 deletion Externals/hidapi/libusb/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion Externals/hidapi/linux/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion Externals/hidapi/mac/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion Externals/hidapi/windows/CMakeLists.txt

This file was deleted.

4 changes: 3 additions & 1 deletion Source/Core/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4748766

Please sign in to comment.