A Gradle plugin for seamlessly integrating with other build tools, including GNU make, CMake, qmake, and more.
A Gradle plugin for seamlessly integrating with other build tools, including GNU make, CMake, qmake, and more.
apply plugin: 'com.cisco.external-build'
import com.cisco.gradle.externalbuild.ExternalNativeLibrarySpec
import com.cisco.gradle.externalbuild.GnuMake
def getOutputDir = { file("${buildDir}/external-foo/${it.targetPlatform.name}") }
model {
components {
foo(ExternalNativeLibrarySpec) {
buildConfig(GnuMake) {
targets 'all', 'install'
lib project: ':bar', library: 'bar'
environment = [
'PATH': toolChainPath,
'OUTPUT_DIR': getOutputDir(it),
'EXTERNAL_LIBRARIES': requiredLibraries.join(' '),
'EXTERNAL_INCLUDES': requiredIncludes.join(' '),
]
}
buildOutput {
def outputDir = getOutputDir(it)
outputFile = file("${outputDir}/libs/libfoo.so")
exportedHeaders {
srcDir "${outputDir}/include"
}
}
}
}
}
See the examples
directory for additional examples.
This plugin includes 3 component types:
ExternalNativeExecutableSpec
, but the built binary will also be executed
as part of gradle check
.It includes 5 task types:
Define a component using one of the provided component types:
import com.cisco.gradle.externalbuild.ExternalNativeLibrarySpec
model {
components {
foo(ExternalNativeLibrarySpec) {
buildConfig {
...
}
buildOutput {
...
}
}
}
}
The components each have two methods to configure the external build. buildConfig
specifies the configuration for invoking the external build tool, and buildOutput
specifies the output files from the build to expose to Gradle.
void buildConfig(Closure action)
void buildConfig(Class<Task> taskType, Closure action)
void buildConfig(ExternalNativeComponentSpec component)
void buildConfig(ExternalNativeComponentSpec component, Closure action)
For each binary variant of the component, the plugin will generate a new task of the
type specified, and configure it using the given action. If no task type is given, the
default is OutputRedirectingExec
. If another component is given, this component will
inherit the task type and action from the given component. If a component and action are
given, both the original component's action and the new action will be used to configure
the task.
The delegate and first parameter given to the closure will be an instance of
BuildConfigContext
. This class exposes properties and methods to help configure the
build based on the binary variant (detailed below). In addition, it will delegate to the
Task being configured for any unknown properties or methods, meaning that you can invoke
any method or property exposed by your Task type as if it were present on
BuildConfigContext
.
void buildOutput(Closure action)
For each binary variant of the component, the plugin will retrieve the file specified by the closure to serve as the binary's output.
The delegate and first parameter given to the closure will be an instance of
BuildOutputContext
. This class exposes properties and methods to help Gradle find
the binary outputs of the external build (detailed below).
When a closure is provided to buildConfig
, it will receive an instance of
BuildConfigContext
as its delegate and first parameter.
Properties:
binary
.binary
, as well as the
current System PATH.Methods:
binary
, and optionally includes the current System PATH.binary.lib()
. Note that invocations of
this helper should always be placed before reading requiredLibraries
or requiredIncludes
.Any properties or methods of buildTask
may also be accessed directly (this object will delegate
to buildTask
for unknown properties and methods).
When a closure is provided to buildOutput
, it will receive an instance of
BuildOutputContext
as its delegate and first parameter.
Properties:
binary
.Methods:
exportedHeaders
construct on native source sets in Gradle.Author: Andrew Richardson ([email protected])
Created for Cisco and released under the terms of the Apache 2.0 License (contribution #135872681).