forked from libusb/hidapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
465 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR) | ||
|
||
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) | ||
add_subdirectory(src) | ||
# compatinility with find_package() vs add_subdirectory | ||
set(hidapi_VERSION "${hidapi_VERSION}" PARENT_SCOPE) | ||
return() | ||
endif() | ||
# All of the below in this file is meant for a standalone build. | ||
# When building as a subdirectory of a larger project, most of the options may not make sense for it, | ||
# so it is up to developer to configure those, e.g.: | ||
# | ||
# # a subfolder of a master project, e.g.: 3rdparty/hidapi/CMakeLists.txt | ||
# | ||
# set(HIDAPI_WITH_HIDRAW OFF) | ||
# set(CMAKE_FRAMEWORK ON) | ||
# # and keep everything else to their defaults | ||
# add_subdirectory(hidapi) | ||
# | ||
|
||
set(DEFAULT_CMAKE_BUILD_TYPES "Debug" "Release" "MinSizeRel" "RelWithDebInfo") | ||
if(NOT DEFINED CMAKE_BUILD_TYPE OR NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "${DEFAULT_CMAKE_BUILD_TYPES}" FORCE) | ||
endif() | ||
# This part is for convenience, when used one of the standard build types with cmake-gui | ||
list(FIND DEFAULT_CMAKE_BUILD_TYPES "${CMAKE_BUILD_TYPE}" _build_type_index) | ||
if(${_build_type_index} GREATER -1) | ||
# set it optionally, so a custom CMAKE_BUILD_TYPE can be used as well, if needed | ||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${DEFAULT_CMAKE_BUILD_TYPES}) | ||
endif() | ||
unset(_build_type_index) | ||
# | ||
|
||
project(hidapi LANGUAGES C) | ||
|
||
if(APPLE) | ||
if(NOT CMAKE_VERSION VERSION_LESS "3.15") | ||
option(CMAKE_FRAMEWORK "Build macOS/iOS Framework version of the library" OFF) | ||
endif() | ||
elseif(NOT WIN32) | ||
if(CMAKE_SYSTEM_NAME MATCHES "Linux") | ||
option(HIDAPI_WITH_HIDRAW "Build HIDRAW-based implementation of HIDAPI" ON) | ||
option(HIDAPI_WITH_LIBUSB "Build LIBUSB-based implementation of HIDAPI" ON) | ||
endif() | ||
endif() | ||
|
||
option(BUILD_SHARED_LIBS "Build shared version of the libraries, otherwise build statically" ON) | ||
|
||
set(HIDAPI_INSTALL_TARGETS ON) | ||
set(HIDAPI_PRINT_VERSION ON) | ||
|
||
add_subdirectory(src) | ||
|
||
set(BUILD_HIDTEST_DEFAULT OFF) | ||
if(CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
set(BUILD_HIDTEST_DEFAULT ON) | ||
endif() | ||
option(HIDAPI_BUILD_HIDTEST "Build small console test application hidtest" ${BUILD_HIDTEST_DEFAULT}) | ||
if(HIDAPI_BUILD_HIDTEST) | ||
add_subdirectory(hidtest) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
project(hidtest C) | ||
|
||
set(HIDAPI_HIDTEST_TARGETS) | ||
if(NOT WIN32 AND NOT APPLE AND CMAKE_SYSTEM_NAME MATCHES "Linux") | ||
if(TARGET hidapi::hidraw) | ||
add_executable(hidtest_hidraw test.c) | ||
target_link_libraries(hidtest_hidraw hidapi::hidraw) | ||
list(APPEND HIDAPI_HIDTEST_TARGETS hidtest_hidraw) | ||
endif() | ||
if(TARGET hidapi::libusb) | ||
add_executable(hidtest_libusb test.c) | ||
target_link_libraries(hidtest_libusb hidapi::libusb) | ||
list(APPEND HIDAPI_HIDTEST_TARGETS hidtest_libusb) | ||
endif() | ||
else() | ||
add_executable(hidtest test.c) | ||
target_link_libraries(hidtest hidapi::hidapi) | ||
list(APPEND HIDAPI_HIDTEST_TARGETS hidtest) | ||
endif() | ||
|
||
install(TARGETS ${HIDAPI_HIDTEST_TARGETS} | ||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
cmake_minimum_required(VERSION 3.6.3 FATAL_ERROR) | ||
|
||
add_library(hidapi_libusb | ||
${HIDAPI_PUBLIC_HEADERS} | ||
hid.c | ||
) | ||
target_link_libraries(hidapi_libusb PUBLIC hidapi_include) | ||
|
||
if(TARGET usb-1.0) | ||
target_link_libraries(hidapi_libusb PRIVATE usb-1.0) | ||
else() | ||
include(FindPkgConfig) | ||
pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0>=1.0.9) | ||
target_link_libraries(hidapi_libusb PRIVATE PkgConfig::libusb) | ||
endif() | ||
|
||
find_package(Threads REQUIRED) | ||
target_link_libraries(hidapi_libusb PRIVATE Threads::Threads) | ||
|
||
set_target_properties(hidapi_libusb | ||
PROPERTIES | ||
EXPORT_NAME "libusb" | ||
OUTPUT_NAME "hidapi-libusb" | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION ${PROJECT_VERSION_MAJOR} | ||
PUBLIC_HEADER "${HIDAPI_PUBLIC_HEADERS}" | ||
) | ||
|
||
# compatibility with find_package() | ||
add_library(hidapi::libusb ALIAS hidapi_libusb) | ||
# compatibility with raw library link | ||
add_library(hidapi-libusb ALIAS hidapi_libusb) | ||
|
||
if(HIDAPI_INSTALL_TARGETS) | ||
install(TARGETS hidapi_libusb EXPORT hidapi | ||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/hidapi" | ||
) | ||
endif() | ||
|
||
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-libusb.pc.in") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
cmake_minimum_required(VERSION 3.6.3 FATAL_ERROR) | ||
|
||
add_library(hidapi_hidraw | ||
${HIDAPI_PUBLIC_HEADERS} | ||
hid.c | ||
) | ||
target_link_libraries(hidapi_hidraw PUBLIC hidapi_include) | ||
|
||
find_package(Threads REQUIRED) | ||
|
||
include(FindPkgConfig) | ||
pkg_check_modules(libudev REQUIRED IMPORTED_TARGET libudev) | ||
|
||
target_link_libraries(hidapi_hidraw PRIVATE PkgConfig::libudev Threads::Threads) | ||
|
||
set_target_properties(hidapi_hidraw | ||
PROPERTIES | ||
EXPORT_NAME "hidraw" | ||
OUTPUT_NAME "hidapi-hidraw" | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION ${PROJECT_VERSION_MAJOR} | ||
PUBLIC_HEADER "${HIDAPI_PUBLIC_HEADERS}" | ||
) | ||
|
||
# compatibility with find_package() | ||
add_library(hidapi::hidraw ALIAS hidapi_hidraw) | ||
# compatibility with raw library link | ||
add_library(hidapi-hidraw ALIAS hidapi_hidraw) | ||
|
||
if(HIDAPI_INSTALL_TARGETS) | ||
install(TARGETS hidapi_hidraw EXPORT hidapi | ||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/hidapi" | ||
) | ||
endif() | ||
|
||
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi-hidraw.pc.in") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
cmake_minimum_required(VERSION 3.4.3 FATAL_ERROR) | ||
|
||
add_library(hidapi_darwin | ||
${HIDAPI_PUBLIC_HEADERS} | ||
hid.c | ||
) | ||
|
||
find_package(Threads REQUIRED) | ||
|
||
target_link_libraries(hidapi_darwin | ||
PUBLIC hidapi_include | ||
PRIVATE Threads::Threads | ||
PRIVATE "-framework IOKit" "-framework CoreFoundation" "-framework AppKit" | ||
) | ||
|
||
set_target_properties(hidapi_darwin | ||
PROPERTIES | ||
EXPORT_NAME "darwin" | ||
OUTPUT_NAME "hidapi" | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION ${PROJECT_VERSION_MAJOR} | ||
MACHO_COMPATIBILITY_VERSION ${PROJECT_VERSION_MAJOR} | ||
FRAMEWORK_VERSION ${PROJECT_VERSION_MAJOR} | ||
PUBLIC_HEADER "${HIDAPI_PUBLIC_HEADERS}" | ||
) | ||
|
||
# compatibility with find_package() | ||
add_library(hidapi::darwin ALIAS hidapi_darwin) | ||
# compatibility with raw library link | ||
add_library(hidapi ALIAS hidapi_darwin) | ||
|
||
set(PUBLIC_HEADER_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") | ||
if(NOT CMAKE_FRAMEWORK) | ||
set(PUBLIC_HEADER_DESTINATION "${PUBLIC_HEADER_DESTINATION}/hidapi") | ||
endif() | ||
|
||
if(HIDAPI_INSTALL_TARGETS) | ||
install(TARGETS hidapi_darwin EXPORT hidapi | ||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
FRAMEWORK DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
PUBLIC_HEADER DESTINATION "${PUBLIC_HEADER_DESTINATION}" | ||
) | ||
endif() | ||
|
||
hidapi_configure_pc("${PROJECT_ROOT}/pc/hidapi.pc.in") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.