forked from gradle/native-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
executable file
·247 lines (223 loc) · 7.86 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
apply plugin: 'groovy'
apply plugin: 'cpp'
allprojects {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
repositories {
mavenCentral()
maven { url "http://repo.gradle.org/gradle/libs-releases-local" }
}
dependencies {
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}
group = 'net.rubygrapefruit'
version = '0.11'
if (!project.hasProperty('release')) {
version = "${version}-dev"
}
sourceCompatibility = 1.5
targetCompatibility = 1.5
tasks.withType(Upload) {
repositories {
mavenDeployer {
if (project.hasProperty('release')) {
repository(url: uri("https://gradle.artifactoryonline.com/gradle/libs-releases-local")) {
authentication(userName: artifactoryUserName, password: artifactoryPassword)
}
} else {
repository(url: uri("$rootProject.buildDir/repo"))
}
}
}
}
}
dependencies {
testCompile 'org.codehaus.groovy:groovy-all:2.4.1'
}
def nativeHeadersDir = file("$buildDir/nativeHeaders")
task nativeHeaders {
def outputFile = file("$nativeHeadersDir/native.h")
def classes = [
'net.rubygrapefruit.platform.internal.jni.NativeLibraryFunctions',
'net.rubygrapefruit.platform.internal.jni.PosixFileFunctions',
'net.rubygrapefruit.platform.internal.jni.PosixFileSystemFunctions',
'net.rubygrapefruit.platform.internal.jni.PosixProcessFunctions',
'net.rubygrapefruit.platform.internal.jni.PosixTerminalFunctions',
'net.rubygrapefruit.platform.internal.jni.TerminfoFunctions',
'net.rubygrapefruit.platform.internal.jni.WindowsConsoleFunctions',
'net.rubygrapefruit.platform.internal.jni.WindowsHandleFunctions',
'net.rubygrapefruit.platform.internal.jni.WindowsRegistryFunctions',
'net.rubygrapefruit.platform.internal.jni.WindowsFileFunctions',
'net.rubygrapefruit.platform.internal.jni.FileEventFunctions',
'net.rubygrapefruit.platform.internal.jni.PosixTypeFunctions'
]
inputs.files sourceSets.main.output
inputs.property('classes', classes)
outputs.file outputFile
doLast {
outputFile.parentFile.mkdirs()
exec {
executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
args '-o', outputFile
args '-classpath', sourceSets.main.output.classesDir
args classes
}
}
}
model {
platforms {
osx_i386 {
architecture "i386"
operatingSystem "osx"
}
osx_amd64 {
architecture "amd64"
operatingSystem "osx"
}
linux_i386 {
architecture "i386"
operatingSystem "linux"
}
linux_amd64 {
architecture "amd64"
operatingSystem "linux"
}
windows_i386 {
architecture "i386"
operatingSystem "windows"
}
windows_amd64 {
architecture "amd64"
operatingSystem "windows"
}
freebsd_i386 {
architecture "i386"
operatingSystem "freebsd"
}
freebsd_amd64 {
architecture "amd64"
operatingSystem "freebsd"
}
}
}
libraries {
nativePlatform {
baseName 'native-platform'
}
nativePlatformCurses {
baseName 'native-platform-curses'
targetPlatforms "osx_i386", "osx_amd64", "linux_i386", "linux_amd64", "freebsd_i386", "freebsd_amd64"
binaries.all {
linker.args "-lcurses"
}
}
all {
binaries.all {
if (targetPlatform.operatingSystem.macOsX) {
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/darwin"
cppCompiler.args '-mmacosx-version-min=10.4'
linker.args '-mmacosx-version-min=10.4'
} else if (targetPlatform.operatingSystem.linux) {
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"
} else if (targetPlatform.operatingSystem.windows) {
cppCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cppCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"
linker.args "Shlwapi.lib", "Advapi32.lib"
} else if (targetPlatform.operatingSystem.freeBSD) {
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/freebsd"
}
cppCompiler.args "-I${nativeHeadersDir}"
tasks.withType(CppCompile) { task ->
task.dependsOn nativeHeaders
}
}
}
}
sources {
nativePlatform {
cpp {
source.srcDirs = ['src/shared/cpp', 'src/main/cpp']
exportedHeaders.srcDirs = ['src/shared/headers']
}
}
nativePlatformCurses {
cpp {
source.srcDirs = ['src/shared/cpp', 'src/curses/cpp']
exportedHeaders.srcDirs = ['src/shared/headers']
}
}
}
configurations {
jni
}
def deployer = uploadJni.repositories.mavenDeployer
binaries.withType(SharedLibraryBinary) { binary ->
if (!buildable) {
return
}
def arch = System.properties['os.arch']
if (targetPlatform.operatingSystem.name in ['linux', 'freebsd'] && targetPlatform.architecture.name != arch) {
// Native plugins don't detect whether multilib support is available or not. Assume not for now
return
}
def variantName = "${targetPlatform.operatingSystem.name}-${targetPlatform.architecture.name}"
def taskName = "jar-${variantName}"
def nativeJar = project.tasks.findByName(taskName)
if (nativeJar == null) {
nativeJar = project.task(taskName, type: Jar) {
baseName = "native-platform-$variantName"
}
artifacts {
jni nativeJar
runtime nativeJar
}
def jniPom = deployer.addFilter(variantName) { artifact, file ->
return file == nativeJar.archivePath
}
jniPom.groupId = project.group
jniPom.artifactId = nativeJar.baseName
jniPom.version = project.version
jniPom.scopeMappings.mappings.clear()
}
def builderTask = binary.tasks.link
nativeJar.into("net/rubygrapefruit/platform/$variantName") { from builderTask.outputFile }
nativeJar.dependsOn builderTask
test.dependsOn nativeJar
}
javadoc {
exclude '**/internal/**'
}
task sourceZip(type: Zip) {
from sourceSets.main.allSource
classifier = 'sources'
extension = 'jar'
}
task javadocZip(type: Zip) {
from javadoc
classifier = 'javadoc'
extension = 'jar'
}
artifacts {
archives sourceZip
archives javadocZip
}
def mainPom = uploadArchives.repositories.mavenDeployer.pom
mainPom.groupId = project.group
mainPom.artifactId = jar.baseName
mainPom.version = project.version
mainPom.scopeMappings.mappings.clear()
mainPom.withXml { provider ->
def node = provider.asNode()
def deps = node.appendNode('dependencies')
['osx-i386', 'osx-amd64', 'linux-amd64', 'linux-i386',
'windows-amd64', 'windows-i386', 'freebsd-i386', 'freebsd-amd64'].each { platform ->
def dep = deps.appendNode('dependency')
dep.appendNode('groupId', project.group)
dep.appendNode('artifactId', "native-platform-${platform}")
dep.appendNode('version', project.version)
}
}