Skip to content

Instantly share code, notes, and snippets.

@zh-se
Created July 17, 2014 13:41
Show Gist options
  • Save zh-se/84c295f16bac00bfdf35 to your computer and use it in GitHub Desktop.
Save zh-se/84c295f16bac00bfdf35 to your computer and use it in GitHub Desktop.
You can add support for Google Protocol Buffers to an Xcode 5 project using Cocoapods by adding the following line to your Podfile.
pod 'GoogleProtobuf', '~> 2.5.0'
This will place the C++ version of the protobuf code into a Pod for your project. It will also add the protoc compiler in the folder Pods/GoogleProtobuf/bin/protoc within your project.
You can create a custom build rule in your project that automatically converts the .proto files into .ph.{h,cc} files. Here is how I did that:
Setup a build rule to "Process Source files with names matching: *.proto Using Custom Script". The script should include the following:
cd ${INPUT_FILE_DIR}
${SRCROOT}/Pods/GoogleProtobuf/bin/protoc --proto_path=${INPUT_FILE_DIR} ${INPUT_FILE_PATH} --cpp_out=${INPUT_FILE_DIR}/cpp
Set the output files to include the following:
$(INPUT_FILE_DIR)/cpp/$(INPUT_FILE_BASE).pb.h
$(INPUT_FILE_DIR)/cpp/$(INPUT_FILE_BASE).pb.cc
Any .proto files you include in your project will now automatically be converted to C++ and then compiled as part of your build.
Also, when i did #import xyz.pb.h the project wasn't building. When I renamed my .m file to .mm i was able to build. This point is mentioned in the tutorial very subtly :P.
Basically, any .m file which is importing a any .pb.h file, should be renamed with extension .mm
links:
http://stackoverflow.com/questions/19444376/compile-protobuf-with-xcode-5/19582682#19582682
http://stackoverflow.com/questions/10277576/google-protocol-buffers-on-ios/15246414#15246414
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment