-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
170 lines (135 loc) · 5.83 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
cmake_minimum_required(VERSION 3.16)
project(whb04bhid CXX)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule (hidapi,libWRP-key) update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
else()
message(FATAL_ERROR "The submodules (hidapi,libWRP-key) were not downloaded!\nGIT_SUBMODULE was turned off or failed.\nPlease update submodules and try again.")
endif()
# Clean build directories
if(EXISTS "${CMAKE_SOURCE_DIR}/extern/hidapi/build")
message(STATUS "** Removing ${CMAKE_SOURCE_DIR}/extern/hidapi/build")
file(REMOVE ${CMAKE_SOURCE_DIR}/extern/libWRP-key/build)
endif()
# Recreate build directories
message(STATUS "** Creating build directories")
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/extern/hidapi/build)
# BUilding hidapi
message(STATUS "BUILDING HIDAPI")
execute_process(COMMAND ${CMAKE_COMMAND} -DBUILD_SHARED_LIBS=OFF ..
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/extern/hidapi/build"
RESULT_VARIABLE RESULT_VAR)
if(NOT RESULT_VAR EQUAL "0")
message(FATAL_ERROR "Configure failed")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/extern/hidapi/build"
RESULT_VARIABLE RESULT_VAR)
if(NOT RESULT_VAR EQUAL "0")
message(FATAL_ERROR "Build failed")
endif()
# Add include search paths
include_directories(${PROJECT_SOURCE_DIR}/extern/hidapi/hidapi)
include_directories(${PROJECT_SOURCE_DIR}/extern/hidapi/libusb)
include_directories(${PROJECT_SOURCE_DIR}/extern/libWRP-key/include/WonderRabbitProject)
include_directories(${PROJECT_SOURCE_DIR}/include)
# Add lib search paths
link_directories(${PROJECT_SOURCE_DIR}/extern/hidapi/build/src/linux)
link_directories(${PROJECT_SOURCE_DIR}/extern/hidapi/build/src/libusb)
# Build the executable
set_property(GLOBAL PROPERTY CXX_STANDARD 11)
if(WIN32)
add_subdirectory(${PROJECT_SOURCE_DIR}/windows)
add_executable(whb04bhid src/whb04bhid.cpp windows/winmain.cpp)
endif()
if(NOT WIN32 AND NOT APPLE AND CMAKE_SYSTEM_NAME MATCHES "Linux")
add_executable(whb04bhid src/whb04bhid.cpp linux/linuxmain.cpp)
endif()
target_link_libraries(whb04bhid hidapi-hidraw)
target_link_libraries(whb04bhid udev)
#[[
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}"
)
include(ExternalProject)
ExternalProject_Add(hidapi
GIT_REPOSITORY https://github.com/libusb/hidapi
GIT_TAG "75aafc3ac972947a5ded5e5e85a9d62b9ed06b59"
SOURCE_DIR "${CMAKE_BINARY_DIR}/hidapi-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/hidapi-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hidapi-download"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hidapi-download"
)
include(FetchContent)
FetchContent_Declare(
hidapi
GIT_REPOSITORY "https://github.com/libusb/hidapi"
GIT_TAG "75aafc3ac972947a5ded5e5e85a9d62b9ed06b59"
)
FetchContent_MakeAvailable(hidapi)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule (hidapi,libWRP-key) update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
# verify that git submodule update worked
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/hidapi/CMakeLists.txt")
message(FATAL_ERROR "The submodules (hidapi,libWRP-key) were not downloaded!\nGIT_SUBMODULE was turned off or failed.\nPlease update submodules and try again.")
else()
execute_process(COMMAND "mkdir build"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/extern/hidapi
RESULT_VARIABLE CMD_RESULT)
execute_process(COMMAND "cmake .."
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/extern/hidapi/build
RESULT_VARIABLE CMD_RESULT)
endif()
include_directories(${PROJECT_SOURCE_DIR}/include)
# Add the submodules
add_subdirectory(${PROJECT_SOURCE_DIR}/extern/hidapi)
add_subdirectory(${PROJECT_SOURCE_DIR}/extern/libWRP-key)
include_directories(${PROJECT_SOURCE_DIR}/extern/hidapi/hidapi)
include_directories(${PROJECT_SOURCE_DIR}/extern/libWRP-key/include)
]]