ENH: Add code to support calling the VS reload macro from Visual Studio 7.1 and 9.0 in addition to 8.0 sp1... Make new macros file with VS 7.1 so that it can be read by 7.1 and later. VS 7.1 does not appear to run the macros while a build is in progress, but does not return any errors either, so for now, the reload macro is not called when using 7.1. If I can figure out how to get 7.1 to execute the macro, I will uncomment the code in cmGlobalVisualStudio71Generator::GetUserMacrosDirectory() to activate executing the macros in VS 7.1, too.

This commit is contained in:
David Cole 2008-02-15 11:49:58 -05:00
parent ed76198b84
commit ca2a16c0a2
10 changed files with 172 additions and 41 deletions

View File

@ -94,7 +94,41 @@ HRESULT InstanceCallMacro(
hr = vsIDE->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, hr = vsIDE->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &params, &result, &excep, &arg); DISPATCH_METHOD, &params, &result, &excep, &arg);
ReportHRESULT(hr, "Invoke(ExecuteCommand)");
std::ostringstream oss;
oss << std::endl;
oss << "Invoke(ExecuteCommand)" << std::endl;
oss << " Macro: " << macro.c_str() << std::endl;
oss << " Args: " << args.c_str() << std::endl;
if (DISP_E_EXCEPTION == hr)
{
oss << "DISP_E_EXCEPTION EXCEPINFO:" << excep.wCode << std::endl;
oss << " wCode: " << excep.wCode << std::endl;
oss << " wReserved: " << excep.wReserved << std::endl;
if (excep.bstrSource)
{
oss << " bstrSource: " <<
(const char*)(_bstr_t)excep.bstrSource << std::endl;
}
if (excep.bstrDescription)
{
oss << " bstrDescription: " <<
(const char*)(_bstr_t)excep.bstrDescription << std::endl;
}
if (excep.bstrHelpFile)
{
oss << " bstrHelpFile: " <<
(const char*)(_bstr_t)excep.bstrHelpFile << std::endl;
}
oss << " dwHelpContext: " << excep.dwHelpContext << std::endl;
oss << " pvReserved: " << excep.pvReserved << std::endl;
oss << " pfnDeferredFillIn: " << excep.pfnDeferredFillIn << std::endl;
oss << " scode: " << excep.scode << std::endl;
}
std::string exstr(oss.str());
ReportHRESULT(hr, exstr.c_str());
VariantClear(&result); VariantClear(&result);
} }

View File

