-
Notifications
You must be signed in to change notification settings - Fork 15.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly pick up & use Protobuf_PROTOC_EXECUTABLE
in cross-compilation
#14576
Comments
Thanks for reporting this! If you happen to know what needs to change to fix this I'd be happy to review a PR. I'm not very familiar with cross-compiling via cmake though, so this might take me some time to track down and fix |
@traversaro, is this something you think you could help with? 🙃 |
Yes, for sure if there is interest upstream I can prepare a PR. As a preliminary analysis, after thinking a bit I am afraid of the the fine details on how we can do this "overloading" of the location and the unintended side-effects, especially when using multiple config CMake generators. Probably a simpler solution is to just make sure that protobuf/cmake/protobuf-generate.cmake Line 146 in 92619cd
protobuf::protoc instead of the protobuf_generate CMake function will not work out of the box, but anyhow the fix for those cases would be quite straightforward (use ${Protobuf_PROTOC_EXECUTABLE} in place of protobuf::protoc ). To get an idea, we can do something similar to what we did in gazebosim/gz-msgs#392 .
|
Setting Protobuf_PROTOC_EXECUTABLE used to work. Now it looks like the new variable is protobuf_PROTOC_EXE but as mentioned earlier it gets ignored |
I had to set |
Yes, I was referring exactly to that with "I am afraid of the the fine details on how we can do this "overloading" of the location and the unintended side-effects, especially when using multiple config CMake generators.", sorry about that. I hope to prepare a concrete proposal to address this in the next week. |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
Ops, sorry about that. I forgot to follow up on my original " I hope to prepare a concrete proposal to address this in the next week.". |
Any update over here? The suggested workaround doesnt work for me and it throws error saying i cant use |
How are you including protobuf in your CMake project, via |
if(PROTOBUF_COMPILE)
include(FetchContent)
set(FETCHCONTENT_QUIET ON)
set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
find_package(Git REQUIRED)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_CONFORMANCE OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_EXPORT OFF CACHE BOOL "" FORCE)
set(protobuf_WITH_ZLIB OFF CACHE BOOL "" FORCE)
fetchcontent_declare(
protobuf GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git" GIT_TAG v3.15.6
PATCH_COMMAND "" SOURCE_SUBDIR cmake
)
fetchcontent_makeavailable(protobuf)
fetchcontent_getproperties(protobuf SOURCE_DIR PROTOBUF_INCLUDE_DIR)
else()
set(PROTOBUF_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/build/x64/_deps/protobuf-src")
endif(PROTOBUF_COMPILE)
set(PROTOBUF_INCLUDE_DIR "${PROTOBUF_INCLUDE_DIR}/src")
include_directories(${PROTOBUF_INCLUDE_DIR})
message("PROTOBUF_INCLUDE_DIR value : ${PROTOBUF_INCLUDE_DIR}")
set(Protobuf_INCLUDE_DIR ${PROTOBUF_INCLUDE_DIR})
set(Protobuf_LIBRARIES "${PROTOBUF_INCLUDE_DIR}/protobuf-build/libprotoc.lib")
set(Protobuf_PROTOC_EXECUTABLE "${PROTOBUF_INCLUDE_DIR}/protobuf-build/protoc.exe")
find_package(Protobuf REQUIRED)
set_target_properties(
"protobuf::protoc" PROPERTIES IMPORTED_LOCATION_RELWITHDEBINFO ${Protobuf_LIBRARIES}
IMPORTED_LOCATION_RELEASE ${Protobuf_PROTOC_EXECUTABLE}
) I am doing fetchcontent in cmake and then using find_package |
You need to use either |
But if I am to cross compile protobuf, i would have to build it in machine where cross compilation tools are available. In such cases, if i dont use FetchContent i wont be able to build it using my setup. And if i dont use |
In the kind of cross-compilation builds to which the workaround in the OP refers, protobuf is cross-compiled and installed before you configure for cross-compilation the package that depends on protobuf, and this cross-compiled protobuf is found via |
Since I'm keeping an eye on this issue, I'll also leave a revised version of OP's for the internet wanderers like me. find_package(protobuf CONFIG REQUIRED)
if(CMAKE_CROSSCOMPILING)
find_program(_PROTOBUF_PROTOC_EXECUTABLE protoc)
if(NOT TARGET protobuf::protoc)
add_executable(protobuf::protoc IMPORTED)
endif()
set_target_properties(protobuf::protoc PROPERTIES
IMPORTED_LOCATION_RELEASE "${_PROTOBUF_PROTOC_EXECUTABLE}"
IMPORTED_LOCATION_DEBUG "${_PROTOBUF_PROTOC_EXECUTABLE}"
IMPORTED_LOCATION_RELWIHDEBINFO "${_PROTOBUF_PROTOC_EXECUTABLE}"
IMPORTED_LOCATION_NOCONFIG "${_PROTOBUF_PROTOC_EXECUTABLE}"
)
endif()
|
Thank you, this works for me in yocto cross compilation. Any chances that this could be merged? |
…ore recent v27.3 protobuf so I could get rid of this error when running latest meshtastic command: edgemap:~# meshtastic --info Connected to radio Aborting due to: MessageToJson() got an unexpected keyword argument 'always_print_fields_with_no_presence' But as you would guess, playing with evil Google is not that easy. They changed build environment to cmake and decided to get rid of cross compilation support [1]. And giving really nice answer for developers asking about it [2]: “Unfortunately our cross compile setup is extremely specific to the docker images we use and we aren't staffed to support a general cross compiling setup.” So this happens when IqT fundend docker meets IqT funded Google. My take on this is that resilience targeted projects should stay away from both of these names. Resolution: I included patch (0001-remove-always_print_fields_with_no_presence.patch) to remove newly added option and meshtastic works now again with protobuf v21.12. [1] protocolbuffers/protobuf#14576 [2] protocolbuffers/protobuf#17347
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
The issue is still present. |
I've combined and modified some of the workarounds posted above to optionally use protoc provided by vcpkg:
|
It seems that when using
find_package(Protobuf CONFIG)
, any eventual setting ofProtobuf_PROTOC_EXECUTABLE
is ignored.This makes it hard for us in conda-forge, because
find_package(Protobuf CONFIG)
is necessary to avoid picking up CMake's own implementation of finding protobuf (and prefer an up-to-dateprotobuf-config.cmake
; which is necessary for correctly linking abseil for example).On the other hand, we simply must cross-compile on several architectures (e.g. no osx-arm64 runners at scale), and so if
Protobuf_PROTOC_EXECUTABLE
gets ignored (which carefully points to the build environment that matches the arch or the agent, and not the target environment for the final binary) we run intoBad CPU type in executable
when it calls the wrongprotoc
.The work-around we have come up with (and keep reinventing) in several places boils down to (courtesy @traversaro):
However, not everyone encountering this issue might be able to investigate and come up with this solution, so we keep running into it. I don't see why this shouldn't be supported out of the box, hence this issue.
What version of protobuf and what language are you using?
Version: 4.24.3
Language: C++
What operating system (Linux, Windows, ...) and version?
linux/osx
What runtime / compiler are you using (e.g., python version or gcc version)
What did you do?
Cross-compile a package that requires protoc, pass
-DProtobuf_PROTOC_EXECUTABLE=...
to CMake invocationWhat did you expect to see
Correct
protoc
(corresponding toProtobuf_PROTOC_EXECUTABLE
) gets used.What did you see instead?
Wrong
protoc
gets picked up.Anything else we should know about your project / environment
Some examples from conda-forge:
The text was updated successfully, but these errors were encountered: