summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalVisualStudio15Generator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-10-04 17:01:47 (GMT)
committerBrad King <brad.king@kitware.com>2017-10-19 14:20:12 (GMT)
commit9ffb35386fb923a5959eec482bfa131aa3feaa18 (patch)
treea01b2cc99c387db8f4ef234d70ff35de43009b70 /Source/cmGlobalVisualStudio15Generator.cxx
parent17edfa41983c61574e897eda923c90fd33ba8ac3 (diff)
downloadCMake-9ffb35386fb923a5959eec482bfa131aa3feaa18.zip
CMake-9ffb35386fb923a5959eec482bfa131aa3feaa18.tar.gz
CMake-9ffb35386fb923a5959eec482bfa131aa3feaa18.tar.bz2
VS: Select and save a VS 2017 instance persistently
Visual Studio 2017 supports multiple instances installed on a single machine. We use the Visual Studio Installer tool to enumerate instances and select one. Once we select an instance for a given build tree, save the result in `CMAKE_GENERATOR_INSTANCE` so we can re-configure the tree with the same instance on future re-runs of CMake. Fixes: #17268
Diffstat (limited to 'Source/cmGlobalVisualStudio15Generator.cxx')
-rw-r--r--Source/cmGlobalVisualStudio15Generator.cxx47
1 files changed, 47 insertions, 0 deletions
diff --git a/Source/cmGlobalVisualStudio15Generator.cxx b/Source/cmGlobalVisualStudio15Generator.cxx
index d2bf7cc..014d93d 100644
--- a/Source/cmGlobalVisualStudio15Generator.cxx
+++ b/Source/cmGlobalVisualStudio15Generator.cxx
@@ -111,6 +111,53 @@ void cmGlobalVisualStudio15Generator::WriteSLNHeader(std::ostream& fout)
}
}
+bool cmGlobalVisualStudio15Generator::SetGeneratorInstance(
+ std::string const& i, cmMakefile* mf)
+{
+ if (!i.empty()) {
+ if (!this->vsSetupAPIHelper.SetVSInstance(i)) {
+ std::ostringstream e;
+ /* clang-format off */
+ e <<
+ "Generator\n"
+ " " << this->GetName() << "\n"
+ "could not find specified instance of Visual Studio:\n"
+ " " << i;
+ /* clang-format on */
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+ }
+
+ std::string vsInstance;
+ if (!this->vsSetupAPIHelper.GetVSInstanceInfo(vsInstance)) {
+ std::ostringstream e;
+ /* clang-format off */
+ e <<
+ "Generator\n"
+ " " << this->GetName() << "\n"
+ "could not find any instance of Visual Studio.\n";
+ /* clang-format on */
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ // Save the selected instance persistently.
+ std::string genInstance = mf->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE");
+ if (vsInstance != genInstance) {
+ this->CMakeInstance->AddCacheEntry(
+ "CMAKE_GENERATOR_INSTANCE", vsInstance.c_str(),
+ "Generator instance identifier.", cmStateEnums::INTERNAL);
+ }
+
+ return true;
+}
+
+bool cmGlobalVisualStudio15Generator::GetVSInstance(std::string& dir) const
+{
+ return vsSetupAPIHelper.GetVSInstanceInfo(dir);
+}
+
bool cmGlobalVisualStudio15Generator::InitializeWindows(cmMakefile* mf)
{
// If the Win 8.1 SDK is installed then we can select a SDK matching