ENH: add custom commands for targets

This commit is contained in:
Bill Hoffman 2001-12-07 10:58:06 -05:00
parent 728d20302e
commit 30a56de4b7
4 changed files with 120 additions and 13 deletions

View File

@ -69,6 +69,15 @@ void cmBorlandMakefileGenerator::ComputeSystemInfo()
"CMAKE_ROOT has not been defined, bad GUI or driver program");
return;
}
std::string outdir = m_Makefile->GetCurrentOutputDirectory();
if(outdir.find('-') != std::string::npos)
{
std::string message = "The Borland command line tools do not support path names that have - in them. Please re-name your output directory and use _ instead of -.";
message += "\nYour path currently is: ";
message += outdir;
cmSystemTools::Error(message.c_str());
}
std::string fpath =
m_Makefile->GetDefinition("CMAKE_ROOT");
fpath += "/Templates/CMakeBorlandWindowsSystemConfig.cmake";
@ -357,11 +366,18 @@ void cmBorlandMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
}
command += "\n|\n";
std::string customCommands = this->CreateTargetRules(t, name);
const char* cc = 0;
if(customCommands.size() > 0)
{
cc = customCommands.c_str();
}
this->OutputMakeRule(fout, "rules for a shared library",
target.c_str(),
depend.c_str(),
command.c_str(),
command2.c_str());
command2.c_str(),
cc);
}
void cmBorlandMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
@ -373,7 +389,7 @@ void cmBorlandMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
void cmBorlandMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
const char* name,
const cmTarget &)
const cmTarget &t)
{
std::string target = m_LibraryOutputPath + std::string(name) + ".lib";
cmSystemTools::ConvertToWindowsSlashes(target);
@ -391,12 +407,18 @@ void cmBorlandMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
command += "\n|\n";
std::string comment = "rule to build static library: ";
comment += name;
std::string customCommands = this->CreateTargetRules(t, name);
const char* cc = 0;
if(customCommands.size() > 0)
{
cc = customCommands.c_str();
}
this->OutputMakeRule(fout,
comment.c_str(),
target.c_str(),
depend.c_str(),
deleteCommand.c_str(),
command.c_str());
command.c_str(), cc);
}
void cmBorlandMakefileGenerator::OutputExecutableRule(std::ostream& fout,
@ -428,11 +450,17 @@ void cmBorlandMakefileGenerator::OutputExecutableRule(std::ostream& fout,
std::string comment = "rule to build executable: ";
comment += name;
std::string customCommands = this->CreateTargetRules(t, name);
const char* cc = 0;
if(customCommands.size() > 0)
{
cc = customCommands.c_str();
}
this->OutputMakeRule(fout,
comment.c_str(),
target.c_str(),
depend.c_str(),
command.c_str());
command.c_str(), cc);
}

View File

@ -459,10 +459,16 @@ void cmNMakeMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
command += "<<\n";
}
std::string customCommands = this->CreateTargetRules(t, name);
const char* cc = 0;
if(customCommands.size() > 0)
{
cc = customCommands.c_str();
}
this->OutputMakeRule(fout, "rules for a shared library",
target.c_str(),
depend.c_str(),
command.c_str());
command.c_str(), cc);
}
void cmNMakeMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
@ -474,7 +480,7 @@ void cmNMakeMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
void cmNMakeMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
const char* name,
const cmTarget &)
const cmTarget &t)
{
std::string target = m_LibraryOutputPath + std::string(name) + m_StaticLibraryExtension;
std::string depend = "$(";
@ -498,11 +504,17 @@ void cmNMakeMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
std::string comment = "rule to build static library: ";
comment += name;
std::string customCommands = this->CreateTargetRules(t, name);
const char* cc = 0;
if(customCommands.size() > 0)
{
cc = customCommands.c_str();
}
this->OutputMakeRule(fout,
comment.c_str(),
target.c_str(),
depend.c_str(),
command.c_str());
command.c_str(), cc);
}
void cmNMakeMakefileGenerator::OutputExecutableRule(std::ostream& fout,
@ -541,11 +553,17 @@ void cmNMakeMakefileGenerator::OutputExecutableRule(std::ostream& fout,
std::string comment = "rule to build executable: ";
comment += name;
std::string customCommands = this->CreateTargetRules(t, name);
const char* cc = 0;
if(customCommands.size() > 0)
{
cc = customCommands.c_str();
}
this->OutputMakeRule(fout,
comment.c_str(),
target.c_str(),
depend.c_str(),
command.c_str());
command.c_str(), cc);
}

