From 994696e0ad9adc6e25e8ae77c0f84f8998789e3f Mon Sep 17 00:00:00 2001 From: Nicolas Schneider Date: Wed, 22 Mar 2017 09:59:09 +0100 Subject: [PATCH 1/4] add vs2017 backend VS2017 requires the 'WindowsTargetPlatformVersion' property to be set. We gather the version to use from the environment variable 'WindowsSDKVersion' that will be set by the VS developer command prompt. --- mesonbuild/backend/vs2010backend.py | 9 +++++++++ mesonbuild/backend/vs2017backend.py | 27 +++++++++++++++++++++++++++ mesonbuild/coredata.py | 2 +- mesonbuild/mesonmain.py | 3 +++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 mesonbuild/backend/vs2017backend.py diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index e1f732595..6b4859d62 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -62,6 +62,7 @@ class Vs2010Backend(backends.Backend): self.sources_conflicts = {} self.platform_toolset = None self.vs_version = '2010' + self.windows_target_platform_version = None def object_filename_from_source(self, target, source): basename = os.path.basename(source.fname) @@ -354,6 +355,8 @@ class Vs2010Backend(backends.Backend): p.text = self.platform pname = ET.SubElement(globalgroup, 'ProjectName') pname.text = project_name + if self.windows_target_platform_version: + ET.SubElement(globalgroup, 'WindowsTargetPlatformVersion').text = self.windows_target_platform_version ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.Default.props') type_config = ET.SubElement(root, 'PropertyGroup', Label='Configuration') ET.SubElement(type_config, 'ConfigurationType') @@ -589,6 +592,8 @@ class Vs2010Backend(backends.Backend): p.text = self.platform pname = ET.SubElement(globalgroup, 'ProjectName') pname.text = project_name + if self.windows_target_platform_version: + ET.SubElement(globalgroup, 'WindowsTargetPlatformVersion').text = self.windows_target_platform_version ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.Default.props') # Start configuration type_config = ET.SubElement(root, 'PropertyGroup', Label='Configuration') @@ -1006,6 +1011,8 @@ class Vs2010Backend(backends.Backend): p.text = self.platform pname = ET.SubElement(globalgroup, 'ProjectName') pname.text = project_name + if self.windows_target_platform_version: + ET.SubElement(globalgroup, 'WindowsTargetPlatformVersion').text = self.windows_target_platform_version ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.Default.props') type_config = ET.SubElement(root, 'PropertyGroup', Label='Configuration') ET.SubElement(type_config, 'ConfigurationType').text = "Utility" @@ -1085,6 +1092,8 @@ if %%errorlevel%% neq 0 goto :VCEnd''' p.text = self.platform pname = ET.SubElement(globalgroup, 'ProjectName') pname.text = project_name + if self.windows_target_platform_version: + ET.SubElement(globalgroup, 'WindowsTargetPlatformVersion').text = self.windows_target_platform_version ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.Default.props') type_config = ET.SubElement(root, 'PropertyGroup', Label='Configuration') ET.SubElement(type_config, 'ConfigurationType') diff --git a/mesonbuild/backend/vs2017backend.py b/mesonbuild/backend/vs2017backend.py new file mode 100644 index 000000000..8301790de --- /dev/null +++ b/mesonbuild/backend/vs2017backend.py @@ -0,0 +1,27 @@ +# Copyright 2014-2016 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from .vs2010backend import Vs2010Backend + + +class Vs2017Backend(Vs2010Backend): + def __init__(self, build): + super().__init__(build) + self.name = 'vs2017' + self.platform_toolset = 'v141' + self.vs_version = '2017' + # WindowsSDKVersion should be set by command prompt. + self.windows_target_platform_version = os.getenv('WindowsSDKVersion', None) diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index e88cdc8e7..0d2af6973 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -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', 'xcode'] +backendlist = ['ninja', 'vs2010', 'vs2015', 'vs2017', 'xcode'] class UserOption: def __init__(self, name, description, choices): diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 031486c87..38c00a0a1 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -151,6 +151,9 @@ If you want to change option values, use the mesonconf tool instead.''' elif self.options.backend == 'vs2015': from .backend import vs2015backend g = vs2015backend.Vs2015Backend(b) + elif self.options.backend == 'vs2017': + from .backend import vs2017backend + g = vs2017backend.Vs2017Backend(b) elif self.options.backend == 'xcode': from .backend import xcodebackend g = xcodebackend.XCodeBackend(b) From 52076967b6a4f70b60423dd19308b219e4c80a9a Mon Sep 17 00:00:00 2001 From: Nicolas Schneider Date: Wed, 22 Mar 2017 11:32:50 +0100 Subject: [PATCH 2/4] add appveyor config for VS2017 The 'Visual Studio 2017' image does not include VS2010, so we have to use the 'Visual Studio 2015' image by default and only use the 2017 image for msvc2017 compiler tests. --- .appveyor.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index 289758d8f..d69d37a36 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -20,6 +20,16 @@ environment: compiler: msvc2015 backend: vs2015 + - arch: x86 + compiler: msvc2017 + backend: ninja + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + + - arch: x86 + compiler: msvc2017 + backend: vs2015 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + - arch: x64 compiler: msvc2015 backend: ninja @@ -28,6 +38,16 @@ environment: compiler: msvc2015 backend: vs2015 + - arch: x64 + compiler: msvc2017 + backend: ninja + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + + - arch: x64 + compiler: msvc2017 + backend: vs2015 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + platform: - x64 @@ -43,6 +63,7 @@ install: - cmd: echo Using Python at %MESON_PYTHON_PATH% - cmd: if %compiler%==msvc2010 ( call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" %arch% ) - cmd: if %compiler%==msvc2015 ( call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %arch% ) + - cmd: if %compiler%==msvc2017 ( call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" -arch=%arch% ) build_script: - cmd: echo No build step. From 776de065a8e1bfe94938d535bdf06c1cad9dc28b Mon Sep 17 00:00:00 2001 From: Nicolas Schneider Date: Wed, 22 Mar 2017 11:54:40 +0100 Subject: [PATCH 3/4] appveyor: use vs2017 backend for msvc2017 compiler --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index d69d37a36..8f215c987 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -27,7 +27,7 @@ environment: - arch: x86 compiler: msvc2017 - backend: vs2015 + backend: vs2017 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - arch: x64 @@ -45,7 +45,7 @@ environment: - arch: x64 compiler: msvc2017 - backend: vs2015 + backend: vs2017 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 platform: From 92ed60729070c5b94c34ab24b1553d40978b645d Mon Sep 17 00:00:00 2001 From: Nicolas Schneider Date: Thu, 23 Mar 2017 10:34:32 +0100 Subject: [PATCH 4/4] 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. --- mesonbuild/backend/vs2010backend.py | 23 +++++++++++++++++++++++ mesonbuild/coredata.py | 2 +- mesonbuild/mesonmain.py | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 6b4859d62..a3af95f18 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.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 diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 0d2af6973..d3a124165 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -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): diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 38c00a0a1..7db6310a6 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -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)