forked from sailing-pmls/bosen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
153 lines (139 loc) · 4.15 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
apply plugin: "cpp"
apply plugin: "java"
version = 0.21
model {
toolChains {
clang(Clang)
gcc(Gcc)
}
platforms {
linux_amd64 {
architecture "amd64"
operatingSystem "linux"
}
}
}
if(!buildDir.exists()) {
buildDir.mkdir();
}
def jniDir = file("src/main/java/com/petuum/petuum_ps")
def package_name = "com.petuum.petuum_ps"
task generateNativeHeaders {
def interfaceTree = fileTree(dir: "interface", include: "petuum.i")
def nativeHeaderDir = file("src/petuum_ps/wrapper")
if(! buildDir.exists()) {
buildDir.mkdir()
}
if(! nativeHeaderDir.exists()) {
nativeHeaderDir.mkdir()
}
if (! jniDir.exists()) {
jniDir.mkdir()
}
doLast {
interfaceTree.each({file ->
def wrapper_name = file.getName().replace('.i', '_wrapper.cxx')
exec {
executable "swig"
args '-java'
args '-c++'
args '-package', package_name
args "-I$projectDir/src/petuum_ps"
args '-outdir', jniDir
args '-o', "$nativeHeaderDir/"+wrapper_name
args '-l', file
}
})
}
}
//download third_party libraries
task compileThirdPartyLibaries(type: Exec) {
workingDir projectDir
executable "make"
args "path"
args "third_party_core"
}
//Build Petuum Library
libraries {
petuum_ps {
binaries.all {
if(targetPlatform.operatingSystem.linux) {
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"
}
if(targetPlatform.operatingSystem.macOsX) {
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/darwin"
}
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cppCompiler.args '-I', "$projectDir/src"
cppCompiler.args '-I', "$projectDir/third_party/include"
cppCompiler.args '-fPIC'
cppCompiler.args '-g'
cppCompiler.args '-O3'
cppCompiler.args '-std=c++11'
cppCompiler.args '-Wall'
cppCompiler.args '-Wno-sign-compare'
cppCompiler.args '-fno-builtin-malloc'
cppCompiler.args '-fno-builtin-calloc'
cppCompiler.args '-fno-builtin-realloc'
cppCompiler.args '-fno-builtin-free'
cppCompiler.args '-fno-omit-frame-pointer'
linker.args '-L', "$projectDir/third_party/lib"
linker.args '-pthread'
linker.args '-lnsl'
linker.args '-luuid'
linker.args '-lrt'
linker.args '-lglog'
linker.args '-lzmq'
linker.args '-lboost_thread'
linker.args '-lboost_system'
linker.args '-lgflags'
linker.args '-ltcmalloc'
linker.args '-lconfig++'
}
}
}
sources {
petuum_ps {
cpp {
file("src/petuum_ps").listFiles().each{file ->
if(file.isDirectory()) {
source.srcDirs file
}
}
source.exclude "*.hpp"
source.exclude "*.o"
exportedHeaders.srcDirs "src"
}
}
}
task buildNativeLibrary {
//dependsOn generateNativeHeaders
dependsOn compileThirdPartyLibaries
outputFile = []
binaries.withType(SharedLibraryBinary) {binary ->
if(!buildable) {
return
}
buildNativeLibrary.dependsOn binary
buildNativeLibrary.outputFile.add(binary.tasks.builder.outputFile)
}
}
task copyLibrary(dependsOn: buildNativeLibrary, type: Copy) {
from buildNativeLibrary.outputFile
into file("$buildDir/libs")
}
build.dependsOn buildNativeLibrary
build.dependsOn copyLibrary
//java part
repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
mavenCentral()
}
dependencies {
compile fileTree (dir: 'jar', includes: ['*.jar'])
compile 'org.apache.commons:commons-math3:3.3'
}
jar.dependsOn buildNativeLibrary
jar.baseName = "petuum"