241 lines
7.3 KiB
Groovy
Raw Normal View History

2014-03-21 02:32:11 +01:00
apply plugin: 'cpp'
2016-04-30 17:26:55 -04:00
import java.nio.file.Paths
2014-03-21 02:32:11 +01:00
2016-04-30 17:26:55 -04:00
String bulletSrcPath = bulletFolder + '/src'
2014-03-21 02:32:11 +01:00
2016-04-30 17:39:04 -04:00
if (!hasProperty('mainClass')) {
ext.mainClass = ''
}
2014-03-21 02:32:11 +01:00
dependencies {
compile project(':jme3-bullet')
}
clean { dependsOn 'cleanHeaders', 'cleanUnzipped' }
// clean up auto-generated C++ headers
task cleanHeaders(type: Delete) {
delete fileTree(dir: 'src/native/cpp', include: 'com_jme3_bullet_*.h')
}
// clean up unzipped files
task cleanUnzipped(type: Delete) {
delete bulletFolder
}
// clean up the downloaded archive
task cleanZipFile(type: Delete) {
delete bulletZipFile
}
2014-03-21 02:32:11 +01:00
2016-04-30 17:26:55 -04:00
model {
components {
bulletjme(NativeLibrarySpec) {
targetPlatform 'Windows64'
targetPlatform 'Windows32'
targetPlatform 'Mac64'
targetPlatform 'Mac32'
targetPlatform 'Linux64'
targetPlatform 'Linux32'
sources {
cpp {
source {
srcDir 'src/native/cpp'
srcDir bulletSrcPath
exclude 'Bullet3Collision/**'
exclude 'Bullet3Dynamics/**'
exclude 'Bullet3Geometry/**'
2016-07-13 17:16:28 +02:00
exclude 'Bullet3OpenCL/**'
exclude 'Bullet3Serialize/**'
2016-04-30 17:26:55 -04:00
include '**/*.cpp'
}
exportedHeaders {
srcDir 'src/native/cpp'
srcDir bulletSrcPath
exclude 'Bullet3Collision/**'
exclude 'Bullet3Dynamics/**'
exclude 'Bullet3Geometry/**'
2016-07-13 17:16:28 +02:00
exclude 'Bullet3OpenCL/**'
exclude 'Bullet3Serialize/**'
2016-04-30 17:26:55 -04:00
include '**/*.h'
}
}
}
}
2014-12-01 23:41:13 -05:00
}
2016-11-25 22:26:38 -05:00
2016-04-30 17:26:55 -04:00
binaries {
withType(SharedLibraryBinarySpec) {
def projectPath = project.projectDir.absolutePath
def javaHome = org.gradle.internal.jvm.Jvm.current().javaHome
def os = targetPlatform.operatingSystem.name
def arch = targetPlatform.architecture.name
def fileName = sharedLibraryFile.name
2016-11-25 22:26:38 -05:00
2016-04-30 17:26:55 -04:00
// Gradle decided to change underscores to dashes - fix that.
arch = arch.replaceAll('-', '_')
2016-11-25 22:26:38 -05:00
2016-04-30 17:26:55 -04:00
// For all binaries that can't be built on the current system
if (buildNativeProjects != "true") {
buildable = false
}
if (!buildable) {
if (sharedLibraryFile.exists()) {
// Add binary to jar file if the binary exists in the build folder already,
// e.g. when the build of jme3-bullet-native has been run on a virtual box
// and the project hasn't been cleaned yet.
jar.into("native/${os}/${arch}") {
from sharedLibraryFile
}
} else {
// Get from libs folder if no fresh build is available in the build folder and add to jar file
def precompiledFile = Paths.get(projectPath, 'libs', 'native', os, arch, fileName).toFile()
if (precompiledFile.exists()) {
jar.into("native/${os}/${arch}") {
from precompiledFile
}
}
}
return
}
cppCompiler.define('BT_NO_PROFILE')
if (toolChain in VisualCpp) {
2016-04-30 17:26:55 -04:00
cppCompiler.args "/I$javaHome\\include"
} else{
2016-04-30 17:26:55 -04:00
cppCompiler.args '-I', "$javaHome/include"
}
2016-04-30 17:26:55 -04:00
if (os == "osx") {
cppCompiler.args '-I', "$javaHome/include/darwin"
cppCompiler.args "-Ofast"
cppCompiler.args "-U_FORTIFY_SOURCE"
2016-04-30 17:26:55 -04:00
} else if (os == "linux") {
2016-04-22 00:23:50 -04:00
cppCompiler.args "-fvisibility=hidden"
2016-04-30 17:26:55 -04:00
cppCompiler.args '-I', "$javaHome/include/linux"
2014-12-01 23:41:13 -05:00
cppCompiler.args "-fPIC"
cppCompiler.args "-Ofast"
cppCompiler.args "-U_FORTIFY_SOURCE"
2014-12-01 23:41:13 -05:00
cppCompiler.args "-fpermissive"
2016-04-22 00:23:50 -04:00
linker.args "-fvisibility=hidden"
2016-04-30 17:26:55 -04:00
} else if (os == "windows") {
if (toolChain in Gcc) {
if (toolChain.name.startsWith('mingw')) {
2016-04-30 17:26:55 -04:00
cppCompiler.args '-I', "$projectDir/src/native/cpp/fake_win32"
} else {
2016-04-30 17:26:55 -04:00
cppCompiler.args '-I', "$javaHome/include/win32"
}
cppCompiler.args "-fpermissive"
cppCompiler.args "-static"
cppCompiler.args "-Ofast"
cppCompiler.args "-U_FORTIFY_SOURCE"
linker.args "-static"
2016-04-22 00:23:50 -04:00
linker.args "-Wl,--exclude-all-symbols"
}
else if (toolChain in VisualCpp) {
2016-04-30 17:26:55 -04:00
cppCompiler.args "/I$javaHome\\include\\win32"
}
cppCompiler.define('WIN32')
2014-12-01 23:41:13 -05:00
}
2016-11-25 22:26:38 -05:00
tasks.all {
dependsOn unzipBulletIfNeeded
dependsOn ':jme3-bullet:generateNativeHeaders'
}
2014-12-01 23:41:13 -05:00
2016-04-30 17:26:55 -04:00
// Add output to jar file
jar.into("native/${os}/${arch}") {
from sharedLibraryFile
2014-03-21 02:32:11 +01:00
}
2016-11-25 22:26:38 -05:00
2016-04-30 17:26:55 -04:00
// Add depend on build
jar.dependsOn tasks
// Add output to libs folder
task "copyBinaryToLibs${targetPlatform.name}"(type: Copy, dependsOn: tasks) {
from sharedLibraryFile
into "libs/native/${os}/${arch}"
2014-03-21 02:32:11 +01:00
}
2016-04-30 17:26:55 -04:00
// Add depend on copy
jar.dependsOn("copyBinaryToLibs${targetPlatform.name}")
}
withType(StaticLibraryBinarySpec) {
buildable = false
2014-03-21 02:32:11 +01:00
}
}
2016-04-30 17:26:55 -04:00
platforms {
Windows32 {
architecture "x86"
operatingSystem "windows"
}
Windows64 {
architecture "x86_64"
operatingSystem "windows"
}
Mac32 {
architecture "x86"
operatingSystem "osx"
}
Mac64 {
architecture "x86_64"
operatingSystem "osx"
}
Linux32 {
architecture "x86"
operatingSystem "linux"
}
Linux64 {
architecture "x86_64"
operatingSystem "linux"
2014-03-21 02:32:11 +01:00
}
}
2016-04-30 17:26:55 -04:00
}
2016-04-30 17:26:55 -04:00
// Java source sets for IDE access and source jar bundling / mavenization
sourceSets {
main {
java {
srcDir 'src/native/cpp'
}
2014-03-21 02:32:11 +01:00
}
}
task downloadBullet(type: MyDownload) {
sourceUrl = bulletUrl
target = file(bulletZipFile)
}
task unzipBullet(type: Copy) {
2016-04-30 17:26:55 -04:00
from zipTree(bulletZipFile)
into file('.')
2014-03-21 02:32:11 +01:00
}
2016-04-30 17:26:55 -04:00
2014-03-21 02:32:11 +01:00
unzipBullet.dependsOn {
2016-04-30 17:26:55 -04:00
if (!file(bulletZipFile).exists()) {
2014-03-21 02:32:11 +01:00
downloadBullet
}
}
2016-11-24 15:31:15 -05:00
task unzipBulletIfNeeded {
2015-01-26 18:44:29 +01:00
}
2016-04-30 17:26:55 -04:00
unzipBulletIfNeeded.dependsOn {
if (buildNativeProjects == "true" && !file(bulletFolder).isDirectory()) {
unzipBullet
}
2014-03-21 02:32:11 +01:00
}
// Helper class to wrap ant download task
2014-03-21 02:32:11 +01:00
class MyDownload extends DefaultTask {
@Input
String sourceUrl
@OutputFile
File target
@TaskAction
void download() {
2016-04-30 17:26:55 -04:00
ant.get(src: sourceUrl, dest: target)
2014-03-21 02:32:11 +01:00
}
}