@@ -8,7 +8,6 @@ endfunction()
8
8
# Define default options via env vars
9
9
_trezor_default_val(USE_DEVICE_TREZOR ON )
10
10
_trezor_default_val(USE_DEVICE_TREZOR_MANDATORY OFF )
11
- _trezor_default_val(USE_DEVICE_TREZOR_PROTOBUF_TEST ON )
12
11
_trezor_default_val(USE_DEVICE_TREZOR_LIBUSB ON )
13
12
_trezor_default_val(USE_DEVICE_TREZOR_UDP_RELEASE OFF )
14
13
_trezor_default_val(USE_DEVICE_TREZOR_DEBUG OFF )
@@ -17,38 +16,11 @@ _trezor_default_val(TREZOR_DEBUG OFF)
17
16
# Main options
18
17
OPTION (USE_DEVICE_TREZOR "Trezor support compilation" $ENV{USE_DEVICE_TREZOR} )
19
18
OPTION (USE_DEVICE_TREZOR_MANDATORY "Trezor compilation is mandatory, fail build if Trezor support cannot be compiled" $ENV{USE_DEVICE_TREZOR_MANDATORY} )
20
- OPTION (USE_DEVICE_TREZOR_PROTOBUF_TEST "Trezor Protobuf test" $ENV{USE_DEVICE_TREZOR_PROTOBUF_TEST} )
21
19
OPTION (USE_DEVICE_TREZOR_LIBUSB "Trezor LibUSB compilation" $ENV{USE_DEVICE_TREZOR_LIBUSB} )
22
20
OPTION (USE_DEVICE_TREZOR_UDP_RELEASE "Trezor UdpTransport in release mode" $ENV{USE_DEVICE_TREZOR_UDP_RELEASE} )
23
21
OPTION (USE_DEVICE_TREZOR_DEBUG "Trezor Debugging enabled" $ENV{USE_DEVICE_TREZOR_DEBUG} )
24
22
OPTION (TREZOR_DEBUG "Main Trezor debugging switch" $ENV{TREZOR_DEBUG} )
25
23
26
- # Helper function to fix cmake < 3.6.0 FindProtobuf variables
27
- function (_trezor_protobuf_fix_vars)
28
- if (${CMAKE_VERSION} VERSION_LESS "3.6.0" )
29
- foreach (UPPER
30
- PROTOBUF_SRC_ROOT_FOLDER
31
- PROTOBUF_IMPORT_DIRS
32
- PROTOBUF_DEBUG
33
- PROTOBUF_LIBRARY
34
- PROTOBUF_PROTOC_LIBRARY
35
- PROTOBUF_INCLUDE_DIR
36
- PROTOBUF_PROTOC_EXECUTABLE
37
- PROTOBUF_LIBRARY_DEBUG
38
- PROTOBUF_PROTOC_LIBRARY_DEBUG
39
- PROTOBUF_LITE_LIBRARY
40
- PROTOBUF_LITE_LIBRARY_DEBUG
41
- )
42
- if (DEFINED ${UPPER} )
43
- string (REPLACE "PROTOBUF_" "Protobuf_" Camel ${UPPER} )
44
- if (NOT DEFINED ${Camel} )
45
- set (${Camel} ${${UPPER} } PARENT_SCOPE)
46
- endif ()
47
- endif ()
48
- endforeach ()
49
- endif ()
50
- endfunction ()
51
-
52
24
macro (trezor_fatal_msg msg)
53
25
if ($ENV{USE_DEVICE_TREZOR_MANDATORY} )
54
26
message (FATAL_ERROR
@@ -71,42 +43,25 @@ macro(trezor_fatal_msg msg)
71
43
endmacro ()
72
44
73
45
# Use Trezor master switch
74
- if (USE_DEVICE_TREZOR)
75
- # Protobuf is required to build protobuf messages for Trezor
76
- include (FindProtobuf OPTIONAL )
77
-
78
- # PkgConfig works better with new Protobuf
79
- find_package (PkgConfig QUIET )
80
- pkg_check_modules(PROTOBUF protobuf)
46
+ if (NOT USE_DEVICE_TREZOR)
47
+ message (STATUS "Trezor: support disabled by USE_DEVICE_TREZOR" )
48
+ else ()
49
+ # Look for ProtobufConfig.cmake, provided by Protobuf
50
+ find_package (Protobuf CONFIG)
81
51
52
+ # Look for FindProtobuf.cmake, provided by CMake
82
53
if (NOT Protobuf_FOUND)
83
- FIND_PACKAGE (Protobuf CONFIG )
54
+ find_package (Protobuf)
84
55
endif ()
56
+
85
57
if (NOT Protobuf_FOUND)
86
- FIND_PACKAGE (Protobuf )
58
+ trezor_fatal_msg( "Trezor library not found" )
87
59
endif ()
60
+ endif ()
88
61
89
- _trezor_protobuf_fix_vars()
90
-
91
- # Early fail for optional Trezor support
92
- if (NOT Protobuf_FOUND AND NOT Protobuf_LIBRARY AND NOT Protobuf_PROTOC_EXECUTABLE AND NOT Protobuf_INCLUDE_DIR)
93
- trezor_fatal_msg("Trezor: Could not find Protobuf" )
94
- elseif (${CMAKE_CXX_STANDARD} LESS 17 AND ${Protobuf_VERSION} GREATER 21)
95
- trezor_fatal_msg("Trezor: Unsupported Protobuf version ${Protobuf_VERSION} with C++ ${CMAKE_CXX_STANDARD} . Please, use Protobuf v21." )
96
- elseif (NOT Protobuf_LIBRARY)
97
- trezor_fatal_msg("Trezor: Protobuf library not found: ${Protobuf_LIBRARY} " )
98
- unset (Protobuf_FOUND)
99
- elseif (NOT Protobuf_PROTOC_EXECUTABLE OR NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE} " )
100
- trezor_fatal_msg("Trezor: Protobuf executable not found: ${Protobuf_PROTOC_EXECUTABLE} " )
101
- unset (Protobuf_FOUND)
102
- elseif (NOT Protobuf_INCLUDE_DIR OR NOT EXISTS "${Protobuf_INCLUDE_DIR} " )
103
- trezor_fatal_msg("Trezor: Protobuf include dir not found: ${Protobuf_INCLUDE_DIR} " )
104
- unset (Protobuf_FOUND)
105
- else ()
106
- message (STATUS "Trezor: Protobuf lib: ${Protobuf_LIBRARY} , inc: ${Protobuf_INCLUDE_DIR} , protoc: ${Protobuf_PROTOC_EXECUTABLE} " )
107
- set (Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIR} )
108
- set (Protobuf_FOUND 1) # override found if all required info was provided by variables
109
- endif ()
62
+ # Try to build protobuf messages
63
+ if (Protobuf_FOUND AND USE_DEVICE_TREZOR)
64
+ find_program (Protobuf_PROTOC_EXECUTABLE protoc REQUIRED)
110
65
111
66
if (TREZOR_DEBUG)
112
67
set (USE_DEVICE_TREZOR_DEBUG 1)
@@ -117,88 +72,28 @@ if (USE_DEVICE_TREZOR)
117
72
if (USE_DEVICE_TREZOR_DEBUG)
118
73
add_definitions (-DWITH_TREZOR_DEBUGGING=1)
119
74
endif ()
120
- else ()
121
- message (STATUS "Trezor: support disabled by USE_DEVICE_TREZOR" )
122
- endif ()
123
-
124
- if (Protobuf_FOUND AND USE_DEVICE_TREZOR)
125
- if (NOT "$ENV{TREZOR_PYTHON} " STREQUAL "" )
126
- set (TREZOR_PYTHON "$ENV{TREZOR_PYTHON} " CACHE INTERNAL "Copied from environment variable TREZOR_PYTHON" )
127
- else ()
128
- find_package (Python QUIET COMPONENTS Interpreter) # cmake 3.12+
129
- if (Python_Interpreter_FOUND)
130
- set (TREZOR_PYTHON "${Python_EXECUTABLE} " )
131
- endif ()
132
- endif ()
133
-
134
- if (NOT TREZOR_PYTHON)
135
- find_package (PythonInterp)
136
- if (PYTHONINTERP_FOUND AND PYTHON_EXECUTABLE)
137
- set (TREZOR_PYTHON "${PYTHON_EXECUTABLE} " )
138
- endif ()
139
- endif ()
140
75
141
- if (NOT TREZOR_PYTHON)
142
- trezor_fatal_msg("Trezor: Python not found" )
143
- endif ()
144
- endif ()
145
-
146
- # Protobuf compilation test
147
- if (Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
148
- execute_process (COMMAND ${Protobuf_PROTOC_EXECUTABLE} -I "${CMAKE_CURRENT_LIST_DIR} " -I "${Protobuf_INCLUDE_DIR} " "${CMAKE_CURRENT_LIST_DIR} /test-protobuf.proto" --cpp_out ${CMAKE_BINARY_DIR} RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
149
- if (RET)
150
- trezor_fatal_msg("Trezor: Protobuf test generation failed: ${OUT} ${ERR} " )
151
- endif ()
152
-
153
- if (ANDROID)
154
- set (CMAKE_TRY_COMPILE_LINKER_FLAGS "${CMAKE_TRY_COMPILE_LINKER_FLAGS} -llog" )
155
- set (CMAKE_TRY_COMPILE_LINK_LIBRARIES "${CMAKE_TRY_COMPILE_LINK_LIBRARIES} log" )
156
- endif ()
76
+ # .proto files to compile
77
+ set (_proto_files "messages.proto"
78
+ "messages-common.proto"
79
+ "messages-management.proto"
80
+ "messages-monero.proto" )
81
+ if (USE_DEVICE_TREZOR_DEBUG)
82
+ list (APPEND _proto_files "messages-debug.proto" )
83
+ endif ()
157
84
158
- if (USE_DEVICE_TREZOR_PROTOBUF_TEST)
159
- if (PROTOBUF_LDFLAGS)
160
- set (PROTOBUF_TRYCOMPILE_LINKER "${PROTOBUF_LDFLAGS} " )
161
- else ()
162
- set (PROTOBUF_TRYCOMPILE_LINKER "${Protobuf_LIBRARY} " )
163
- endif ()
164
-
165
- try_compile (Protobuf_COMPILE_TEST_PASSED
166
- "${CMAKE_BINARY_DIR} "
167
- SOURCES
168
- "${CMAKE_BINARY_DIR} /test-protobuf.pb.cc"
169
- "${CMAKE_CURRENT_LIST_DIR} /test-protobuf.cpp"
170
- CMAKE_FLAGS
171
- CMAKE_EXE_LINKER_FLAGS ${CMAKE_TRY_COMPILE_LINKER_FLAGS}
172
- "-DINCLUDE_DIRECTORIES=${Protobuf_INCLUDE_DIR} ;${CMAKE_BINARY_DIR} "
173
- "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} "
174
- LINK_LIBRARIES "${PROTOBUF_TRYCOMPILE_LINKER} " ${CMAKE_TRY_COMPILE_LINK_LIBRARIES}
175
- OUTPUT_VARIABLE OUTPUT
176
- )
177
- if (NOT Protobuf_COMPILE_TEST_PASSED)
178
- trezor_fatal_msg("Trezor: Protobuf Compilation test failed: ${OUTPUT} ." )
179
- endif ()
180
- else ()
181
- message (STATUS "Trezor: Protobuf Compilation test skipped, build may fail later" )
182
- endif ()
183
- endif ()
85
+ set (_include_dir "${CMAKE_CURRENT_LIST_DIR} /../external/trezor-common/protob" )
86
+ set (_proto_files_absolute)
87
+ foreach (file IN LISTS _proto_files)
88
+ list (APPEND _proto_files_absolute "${_include_dir} /${file} " )
89
+ endforeach ()
184
90
185
- # Try to build protobuf messages
186
- if (Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
187
- set (ENV{PROTOBUF_INCLUDE_DIRS} "${Protobuf_INCLUDE_DIR} " )
188
- set (ENV{PROTOBUF_PROTOC_EXECUTABLE} "${Protobuf_PROTOC_EXECUTABLE} " )
189
- set (TREZOR_PROTOBUF_PARAMS "" )
190
- if (USE_DEVICE_TREZOR_DEBUG)
191
- set (TREZOR_PROTOBUF_PARAMS "--debug" )
192
- endif ()
193
-
194
- execute_process (COMMAND ${TREZOR_PYTHON} tools/build_protob.py ${TREZOR_PROTOBUF_PARAMS} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} /../src/device_trezor/trezor RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
91
+ execute_process (COMMAND ${Protobuf_PROTOC_EXECUTABLE} --cpp_out "${CMAKE_CURRENT_LIST_DIR} /../src/device_trezor/trezor/messages" "-I${_include_dir} " ${_proto_files_absolute} RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
195
92
if (RET)
196
- trezor_fatal_msg("Trezor: protobuf messages could not be regenerated (err=${RET} , python ${PYTHON} )."
197
- "OUT: ${OUT} , ERR: ${ERR} ."
198
- "Please read src/device_trezor/trezor/tools/README.md" )
93
+ trezor_fatal_msg("Trezor: protobuf messages could not be (re)generated (err=${RET} ). OUT: ${OUT} , ERR: ${ERR} ." )
199
94
endif ()
200
95
201
- message (STATUS "Trezor: protobuf messages regenerated out: \" ${OUT} . \" " )
96
+ message (STATUS "Trezor: protobuf messages regenerated" )
202
97
set (DEVICE_TREZOR_READY 1)
203
98
add_definitions (-DDEVICE_TREZOR_READY=1)
204
99
add_definitions (-DPROTOBUF_INLINE_NOT_IN_HEADERS=0)
@@ -236,19 +131,4 @@ if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
236
131
elseif (USE_DEVICE_TREZOR_LIBUSB AND NOT ANDROID)
237
132
trezor_fatal_msg("Trezor: LibUSB not found or test failed, please install libusb-1.0.26" )
238
133
endif ()
239
-
240
- if (BUILD_GUI_DEPS)
241
- set (TREZOR_DEP_LIBS "" )
242
- set (TREZOR_DEP_LINKER "" )
243
-
244
- if (Protobuf_LIBRARY)
245
- list (APPEND TREZOR_DEP_LIBS ${Protobuf_LIBRARY} )
246
- string (APPEND TREZOR_DEP_LINKER " -lprotobuf" )
247
- endif ()
248
-
249
- if (TREZOR_LIBUSB_LIBRARIES)
250
- list (APPEND TREZOR_DEP_LIBS ${TREZOR_LIBUSB_LIBRARIES} )
251
- string (APPEND TREZOR_DEP_LINKER " -lusb-1.0 ${LIBUSB_DEP_LINKER} " )
252
- endif ()
253
- endif ()
254
134
endif ()
0 commit comments