[cmake-developers] How to handle dependencies of protobuf files ?

Alexander Neundorf neundorf at kde.org
Tue May 29 16:00:24 EDT 2018


Hi,

On 2018 M05 29, Tue 09:52:16 CEST Brad King wrote:
> On 05/15/2018 03:45 PM, Alexander Neundorf wrote:
> > I think to do it properly, there would have to be a dependency scanning
> > for
> > proto files like there is for C/C++ headers.
> 
> In order to handle implicit dependencies like that implied by
> 
>     import "MyBase.proto";
> 
> then they would somehow need to be extracted from source content.
> Ideally protoc should be able to write a depfile as a side effect.
 
Parsing them using cmake would more or less work, also the include dirs are 
known, so technically this would probably work. But the parsing would happen 
at cmake-time, not at compile-time, but editing a proto-file does not trigger a 
cmake run...
Would that have to be implemented similar to the C dependency scanning ?

> Otherwise all dependencies should be listed explicitly somewhere.

so the cheap solution would be to add an argument to PROTOBUF_GENERATE_CPP() 
to list proto-files these proto-files depend on which is forwarded to (every) 
add_custom_command() call inside PROTOBUF_GENERATE_CPP().

Not very elegant, but at least it would make it work correctly.

This would require that if in a set of proto-files there are different 
dependencies, for each of those with different dependencies a separate 
PROTOBUF_GENERATE_CPP() would be needed.
A bit ugly, but better than now.

Alex



More information about the cmake-developers mailing list