protobuf_generate() ignores --proto_path passed through PROTOC_OPTIONS
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- cmake, cpp
- Domain
- build-system
Research direction
Reproduce the issue with the provided CMakeLists.txt and compare PROTOC_OPTIONS with IMPORT_DIRS. Start at protobuf-generate.cmake line 131 and trace how include directories and declared outputs are derived. Done means the documented or implemented handling matches protoc, generated files are declared at their actual locations, and repeated builds do not rerun unnecessarily.
Written by the indexing model from the issue text.
Description
What version of protobuf and what language are you using?
Version: v36.1
Language: C++, through the CMake protobuf_generate() function
What
supported operating system version
are you using (e.g. Linux, Windows) ?
Linux (Arch Linux, x86_64)
What
supported runtime / compiler version
are you using (e.g. python version, gcc version)
GCC 16.2.1, CMake 4.4.3, Ninja 1.13.2
What did you do?
-
put the below
CMakeLists.txtin an empty directory. It writes a.protointo the build tree and passes that directory to protoc with--proto_pathinPROTOC_OPTIONS:cmake_minimum_required(VERSION 3.16) project(repro CXX) find_package(protobuf CONFIG REQUIRED) set(gen_dir ${CMAKE_CURRENT_BINARY_DIR}/gen) file(WRITE ${gen_dir}/foo.proto "syntax = \"proto3\";\nmessage Foo { int32 x = 1; }\n") protobuf_generate(OUT_VAR srcs PROTOS ${gen_dir}/foo.proto PROTOC_OPTIONS --proto_path=${gen_dir}) add_custom_target(gen ALL DEPENDS ${srcs}) -
Configure with the build dir outside the source dir:
cmake -S . -B ../build -
Configure and build with the build dir inside it:
cmake -S . -B build, thencmake --build buildtwice.
What did you expect to see
Both configure, and the build generates foo.pb.h and foo.pb.cc in the build dir once. That's what protoc does with the same option: protoc --proto_path=<build>/gen --cpp_out=<build> <build>/gen/foo.proto.
What did you see instead?
Step 2 fails to configure:
CMake Error at /usr/lib/cmake/protobuf/protobuf-generate.cmake:131 (message):
Error: protobuf_generate could not find any correct proto include
directory.
Step 3 configures, but protobuf_generate() declares build/build/gen/foo.pb.h while protoc writes build/foo.pb.h. So the declared outputs never exist, and protoc seems to rerun on every build.
Anything else we should know about your project / environment
Passing the directory as IMPORT_DIRS ${gen_dir} instead works. So (just thinking out loud): either protobuf_generate() should take -I/--proto_path from PROTOC_OPTIONS into account, ahead of the others as protoc does, or the docs and the error message should say that import roots have to go in IMPORT_DIRS.
- Dominant language
- C++
- Stars
- 72.2k
- Forks
- 16.4k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 342
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from protocolbuffers/protobuf
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
protocolbuffers/protobuf#31768 ·
Maintainers usually reply within 1 day
-
feature request packaging & distribution python
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
protocolbuffers/protobuf#31654 ·
Maintainers usually reply within 1 day
-
google-protobuf 0.36.2-release fails to compile for ARMv7: @progbits rejected in global_asm!Possibly taken @farisbasha claimed this 1 day ago. Openbug help wanted rust
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
protocolbuffers/protobuf#31619 · 3 comments ·
Maintainers usually reply within 1 day
-
Null pointer passed to memcpy in lupb_decode() when the second argument is nilPossibly taken A pull request linked to this issue is open or already merged. Openbug help wanted lua
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
protocolbuffers/protobuf#31392 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
protocolbuffers/protobuf#31032 ·
Maintainers usually reply within 1 day
All issues in protocolbuffers/protobuf
Similar issues
-
agent:Windows bug in progress pri:medium sev:low testing windows
Difficulty 1/5 Under an hour Newbie friendliness 91/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
godotengine/godot#125651 ·
Maintainers usually reply within 1 day
-
Android: with view recycling on, a recycled View keeps its nextFocusLeftPossibly taken A pull request linked to this issue is open or already merged. OpenNeeds: Triage :mag: Platform: Android
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
react/react-native#60167 ·
Maintainers usually reply within 2 days
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 2 days