protobuf_generate() returns paths with // when a proto is directly in its import directory
Maintainers usually reply within 1 day
@tonyliaoss is already working on this.
Since Oct 6, 2026.
Assessment
This issue has not been assessed yet.
Description
What language does this apply to?
CMake protobuf_generate() function (cmake/protobuf-generate.cmake);
Describe the problem you are trying to solve.
protobuf_generate() builds output paths as ${PROTOC_OUT_DIR}/${_rel_dir}/${_basename}${_ext}. When a proto sits directly in its import directory, _rel_dir is empty and the path gets a //:
protobuf_generate(OUT_VAR srcs PROTOS proto/foo.proto IMPORT_DIRS proto)
# srcs: <build>//foo.pb.h;<build>//foo.pb.cc
The same happens with APPEND_PATH, for protos in CMAKE_CURRENT_SOURCE_DIR.
CMake normalizes paths internally, so the build itself is fine it seems. But the returned strings don't match the same path written normally... so something like list(FIND), list(REMOVE_ITEM) and STREQUAL against ${CMAKE_CURRENT_BINARY_DIR}/foo.pb.h would miss, and stripping the output dir with string(REPLACE) leaves /foo.pb.h.
Describe the solution you'd like
something like below to only add the separator when there's a subdirectory:
set(_rel_prefix)
if(NOT _rel_dir STREQUAL "")
set(_rel_prefix "${_rel_dir}/")
endif()
set(_generated_srcs)
foreach(_ext ${protobuf_generate_GENERATE_EXTENSIONS})
list(APPEND _generated_srcs "${protobuf_generate_PROTOC_OUT_DIR}/${_rel_prefix}${_basename}${_ext}")
endforeach()
Describe alternatives you've considered
cmake_path(APPEND) would join the pieces without the extra "/", but it needs CMake 3.20, and protobuf supports 3.16.
Additional context
CMake's FindProtobuf copy of protobuf_generate() doesn't add the // with APPEND_PATH or in protobuf_generate_cpp(). So moving from find_package(Protobuf) to find_package(protobuf CONFIG) changes those strings.
- 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