View File

@ -545,6 +545,36 @@ void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
}
std::string cmUnixMakefileGenerator::CreateTargetRules(const cmTarget &target,
const char* targetName)
{
std::string customRuleCode = "";
bool initNext = false;
for (std::vector<cmCustomCommand>::const_iterator cr =
target.GetCustomCommands().begin();
cr != target.GetCustomCommands().end(); ++cr)
{
cmCustomCommand cc(*cr);
cc.ExpandVariables(*m_Makefile);
if (cc.GetSourceName() == targetName)
{
if(initNext)
{
customRuleCode += "\n\t";
}
else
{
initNext = true;
}
std::string command = cmSystemTools::EscapeSpaces(cc.GetCommand().c_str());
command = this->ConvertToNativePath(command.c_str());
customRuleCode += command + " " + cc.GetArguments();
}
}
return customRuleCode;
}
void cmUnixMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
const char* name,
const cmTarget &t)
@ -566,11 +596,18 @@ void cmUnixMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
linklibs << std::ends;
command2 += linklibs.str();
delete [] linklibs.str();
std::string customCommands = this->CreateTargetRules(t, name);
const char* cc = 0;
if(customCommands.size() > 0)
{
cc = customCommands.c_str();
}
this->OutputMakeRule(fout, "rules for a shared library",
target.c_str(),
depend.c_str(),
command.c_str(),
command2.c_str());
command2.c_str(),
cc);
}
void cmUnixMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
@ -591,17 +628,24 @@ void cmUnixMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
linklibs << std::ends;
command2 += linklibs.str();
delete [] linklibs.str();
std::string customCommands = this->CreateTargetRules(t, name);
const char* cc = 0;
if(customCommands.size() > 0)
{
cc = customCommands.c_str();
}
this->OutputMakeRule(fout, "rules for a shared module library",
target.c_str(),
depend.c_str(),
command.c_str(),
command2.c_str());
command2.c_str(),
cc);
}
void cmUnixMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
const char* name,
const cmTarget &)
const cmTarget &t)
{
std::string target = m_LibraryOutputPath + "lib" + std::string(name) + ".a";
std::string depend = "$(";
@ -618,12 +662,19 @@ void cmUnixMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
command2 += std::string(name) + ".a";
std::string comment = "rule to build static library: ";
comment += name;
std::string customCommands = this->CreateTargetRules(t, name);
const char* cc = 0;
if(customCommands.size() > 0)
{
cc = customCommands.c_str();
}
this->OutputMakeRule(fout,
comment.c_str(),
target.c_str(),
depend.c_str(),
command.c_str(),
command2.c_str());
command2.c_str(),
cc);
}
void cmUnixMakefileGenerator::OutputExecutableRule(std::ostream& fout,
@ -643,11 +694,19 @@ void cmUnixMakefileGenerator::OutputExecutableRule(std::ostream& fout,
command += " -o " + m_ExecutableOutputPath + name;
std::string comment = "rule to build executable: ";
comment += name;
std::string customCommands = this->CreateTargetRules(t, name);
const char* cc = 0;
if(customCommands.size() > 0)
{
cc = customCommands.c_str();
}
this->OutputMakeRule(fout,
comment.c_str(),
target.c_str(),
depend.c_str(),
command.c_str());
command.c_str(),
cc);
}

View File

@ -165,6 +165,8 @@ protected:
void SetSharedLibraryExtension(const char* e) {m_SharedLibraryExtension = e;}
void SetLibraryPrefix(const char* e) { m_LibraryPrefix = e;}
virtual std::string ConvertToNativePath(const char* s) { return s; }
std::string cmUnixMakefileGenerator::CreateTargetRules(const cmTarget &target,
const char* targetName);
protected:
std::string m_ExecutableOutputPath;
std::string m_LibraryOutputPath;