model { toolChains { clang(Clang) { target('x86') { cppCompiler.withArguments { args -> args << '-std=c++11' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic-errors' args << '-fPIC' << '-m32' args << '-Wno-unused-parameter' << '-Wno-missing-field-initializers' << '-Wno-unused-private-field' } linker.withArguments { args -> args << '-m32' } } target('x64') { cppCompiler.withArguments { args -> args << '-std=c++11' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic-errors' args << '-fPIC' args << '-Wno-missing-field-initializers' << '-Wno-unused-private-field' << '-Wno-unused-parameter' } } } } } ext.setupReleaseDefines = { cppCompiler, linker -> cppCompiler.args '-O2' } ext.setupDebugDefines = { cppCompiler, linker -> cppCompiler.args '-g', '-O0' } // Used only on Windows. ext.setupDef = { linker, deffile -> } ext.debugStripSetup = { if (!project.hasProperty('debug')) { project.tasks.whenObjectAdded { task -> if (task.name.contains('link') && task.name.contains('SharedLibrary')) { def library = task.outputFile.absolutePath task.doLast { exec { commandLine "dsymutil", library } exec { commandLine "strip", '-S', library } } } } } } ext.checkNativeSymbols = { getSymbolFunc -> project.tasks.whenObjectAdded { task -> if (task.name.contains('link') && task.name.contains('SharedLibrary')) { def library = task.outputFile.absolutePath task.doLast { def nmOutput = new ByteArrayOutputStream() exec { commandLine "nm", library standardOutput nmOutput } // Remove '\r' so we can check for full string contents String nmSymbols = nmOutput.toString().replace('\r', '') def symbolList = getSymbolFunc() symbolList.each { //Add \n so we can check for the exact symbol def found = nmSymbols.contains(it + '\n') if (!found) { throw new GradleException("Found a definition that does not have a matching symbol ${it}") } } } } } }