From 5f5c92b9a2c2f9c780c08e23231b93af71f175bd Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 13 Nov 2013 14:27:51 -0500 Subject: [PATCH] VS: Add internal APIs to find MSBuild, devenv/VCExpress, and msdev Teach the VS generators to compute the locations of these tools directly from registry entries. Add internal APIs to get the locations on demand. --- Source/cmGlobalVisualStudio10Generator.cxx | 45 ++++++++++++++++++++++ Source/cmGlobalVisualStudio10Generator.h | 7 ++++ Source/cmGlobalVisualStudio6Generator.cxx | 28 ++++++++++++++ Source/cmGlobalVisualStudio6Generator.h | 4 ++ Source/cmGlobalVisualStudio7Generator.cxx | 28 ++++++++++++++ Source/cmGlobalVisualStudio7Generator.h | 5 +++ Source/cmGlobalVisualStudio8Generator.cxx | 20 ++++++++++ Source/cmGlobalVisualStudio8Generator.h | 2 + 8 files changed, 139 insertions(+) diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 7be10b16b..d4d67d06f 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -98,6 +98,7 @@ cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator( "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\10.0\\Setup\\VC;" "ProductDir", vc10Express, cmSystemTools::KeyWOW64_32); this->MasmEnabled = false; + this->MSBuildCommandInitialized = false; } //---------------------------------------------------------------------------- @@ -255,7 +256,51 @@ std::string cmGlobalVisualStudio10Generator::GetUserMacrosRegKeyBase() return "Software\\Microsoft\\VisualStudio\\10.0\\vsmacros"; } +//---------------------------------------------------------------------------- +std::string const& cmGlobalVisualStudio10Generator::GetMSBuildCommand() +{ + if(!this->MSBuildCommandInitialized) + { + this->MSBuildCommandInitialized = true; + this->MSBuildCommand = this->FindMSBuildCommand(); + } + return this->MSBuildCommand; +} +//---------------------------------------------------------------------------- +std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand() +{ + std::string msbuild; + std::string mskey = + "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\"; + mskey += this->GetToolsVersion(); + mskey += ";MSBuildToolsPath"; + if(cmSystemTools::ReadRegistryValue(mskey.c_str(), msbuild, + cmSystemTools::KeyWOW64_32)) + { + cmSystemTools::ConvertToUnixSlashes(msbuild); + msbuild += "/"; + } + msbuild += "MSBuild.exe"; + return msbuild; +} + +//---------------------------------------------------------------------------- +std::string cmGlobalVisualStudio10Generator::FindDevEnvCommand() +{ + if(this->ExpressEdition) + { + // Visual Studio Express >= 10 do not have "devenv.com" or + // "VCExpress.exe" that we can use to build reliably. + // Tell the caller it needs to use MSBuild instead. + return ""; + } + // Skip over the cmGlobalVisualStudio8Generator implementation because + // we expect a real devenv and do not want to look for VCExpress. + return this->cmGlobalVisualStudio71Generator::FindDevEnvCommand(); +} + +//---------------------------------------------------------------------------- void cmGlobalVisualStudio10Generator::GenerateBuildCommand( std::vector& makeCommand, const char* makeProgram, diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index f358e5eba..ad0aa6d1b 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -94,6 +94,8 @@ public: protected: virtual const char* GetIDEVersion() { return "10.0"; } + std::string const& GetMSBuildCommand(); + std::string PlatformToolset; bool ExpressEdition; bool MasmEnabled; @@ -111,5 +113,10 @@ private: std::string SourceRel; }; LongestSourcePath LongestSource; + + std::string MSBuildCommand; + bool MSBuildCommandInitialized; + virtual std::string FindMSBuildCommand(); + virtual std::string FindDevEnvCommand(); }; #endif diff --git a/Source/cmGlobalVisualStudio6Generator.cxx b/Source/cmGlobalVisualStudio6Generator.cxx index 612e50fd6..51f38c275 100644 --- a/Source/cmGlobalVisualStudio6Generator.cxx +++ b/Source/cmGlobalVisualStudio6Generator.cxx @@ -33,6 +33,7 @@ std::string GetVS6TargetName(const std::string& targetName) cmGlobalVisualStudio6Generator::cmGlobalVisualStudio6Generator() { this->FindMakeProgramFile = "CMakeVS6FindMake.cmake"; + this->MSDevCommandInitialized = false; } void cmGlobalVisualStudio6Generator @@ -77,6 +78,33 @@ void cmGlobalVisualStudio6Generator::GenerateConfigurations(cmMakefile* mf) } } +//---------------------------------------------------------------------------- +std::string const& cmGlobalVisualStudio6Generator::GetMSDevCommand() +{ + if(!this->MSDevCommandInitialized) + { + this->MSDevCommandInitialized = true; + this->MSDevCommand = this->FindMSDevCommand(); + } + return this->MSDevCommand; +} + +//---------------------------------------------------------------------------- +std::string cmGlobalVisualStudio6Generator::FindMSDevCommand() +{ + std::string vscmd; + std::string vskey = this->GetRegistryBase() + "\\Setup;VsCommonDir"; + if(cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd, + cmSystemTools::KeyWOW64_32)) + { + cmSystemTools::ConvertToUnixSlashes(vscmd); + vscmd += "/MSDev98/Bin/"; + } + vscmd += "msdev.exe"; + return vscmd; +} + +//---------------------------------------------------------------------------- void cmGlobalVisualStudio6Generator::GenerateBuildCommand( std::vector& makeCommand, diff --git a/Source/cmGlobalVisualStudio6Generator.h b/Source/cmGlobalVisualStudio6Generator.h index 1ffa1309a..24f46b390 100644 --- a/Source/cmGlobalVisualStudio6Generator.h +++ b/Source/cmGlobalVisualStudio6Generator.h @@ -102,6 +102,10 @@ private: const std::set& dependencies); void WriteDSWFooter(std::ostream& fout); virtual std::string WriteUtilityDepend(cmTarget* target); + std::string MSDevCommand; + bool MSDevCommandInitialized; + std::string const& GetMSDevCommand(); + std::string FindMSDevCommand(); }; #endif diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 04563f3ea..2602f8397 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -22,6 +22,7 @@ cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator( { this->FindMakeProgramFile = "CMakeVS7FindMake.cmake"; this->IntelProjectVersion = 0; + this->DevEnvCommandInitialized = false; if (!platformName) { @@ -110,6 +111,33 @@ void cmGlobalVisualStudio7Generator } +//---------------------------------------------------------------------------- +std::string const& cmGlobalVisualStudio7Generator::GetDevEnvCommand() +{ + if(!this->DevEnvCommandInitialized) + { + this->DevEnvCommandInitialized = true; + this->DevEnvCommand = this->FindDevEnvCommand(); + } + return this->DevEnvCommand; +} + +//---------------------------------------------------------------------------- +std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand() +{ + std::string vscmd; + std::string vskey = this->GetRegistryBase() + ";InstallDir"; + if(cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd, + cmSystemTools::KeyWOW64_32)) + { + cmSystemTools::ConvertToUnixSlashes(vscmd); + vscmd += "/"; + } + vscmd += "devenv.com"; + return vscmd; +} + +//---------------------------------------------------------------------------- void cmGlobalVisualStudio7Generator::GenerateBuildCommand( std::vector& makeCommand, const char* makeProgram, diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index a6c2581d4..d272fa083 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -110,6 +110,9 @@ public: protected: virtual const char* GetIDEVersion() { return "7.0"; } + std::string const& GetDevEnvCommand(); + virtual std::string FindDevEnvCommand(); + static cmIDEFlagTable const* GetExtraFlagTableVS7(); virtual void OutputSLNFile(cmLocalGenerator* root, std::vector& generators); @@ -168,6 +171,8 @@ protected: private: char* IntelProjectVersion; + std::string DevEnvCommand; + bool DevEnvCommandInitialized; }; #define CMAKE_CHECK_BUILD_SYSTEM_TARGET "ZERO_CHECK" diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index b9bc1ae69..949dd1bbe 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -104,6 +104,26 @@ cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator( } } +//---------------------------------------------------------------------------- +std::string cmGlobalVisualStudio8Generator::FindDevEnvCommand() +{ + // First look for VCExpress. + std::string vsxcmd; + std::string vsxkey = + "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\"; + vsxkey += this->GetIDEVersion(); + vsxkey += ";InstallDir"; + if(cmSystemTools::ReadRegistryValue(vsxkey.c_str(), vsxcmd, + cmSystemTools::KeyWOW64_32)) + { + cmSystemTools::ConvertToUnixSlashes(vsxcmd); + vsxcmd += "/VCExpress.exe"; + return vsxcmd; + } + // Now look for devenv. + return this->cmGlobalVisualStudio71Generator::FindDevEnvCommand(); +} + //---------------------------------------------------------------------------- ///! Create a local generator appropriate to this Global Generator cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator() diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h index 2376f8a85..ad01a24b3 100644 --- a/Source/cmGlobalVisualStudio8Generator.h +++ b/Source/cmGlobalVisualStudio8Generator.h @@ -69,6 +69,8 @@ public: protected: virtual const char* GetIDEVersion() { return "8.0"; } + virtual std::string FindDevEnvCommand(); + virtual bool VSLinksDependencies() const { return false; } bool AddCheckTarget();