Reuse object files

Hi,

I inherited a fairly large single source directory (all files are in src/), and the Makefile builds a lot of executables. Building all these executables doesn’t take that long because many of the object files created as shared across the build targets.

I’m porting the build system from Make to Gradle, and I am using a project per executable where each project’s sources are listed explicitly, not globbed due to the nature of the source directory. This works, but Gradle recompiles the same set of files over and over again. Is there anyway to speed up the build with this type of a source directory structure (or lack thereof)?

I can probably move the most used files into another project and have the executables depend on that project, but I wasn’t sure if Gradle has something special for this type of situation or if this is starting to bark up Gradle’s ideas for a native caching mechanism.

Thanks

I have a similar setup and it works fine, i.e. Gradle doesn’t recompile when it doesn’t need to. There must be something else in your build script which triggers that behavior.

Ah, I missed that part, sorry. You should probably turn the shared files into a static library if you don’t want Gradle to re-compile them for every single executable.

I think I’m going to try that. Also, is it possible to set the cppCompiler to output object files to a custom directory? My thinking there is to have all these NativeExecutableSpec binaries write their object files to a common directory and Gradle will see these with subsequent builds and avoid rebuilding any source file that already has an object file in that directory (not sure what is how it works for Gradle). Any thoughts on this?

1 Like