Find JVM shared library better across versions and operating systems
We now use "-rpath" on both Linux and macOS. This linker flag sets the ELF RPATH on Linux, and the "@rpath" attribute on macOS, but effectively it's doing the same thing, and that same thing is exactly what we want. I think. On Linux, we also now look for the JVM shared library in three different places. The library has moved between Java 8 and 9, and even on Java 9 it goes in a different place on Fedora 28 versus Ubuntu 16.04.
This commit is contained in:
parent
24151e7422
commit
fbac524a02
|
@ -42,11 +42,9 @@ model {
|
||||||
switch (targetPlatform.operatingSystem.name) {
|
switch (targetPlatform.operatingSystem.name) {
|
||||||
case 'linux':
|
case 'linux':
|
||||||
headers.srcDirs "$jniIncludeDir/linux"
|
headers.srcDirs "$jniIncludeDir/linux"
|
||||||
switch (targetPlatform.architecture.name) {
|
def subdirs = ['jre/lib/amd64/server', 'lib/amd64/server', 'lib/server']
|
||||||
case 'x86-64':
|
def candidates = subdirs.collect { file("$currentJavaHome/$it/libjvm.so") }
|
||||||
sharedLibraryLinkFile = file("$currentJavaHome/jre/lib/amd64/server/libjvm.so")
|
sharedLibraryLinkFile = candidates.find { it.exists() }
|
||||||
break
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
case 'osx':
|
case 'osx':
|
||||||
headers.srcDirs "$jniIncludeDir/darwin"
|
headers.srcDirs "$jniIncludeDir/darwin"
|
||||||
|
@ -79,17 +77,11 @@ model {
|
||||||
buildable = false
|
buildable = false
|
||||||
}
|
}
|
||||||
withType(SharedLibraryBinarySpec) {
|
withType(SharedLibraryBinarySpec) {
|
||||||
switch ("$targetPlatform.operatingSystem.name/$targetPlatform.architecture.name") {
|
def libDir = $.repositories['libs'].resolveLibrary('jdk')
|
||||||
case 'linux/x86-64':
|
.binaries.withType(SharedLibraryBinary)
|
||||||
$
|
.find { it.targetPlatform.name == targetPlatform.name }
|
||||||
.repositories['libs']
|
.sharedLibraryLinkFile.parent
|
||||||
.resolveLibrary('jdk')
|
linker.args "-Wl,-rpath,$libDir"
|
||||||
.binaries
|
|
||||||
.withType(SharedLibraryBinary)
|
|
||||||
.findResults { it.sharedLibraryLinkFile }
|
|
||||||
*.parentFile
|
|
||||||
.each { linker.args "-Wl,-rpath=$it" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue