VS10: Avoid creating .rule files next to outputs (#13141)

Hide custom command .rule files inside the CMakeFiles directory.  Ensure
a short, deterministic, and unique name by using a hash of the directory
path containing the output file.  Preserve the file name so the entry in
the IDE is human-readable.  Clarify the comment that explains why the
rule file must be created on disk.
This commit is contained in:
Brad King 2012-04-18 15:50:49 -04:00
parent 369e3464be
commit 72333a4648
3 changed files with 24 additions and 1 deletions

View File

@ -212,3 +212,21 @@ bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
return false; return false;
} }
} }
//----------------------------------------------------------------------------
std::string
cmGlobalVisualStudio10Generator
::GenerateRuleFile(std::string const& output) const
{
// The VS 10 generator needs to create the .rule files on disk.
// Hide them away under the CMakeFiles directory.
std::string ruleDir = this->GetCMakeInstance()->GetHomeOutputDirectory();
ruleDir += cmake::GetCMakeFilesDirectory();
ruleDir += "/";
ruleDir += cmSystemTools::ComputeStringMD5(
cmSystemTools::GetFilenamePath(output).c_str());
std::string ruleFile = ruleDir + "/";
ruleFile += cmSystemTools::GetFilenameName(output);
ruleFile += ".rule";
return ruleFile;
}

View File

@ -75,6 +75,10 @@ public:
virtual const char* GetCMakeCFGIntDir() const virtual const char* GetCMakeCFGIntDir() const
{ return "$(Configuration)";} { return "$(Configuration)";}
bool Find64BitTools(cmMakefile* mf); bool Find64BitTools(cmMakefile* mf);
/** Generate an <output>.rule file path for a given command output. */
virtual std::string GenerateRuleFile(std::string const& output) const;
protected: protected:
virtual const char* GetIDEVersion() { return "10.0"; } virtual const char* GetIDEVersion() { return "10.0"; }

View File

@ -459,7 +459,8 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source,
command) command)
{ {
std::string sourcePath = source->GetFullPath(); std::string sourcePath = source->GetFullPath();
// the rule file seems to need to exist for vs10 // VS 10 will always rebuild a custom command attached to a .rule
// file that doesn't exist so create the file explicitly.
if (source->GetPropertyAsBool("__CMAKE_RULE")) if (source->GetPropertyAsBool("__CMAKE_RULE"))
{ {
if(!cmSystemTools::FileExists(sourcePath.c_str())) if(!cmSystemTools::FileExists(sourcePath.c_str()))