-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.py
117 lines (92 loc) · 2.78 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
import argparse
import os
from pathlib import Path
import shutil
import subprocess
import sys
# Colors
CRED = "\033[91m"
CGREEN = "\033[92m"
CCYAN = "\033[96m"
CEND = "\033[0m"
def GenerateFiles(args):
# Create build directory in root folder
buildDir = os.path.realpath(os.path.dirname(__file__)) + "/Build/" + args.config
try:
Path(buildDir).mkdir(parents=True, exist_ok=True)
except OSError:
os.chdir(buildDir)
return True
os.chdir(buildDir)
callArgs = [ "cmake", "-GNinja" ]
buildOptions = {
"Debug" : "-DCMAKE_BUILD_TYPE=Debug",
"Development" : "-DCMAKE_BUILD_TYPE=RelWithDebInfo",
"Release" : "-DCMAKE_BUILD_TYPE=Release",
}
callArgs.append(buildOptions.get(args.config, ""))
# Turn submodule updating off
if args.nosub:
callArgs.append("-DSUBMODULE=OFF")
# Turn documentation building off
if args.nodoc:
callArgs.append("-DBUILD_DOCS=OFF")
# Turn CLI off
if args.nocli:
callArgs.append("-DBUILD_CLI=OFF")
callArgs.append("../..")
# Generate CMake files
value = subprocess.call(
callArgs,
stdout=subprocess.DEVNULL,
stderr=sys.stderr
)
if value != 0:
print(CRED + "Failed to generate files!" + CEND)
return False
print(CGREEN + "Generated files." + CEND)
return True
def Build():
value = subprocess.call(
[ "cmake", "--build", "." ]
)
if value != 0:
print(CRED + "Build failed!" + CEND)
return
print(CGREEN + "Built." + CEND)
def Main():
os.system("color")
parser = argparse.ArgumentParser(
description="Generate Ninja build files for Cinder, and build the API library and CLI tool.",
epilog="If you wish to invoke CMake directly, go to the README."
)
parser.add_argument(
"-c", "--conf",
default="Release",
choices=["Debug", "Development", "Release"],
help="Configuration to build, directly corresponds to Debug, RelWithDebInfo, and Release.",
dest="config"
)
parser.add_argument(
"-nosub", "--nosubmodule",
action="store_true",
help="Disable updating submodules, only turn off if you have made changes to them.",
dest="nosub"
)
parser.add_argument(
"-nodoc", "--nodocumentation",
action="store_true",
help="Do not build the Cinder documentation.",
dest="nodoc"
)
parser.add_argument(
"-nocli",
action="store_true",
help="Do not build the Cinder CLI tool.",
dest="nocli"
)
args = parser.parse_args()
if GenerateFiles(args):
Build()
if __name__ == "__main__":
Main()