From 23562e6da33155419c84e3f62254c738d74daa09 Mon Sep 17 00:00:00 2001 From: "seanchann.zhou" Date: Fri, 6 Dec 2024 21:40:15 +0800 Subject: [PATCH] [BUILD] Fix cross-compilation with protoc (#3186) --- CMakeLists.txt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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