Gradle native pass to linker precompiled objects

I’m porting a Makefile project in Gradle. There are several cpp files that need to be passed to an Oracle precompiler, which outputs .o objects files. This .o files are in turn to be passed to the linker along with the other “regular” .o files produced by g++.
How to reproduce this in Gradle?

Please note: I succeded in generating cpp files, and compiling-linking them with other regular cpp files, using a CppSourceSet. Unfortunately, I didn’t find an equivalent “CppObjectSet”. The only idea that came in my mind is to create a static library with all these .o files, and put it inside the project dependencies.

Any better idea?

I had the same challenge with my build. I resolved it by defining a pre-defined library and adding a dependency on it on my component. I place it first so that it will added as the first library after the compiled object files (I found that gradle lists the libraries in the inputs in the order that they are defined).

repositories {
libs(PrebuiltLibraries) {

rwmys12 {
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("$LIB_HOME/lib/rw/rwmys12s.o")
}
}

}

in the component

   mys_exe (NativeExecutableSpec) {
        sources {
            cpp {
                lib library: 'rwmys12'
                lib library: 'json'
            }

        }

this caused the linker options.txt to look like:

-o
/home//workspace/src/mts/build/exe/mts/mts
/home//workspace/src/mts/build/objs/mys_exe/mysCpp/bvyeehr1ja14krnk6yy0q2qq8/mys.o
/home//workspace/lib/rw/rwmys12s.o
/home//workspace/lib/libjsoncpp.so

I tried to put it in the linker.args but that will place the .o file after the library list since gradle lists the linker arguments last.

Thanks Walter for providing your solution. It is the best one for the current state of the native support in Gradle regarding compilation only dependencies (aka object file dependencies).

I’m a bit late to the game but regarding an alternative, creating a static library with your object files should give your expected result in most cases.

I have opened an epic to capture the essential of this underlying work. Multiple issues will need to be addressed and will be part of that epic once we start working on improving this scenario.