aboutsummaryrefslogtreecommitdiff
path: root/cmake/CheckTrezor.cmake
diff options
context:
space:
mode:
authorDusan Klinec <dusan.klinec@gmail.com>2018-11-05 00:38:58 +0100
committerDusan Klinec <dusan.klinec@gmail.com>2018-11-25 11:57:19 +0100
commit2ffe53d9e668c1993fc6f1cbcd7d74c895a5fbb7 (patch)
tree6d6c2fb1a32e5a489c7892756b61ac9fc764cf69 /cmake/CheckTrezor.cmake
parentMerge pull request #4781 (diff)
downloadmonero-2ffe53d9e668c1993fc6f1cbcd7d74c895a5fbb7.tar.xz
device/trezor: webusb transport added, cmake fixes
- webusb transport based on libusb added. Provides direct access to Trezor via USB, no need for Trezor bridge. - trezor protocol message handler improved, no recursion used. Ready for upcoming integration tests. - libusb (for docker) bumped from v1.0.9 to v1.0.22, newer version required for webusb transport, for device enumeration. - cmake improvements and fixes. Cmake Trezor checks are moved to a dedicated CheckTrezor.cmake file. In case of a problem Trezor is excluded from build. - ifdefs made consistent to Ledger. - UDP Transport enumeration disabled by default in release mode
Diffstat (limited to 'cmake/CheckTrezor.cmake')
-rw-r--r--cmake/CheckTrezor.cmake79
1 files changed, 79 insertions, 0 deletions
diff --git a/cmake/CheckTrezor.cmake b/cmake/CheckTrezor.cmake
new file mode 100644
index 000000000..ea21237fd
--- /dev/null
+++ b/cmake/CheckTrezor.cmake
@@ -0,0 +1,79 @@
+OPTION(USE_DEVICE_TREZOR "Trezor support compilation" ON)
+OPTION(USE_DEVICE_TREZOR_LIBUSB "Trezor LibUSB compilation" ON)
+OPTION(USE_DEVICE_TREZOR_UDP_RELEASE "Trezor UdpTransport in release mode" OFF)
+
+# Use Trezor master switch
+if (USE_DEVICE_TREZOR)
+ # Protobuf is required to build protobuf messages for Trezor
+ include(FindProtobuf OPTIONAL)
+ find_package(Protobuf)
+ if(NOT Protobuf_FOUND)
+ message(STATUS "Could not find Protobuf")
+ endif()
+
+else()
+ message(STATUS "Trezor support disabled by USE_DEVICE_TREZOR")
+endif()
+
+if(Protobuf_FOUND AND USE_DEVICE_TREZOR)
+ if (NOT "$ENV{TREZOR_PYTHON}" STREQUAL "")
+ set(TREZOR_PYTHON "$ENV{TREZOR_PYTHON}" CACHE INTERNAL "Copied from environment variable TREZOR_PYTHON")
+ else()
+ find_package(Python QUIET COMPONENTS Interpreter) # cmake 3.12+
+ if(Python_Interpreter_FOUND)
+ set(TREZOR_PYTHON "${Python_EXECUTABLE}")
+ endif()
+ endif()
+
+ if(NOT TREZOR_PYTHON)
+ find_package(PythonInterp)
+ if(PYTHONINTERP_FOUND AND PYTHON_EXECUTABLE)
+ set(TREZOR_PYTHON "${PYTHON_EXECUTABLE}")
+ endif()
+ endif()
+
+ if(NOT TREZOR_PYTHON)
+ message(STATUS "Trezor: Python not found")
+ endif()
+endif()
+
+# Try to build protobuf messages
+if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
+ set(ENV{PROTOBUF_INCLUDE_DIRS} "${Protobuf_INCLUDE_DIRS}")
+ set(ENV{PROTOBUF_PROTOC_EXECUTABLE} "${Protobuf_PROTOC_EXECUTABLE}")
+ execute_process(COMMAND ${TREZOR_PYTHON} tools/build_protob.py WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../src/device_trezor/trezor RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
+ if(RET)
+ message(WARNING "Trezor protobuf messages could not be regenerated (err=${RET}, python ${PYTHON})."
+ "OUT: ${OUT}, ERR: ${ERR}."
+ "Please read src/device_trezor/trezor/tools/README.md")
+ else()
+ message(STATUS "Trezor protobuf messages regenerated ${OUT}")
+ set(DEVICE_TREZOR_READY 1)
+ add_definitions(-DDEVICE_TREZOR_READY=1)
+
+ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+ add_definitions(-DTREZOR_DEBUG=1)
+ endif()
+
+ if(USE_DEVICE_TREZOR_UDP_RELEASE)
+ add_definitions(-DWITH_DEVICE_TREZOR_UDP_RELEASE=1)
+ endif()
+
+ if (Protobuf_INCLUDE_DIR)
+ include_directories(${Protobuf_INCLUDE_DIR})
+ endif()
+
+ # LibUSB support, check for particular version
+ # Include support only if compilation test passes
+ if (USE_DEVICE_TREZOR_LIBUSB)
+ find_package(LibUSB)
+ endif()
+
+ if (LibUSB_COMPILE_TEST_PASSED)
+ add_definitions(-DHAVE_TREZOR_LIBUSB=1)
+ if(LibUSB_INCLUDE_DIRS)
+ include_directories(${LibUSB_INCLUDE_DIRS})
+ endif()
+ endif()
+ endif()
+endif()