protocolbuffers / protocolbuffers/protobuf

Support maintaining source directory structure at generated location when using protobuf_generate

Open
#17,349 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

c++ cmake help wanted
Dominant language
C++
Stars
72k
Forks
16.3k
Avg merge
1d 17h
Merged PRs (30d)
140

Description

What language does this apply to?
C++ but I suspect is it the same for all.

Describe the problem you are trying to solve.
I use protobuf_generate to generate the .pb.h and .pb.cc. They are generated but they appear all in the same directory location loosing the original directory structure. In other words, the output is a flat directory.

Now, this happens because I need to set multiple paths with IMPORT_DIRS so that the import statements in my .proto files succeed at finding the other source files. This works perfectly and is in line with the fact that the variable is indeed IMPORT_DIRS and not IMPORT_DIR. It is also in line with the fact that the name starts with IMPORT, implying that it relates to the IMPORT statement in the proto files.

However, it appears that protobuf_generate overloads the definition of IMPORT_DIRS with an alternate use by using it as a ROOT directory in order to maintain the directory structure.

Describe the solution you'd like
Use a discrete SRC_ROOT to specify the source base location.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the protobuf_generate entry point and trace how IMPORT_DIRS affects both import resolution and generated output paths. Review the related build-system tests if available, then verify that a separate source-root setting preserves the source directory structure without changing import lookup behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.