Could you tell what version of Gradle are you using? It appears that C/C++ support undergoes a major rewrite, so I’m preferring to be on the bleeding edge and using 1.9 nightly builds now. I’ve tried to create the following directory structure to resemble what you’re using:
And changed your ‘build.gradle’ file in the following way:
apply plugin: 'cpp'
Note that element ‘c’ contains element ‘source’ nested in it; it can also contain ‘exportedHeaders’ at the same level where you specify headers exported by the library. Also, ‘include’ specifies the mask of source files to include while ‘srcDirs’ points to set of source directories to look at. I think that if you won’t specify ‘srcDirs’ here and leave mask as “lib/.c", then Gradle will look for files matching "lib/.c” in default source directory for component, that being “src/lib/c”; in other words, your source would have to be placed at src/lib/c/lib — probably not what you wanted.
So, with directory structure and ‘build.gradle’ as above, ‘gradle udunits2StaticLibrary --info’ yields following when compilation is run:
Executing task ':compileUdunits2StaticLibraryLibC' (up-to-date check took 0.024 secs) due to:
Output file /home/ulenspiegel/24/build/objectFiles/udunits2StaticLibrary/libC has changed.
Output file /home/ulenspiegel/24/build/objectFiles/udunits2StaticLibrary/libC/source1.o has been removed.
Starting process 'command '/usr/bin/gcc''. Working directory: /home/ulenspiegel/24/build/objectFiles/udunits2StaticLibrary/libC Command: /usr/bin/gcc -x c -c @/home/ulenspiegel/24/build/tmp/compileUdunits2StaticLibraryLibC/compiler-options.txt
In my case it appears that gcc is started to compile ‘source1.c’. At that, ‘source2.cc’ is not included in library at all because of include mask.