Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here are some steps you can take to avoid unnecessary recompilation of Protobuf-generated files with CMake:

  1. Set up dependencies: Make sure that your protobuf-generated files depend on the .proto files and any other files that are inputs to the code generation process. This can be achieved by using CMake's add_dependencies function.

  2. Preserve file timestamps: CMake can modify the file timestamps of the generated files during the build process, which can lead to unnecessary recompilation. To avoid this, you can set the FILENAMECOMPUTE parameter of the configurefile function to "ALL".

  3. Use targetsources: Instead of adding the generated files directly to a target using the addexecutable or addlibrary functions, use the targetsources function. This function allows you to specify a list of source files that belong to a target, without actually compiling them.

  4. Use out-of-source builds: When building your project, try to use an out-of-source build directory. This will ensure that the generated files are placed in a separate directory from the source files, which can help avoid unnecessary recompilation.

  5. Use a custom command: If none of the above steps work, you can use a custom command to generate the protobuf-generated files. This command can be triggered manually or as part of the build process using the addcustomcommand function.