@@ -23,32 +23,6 @@ OPTION(USE_DEVICE_TREZOR_UDP_RELEASE "Trezor UdpTransport in release mode" $ENV{
23
23
OPTION (USE_DEVICE_TREZOR_DEBUG "Trezor Debugging enabled" $ENV{USE_DEVICE_TREZOR_DEBUG} )
24
24
OPTION (TREZOR_DEBUG "Main Trezor debugging switch" $ENV{TREZOR_DEBUG} )
25
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 ()
51
-
52
26
macro (trezor_fatal_msg msg)
53
27
if ($ENV{USE_DEVICE_TREZOR_MANDATORY} )
54
28
message (FATAL_ERROR
@@ -72,40 +46,21 @@ endmacro()
72
46
73
47
# Use Trezor master switch
74
48
if (USE_DEVICE_TREZOR)
75
- # Protobuf is required to build protobuf messages for Trezor
76
- include (FindProtobuf OPTIONAL )
49
+ # Look for protobuf-config.cmake, provided by Protobuf
50
+ find_package (Protobuf CONFIG )
77
51
78
- # PkgConfig works better with new Protobuf
79
- find_package (PkgConfig QUIET )
80
- pkg_check_modules(PROTOBUF protobuf)
81
-
82
- if (NOT Protobuf_FOUND)
83
- FIND_PACKAGE (Protobuf CONFIG)
84
- endif ()
85
- if (NOT Protobuf_FOUND)
86
- FIND_PACKAGE (Protobuf)
52
+ if (Protobuf_FOUND)
53
+ # https://github.com/protocolbuffers/protobuf/issues/14576
54
+ find_program (Protobuf_PROTOC_EXECUTABLE protoc REQUIRED)
55
+ set (Protobuf_LIBRARY protobuf::libprotobuf) # Compatibility with FindProtobuf.cmake
56
+ else ()
57
+ # Look for FindProtobuf.cmake, provided by CMake
58
+ find_package (Protobuf)
87
59
endif ()
88
60
89
- _trezor_protobuf_fix_vars()
90
-
91
61
# 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
62
+ if (NOT Protobuf_FOUND)
63
+ trezor_fatal_msg("Trezor: protobuf library not found" )
109
64
endif ()
110
65
111
66
if (TREZOR_DEBUG)
0 commit comments