1
- # Function for setting default options default values via env vars
2
- function (_trezor_default_val val_name val_default)
3
- if (NOT DEFINED ENV{${val_name} })
4
- set (ENV{${val_name} } ${val_default} )
5
- endif ()
6
- endfunction ()
7
-
8
- # Define default options via env vars
9
- _trezor_default_val(USE_DEVICE_TREZOR ON )
10
- _trezor_default_val(USE_DEVICE_TREZOR_MANDATORY OFF )
11
- _trezor_default_val(USE_DEVICE_TREZOR_PROTOBUF_TEST ON )
12
- _trezor_default_val(USE_DEVICE_TREZOR_LIBUSB ON )
13
- _trezor_default_val(USE_DEVICE_TREZOR_UDP_RELEASE OFF )
14
- _trezor_default_val(USE_DEVICE_TREZOR_DEBUG OFF )
15
- _trezor_default_val(TREZOR_DEBUG OFF )
16
-
17
1
# Main options
18
- OPTION (USE_DEVICE_TREZOR "Trezor support compilation" $ENV{USE_DEVICE_TREZOR} )
19
- 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
- OPTION (USE_DEVICE_TREZOR_LIBUSB "Trezor LibUSB compilation" $ENV{USE_DEVICE_TREZOR_LIBUSB} )
22
- OPTION (USE_DEVICE_TREZOR_UDP_RELEASE "Trezor UdpTransport in release mode" $ENV{USE_DEVICE_TREZOR_UDP_RELEASE} )
23
- OPTION (USE_DEVICE_TREZOR_DEBUG "Trezor Debugging enabled" $ENV{USE_DEVICE_TREZOR_DEBUG} )
24
- OPTION (TREZOR_DEBUG "Main Trezor debugging switch" $ENV{TREZOR_DEBUG} )
25
-
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 ()
2
+ OPTION (USE_DEVICE_TREZOR "Trezor support compilation" ON )
3
+ OPTION (USE_DEVICE_TREZOR_MANDATORY "Trezor compilation is mandatory, fail build if Trezor support cannot be compiled" OFF )
4
+ OPTION (USE_DEVICE_TREZOR_LIBUSB "Trezor LibUSB compilation" ON )
5
+ OPTION (USE_DEVICE_TREZOR_UDP_RELEASE "Trezor UdpTransport in release mode" OFF )
6
+ OPTION (USE_DEVICE_TREZOR_DEBUG "Trezor Debugging enabled" OFF )
7
+ OPTION (TREZOR_DEBUG "Main Trezor debugging switch" OFF )
51
8
52
9
macro (trezor_fatal_msg msg)
53
10
if ($ENV{USE_DEVICE_TREZOR_MANDATORY} )
@@ -71,134 +28,54 @@ macro(trezor_fatal_msg msg)
71
28
endmacro ()
72
29
73
30
# 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)
31
+ if (NOT USE_DEVICE_TREZOR)
32
+ message (STATUS "Trezor: support disabled by USE_DEVICE_TREZOR" )
33
+ else ()
34
+ # Look for ProtobufConfig.cmake, provided by Protobuf
35
+ find_package (Protobuf CONFIG)
81
36
37
+ # Look for FindProtobuf.cmake, provided by CMake
82
38
if (NOT Protobuf_FOUND)
83
- FIND_PACKAGE (Protobuf CONFIG )
39
+ find_package (Protobuf)
84
40
endif ()
41
+
85
42
if (NOT Protobuf_FOUND)
86
- FIND_PACKAGE (Protobuf )
43
+ trezor_fatal_msg( "Trezor library not found" )
87
44
endif ()
45
+ endif ()
88
46
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 ()
47
+ # Try to build protobuf messages
48
+ if (Protobuf_FOUND AND USE_DEVICE_TREZOR)
49
+ find_program (Protobuf_PROTOC_EXECUTABLE protoc REQUIRED)
110
50
111
51
if (TREZOR_DEBUG)
112
52
set (USE_DEVICE_TREZOR_DEBUG 1)
113
53
message (STATUS "Trezor: debug build enabled" )
114
- endif ()
115
-
116
- # Compile debugging support (for tests)
117
- if (USE_DEVICE_TREZOR_DEBUG)
54
+ # Compile debugging support (for tests)
118
55
add_definitions (-DWITH_TREZOR_DEBUGGING=1)
119
56
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
57
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 ()
58
+ # .proto files to compile
59
+ set (_proto_files "messages.proto"
60
+ "messages-common.proto"
61
+ "messages-management.proto"
62
+ "messages-monero.proto" )
63
+ if (TREZOR_DEBUG)
64
+ list (APPEND _proto_files "messages-debug.proto" )
65
+ endif ()
140
66
141
- if (NOT TREZOR_PYTHON)
142
- trezor_fatal_msg("Trezor: Python not found" )
143
- endif ()
144
- endif ()
67
+ set (_include_dir "${CMAKE_CURRENT_LIST_DIR} /../external/trezor-common/protob" )
68
+ set (_proto_files_absolute)
69
+ foreach (file IN LISTS _proto_files)
70
+ list (APPEND _proto_files_absolute "${_include_dir} /${file} " )
71
+ endforeach ()
145
72
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)
73
+ 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)
149
74
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" )
75
+ trezor_fatal_msg("Trezor: protobuf messages could not be (re)generated (err=${RET} ). OUT: ${OUT} , ERR: ${ERR} ." )
156
76
endif ()
157
77
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 ()
184
-
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)
195
- 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" )
199
- endif ()
200
-
201
- message (STATUS "Trezor: protobuf messages regenerated out: \" ${OUT} .\" " )
78
+ message (STATUS "Trezor: protobuf messages regenerated" )
202
79
set (DEVICE_TREZOR_READY 1)
203
80
add_definitions (-DDEVICE_TREZOR_READY=1)
204
81
add_definitions (-DPROTOBUF_INLINE_NOT_IN_HEADERS=0)
@@ -236,19 +113,4 @@ if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
236
113
elseif (USE_DEVICE_TREZOR_LIBUSB AND NOT ANDROID)
237
114
trezor_fatal_msg("Trezor: LibUSB not found or test failed, please install libusb-1.0.26" )
238
115
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
116
endif ()
0 commit comments