I am new to Gradle and Groovy and I have a question regarding the cpp plugin.
I have a C++ artifact in a Nexus repository which is a zip file including a lib + some header files (lets call this libA). I have now a Gradle native project defined which has now a dependency to libA. I have read through the documentation and it seems that dependency resolution is not supported yet in Gradle 2.1 for native projects. I have found this post here: http://forums.gradle.org/gradle/topics/right_way_to_copy_contents_from_dependency_archives which talks about downloading a zip package and extracting it.
Unfortunatetly I am struggling with getting this to work with a cpp project. Is there somewhere a full working example that downloads a zip file, unpacks it and is used by a cpp project by defining a dependency (probably via PrebuiltLibraries).
I have added a dependsOn dependency to extractTinyXml in the afterEvaluate section and added some logs into the extractTinyXml task. I see the logs added in the task but it does not unzip the package.
Here’s an end-to-end example of doing this with a C executable and a prebuilt library. This should be directly portable to a C++ build (i.e. CppCompile instead of CCompile and cpp source set instead of c). I used a file-based dependency, but this could just as easily be a dependency in a repository somewhere.
apply plugin: 'c'
// Define a configuration to represent the zipped libraries
configurations {
cunit
}
dependencies {
cunit files("libs/cunit.zip")
}
// Task to explode the zipped library into a temporary dir
task extractCunitZip(type: Copy) {
ext.libsdir = "${buildDir}/libs"
from { configurations.cunit.collect { zipTree(it) } }
into libsdir
}
model {
repositories {
// Set up a prebuilt library to represent the unzipped archive
lib(PrebuiltLibraries) {
cunit {
headers.srcDir "${extractCunitZip.libsdir}/cunit/2.1-2/include"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("${extractCunitZip.libsdir}/cunit/2.1-2/lib/osx/libcunit.a")
}
}
}
}
}
executables {
cuniter {
binaries.all {
// Inject the compile task dependency on the extraction task
tasks.withType(CCompile) {
dependsOn extractCunitZip
}
}
}
}
sources {
cuniter {
c {
// Link to the prebuilt library
lib library: 'cunit', linkage: 'static'
}
}
}