[CMake] using cmake with google's protocol buffers

Neil Girdhar mistersheik at gmail.com
Thu Sep 18 14:35:11 EDT 2008


Hi Eric.

Thanks a lot for getting back to me.

2008/9/18 Eric Noulard <eric.noulard at gmail.com>

> 2008/9/18 Neil Girdhar <mistersheik at gmail.com>:
> >
> > Hi, I'm trying to add a special cmake rule to build google's protocol
> > buffers, and I was hoping someone could help me do it.  I've broken down
> the
> > details of the protocol compiler here, so all that's missing is a cmake
> > expert.
>
> Did you look at the recently posted CMake module:
> http://www.cmake.org/pipermail/cmake/2008-September/023963.html
>

That's great!

I couldn't figure out how to use it though.  I copied it to cmake's modules
directory (there should be a ~/.cmake/Modules place where you can add your
own modules), and got it loaded just fine.  I had to add
/opt/local/include/google/protobuf so that it would find the place where
macports puts protobufs, but there is no documentation on how to use
wrap_proto(...).  It looks like I need to put at least two things in those
brackets, but what?

Thanks

Neil


>
> I've added some suggested "basic" commands afterwards
> but I really suggest to try the preceding module and may be improve it or
> fix it, if it does not suit your needs and give feedback to the original
> author.
>
> > I have some ".proto" files that live in the same directories as the
> source.
> > I want to specify a rule that calls this:
> >
> > protoc DIR/SOMEFILE.proto  --cpp_out=SOMEDIR
> >
> > SOMEDIR should probably be DIR/CMakeFiles/DIR.dir
>
> What would you do that?
> I suggest that SOMEDIR should be
> ${CMAKE_CURRENT_BINARY_DIR}
> which the directory in the build tree which the sibbling
> of the corresponding source tree directory (${CMAKE_CURRENT_SOURCE_DIR})
>
> > this will generate
> > SOMEDIR/SOMEFILE.pb.h
> > SOMEDIR/SOMEFILE.pb.cc
>
> Then something like this in DIR/CMakeLists.txt
>
> ADD_CUSTOM_COMMAND(
>         OUTPUT SOMEFILE.pb.h SOMEFILE.pb.cc
>         COMMAND protoc SOMEFILE.proto --cpp_out=${CMAKE_CURRENT_BINARY_DIR}
>         DEPENDS
>         SOMEFILE.proto
>         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
>
>
>
> > I want to include SOMEFILE.pb.h in my source files and
> > I want them to be found.
> > I want to compile and link SOMEFILE.pb.cc automatically
>
> Then those file are compiled in a LIBRARY or EXECUTABLE
> ADD_LIBRARY(mylib
>                        SOMEFILE.pb.h SOMEFILE.pb.cc)
>
> then do not forget to tell CMake that those files are to be generated:
> set_source_files_properties(SOMEFILE.pb.h SOMEFILE.pb.cc
>                                         PROPERTIES
>                                         GENERATED TRUE)
> >
> > what is the easiest set of rules that I can use to extend cmake to do
> this?
>

Thanks for the rules!  I'll fall back on these if I can't get the module to
work.  The module is a bit nice of a solution.

>
>
>
> --
> Erk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080918/b8072695/attachment-0001.htm>


More information about the CMake mailing list