Brian Silverman | f7bd1c2 | 2015-12-24 16:07:11 -0800 | [diff] [blame^] | 1 | model { |
| 2 | toolChains { |
| 3 | gcc(Gcc) { |
| 4 | target('x86') { |
| 5 | cppCompiler.withArguments { args -> |
| 6 | args << '-std=c++11' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic' |
| 7 | args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic' |
| 8 | //TODO: When the compiler allows us to actually call deprecated functions from within |
| 9 | // deprecated function, remove this line (this will cause calling deprecated functions |
| 10 | // to be treated as a warning rather than an error). |
| 11 | args << '-Wno-error=deprecated-declarations' |
| 12 | args << '-m32' |
| 13 | } |
| 14 | linker.withArguments { args -> |
| 15 | args << '-rdynamic' |
| 16 | args << '-m32' |
| 17 | } |
| 18 | } |
| 19 | target('x64') { |
| 20 | cppCompiler.withArguments { args -> |
| 21 | args << '-std=c++11' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic' |
| 22 | args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic' |
| 23 | //TODO: When the compiler allows us to actually call deprecated functions from within |
| 24 | // deprecated function, remove this line (this will cause calling deprecated functions |
| 25 | // to be treated as a warning rather than an error). |
| 26 | args << '-Wno-error=deprecated-declarations' |
| 27 | } |
| 28 | linker.withArguments { args -> |
| 29 | args << '-rdynamic' |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | ext.setupReleaseDefines = { cppCompiler, linker -> |
| 37 | cppCompiler.args '-O2', '-g' |
| 38 | } |
| 39 | |
| 40 | ext.setupDebugDefines = { cppCompiler, linker -> |
| 41 | cppCompiler.args '-g', '-O0' |
| 42 | } |
| 43 | |
| 44 | ext.releaseSetup = { releaseTasks -> |
| 45 | binaries.withType(SharedLibraryBinarySpec) { binary -> |
| 46 | if (!project.hasProperty('debug')) { |
| 47 | def library = binary.sharedLibraryFile.absolutePath |
| 48 | def debugLibrary = binary.sharedLibraryFile.absolutePath + ".debug" |
| 49 | if (project.tasks.findByName("firstObjcopy${binary.name}") == null) { |
| 50 | def firstObjcopy = project.tasks.create("firstObjcopy${binary.name}", Exec) { task -> |
| 51 | task.commandLine 'objcopy', '--only-keep-debug', library, debugLibrary |
| 52 | } |
| 53 | def strip = project.tasks.create("strip${binary.name}", Exec) { task -> |
| 54 | task.commandLine 'strip', '-g', library |
| 55 | } |
| 56 | def secondObjcopy = project.tasks.create("secondObjcopy${binary.name}", Exec) { task -> |
| 57 | task.commandLine 'objcopy', "--add-gnu-debuglink=$debugLibrary", library |
| 58 | } |
| 59 | secondObjcopy.dependsOn strip |
| 60 | strip.dependsOn firstObjcopy |
| 61 | binary.tasks.whenObjectAdded { task -> |
| 62 | if (task.name.contains('link')) { |
| 63 | firstObjcopy.dependsOn task |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | releaseTasks.each { it.dependsOn project.tasks.getByName("secondObjcopy${binary.name}") } |
| 68 | } |
| 69 | } |
| 70 | } |