# Protobuf generate relative to package/workdir APPEND\_PATH

**URL:** <https://discourse.cmake.org/t/protobuf-generate-relative-to-package-workdir-append-path/15379>\
**Category:** Code\
**Created:** [December 9, 2025, 7:39pm UTC](https://discourse.cmake.org/t/protobuf-generate-relative-to-package-workdir-append-path/15379 "2025-12-09T19:39:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rchildre3](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rchildre3/32/5937_2.png) [@rchildre3](https://discourse.cmake.org/u/rchildre3)\
**Post date:** [December 9, 2025, 7:39pm UTC](https://discourse.cmake.org/t/protobuf-generate-relative-to-package-workdir-append-path/15379/1 "2025-12-09T19:39:27Z")

</div>

I am having difficulty with the `protobuf_generate` of `FindProtobuf.cmake`

in my project

```auto
.
├── a
│ ├── b
│ │ ├── c
│ │ │ ├── CMakeLists.txt
│ │ │ └── d.proto
├── e
│ ├── f
│ │ ├── g
│ │ │ ├── CMakeLists.txt
│ │ │ └── h.proto

```

where `a/b/c/CMakeLists.txt`

has the following `protobuf_generate` call:

```auto
protobuf_generate(
    TARGET d_tgt
    PROTOC_OUT_DIR ${CMAKE_BINARY_DIR}
    PROTOS d.proto
    IMPORT_DIRS ${CMAKE_SOURCE_DIR}
)

```

_Note that the `APPEND_PATH` flag is not set_

and `d.proto` contains the include:

`import "e/f/g/h.proto";`

and the generated protoc call

`cd ${CMAKE_BINARY_DIR}/a/b/c && protoc --cpp_out :${CMAKE_BINARY_DIR} -I ${CMAKE_SOURCE_DIR}/a/b/c -I ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/a/b/c/d.proto`

The inclusion of `-I ${CMAKE_SOURCE_DIR}/a/b/c` as it makes `protoc` think that module needs `descriptor_table_` name of only `d`, when the linkage in `e/f/g/h` is expecting an `a/b/c/d` name.

If the `APPEND_PATH` flag is not included no additional paths should be included in the invocation of `protoc`

In the current flow of `FindProtobuf.cmake` whether the `APPEND_PATH` flag is set or not, additional include flags get included

Related to:

> <https://stackoverflow.com/questions/71659541/dependent-proto-buffer-files-produces-a-descriptor-table-2eproto-has-not-be>

> <https://github.com/protocolbuffers/protobuf/issues/7439>
>
> version : 3.8.0
> 
> compile command:
> \`protoc --cpp\_out=./ google/protobuf/descr…iptor.proto -Igoogle/protobuf\`
> 
> then I got descriptor.pb.h. Howerver, this pb.h is different with the original google/protobuf/descriptor.pb.h.
> 
> e.g. I got：
> 
> \`extern const ::PROTOBUF\_NAMESPACE\_ID::internal::DescriptorTable descriptor\_table\_descriptor\_2eproto;\`
> 
> in my file.
> 
> while in the original file, it is:
> 
> \`extern PROTOBUF\_EXPORT const ::PROTOBUF\_NAMESPACE\_ID::internal::DescriptorTable descriptor\_table\_google\_2fprotobuf\_2fdescriptor\_2eproto;
> \`
> 
> so, how to compile the descriptor.proto to get the right pb.h ?
> 
> by the way, I got a similar issue with 
> 
> \`descriptor\_table\_proto\_2fcommon\_2eproto #6179\` https://github.com/protocolbuffers/protobuf/issues/6179
