Gradle Native C ++ Assembly: How to Override Top-Level Properties in a Multiproject Assembly

I need to build a large source tree containing several C ++ projects. I would like to have a top-level assembly file that defines assembly conventions, such as shared included directories and compiler / linker flags, and then can override or add to conventions at the subproject level.

I managed to add compiler / linker flags as follows:

Top Level Build File:

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
          }
     }

Subproject assembly file:

def extraCompilerArgs = [
  '--std=c++11'
]

binaries.all {
  extraCompilerArgs.each { arg ->
    cppCompiler.args << arg
  }
}

However, I cannot apply the same principle to add additional include directories (to add to compiler arguments). I tried this in the subproject assembly file:

binaries.withType(NativeLibraryBinarySpec) { binary ->
  binary.headerDirs.add('extra_include_dir')
} 

but it does not add an additional directory. What am I doing wrong here?

+4

Source: https://habr.com/ru/post/1621838/


All Articles