model { toolChains { gcc(Gcc) { target('x86') { cppCompiler.withArguments { args -> args << '-std=c++11' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic' args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic' //TODO: When the compiler allows us to actually call deprecated functions from within // deprecated function, remove this line (this will cause calling deprecated functions // to be treated as a warning rather than an error). args << '-Wno-error=deprecated-declarations' << '-pthread' args << '-m32' } linker.withArguments { args -> args << '-rdynamic' << '-pthread' args << '-m32' } } target('x64') { cppCompiler.withArguments { args -> args << '-std=c++11' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic' args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic' //TODO: When the compiler allows us to actually call deprecated functions from within // deprecated function, remove this line (this will cause calling deprecated functions // to be treated as a warning rather than an error). args << '-Wno-error=deprecated-declarations' << '-pthread' } linker.withArguments { args -> args << '-rdynamic' << '-pthread' } } } } } ext.setupReleaseDefines = { cppCompiler, linker -> cppCompiler.args '-O2', '-g' } 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 def debugLibrary = task.outputFile.absolutePath + ".debug" task.doLast { exec { commandLine "objcopy", '--only-keep-debug', library, debugLibrary } exec { commandLine "strip", '-g', library } exec { commandLine "objcopy", "--add-gnu-debuglink=$debugLibrary", 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}") } } } } } }