0
我有一个头文件是在构建时在编译任务依赖的任务中生成的,问题在于编译任务在增量编译中更改头文件时无法识别。所以即使任务运行,它也不会编译源文件。如何获得gradle incremental本机C++编译来处理生成的头文件?
我本来希望生成的头文件应该显示为“发现的包含”,并导致源文件被重建,但并非如此。
下面是我想到的最好的,但它不起作用。
apply plugin: 'cpp'
model {
binaries {
all {
cppCompiler.args "-I$buildDir/gen"
}
}
components {
test(NativeExecutableSpec) {
sources {
cpp {
source {
srcDir "."
include "*.cpp"
}
}
}
}
}
}
task generateHeader(type: Copy) {
into "$buildDir/gen"
from(rootProject.file('template.h')) {
rename(/template/, 'generated')
expand([text: 'foo'])
}
}
tasks.all { task ->
def match = task.name =~ /^compile.*Cpp$/
if (match) {
task.dependsOn generateHeader
task.inputs.files project.fileTree(dir: "$buildDir/gen").matching {
include '*.h'
}
}
}
示例项目:https://github.com/thejk/gradle-incremental-cpp-generated-header