add 'vs' backend that automatically chooses between the vs backends

For newer VS versions, we can simply rely on 'VisualStudioVersion' being
set in the environment.
For VS2010, we fall back to check 'VSINSTALLDIR' for the version string.
If the backend can not be auto detected, we raise an exception to make the
user choose an explicit backend.
We also print the detected backend to the meson log.
pull/1491/head
Nicolas Schneider 8 years ago
parent 776de065a8
commit 92ed607290
  1. 23
      mesonbuild/backend/vs2010backend.py
  2. 2
      mesonbuild/coredata.py
  3. 4
      mesonbuild/mesonmain.py

@ -27,6 +27,29 @@ from ..compilers import CompilerArgs
from ..mesonlib import MesonException, File
from ..environment import Environment
def autodetect_vs_version(build):
vs_version = os.getenv('VisualStudioVersion', None)
if vs_version:
if vs_version == '14.0':
from mesonbuild.backend.vs2015backend import Vs2015Backend
return Vs2015Backend(build)
if vs_version == '15.0':
from mesonbuild.backend.vs2017backend import Vs2017Backend
return Vs2017Backend(build)
raise MesonException('Could not detect Visual Studio (unknown Visual Studio version: "{}")!\n'
'Please specify the exact backend to use.'.format(vs_version))
vs_install_dir = os.getenv('VSINSTALLDIR', None)
if not vs_install_dir:
raise MesonException('Could not detect Visual Studio (neither VisualStudioVersion nor VSINSTALLDIR set in '
'environment)!\nPlease specify the exact backend to use.')
if 'Visual Studio 10.0' in vs_install_dir:
return Vs2010Backend(build)
raise MesonException('Could not detect Visual Studio (unknown VSINSTALLDIR: "{}")!\n'
'Please specify the exact backend to use.'.format(vs_install_dir))
def split_o_flags_args(args):
"""
Splits any /O args and returns them. Does not take care of flags overriding

@ -18,7 +18,7 @@ from .mesonlib import MesonException, commonpath
from .mesonlib import default_libdir, default_libexecdir, default_prefix
version = '0.40.0.dev1'
backendlist = ['ninja', 'vs2010', 'vs2015', 'vs2017', 'xcode']
backendlist = ['ninja', 'vs', 'vs2010', 'vs2015', 'vs2017', 'xcode']
class UserOption:
def __init__(self, name, description, choices):

@ -145,6 +145,10 @@ If you want to change option values, use the mesonconf tool instead.'''
if self.options.backend == 'ninja':
from .backend import ninjabackend
g = ninjabackend.NinjaBackend(b)
elif self.options.backend == 'vs':
from .backend import vs2010backend
g = vs2010backend.autodetect_vs_version(b)
mlog.log('Auto detected Visual Studio backend:', mlog.bold(g.name))
elif self.options.backend == 'vs2010':
from .backend import vs2010backend
g = vs2010backend.Vs2010Backend(b)

Loading…
Cancel
Save