-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
CMakeLists.txt
122 lines (92 loc) · 3.52 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
cmake_minimum_required(VERSION 3.9)
project(pi400kb)
# for asprintf
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
add_compile_definitions(_GNU_SOURCE)
option(NO_OUTPUT "Disable USB HID output" OFF)
if(NOT HOOK_PATH)
set(HOOK_PATH "/home/pi/pi400kb/hook.sh" CACHE STRING "Path to .sh toggle hook")
endif()
if(NOT KEYBOARD_VID)
set(KEYBOARD_VID "0x04d9" CACHE STRING "Vendor ID for keyboard")
endif()
if(NOT KEYBOARD_PID)
set(KEYBOARD_PID "0x0007" CACHE STRING "Product ID for keyboard")
endif()
if(NOT KEYBOARD_DEV)
set(KEYBOARD_DEV "/dev/input/by-id/usb-_Raspberry_Pi_Internal_Keyboard-event-kbd" CACHE STRING "Device path for keyboard")
endif()
if(NOT MOUSE_VID)
set(MOUSE_VID "0x093a" CACHE STRING "Vendor ID for mouse")
endif()
if(NOT MOUSE_PID)
set(MOUSE_PID "0x2510" CACHE STRING "Product ID for mouse")
endif()
if(NOT MOUSE_DEV)
set(MOUSE_DEV "/dev/input/by-id/usb-PixArt_USB_Optical_Mouse-event-mouse" CACHE STRING "Device path for mouse")
endif()
add_library(libusbgx INTERFACE)
target_sources(libusbgx INTERFACE
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/usbg.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/usbg_common.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/usbg_common_libconfig.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/usbg_schemes_libconfig.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/usbg_error.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/function/ether.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/function/ffs.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/function/hid.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/function/loopback.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/function/midi.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/function/ms.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/function/phonet.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/function/serial.c
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/function/uac2.c
)
# disable -Waddress-of-packed-member unaligned pointer warning
set_source_files_properties(
${CMAKE_CURRENT_LIST_DIR}/libusbgx/src/function/ether.c
PROPERTIES COMPILE_FLAGS
"-Wno-address-of-packed-member"
)
target_include_directories(libusbgx INTERFACE ${CMAKE_CURRENT_LIST_DIR}/libusbgx/include)
target_include_directories(libusbgx INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(libusbgx INTERFACE HAS_GADGET_SCHEMES)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/libusbgx/include/usbg/usbg_version.h.in)
set(USBG_VERSION_HEX "0x00000000")
configure_file(${CMAKE_CURRENT_LIST_DIR}/libusbgx/include/usbg/usbg_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/usbg_version.h @ONLY)
else()
message(FATAL_ERROR "Missing usbg_version.h.in. Did you forget to `git submodule update --init`?")
endif()
find_library(libconfig libconfig)
target_link_libraries(libusbgx INTERFACE config)
add_executable(
pi400kb
pi400.c
gadget-hid.c
)
target_compile_definitions(pi400kb PRIVATE
HAS_GADGET_SCHEMES
HOOK_PATH="${HOOK_PATH}"
MOUSE_VID=${MOUSE_VID}
MOUSE_PID=${MOUSE_PID}
MOUSE_DEV="${MOUSE_DEV}"
KEYBOARD_VID=${KEYBOARD_VID}
KEYBOARD_PID=${KEYBOARD_PID}
KEYBOARD_DEV="${KEYBOARD_DEV}"
)
if(NO_OUTPUT)
target_compile_definitions(pi400kb PRIVATE NO_OUTPUT)
endif()
target_link_libraries(pi400kb libusbgx)
install(FILES
${CMAKE_CURRENT_LIST_DIR}/hook.sh
${CMAKE_CURRENT_LIST_DIR}/pi400kb.service
${CMAKE_CURRENT_LIST_DIR}/README.md
DESTINATION .
)
install(TARGETS pi400kb DESTINATION .)
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_GENERATOR "ZIP" "TGZ")
include(CPack)