BUG: Using a better technique to produce the rule file name for a custom command when the output is not in the current directory or lower.

This commit is contained in:
Brad King 2005-02-24 12:19:20 -05:00
parent a21c0449ab
commit b40745c925
2 changed files with 12 additions and 32 deletions

View File

@ -659,8 +659,15 @@ cmLocalUnixMakefileGenerator2
std::string dir = "CMakeCustomRules.dir"; std::string dir = "CMakeCustomRules.dir";
cmSystemTools::MakeDirectory(this->ConvertToFullPath(dir).c_str()); cmSystemTools::MakeDirectory(this->ConvertToFullPath(dir).c_str());
// Construct the name of the rule file. // Convert the output name to a relative path if possible.
std::string customName = this->GetCustomBaseName(cc); std::string output = this->ConvertToRelativePath(cc.GetOutput());
// Construct the name of the rule file by transforming the output
// name to a valid file name. Since the output is already a file
// everything but the path characters is valid.
std::string customName = output;
cmSystemTools::ReplaceString(customName, "../", "___");
cmSystemTools::ReplaceString(customName, "/", "_");
std::string ruleFileName = dir; std::string ruleFileName = dir;
ruleFileName += "/"; ruleFileName += "/";
ruleFileName += customName; ruleFileName += customName;
@ -689,7 +696,7 @@ cmLocalUnixMakefileGenerator2
} }
this->WriteDisclaimer(ruleFileStream); this->WriteDisclaimer(ruleFileStream);
ruleFileStream ruleFileStream
<< "# Custom command rule file for " << customName.c_str() << ".\n\n"; << "# Custom command rule file for " << output.c_str() << ".\n\n";
// Collect the commands. // Collect the commands.
std::vector<std::string> commands; std::vector<std::string> commands;
@ -709,13 +716,13 @@ cmLocalUnixMakefileGenerator2
comment = cc.GetComment(); comment = cc.GetComment();
} }
std::string preEcho = "Generating "; std::string preEcho = "Generating ";
preEcho += customName; preEcho += output;
preEcho += "..."; preEcho += "...";
this->WriteMakeRule(ruleFileStream, comment, preEcho.c_str(), this->WriteMakeRule(ruleFileStream, comment, preEcho.c_str(),
cc.GetOutput(), depends, commands); cc.GetOutput(), depends, commands);
// Write the clean rule for this custom command. // Write the clean rule for this custom command.
std::string cleanTarget = customName; std::string cleanTarget = output;
cleanTarget += ".clean"; cleanTarget += ".clean";
commands.clear(); commands.clear();
depends.clear(); depends.clear();
@ -2280,32 +2287,6 @@ cmLocalUnixMakefileGenerator2
return obj; return obj;
} }
//----------------------------------------------------------------------------
std::string
cmLocalUnixMakefileGenerator2
::GetCustomBaseName(const cmCustomCommand& cc)
{
// If the full path to the output file includes this build
// directory, we want to use the relative path for the filename of
// the custom file. Otherwise, we will use just the filename
// portion.
std::string customName;
if(cmSystemTools::FileIsFullPath(cc.GetOutput()) &&
(std::string(cc.GetOutput()).find(m_Makefile->GetStartOutputDirectory()) == 0))
{
// Use the relative path but convert it to a valid file name.
customName =
cmSystemTools::RelativePath(m_Makefile->GetStartOutputDirectory(),
cc.GetOutput());
cmSystemTools::ReplaceString(customName, "/", "_");
}
else
{
customName = cmSystemTools::GetFilenameName(cc.GetOutput());
}
return customName;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* const char*
cmLocalUnixMakefileGenerator2 cmLocalUnixMakefileGenerator2

View File

@ -196,7 +196,6 @@ protected:
std::string GetSubdirTargetName(const char* pass, const char* subdir); std::string GetSubdirTargetName(const char* pass, const char* subdir);
std::string GetObjectFileName(const cmTarget& target, std::string GetObjectFileName(const cmTarget& target,
const cmSourceFile& source); const cmSourceFile& source);
std::string GetCustomBaseName(const cmCustomCommand& cc);
const char* GetSourceFileLanguage(const cmSourceFile& source); const char* GetSourceFileLanguage(const cmSourceFile& source);
std::string ConvertToFullPath(const std::string& localPath); std::string ConvertToFullPath(const std::string& localPath);
std::string ConvertToRelativePath(const char* p); std::string ConvertToRelativePath(const char* p);