-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlibssh.gradle
More file actions
144 lines (121 loc) · 4.39 KB
/
libssh.gradle
File metadata and controls
144 lines (121 loc) · 4.39 KB
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
task prepareLibSshirectories {
mustRunAfter clean
doLast {
mkdir project.file("$project.libssh_build/release")
mkdir project.file("$project.libssh_build/debug")
}
}
// Runs the configure step.
def types = ["Debug", "Release"]
types.each { type ->
project.tasks.create("configureLibSSH$type", Exec) {
// Make sure that OpenSSL is built and installed.
dependsOn "openSSL"
// Create an alias to the build directory.
def build_dir = file("$libssh_build/${type.toLowerCase()}")
// LibSSH is configured with CMake. We want to build static libraries. Also set
// the archive to be stored in build/lib instead of build/src (the default).
executable "cmake"
args "$libssh_dir"
if (project.platform == "osx-universal") {
args "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64", "-DCMAKE_OSX_DEPLOYMENT_TARGET=\"11.0\""
environment "ARCHFLAGS", "-arch arm64 -arch x86_64"
} else if (project.platform == "linux-arm64") {
if (project.hasProperty('forcecrossbuild')) {
args "-DCMAKE_TOOLCHAIN_FILE=/usr/local/toolchain-config.cmake"
}
args "-DOPENSSL_CRYPTO_LIBRARY=${project.openssl_install}/lib/libcrypto.a"
args "-DOPENSSL_SSL_LIBRARY=${project.openssl_install}/lib/libssl.a"
args "-DOPENSSL_INCLUDE_DIR=${project.openssl_install}/include"
} else if (project.platform.contains("windows")) {
args "-DOPENSSL_ROOT_DIR=${project.openssl_install}"
}
args "-DBUILD_SHARED_LIBS=OFF", "-DWITH_ZLIB=OFF", "-DWITH_EXAMPLES=OFF",
"-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${build_dir}/lib", "-DCMAKE_BUILD_TYPE=$type"
workingDir build_dir
environment "OPENSSL_ROOT_DIR": "${project.openssl_install}"
def platformArg = "x64"
if (project.platform == "windows-arm64") {
platformArg = "arm64"
}
// Add the arch specifier for Windows.
if (project.platform.contains("windows")) {
args "-A"
args platformArg
}
dependsOn prepareLibSshirectories
}
}
// Runs the build step.
types.each { type ->
project.tasks.create("buildLibSSH$type", Exec) {
// Make sure that we are configured.
dependsOn "configureLibSSH$type"
// Create an alias to the build directory.
def build_dir = file("$libssh_build/${type.toLowerCase()}")
// Use CMake to invoke the low-level build system.
executable "cmake"
args "--build", ".", "--parallel", "${project.processors}"
workingDir build_dir
def platformArg = "/p:Platform=x64"
if (project.platform == "windows-arm64") {
platformArg = "/p:Platform=arm64"
}
// Specify arch and build type on Windows.
if (project.platform.contains("windows")) {
args "--", "/p:Configuration=$type", "/v:m", platformArg
}
}
}
// Runs the archiver step.
types.each { type ->
project.tasks.create("create${type}Archive", Exec) {
// Make sure that we have built.
dependsOn "buildLibSSH$type"
// Create an alias to the libraries directories.
def ssl_libs = file("${project.openssl_install}/lib")
def ssh_libs = file("${project.libssh_build}/${type.toLowerCase()}/lib")
if (project.platform.contains("windows")) {
// LibSSH libraries are one layer deeper on windows.
ssh_libs = file("$ssh_libs/$type")
// Use "lib" to merge libraries.
executable "lib"
args "/OUT:ssh${project.pub_version}.lib"
workingDir ssh_libs
// Add libraries to merge.
args "$ssl_libs/libcrypto.lib"
args "$ssh_libs/ssh.lib"
doLast {
copy {
from "$ssl_libs/ossl_static.pdb"
into "$ssh_libs"
}
}
} else if (project.platform.contains("osx")) {
// Use libtool to merge libraries.
executable "libtool"
args "-static", "-o", "libssh${project.pub_version}.a"
workingDir ssh_libs
// Add libraries to merge.
args "$ssl_libs/libcrypto.a"
args "$ssh_libs/libssh.a"
} else {
// Use ar to merge libraries.
executable "ar"
args "-M"
workingDir ssh_libs
// Add libraries to merge.
def str = "create libssh${project.pub_version}.a\n"
str += "addlib $ssl_libs/libcrypto.a\n"
str += "addlib $ssh_libs/libssh.a\n"
str += "save\nend\n"
standardInput = new ByteArrayInputStream(str.getBytes())
}
}
}
// Create a "mega-task" that builds everything.
types.each { type ->
project.tasks.create("libSSH$type") {
dependsOn "create${type}Archive"
}
}