forked from Ableton/link
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·72 lines (52 loc) · 1.84 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
#!/usr/bin/env python
import argparse
import logging
import os
import sys
from distutils.spawn import find_executable
from subprocess import call
def parse_args():
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument(
'--cmake',
default=find_executable("cmake"),
help='Path to CMake executable (default: %(default)s)')
arg_parser.add_argument(
'-c', '--configuration',
help='Build configuration to use (not supported by IDE generators)')
arg_parser.add_argument(
'-a', '--arguments',
help='Arguments to pass to builder')
return arg_parser.parse_args(sys.argv[1:])
def build_cmake_args(args, build_dir):
if args.cmake is None:
logging.error('CMake not found, please use the --cmake option')
return None
cmake_args = []
cmake_args.append(args.cmake)
cmake_args.append('--build')
cmake_args.append(build_dir)
if args.configuration is not None:
cmake_args.append('--config')
cmake_args.append(args.configuration)
if args.arguments is not None:
cmake_args.append('--')
for arg in args.arguments.split():
cmake_args.append(arg)
return cmake_args
def build(args):
scripts_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.join(scripts_dir, os.pardir)
build_dir = os.path.join(root_dir, 'build')
if not os.path.exists(build_dir):
logging.error(
'Build directory not found, did you forget to run the configure.py script?')
return 2
cmake_args = build_cmake_args(args, build_dir)
if cmake_args is None:
return 1
logging.info('Running CMake')
return call(cmake_args)
if __name__ == '__main__':
logging.basicConfig(format='%(message)s', level=logging.INFO, stream=sys.stdout)
sys.exit(build(parse_args()))