@ -20,16 +20,14 @@
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmake.h" #include "cmake.h"
//----------------------------------------------------------------------------
cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator() cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator()
{ {
this->FindMakeProgramFile = "CMakeVS71FindMake.cmake"; this->FindMakeProgramFile = "CMakeVS71FindMake.cmake";
this->ProjectConfigurationSectionName = "ProjectConfiguration"; this->ProjectConfigurationSectionName = "ProjectConfiguration";
} }
//----------------------------------------------------------------------------
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *cmGlobalVisualStudio71Generator::CreateLocalGenerator() cmLocalGenerator *cmGlobalVisualStudio71Generator::CreateLocalGenerator()
{ {
@ -40,12 +38,66 @@ cmLocalGenerator *cmGlobalVisualStudio71Generator::CreateLocalGenerator()
return lg; return lg;
} }
//----------------------------------------------------------------------------
void cmGlobalVisualStudio71Generator::AddPlatformDefinitions(cmMakefile* mf) void cmGlobalVisualStudio71Generator::AddPlatformDefinitions(cmMakefile* mf)
{ {
mf->AddDefinition("MSVC71", "1"); mf->AddDefinition("MSVC71", "1");
} }
//----------------------------------------------------------------------------
std::string cmGlobalVisualStudio71Generator::GetUserMacrosDirectory()
{
// Macros not supported on Visual Studio 7.1 and earlier because
// they do not appear to work *during* a build when called by an
// outside agent...
//
return "";
#if 0
//
// The COM result from calling a Visual Studio macro with 7.1 indicates
// that the call succeeds, but the macro does not appear to execute...
//
// So, I am leaving this code here to show how to do it, but have not
// yet figured out what the issue is in terms of why the macro does not
// appear to execute...
//
std::string base;
std::string path;
// base begins with the VisualStudioProjectsLocation reg value...
if (cmSystemTools::ReadRegistryValue(
"HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\7.1;"
"VisualStudioProjectsLocation",
base))
{
cmSystemTools::ConvertToUnixSlashes(base);
// 7.1 macros folder:
path = base + "/VSMacros71";
}
// path is (correctly) still empty if we did not read the base value from
// the Registry value
return path;
#endif
}
//----------------------------------------------------------------------------
std::string cmGlobalVisualStudio71Generator::GetUserMacrosRegKeyBase()
{
// Macros not supported on Visual Studio 7.1 and earlier because
// they do not appear to work *during* a build when called by an
// outside agent...
//
return "";
#if 0
return "Software\\Microsoft\\VisualStudio\\7.1\\vsmacros";
#endif
}
//----------------------------------------------------------------------------
void cmGlobalVisualStudio71Generator void cmGlobalVisualStudio71Generator
::WriteSLNFile(std::ostream& fout, ::WriteSLNFile(std::ostream& fout,
cmLocalGenerator* root, cmLocalGenerator* root,
@ -77,7 +129,7 @@ void cmGlobalVisualStudio71Generator
this->WriteSLNFooter(fout); this->WriteSLNFooter(fout);
} }
//----------------------------------------------------------------------------
void void
cmGlobalVisualStudio71Generator cmGlobalVisualStudio71Generator
::WriteSolutionConfigurations(std::ostream& fout) ::WriteSolutionConfigurations(std::ostream& fout)
@ -91,6 +143,7 @@ cmGlobalVisualStudio71Generator
fout << "\tEndGlobalSection\n"; fout << "\tEndGlobalSection\n";
} }
//----------------------------------------------------------------------------
// Write a dsp file into the SLN file, // Write a dsp file into the SLN file,
// Note, that dependencies from executables to // Note, that dependencies from executables to
// the libraries it uses are also done here // the libraries it uses are also done here
@ -112,8 +165,7 @@ cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
fout <<"EndProject\n"; fout <<"EndProject\n";
} }
//----------------------------------------------------------------------------
// Write a dsp file into the SLN file, // Write a dsp file into the SLN file,
// Note, that dependencies from executables to // Note, that dependencies from executables to
// the libraries it uses are also done here // the libraries it uses are also done here
@ -179,6 +231,7 @@ cmGlobalVisualStudio71Generator
} }
} }
//----------------------------------------------------------------------------
// Write a dsp file into the SLN file, Note, that dependencies from // Write a dsp file into the SLN file, Note, that dependencies from
// executables to the libraries it uses are also done here // executables to the libraries it uses are also done here
void cmGlobalVisualStudio71Generator void cmGlobalVisualStudio71Generator
@ -219,7 +272,7 @@ void cmGlobalVisualStudio71Generator
} }
//----------------------------------------------------------------------------
// Write a dsp file into the SLN file, Note, that dependencies from // Write a dsp file into the SLN file, Note, that dependencies from
// executables to the libraries it uses are also done here // executables to the libraries it uses are also done here
void cmGlobalVisualStudio71Generator void cmGlobalVisualStudio71Generator
@ -240,9 +293,7 @@ void cmGlobalVisualStudio71Generator
} }
} }
//----------------------------------------------------------------------------
// Standard end of dsw file // Standard end of dsw file
void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout) void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
{ {
@ -253,7 +304,7 @@ void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
<< "EndGlobal\n"; << "EndGlobal\n";
} }
//----------------------------------------------------------------------------
// ouput standard header for dsw file // ouput standard header for dsw file
void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout) void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
{ {

View File

@ -43,6 +43,19 @@ public:
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator
virtual cmLocalGenerator *CreateLocalGenerator(); virtual cmLocalGenerator *CreateLocalGenerator();
/**
* Where does this version of Visual Studio look for macros for the
* current user? Returns the empty string if this version of Visual
* Studio does not implement support for VB macros.
*/
virtual std::string GetUserMacrosDirectory();
/**
* What is the reg key path to "vsmacros" for this version of Visual
* Studio?
*/
virtual std::string GetUserMacrosRegKeyBase();
protected: protected:
virtual void AddPlatformDefinitions(cmMakefile* mf); virtual void AddPlatformDefinitions(cmMakefile* mf);
virtual void WriteSLNFile(std::ostream& fout, virtual void WriteSLNFile(std::ostream& fout,

View File

@ -20,8 +20,7 @@
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmake.h" #include "cmake.h"
//----------------------------------------------------------------------------
cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator() cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator()
{ {
this->FindMakeProgramFile = "CMakeVS8FindMake.cmake"; this->FindMakeProgramFile = "CMakeVS8FindMake.cmake";
@ -29,8 +28,7 @@ cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator()
this->PlatformName = "Win32"; this->PlatformName = "Win32";
} }
//----------------------------------------------------------------------------
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator() cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator()
{ {
@ -40,8 +38,8 @@ cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator()
lg->SetGlobalGenerator(this); lg->SetGlobalGenerator(this);
return lg; return lg;
} }
//----------------------------------------------------------------------------
// ouput standard header for dsw file // ouput standard header for dsw file
void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout) void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout)
{ {
@ -100,12 +98,6 @@ std::string cmGlobalVisualStudio8Generator::GetUserMacrosDirectory()
{ {
cmSystemTools::ConvertToUnixSlashes(base); cmSystemTools::ConvertToUnixSlashes(base);
// 7.0 macros folder:
//path = base + "/VSMacros";
// 7.1 macros folder:
//path = base + "/VSMacros71";
// 8.0 macros folder: // 8.0 macros folder:
path = base + "/VSMacros80"; path = base + "/VSMacros80";
} }
@ -115,6 +107,12 @@ std::string cmGlobalVisualStudio8Generator::GetUserMacrosDirectory()
return path; return path;
} }
//----------------------------------------------------------------------------
std::string cmGlobalVisualStudio8Generator::GetUserMacrosRegKeyBase()
{
return "Software\\Microsoft\\VisualStudio\\8.0\\vsmacros";
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalVisualStudio8Generator::Generate() void cmGlobalVisualStudio8Generator::Generate()
{ {

View File

@ -57,6 +57,12 @@ public:
*/ */
virtual std::string GetUserMacrosDirectory(); virtual std::string GetUserMacrosDirectory();
/**
* What is the reg key path to "vsmacros" for this version of Visual
* Studio?
*/
virtual std::string GetUserMacrosRegKeyBase();
protected: protected:
virtual bool VSLinksDependencies() const { return false; } virtual bool VSLinksDependencies() const { return false; }

View File

@ -33,6 +33,7 @@ void cmGlobalVisualStudio9Generator::AddPlatformDefinitions(cmMakefile* mf)
mf->AddDefinition("MSVC90", "1"); mf->AddDefinition("MSVC90", "1");
} }
//----------------------------------------------------------------------------
void cmGlobalVisualStudio9Generator::WriteSLNHeader(std::ostream& fout) void cmGlobalVisualStudio9Generator::WriteSLNHeader(std::ostream& fout)
{ {
fout << "Microsoft Visual Studio Solution File, Format Version 10.00\n"; fout << "Microsoft Visual Studio Solution File, Format Version 10.00\n";
@ -92,3 +93,9 @@ std::string cmGlobalVisualStudio9Generator::GetUserMacrosDirectory()
// the Registry value // the Registry value
return path; return path;
} }
//----------------------------------------------------------------------------
std::string cmGlobalVisualStudio9Generator::GetUserMacrosRegKeyBase()
{
return "Software\\Microsoft\\VisualStudio\\9.0\\vsmacros";
}

View File

@ -59,5 +59,11 @@ public:
* Studio does not implement support for VB macros. * Studio does not implement support for VB macros.
*/ */
virtual std::string GetUserMacrosDirectory(); virtual std::string GetUserMacrosDirectory();
/**
* What is the reg key path to "vsmacros" for this version of Visual
* Studio?
*/
virtual std::string GetUserMacrosRegKeyBase();
}; };
#endif #endif

View File

@ -68,19 +68,21 @@ void cmGlobalVisualStudioGenerator::Generate()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile, bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
const std::string& regKeyBase,
std::string& nextAvailableSubKeyName); std::string& nextAvailableSubKeyName);
void RegisterVisualStudioMacros(const std::string& macrosFile); void RegisterVisualStudioMacros(const std::string& macrosFile,
const std::string& regKeyBase);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
#define CMAKE_VSMACROS_FILENAME \ #define CMAKE_VSMACROS_FILENAME \
"CMakeVSMacros1.vsmacros" "CMakeVSMacros2.vsmacros"
#define CMAKE_VSMACROS_RELOAD_MACRONAME \ #define CMAKE_VSMACROS_RELOAD_MACRONAME \
"Macros.CMakeVSMacros1.Macros.ReloadProjects" "Macros.CMakeVSMacros2.Macros.ReloadProjects"
#define CMAKE_VSMACROS_STOP_MACRONAME \ #define CMAKE_VSMACROS_STOP_MACRONAME \
"Macros.CMakeVSMacros1.Macros.StopBuild" "Macros.CMakeVSMacros2.Macros.StopBuild"
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros() void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros()
@ -113,7 +115,7 @@ void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros()
} }
} }
RegisterVisualStudioMacros(dst); RegisterVisualStudioMacros(dst, this->GetUserMacrosRegKeyBase());
} }
} }
@ -140,7 +142,8 @@ cmGlobalVisualStudioGenerator
std::string macrosFile = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME; std::string macrosFile = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
std::string nextSubkeyName; std::string nextSubkeyName;
if (cmSystemTools::FileExists(macrosFile.c_str()) && if (cmSystemTools::FileExists(macrosFile.c_str()) &&
IsVisualStudioMacrosFileRegistered(macrosFile, nextSubkeyName) IsVisualStudioMacrosFileRegistered(macrosFile,
this->GetUserMacrosRegKeyBase(), nextSubkeyName)
) )
{ {
std::string topLevelSlnName; std::string topLevelSlnName;
@ -194,6 +197,12 @@ std::string cmGlobalVisualStudioGenerator::GetUserMacrosDirectory()
return ""; return "";
} }
//----------------------------------------------------------------------------
std::string cmGlobalVisualStudioGenerator::GetUserMacrosRegKeyBase()
{
return "";
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalVisualStudioGenerator::FixUtilityDepends() void cmGlobalVisualStudioGenerator::FixUtilityDepends()
{ {
@ -396,6 +405,7 @@ cmGlobalVisualStudioGenerator::GetUtilityForTarget(cmTarget& target,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile, bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
const std::string& regKeyBase,
std::string& nextAvailableSubKeyName) std::string& nextAvailableSubKeyName)
{ {
bool macrosRegistered = false; bool macrosRegistered = false;
@ -413,8 +423,7 @@ bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
LONG result = ERROR_SUCCESS; LONG result = ERROR_SUCCESS;
DWORD index = 0; DWORD index = 0;
keyname = keyname = regKeyBase + "\\OtherProjects7";
"Software\\Microsoft\\VisualStudio\\8.0\\vsmacros\\OtherProjects7";
hkey = NULL; hkey = NULL;
result = RegOpenKeyEx(HKEY_CURRENT_USER, keyname.c_str(), result = RegOpenKeyEx(HKEY_CURRENT_USER, keyname.c_str(),
0, KEY_READ, &hkey); 0, KEY_READ, &hkey);
@ -517,8 +526,7 @@ bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
nextAvailableSubKeyName = ossNext.str(); nextAvailableSubKeyName = ossNext.str();
keyname = keyname = regKeyBase + "\\RecordingProject7";
"Software\\Microsoft\\VisualStudio\\8.0\\vsmacros\\RecordingProject7";
hkey = NULL; hkey = NULL;
result = RegOpenKeyEx(HKEY_CURRENT_USER, keyname.c_str(), result = RegOpenKeyEx(HKEY_CURRENT_USER, keyname.c_str(),
0, KEY_READ, &hkey); 0, KEY_READ, &hkey);
@ -567,10 +575,10 @@ bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void WriteVSMacrosFileRegistryEntry( void WriteVSMacrosFileRegistryEntry(
const std::string& nextAvailableSubKeyName, const std::string& nextAvailableSubKeyName,
const std::string& macrosFile) const std::string& macrosFile,
const std::string& regKeyBase)
{ {
std::string keyname = std::string keyname = regKeyBase + "\\OtherProjects7";
"Software\\Microsoft\\VisualStudio\\8.0\\vsmacros\\OtherProjects7";
HKEY hkey = NULL; HKEY hkey = NULL;
LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, keyname.c_str(), 0, LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, keyname.c_str(), 0,
KEY_READ|KEY_WRITE, &hkey); KEY_READ|KEY_WRITE, &hkey);
@ -634,13 +642,14 @@ void WriteVSMacrosFileRegistryEntry(
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void RegisterVisualStudioMacros(const std::string& macrosFile) void RegisterVisualStudioMacros(const std::string& macrosFile,
const std::string& regKeyBase)
{ {
bool macrosRegistered; bool macrosRegistered;
std::string nextAvailableSubKeyName; std::string nextAvailableSubKeyName;
macrosRegistered = IsVisualStudioMacrosFileRegistered(macrosFile, macrosRegistered = IsVisualStudioMacrosFileRegistered(macrosFile,
nextAvailableSubKeyName); regKeyBase, nextAvailableSubKeyName);
if (!macrosRegistered) if (!macrosRegistered)
{ {
@ -681,7 +690,7 @@ void RegisterVisualStudioMacros(const std::string& macrosFile)
// //
if (0 == count) if (0 == count)
{ {
IsVisualStudioMacrosFileRegistered(macrosFile, IsVisualStudioMacrosFileRegistered(macrosFile, regKeyBase,
nextAvailableSubKeyName); nextAvailableSubKeyName);
} }
} }
@ -690,7 +699,8 @@ void RegisterVisualStudioMacros(const std::string& macrosFile)
// //
if (0 == count) if (0 == count)
{ {
WriteVSMacrosFileRegistryEntry(nextAvailableSubKeyName, macrosFile); WriteVSMacrosFileRegistryEntry(nextAvailableSubKeyName, macrosFile,
regKeyBase);
} }
} }
} }

View File

@ -49,6 +49,12 @@ public:
*/ */
virtual std::string GetUserMacrosDirectory(); virtual std::string GetUserMacrosDirectory();
/**
* What is the reg key path to "vsmacros" for this version of Visual
* Studio?
*/
virtual std::string GetUserMacrosRegKeyBase();
enum MacroName {MacroReload, MacroStop}; enum MacroName {MacroReload, MacroStop};
/** /**

Binary file not shown.