[CMake] protobuf and imports relative to root (and --proto_path)

David Jobet djobet at tower-research.com
Tue Sep 25 11:53:27 EDT 2018


> What I do have a problem is rerunning protoc automatically on proto-files which
> import proto files that have been modified.
> How do you handle this ?

I just found out I don't.
Any idea on that one ?

Otherwise I'm going to create a small .proto parser (python) that will
just list the imports recursively.
I will add that as DEPENDS to the add_custom_command.

David
On Thu, Aug 23, 2018 at 9:36 PM Alexander Neundorf <neundorf at kde.org> wrote:
>
> On 2018 M08 23, Thu 12:50:14 CEST David Jobet wrote:
> > Hello,
> >
> > I'm trying to port an existing project from premake to cmake.
> > I'm trying to avoid modifying the source files while doing so.
> >
> > Right now, we have several libraries (read in different directories) using
> > proto files with imports between them.
> > All imports are made relative to the root of the project.
> >
> > e.g :
> > work/lib1/sublib1/a.proto
> > work/lib1/sublib1/b.proto
> >
> > with a.proto having a link to b.proto like this "import
> > lib1/sublib1/b.proto"
> >
> > If I compile this with an unchanged FindProtobuf.cmake, I do this :
> >
> > protobuf_generate_cpp(PROTO_SRCS PROTO_HRDS a.proto b.proto)
> > add_library(...)
> >
> > the problem being that it looks like the "namespaces" generated by protoc
> > in b.proto do not match the one used in a.proto : it does not compile.
>
> do you mean protoc fails, or that the C++ compiler fails when compiling the
> generated file ?
> I'm also using proto files with imports between them and don't have problems
> with finding them.
> Are you setting the PROTOBUF_IMPORT_DIRS variable ?
>
> What I do have a problem is rerunning protoc automatically on proto-files which
> import proto files that have been modified.
> How do you handle this ?
>
> > Is there a way to make this work ?
> >
> > Otherwise, I made the patch below which solves my problem. Do you think it
> > could be included in cmake ?
> > it defines a new option PROTO_PATH, so the decl above becomes
> > protobuf_generate_cpp(PROTO_SRCS PROTO_HRDS PROTO_PATH ${CMAKE_SOURCE_DIR}
> > a.proto b.proto)
> >
> > With regards
> >
> > David
> >
> > $ diff share/cmake-3.10/Modules/FindProtobuf.cmake.orig
> > share/cmake-3.10/Modules/FindProtobuf.cmake
>
> can you please use diff -bup ?
> This makes the patch easier to read.
>
> Thanks
> Alex
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list