[CMake] externalproject_add and generating sources

David Jobet david.jobet at free.fr
Thu Jan 26 04:23:08 EST 2017


Hello,

suppose I want to use protobuf and integrate it in my project with externalproject_add. (actually, I just have precompiled binaries and libs + header files, I don't have the full sources)
Once the project has been 'built' (actually, installed by a custom rpm-like tool to a shared path), I can use the protoc compiler to generate protobuf c++ files (.pb.h and .pb.cpp files) from a .proto description file.
I can add_dependencies so that the external project is built before projects depending on libprotobuf.a.

However, I don't know how to do the same thing with .pb.h and .pb.cpp files which use a .proto file and the protoc compiler.

make is fine with it, but ninja complains with an error like this :
ninja: error: '/path_to_external_projects/protobuf/2.6.0.4/bin/protoc', needed by 'some_project/SomeFile.pb.h', missing and no known rule to make it

how can I tell ninja that protoc is going to be provided by externalproject ?
If I use byproducts, ninja is happy, but "ninja clean" deletes /path_to_external_projects/protobuf/2.6.0.4/bin/protoc.
I don't want that to happen since /path_to_external_projects/protobuf/2.6.0.4/bin/protoc is shared with other users.

With regards

David


More information about the CMake mailing list