Browse Source

More MSVC flags, and use sccache if available

default_compile_flags
vector-of-bool 5 years ago
parent
commit
045dd435e1
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      tools/build.py

+ 21
- 1
tools/build.py View File

return False return False




def have_sccache() -> bool:
try:
subprocess.check_output(['sccache', '--version'])
return True
except FileNotFoundError:
return False


def _create_compile_command(opts: BuildOptions, cpp_file: Path, def _create_compile_command(opts: BuildOptions, cpp_file: Path,
obj_file: Path) -> List[str]: obj_file: Path) -> List[str]:
if not opts.is_msvc: if not opts.is_msvc:
] ]
if have_ccache(): if have_ccache():
cmd.insert(0, 'ccache') cmd.insert(0, 'ccache')
elif have_sccache():
cmd.insert(0, 'sccache')
if opts.static: if opts.static:
cmd.append('-static') cmd.append('-static')
if opts.debug: if opts.debug:
'/EHsc', '/EHsc',
'/std:c++latest', '/std:c++latest',
'/permissive-', '/permissive-',
'/experimental:preprocessor',
'/wd5105', # winbase.h
'/DWIN32_LEAN_AND_MEAN',
'/DNOMINMAX',
'/DFMT_HEADER_ONLY=1', '/DFMT_HEADER_ONLY=1',
'/D_CRT_SECURE_NO_WARNINGS',
'/diagnostics:caret',
f'/I{ROOT / "src"}', f'/I{ROOT / "src"}',
str(cpp_file), str(cpp_file),
'/c', '/c',
f'/Fo{obj_file}', f'/Fo{obj_file}',
] ]
if have_ccache():
cmd.insert(0, 'ccache')
elif have_sccache():
cmd.insert(0, 'sccache')
if opts.debug: if opts.debug:
cmd.extend(('/Od', '/DEBUG', '/Z7')) cmd.extend(('/Od', '/DEBUG', '/Z7'))
else: else:
f'Compile command ({cmd}) failed for {cpp_file}:\n{res.stdout.decode()}' f'Compile command ({cmd}) failed for {cpp_file}:\n{res.stdout.decode()}'
) )
stdout: str = res.stdout.decode() stdout: str = res.stdout.decode()
fname_head = f'{cpp_file.name}\r\n'
fname_head = f'{cpp_file.name}\n'
if stdout.startswith(fname_head): if stdout.startswith(fname_head):
stdout = stdout[len(fname_head):] stdout = stdout[len(fname_head):]
if stdout: if stdout:

Loading…
Cancel
Save