blob: 0cff599bb1ccb705481077973c450ef3df32116b [file] [log] [blame]
bsalomonde7bbab2016-03-03 15:43:03 -08001#!/usr/bin/python
2
3# Copyright 2016 Google Inc.
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8
9"""
10Script to build the shaderc library.
11"""
12
13import argparse
14import os
15import shlex
16import shutil
17import subprocess
18import sys
19
20def main():
21 parser = argparse.ArgumentParser(description='Builds shaderc')
22 parser.add_argument('-s', '--src-dir', required=True, help=
23 'path to shaderc source')
24 parser.add_argument('-t', '--build-type', required=True, help=
25 'Either Release or Debug')
26 parser.add_argument('-a', '--arch-type', required=True, help=
27 'Either x86 or x86_64')
28 parser.add_argument('-o', '--output-dir', required=True, help=
29 'Directory for cmake build')
30 parser.add_argument('-p', '--project_type', required=True, help=
31 'Project type to use. Must be "ninja", "MSVS2013", or "MSVS2015"')
32 args = parser.parse_args()
33
34 args.src_dir = os.path.abspath(args.src_dir)
35 args.output_dir = os.path.abspath(args.output_dir)
36
37 if not os.path.isdir(args.src_dir):
38 sys.exit(args.src_dir + ' is not a directory.')
39
40 if args.build_type != 'Debug' and args.build_type != 'Release':
41 sys.exit('Invalid build type: ' + args.build_type);
42
43 if args.arch_type == 'x86':
44 vs_arch = ''
45 elif args.arch_type == 'x86_64':
46 vs_arch = ' Win64'
47 else:
48 sys.exit('Invalid arch type: ' + args.arch_type);
49
50 if args.project_type == 'ninja':
51 generator = 'Ninja'
52 elif args.project_type == 'MSVS2013':
53 generator = 'Visual Studio 12 2013' + vs_arch
54 elif args.project_type == "MSVS2015":
55 generator = 'Visual Studio 14 2015' + vs_arch
56 else:
57 sys.exit('Invalid project type: ' + args.project_type);
58
59 if not os.path.isdir(args.output_dir):
60 try:
61 os.makedirs(args.output_dir)
62 except os.error:
63 sys.exit('Error creating output dir ' + args.output_dir)
64
65 try:
bsalomonc770b752016-04-01 08:40:55 -070066 build_type_arg='-DCMAKE_BUILD_TYPE=' + args.build_type
bsalomonde7bbab2016-03-03 15:43:03 -080067 subprocess.check_call(['cmake', '-G', generator,
egdanielb90e67f2016-03-31 06:16:31 -070068 '-DSPIRV_SKIP_EXECUTABLES=ON', '-DSHADERC_ENABLE_SHARED_CRT=ON',
bsalomonc770b752016-04-01 08:40:55 -070069 args.src_dir, build_type_arg], cwd=args.output_dir)
bsalomonde7bbab2016-03-03 15:43:03 -080070 except subprocess.CalledProcessError as error:
71 sys.exit('Error (ret code: {code}) calling "{cmd}" in {dir}'.format(
72 code = error.returncode, cmd = error.cmd, dir = args.src_dir))
73
74 try:
75 subprocess.check_call(['cmake', '--build', args.output_dir, '--config',
76 args.build_type], cwd=args.output_dir)
77 except subprocess.CalledProcessError as error:
78 sys.exit('Error (ret code: {code}) calling "{cmd}" in {dir}'.format(
79 code = error.returncode, cmd = error.cmd, dir = args.src_dir))
80
81if __name__ == '__main__':
82 main()
83