Skip to content

Commit cfd38b4

Browse files
committed
Fix the bug that protoc cannot be found in cross-compilation
Change-Id: I931ff0ad1951473acd56ae3f5778ac11f7499caa
1 parent 150256c commit cfd38b4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,16 +428,18 @@ if(WITH_OTLP_GRPC
428428
endif()
429429
# Latest Protobuf imported targets and without legacy module support
430430
if(TARGET protobuf::protoc)
431-
project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE
432-
protobuf::protoc)
433-
# If protobuf::protoc is not a imported target, then we use the target
434-
# directly for fallback
435-
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
436-
set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
431+
if(CMAKE_CROSSCOMPILING AND Protobuf_PROTOC_EXECUTABLE)
432+
# Some versions of FindProtobuf.cmake uses mixed case instead of uppercase
433+
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
434+
else()
435+
project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE
436+
protobuf::protoc)
437+
# If protobuf::protoc is not a imported target, then we use the target
438+
# directly for fallback
439+
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
440+
set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
441+
endif()
437442
endif()
438-
elseif(Protobuf_PROTOC_EXECUTABLE)
439-
# Some versions of FindProtobuf.cmake uses mixed case instead of uppercase
440-
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
441443
endif()
442444
include(CMakeDependentOption)
443445

0 commit comments

Comments
 (0)