-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.py
57 lines (42 loc) · 1.82 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
#!/usr/bin/env python3
import argparse
import os
import re
import subprocess
import shutil
SUPPORTED_BUILD_TYPES = ["Debug", "Release", "RelWithDebInfo", "MinSizeRel"]
def check_required_tools():
required_tools = ["cmake", "ninja"]
missing_tools = []
for tool in required_tools:
if shutil.which(tool) is None:
missing_tools.append(tool)
if missing_tools:
print(f"Error: The following required tools are missing: {', '.join(missing_tools)}")
print("Please install them and try again.")
exit(1)
def main():
check_required_tools()
parser = argparse.ArgumentParser(description="A script to run CMake and Ninja with the specified build type.")
parser.add_argument("build_type", nargs='?', default=None, help="Build type to pass to cmake as the CMAKE_BUILD_TYPE parameter.")
args = parser.parse_args()
build_type = args.build_type
if build_type is None:
print("Please select a build type from the list below:")
for i, bt in enumerate(SUPPORTED_BUILD_TYPES):
print(f"{i + 1}. {bt}")
selected = int(input("Enter the number corresponding to your choice: ")) - 1
build_type = SUPPORTED_BUILD_TYPES[selected]
if build_type not in SUPPORTED_BUILD_TYPES:
print(f"Invalid build type: {build_type}. Supported build types are: {', '.join(SUPPORTED_BUILD_TYPES)}")
exit(1)
build_target_folder = f"build/clang/{build_type}"
print(f"The build target folder is: {build_target_folder}")
cmake_cmd = f"cmake -B {build_target_folder} -GNinja -DCMAKE_BUILD_TYPE={build_type}"
ninja_cmd = f"ninja -C {build_target_folder}"
print(f"Running cmake command: {cmake_cmd}")
os.system(cmake_cmd)
print(f"Running ninja command: {ninja_cmd}")
os.system(ninja_cmd)
if __name__ == "__main__":
main()