-
Notifications
You must be signed in to change notification settings - Fork 53
/
build.py
180 lines (136 loc) · 4.97 KB
/
build.py
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import os
import platform
import sys
import multiprocessing
def getParallel(args):
par = multiprocessing.cpu_count()
for x in args:
if x.startswith("--par="):
val = x.split("=",1)[1]
par = int(val)
if par < 1:
par = 1
idx = args.index(x)
args[idx] = ""
return (args,par)
def replace(list, find, replace):
if find in list:
idx = list.index(find)
list[idx] = replace;
return list
def Build(projectName, argv, install, par, sudo, noConfig):
osStr = (platform.system())
buildDir = ""
config = ""
buildType = ""
setup = "--setup" in argv;
argv = replace(argv, "--setup", "")
if "--debug" in argv:
buildType = "Debug"
else:
buildType = "Release"
argv = replace(argv, "--debug", "")
if osStr == "Windows":
buildDir = "out/build/x64-{0}".format(buildType)
config = "--config {0}".format(buildType)
elif osStr == "Darwin":
buildDir = "out/build/osx"
else:
buildDir = "out/build/linux"
if not any("DCMAKE_BUILD_TYPE" in s for s in argv):
argv.append("-DCMAKE_BUILD_TYPE={0}".format(buildType))
argStr = ""
for a in argv:
argStr = argStr + " " + a
parallel = ""
if par != 1:
parallel = " --parallel " + str(par)
mkDirCmd = "mkdir -p {0}".format(buildDir);
CMakeCmd = "cmake -S . -B {0} {1}".format(buildDir, argStr)
BuildCmd = "cmake --build {0} {1} {2} ".format(buildDir, config, parallel)
InstallCmd = ""
if sudo:
sudo = "sudo "
else:
sudo = ""
if install:
InstallCmd = sudo
InstallCmd += "cmake --install {0} {1} ".format(buildDir, config)
print("\n\n====== build.py ("+projectName+") ========")
if not noConfig:
print(mkDirCmd)
print(CMakeCmd)
if not setup:
print(BuildCmd)
if len(InstallCmd):
print(InstallCmd)
print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n\n")
if not noConfig:
os.system(mkDirCmd)
os.system(CMakeCmd)
if not setup:
os.system(BuildCmd)
if len(sudo) > 0:
print("installing "+projectName+": {0}\n".format(InstallCmd))
os.system(InstallCmd)
def help():
print(" --install \n\tInstructs the script to install whatever is currently being built to the default location.")
print(" --install=prefix \n\tinstall to the provided predix.")
print(" --sudo \n\twhen installing, use sudo. May require password.")
print(" --par=n \n\twhen building do use parallel builds with n threads. default = num cores.")
print(" --noauto \n\twhen building do not automaticly fetch dependancies.")
print(" --par=n \n\twhen building do use parallel builds with n threads. default = num cores.")
print(" --debug \n\tdebug build.")
print("any additioanl arguments are forwared to cmake.\n")
print("-build the library")
print(" python build.py")
print("-build the library with cmake configurations")
print(" python build.py --debug -DENABLE_SSE=ON")
print("-build the library and install with sudo")
print(" python build.py --install --sudo")
print("-build the library and install to prefix")
print(" python build.py --install=~/my/install/dir ")
def parseInstallArgs(args):
prefix = ""
doInstall = False
for x in args:
if x.startswith("--install="):
prefix = x.split("=",1)[1]
prefix = os.path.abspath(os.path.expanduser(prefix))
idx = args.index(x)
args[idx] = "-DCMAKE_INSTALL_PREFIX=" + prefix
doInstall = True
if x == "--install":
idx = args.index(x)
osStr = (platform.system())
if osStr == "Windows":
args[idx] = "-DCMAKE_INSTALL_PREFIX=c:/lib"
else:
args[idx] = "-DCMAKE_INSTALL_PREFIX=/usr/local"
doInstall = True
return (args, doInstall)
def main(projectName, argv):
if "--help" in argv:
help()
return
sudo = "--sudo" in argv;
if not sudo:
argv.append("-DSUDO_FETCH=OFF")
if "--noauto" in argv:
argv = replace(argv, "--noauto", "")
argv.append("-DFETCH_AUTO=OFF")
else:
argv.append("-DFETCH_AUTO=ON")
argv = replace(argv, "--relic", "-DENABLE_RELIC=ON -DFETCH_RELIC=ON")
argv = replace(argv, "--boost", "-DENABLE_BOOST=ON -DFETCH_BOOST=ON")
argv = replace(argv, "--sodium", "-DENABLE_SODIUM=ON -DFETCH_SODIUM=ON")
argv = replace(argv, "--openssl", "-DENABLE_OPENSSL=ON")
argv = replace(argv, "--sudo", "-DSUDO_FETCH=ON")
argv, install = parseInstallArgs(argv)
argv, par = getParallel(argv)
argv.append("-DPARALLEL_FETCH="+str(par))
noConfig = "--nc" in argv
argv = replace(argv, "--nc", "")
Build(projectName, argv, install, par, sudo, noConfig)
if __name__ == "__main__":
main("cryptoTools", sys.argv[1:])