Compute a library path from the native software model

Previously we were repeating the library path twice, but that's not
good for long-term maintenance.  That being said, extracting this
information from the depths of the native software model seems *far*
more complex than it should be.  I had hoped for something nicer in
response to
<https://discuss.gradle.org/t/compute-wl-rpath-flag-suitable-for-native-shared-library/25278>,
but so far there's nothing.
This commit is contained in:
Ben Liblit 2018-01-21 16:18:06 -06:00
parent a3f524f7a9
commit 9df594189d
1 changed files with 16 additions and 5 deletions

View File

@ -69,11 +69,22 @@ model {
exportedHeaders.srcDirs = ["$cSourceDir/include"]
lib library: 'jdk'
}
binaries.all {
switch ("$targetPlatform.operatingSystem.name/$targetPlatform.architecture.name") {
case 'linux/x86-64':
// TODO: compute path on following line from 'jdk' library properties somehow
linker.args '-Wl,-rpath', "$currentJavaHome/jre/lib/amd64/server"
binaries {
withType(StaticLibraryBinarySpec) {
buildable = false
}
withType(SharedLibraryBinarySpec) {
switch ("$targetPlatform.operatingSystem.name/$targetPlatform.architecture.name") {
case 'linux/x86-64':
$
.repositories['libs']
.resolveLibrary('jdk')
.binaries
.withType(SharedLibraryBinary)
.findResults { it.sharedLibraryLinkFile }
*.parentFile
.each { linker.args "-Wl,-rpath=$it" }
}
}
}
}