bsalomon | de7bbab | 2016-03-03 15:43:03 -0800 | [diff] [blame] | 1 | #!/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 | """ |
| 10 | Script to build the shaderc library. |
| 11 | """ |
| 12 | |
| 13 | import argparse |
| 14 | import os |
| 15 | import shlex |
| 16 | import shutil |
| 17 | import subprocess |
| 18 | import sys |
| 19 | |
| 20 | def 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: |
bsalomon | c770b75 | 2016-04-01 08:40:55 -0700 | [diff] [blame] | 66 | build_type_arg='-DCMAKE_BUILD_TYPE=' + args.build_type |
bsalomon | de7bbab | 2016-03-03 15:43:03 -0800 | [diff] [blame] | 67 | subprocess.check_call(['cmake', '-G', generator, |
egdaniel | b90e67f | 2016-03-31 06:16:31 -0700 | [diff] [blame] | 68 | '-DSPIRV_SKIP_EXECUTABLES=ON', '-DSHADERC_ENABLE_SHARED_CRT=ON', |
bsalomon | c770b75 | 2016-04-01 08:40:55 -0700 | [diff] [blame] | 69 | args.src_dir, build_type_arg], cwd=args.output_dir) |
bsalomon | de7bbab | 2016-03-03 15:43:03 -0800 | [diff] [blame] | 70 | 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 | |
| 81 | if __name__ == '__main__': |
| 82 | main() |
| 83 | |