Native: How to link object files twice, but compile only once?

Dear community,

I’m currently trying to build a legacy native code base (that I can not modify) with gradle. Unfortunately, it contains cyclic dependencies between shared libraries.

In the current, make based build, this has been solved (or cirumvented) with the folowing approach:

  1. compile all source files to object files 2. link the output of step 1 into a so-called stub shared library, that does not have any dependencies at all 3. link the output of step 1 into the real shared library, use the outputs of step 2 as dependencies

Now I am trying to implement something similar (or better) with gradle. However, the closest I could get so far is this:

apply plugin: 'cpp'
  libraries {
 one {}
 oneStub {}
  sources.oneStub.cpp.source {
 srcDir "src/one/cpp"

But this unnecessarily recompiles all source files.

Is there a way to omit compiling everything twice and tell the “oneStub” link task to just reuse the object files from the “one” link task?

Thank you very much, Daniel

PS: It might be related to this question: