Skip to content

Commit 8a48d35

Browse files
committed
Allow cross-compilation with protobuf
The upstream config module from protobuf always declares targets for the protobuf library and protoc of the same platform. This means one of the two is always wrong, as protoc needs to be run on the build machine, but the library must be linked for the "host" platform. A small change in the CMake scaffold allows the user to pass `-DPROTOBUF_PROTOC_EXECUTABLE=<path/to/protoc>` to cmake when creating the build tree.
1 parent 955a807 commit 8a48d35

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

CMakeLists.txt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -419,20 +419,21 @@ if(WITH_OTLP_GRPC
419419
endif()
420420
endif()
421421
endif()
422-
# Latest Protobuf imported targets and without legacy module support
423-
if(TARGET protobuf::protoc)
424-
project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE
425-
protobuf::protoc)
426-
# If protobuf::protoc is not a imported target, then we use the target
427-
# directly for fallback
428-
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
429-
set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
422+
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
423+
# Latest Protobuf imported targets and without legacy module support
424+
if(TARGET protobuf::protoc)
425+
project_build_tools_get_imported_location(PROTOBUF_PROTOC_EXECUTABLE
426+
protobuf::protoc)
427+
# If protobuf::protoc is not a imported target, then we use the target
428+
# directly for fallback
429+
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
430+
set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
431+
endif()
432+
elseif(Protobuf_PROTOC_EXECUTABLE)
433+
# Some versions of FindProtobuf.cmake uses mixed case instead of uppercase
434+
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
430435
endif()
431-
elseif(Protobuf_PROTOC_EXECUTABLE)
432-
# Some versions of FindProtobuf.cmake uses mixed case instead of uppercase
433-
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
434436
endif()
435-
include(CMakeDependentOption)
436437

437438
message(STATUS "PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC_EXECUTABLE}")
438439
set(SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY})

0 commit comments

Comments
 (0)