diff --git a/CMakeLists.txt b/CMakeLists.txt index 6abf96cd99..bf093f2caf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -428,12 +428,16 @@ if(WITH_OTLP_GRPC endif() # Latest Protobuf imported targets and without legacy module support if(TARGET protobuf::protoc) - project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE - protobuf::protoc) - # If protobuf::protoc is not a imported target, then we use the target - # directly for fallback - if(NOT PROTOBUF_PROTOC_EXECUTABLE) - set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc) + if(CMAKE_CROSSCOMPILING AND Protobuf_PROTOC_EXECUTABLE) + set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE}) + else() + project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE + protobuf::protoc) + # If protobuf::protoc is not a imported target, then we use the target + # directly for fallback + if(NOT PROTOBUF_PROTOC_EXECUTABLE) + set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc) + endif() endif() elseif(Protobuf_PROTOC_EXECUTABLE) # Some versions of FindProtobuf.cmake uses mixed case instead of uppercase