複数の C++ プロジェクトを含む大きなソース ツリーを構築する必要があります。共通のインクルード ディレクトリやコンパイラ/リンカー フラグなどのビルド規則を定義するトップ レベルのビルド ファイルが必要で、サブプロジェクト レベルで規則をオーバーライドまたは追加できるようにしたいと考えています。
次のようにコンパイラ/リンカーフラグに追加できました。
最上位ビルド ファイル:
subprojects {
apply plugin: 'cpp'
ext.commonCompilerArgs = [
'-Wall',
'-Werror',
'-pedantic-errors'
]
components {
binary(NativeLibrarySpec) {
sources {
cpp {
source {
srcDir 'src'
include '*.cpp'
}
exportedHeaders {
srcDir 'include'
include '*.h'
}
}
}
}
}
binaries.withType(NativeLibraryBinarySpec) {
// Compiler args
commonCompilerArgs.forEach { compilerArg ->
cppCompiler.args << compilerArg
}
}
サブプロジェクトのビルド ファイル:
def extraCompilerArgs = [
'--std=c++11'
]
binaries.all {
extraCompilerArgs.each { arg ->
cppCompiler.args << arg
}
}
ただし、同じ原則を適用して追加のインクルード ディレクトリを追加することはできません (コンパイラの引数に追加されます)。サブプロジェクトのビルドファイルでこれを試しました:
binaries.withType(NativeLibraryBinarySpec) { binary ->
binary.headerDirs.add('extra_include_dir')
}
ただし、余分なディレクトリは追加されません。ここで何が間違っていますか?