BUG: Fix/cleanup custom commands and custom targets. Make empty comment strings work. Fix ZERO_CHECK target always out of date for debugging. Fix Makefile driving of custom commands in a custom target. Fix dependencies on custom targets not in ALL in VS generators.

This commit is contained in:
Brad King 2006-09-28 16:40:35 -04:00
parent 7d2de52c1a
commit 9a1d4e92eb
19 changed files with 112 additions and 56 deletions

View File

@ -32,8 +32,9 @@ bool cmAddCustomCommandCommand::InitialPass(
return false; return false;
} }
std::string source, target, comment, main_dependency, std::string source, target, main_dependency, working;
working; std::string comment_buffer;
const char* comment = 0;
std::vector<std::string> depends, outputs, output; std::vector<std::string> depends, outputs, output;
bool verbatim = false; bool verbatim = false;
@ -178,7 +179,8 @@ bool cmAddCustomCommandCommand::InitialPass(
outputs.push_back(filename); outputs.push_back(filename);
break; break;
case doing_comment: case doing_comment:
comment = copy; comment_buffer = copy;
comment = comment_buffer.c_str();
break; break;
default: default:
this->SetError("Wrong syntax. Unknown type of argument."); this->SetError("Wrong syntax. Unknown type of argument.");
@ -223,7 +225,7 @@ bool cmAddCustomCommandCommand::InitialPass(
std::vector<std::string> no_depends; std::vector<std::string> no_depends;
this->Makefile->AddCustomCommandToTarget(target.c_str(), no_depends, this->Makefile->AddCustomCommandToTarget(target.c_str(), no_depends,
commandLines, cctype, commandLines, cctype,
comment.c_str(), working.c_str(), comment, working.c_str(),
escapeOldStyle); escapeOldStyle);
} }
else if(target.empty()) else if(target.empty())
@ -231,7 +233,7 @@ bool cmAddCustomCommandCommand::InitialPass(
// Target is empty, use the output. // Target is empty, use the output.
this->Makefile->AddCustomCommandToOutput(output, depends, this->Makefile->AddCustomCommandToOutput(output, depends,
main_dependency.c_str(), main_dependency.c_str(),
commandLines, comment.c_str(), commandLines, comment,
working.c_str(), false, working.c_str(), false,
escapeOldStyle); escapeOldStyle);
} }
@ -240,7 +242,7 @@ bool cmAddCustomCommandCommand::InitialPass(
// Use the old-style mode for backward compatibility. // Use the old-style mode for backward compatibility.
this->Makefile->AddCustomCommandOldStyle(target.c_str(), outputs, depends, this->Makefile->AddCustomCommandOldStyle(target.c_str(), outputs, depends,
source.c_str(), commandLines, source.c_str(), commandLines,
comment.c_str()); comment);
} }
return true; return true;
} }

View File

@ -19,6 +19,7 @@
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmCustomCommand::cmCustomCommand() cmCustomCommand::cmCustomCommand()
{ {
this->HaveComment = false;
this->EscapeOldStyle = true; this->EscapeOldStyle = true;
this->EscapeAllowMakeVars = false; this->EscapeAllowMakeVars = false;
this->Used = false; this->Used = false;
@ -29,6 +30,7 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
Outputs(r.Outputs), Outputs(r.Outputs),
Depends(r.Depends), Depends(r.Depends),
CommandLines(r.CommandLines), CommandLines(r.CommandLines),
HaveComment(r.HaveComment),
Comment(r.Comment), Comment(r.Comment),
WorkingDirectory(r.WorkingDirectory), WorkingDirectory(r.WorkingDirectory),
EscapeAllowMakeVars(r.EscapeAllowMakeVars), EscapeAllowMakeVars(r.EscapeAllowMakeVars),
@ -41,13 +43,16 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
cmCustomCommand::cmCustomCommand(const std::vector<std::string>& outputs, cmCustomCommand::cmCustomCommand(const std::vector<std::string>& outputs,
const std::vector<std::string>& depends, const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, const cmCustomCommandLines& commandLines,
const char* comment, const char* comment,
const char* workingDirectory): const char* workingDirectory):
Outputs(outputs), Outputs(outputs),
Depends(depends), Depends(depends),
CommandLines(commandLines), CommandLines(commandLines),
HaveComment(comment?true:false),
Comment(comment?comment:""), Comment(comment?comment:""),
WorkingDirectory(workingDirectory?workingDirectory:"") WorkingDirectory(workingDirectory?workingDirectory:""),
EscapeAllowMakeVars(false),
EscapeOldStyle(true)
{ {
this->EscapeOldStyle = true; this->EscapeOldStyle = true;
this->EscapeAllowMakeVars = false; this->EscapeAllowMakeVars = false;
@ -85,7 +90,8 @@ const cmCustomCommandLines& cmCustomCommand::GetCommandLines() const
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* cmCustomCommand::GetComment() const const char* cmCustomCommand::GetComment() const
{ {
return this->Comment.c_str(); const char* no_comment = 0;
return this->HaveComment? this->Comment.c_str() : no_comment;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -70,6 +70,7 @@ private:
std::vector<std::string> Outputs; std::vector<std::string> Outputs;
std::vector<std::string> Depends; std::vector<std::string> Depends;
cmCustomCommandLines CommandLines; cmCustomCommandLines CommandLines;
bool HaveComment;
std::string Comment; std::string Comment;
std::string WorkingDirectory; std::string WorkingDirectory;
bool EscapeAllowMakeVars; bool EscapeAllowMakeVars;

View File

@ -253,14 +253,14 @@ void cmGlobalVisualStudio71Generator
cmCustomCommand cc = l->second.GetPostBuildCommands()[0]; cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
const cmCustomCommandLines& cmds = cc.GetCommandLines(); const cmCustomCommandLines& cmds = cc.GetCommandLines();
std::string project = cmds[0][0]; std::string project = cmds[0][0];
this->WriteProjectConfigurations(fout, project.c_str(), this->WriteProjectConfigurations(fout, project.c_str(),
l->second.IsInAll()); l->second.GetType());
} }
else if ((l->second.GetType() != cmTarget::INSTALL_FILES) else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
&& (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)) && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
{ {
this->WriteProjectConfigurations(fout, si->c_str(), this->WriteProjectConfigurations(fout, si->c_str(),
l->second.IsInAll()); l->second.GetType());
++si; ++si;
} }
} }
@ -415,19 +415,18 @@ 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
::WriteProjectConfigurations(std::ostream& fout, ::WriteProjectConfigurations(std::ostream& fout, const char* name,
const char* name, int targetType)
bool in_all_build)
{ {
std::string guid = this->GetGUID(name); std::string guid = this->GetGUID(name);
for(std::vector<std::string>::iterator i = this->Configurations.begin(); for(std::vector<std::string>::iterator i = this->Configurations.begin();
i != this->Configurations.end(); ++i) i != this->Configurations.end(); ++i)
{ {
fout << "\t\t{" << guid << "}." << *i fout << "\t\t{" << guid << "}." << *i
<< ".ActiveCfg = " << *i << "|Win32\n"; << ".ActiveCfg = " << *i << "|Win32\n";
if (in_all_build) if(targetType != cmTarget::GLOBAL_TARGET)
{ {
fout << "\t\t{" << guid << "}." << *i fout << "\t\t{" << guid << "}." << *i
<< ".Build.0 = " << *i << "|Win32\n"; << ".Build.0 = " << *i << "|Win32\n";
} }
} }

View File

@ -53,9 +53,9 @@ protected:
const char* name, const char* path, cmTarget &t); const char* name, const char* path, cmTarget &t);
virtual void WriteProjectDepends(std::ostream& fout, virtual void WriteProjectDepends(std::ostream& fout,
const char* name, const char* path, cmTarget &t); const char* name, const char* path, cmTarget &t);
virtual void WriteProjectConfigurations(std::ostream& fout, virtual void WriteProjectConfigurations(std::ostream& fout,
const char* name, const char* name,
bool in_all); int targetType);
virtual void WriteExternalProject(std::ostream& fout, const char* name, virtual void WriteExternalProject(std::ostream& fout, const char* name,
const char* path, const char* path,
const std::vector<std::string>& depends); const std::vector<std::string>& depends);

View File

@ -536,14 +536,14 @@ void cmGlobalVisualStudio7Generator
cmCustomCommand cc = l->second.GetPostBuildCommands()[0]; cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
const cmCustomCommandLines& cmds = cc.GetCommandLines(); const cmCustomCommandLines& cmds = cc.GetCommandLines();
std::string name = cmds[0][0]; std::string name = cmds[0][0];
this->WriteProjectConfigurations(fout, name.c_str(), this->WriteProjectConfigurations(fout, name.c_str(),
l->second.IsInAll()); l->second.GetType());
} }
else if ((l->second.GetType() != cmTarget::INSTALL_FILES) else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
&& (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)) && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
{ {
this->WriteProjectConfigurations(fout, si->c_str(), this->WriteProjectConfigurations(fout, si->c_str(),
l->second.IsInAll()); l->second.GetType());
++si; ++si;
} }
} }
@ -651,19 +651,18 @@ cmGlobalVisualStudio7Generator
// 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 cmGlobalVisualStudio7Generator void cmGlobalVisualStudio7Generator
::WriteProjectConfigurations(std::ostream& fout, ::WriteProjectConfigurations(std::ostream& fout, const char* name,
const char* name, int targetType)
bool in_all_build)
{ {
std::string guid = this->GetGUID(name); std::string guid = this->GetGUID(name);
for(std::vector<std::string>::iterator i = this->Configurations.begin(); for(std::vector<std::string>::iterator i = this->Configurations.begin();
i != this->Configurations.end(); ++i) i != this->Configurations.end(); ++i)
{ {
fout << "\t\t{" << guid << "}." << *i fout << "\t\t{" << guid << "}." << *i
<< ".ActiveCfg = " << *i << "|Win32\n"; << ".ActiveCfg = " << *i << "|Win32\n";
if (in_all_build) if(targetType != cmTarget::GLOBAL_TARGET)
{ {
fout << "\t\t{" << guid << "}." << *i fout << "\t\t{" << guid << "}." << *i
<< ".Build.0 = " << *i << "|Win32\n"; << ".Build.0 = " << *i << "|Win32\n";
} }
} }

View File

@ -105,9 +105,9 @@ protected:
const char* name, const char* path, cmTarget &t); const char* name, const char* path, cmTarget &t);
virtual void WriteProjectDepends(std::ostream& fout, virtual void WriteProjectDepends(std::ostream& fout,
const char* name, const char* path, cmTarget &t); const char* name, const char* path, cmTarget &t);
virtual void WriteProjectConfigurations(std::ostream& fout, virtual void WriteProjectConfigurations(std::ostream& fout,
const char* name, const char* name,
bool in_all); int targetType);
virtual void WriteSLNFooter(std::ostream& fout); virtual void WriteSLNFooter(std::ostream& fout);
virtual void WriteSLNHeader(std::ostream& fout); virtual void WriteSLNHeader(std::ostream& fout);
virtual void AddPlatformDefinitions(cmMakefile* mf); virtual void AddPlatformDefinitions(cmMakefile* mf);

View File

@ -227,20 +227,20 @@ cmGlobalVisualStudio8Generator
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void void
cmGlobalVisualStudio8Generator cmGlobalVisualStudio8Generator
::WriteProjectConfigurations(std::ostream& fout, ::WriteProjectConfigurations(std::ostream& fout, const char* name,
const char* name, bool in_all_build) int targetType)
{ {
std::string guid = this->GetGUID(name); std::string guid = this->GetGUID(name);
for(std::vector<std::string>::iterator i = this->Configurations.begin(); for(std::vector<std::string>::iterator i = this->Configurations.begin();
i != this->Configurations.end(); ++i) i != this->Configurations.end(); ++i)
{ {
fout << "\t\t{" << guid << "}." << *i fout << "\t\t{" << guid << "}." << *i
<< "|" << this->PlatformName << ".ActiveCfg = " << "|" << this->PlatformName << ".ActiveCfg = "
<< *i << "|" << this->PlatformName << "\n"; << *i << "|" << this->PlatformName << "\n";
if (in_all_build) if(targetType != cmTarget::GLOBAL_TARGET)
{ {
fout << "\t\t{" << guid << "}." << *i fout << "\t\t{" << guid << "}." << *i
<< "|" << this->PlatformName << ".Build.0 = " << "|" << this->PlatformName << ".Build.0 = "
<< *i << "|" << this->PlatformName << "\n"; << *i << "|" << this->PlatformName << "\n";
} }
} }

View File

@ -56,7 +56,8 @@ protected:
virtual void WriteSLNHeader(std::ostream& fout); virtual void WriteSLNHeader(std::ostream& fout);
virtual void WriteSolutionConfigurations(std::ostream& fout); virtual void WriteSolutionConfigurations(std::ostream& fout);
virtual void WriteProjectConfigurations(std::ostream& fout, virtual void WriteProjectConfigurations(std::ostream& fout,
const char* name, bool in_all); const char* name,
int targetType);
std::string PlatformName; // Win32 or x64 std::string PlatformName; // Win32 or x64
}; };
#endif #endif

View File

@ -1910,7 +1910,7 @@ cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
const char* default_comment) const char* default_comment)
{ {
// Check for a comment provided with the command. // Check for a comment provided with the command.
if(cc.GetComment() && *cc.GetComment()) if(cc.GetComment())
{ {
return cc.GetComment(); return cc.GetComment();
} }

View File

@ -44,11 +44,11 @@ void cmLocalVisualStudio7Generator::Generate()
lang.insert("IDL"); lang.insert("IDL");
lang.insert("DEF"); lang.insert("DEF");
this->CreateCustomTargetsAndCommands(lang); this->CreateCustomTargetsAndCommands(lang);
this->FixTargets(); this->FixGlobalTargets();
this->OutputVCProjFile(); this->OutputVCProjFile();
} }
void cmLocalVisualStudio7Generator::FixTargets() void cmLocalVisualStudio7Generator::FixGlobalTargets()
{ {
// Visual Studio .NET 2003 Service Pack 1 will not run post-build // Visual Studio .NET 2003 Service Pack 1 will not run post-build
// commands for targets in which no sources are built. Add dummy // commands for targets in which no sources are built. Add dummy
@ -58,8 +58,7 @@ void cmLocalVisualStudio7Generator::FixTargets()
l != tgts.end(); l++) l != tgts.end(); l++)
{ {
cmTarget& tgt = l->second; cmTarget& tgt = l->second;
if(tgt.GetType() == cmTarget::GLOBAL_TARGET || if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
tgt.GetType() == cmTarget::UTILITY)
{ {
std::vector<std::string> no_depends; std::vector<std::string> no_depends;
cmCustomCommandLine force_command; cmCustomCommandLine force_command;

View File

@ -71,7 +71,7 @@ private:
std::string& flags); std::string& flags);
std::string GetBuildTypeLinkerFlags(std::string rootLinkerFlags, std::string GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
const char* configName); const char* configName);
void FixTargets(); void FixGlobalTargets();
void OutputVCProjFile(); void OutputVCProjFile();
void WriteVCProjHeader(std::ostream& fout, const char *libName, void WriteVCProjHeader(std::ostream& fout, const char *libName,
cmTarget &tgt, std::vector<cmSourceGroup> &sgs); cmTarget &tgt, std::vector<cmSourceGroup> &sgs);

View File

@ -830,11 +830,21 @@ void cmMakefile::AddUtilityCommand(const char* utilityName, bool all,
target.SetType(cmTarget::UTILITY, utilityName); target.SetType(cmTarget::UTILITY, utilityName);
target.SetInAll(all); target.SetInAll(all);
target.SetMakefile(this); target.SetMakefile(this);
// Store the custom command in the target. // Store the custom command in the target.
std::vector<std::string> outputs; std::string force = this->GetStartOutputDirectory();
cmCustomCommand cc(outputs, depends, commandLines, 0, workingDirectory); force += cmake::GetCMakeFilesDirectory();
cc.SetEscapeOldStyle(escapeOldStyle); force += "/";
target.GetPostBuildCommands().push_back(cc); force += utilityName;
const char* no_main_dependency = 0;
const char* empty_comment = "";
bool no_replace = false;
this->AddCustomCommandToOutput(force.c_str(), depends,
no_main_dependency,
commandLines, empty_comment,
workingDirectory, no_replace,
escapeOldStyle);
target.GetSourceLists().push_back(force);
// Add the target to the set of targets. // Add the target to the set of targets.
cmTargets::iterator it = cmTargets::iterator it =

View File

@ -24,6 +24,12 @@
#include "cmTarget.h" #include "cmTarget.h"
#include "cmake.h" #include "cmake.h"
//----------------------------------------------------------------------------
cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator()
{
this->DriveCustomCommandsOnDepends = true;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefileExecutableTargetGenerator::WriteRuleFiles() void cmMakefileExecutableTargetGenerator::WriteRuleFiles()
{ {

View File

@ -22,6 +22,8 @@
class cmMakefileExecutableTargetGenerator: public cmMakefileTargetGenerator class cmMakefileExecutableTargetGenerator: public cmMakefileTargetGenerator
{ {
public: public:
cmMakefileExecutableTargetGenerator();
/* the main entry point for this class. Writes the Makefiles associated /* the main entry point for this class. Writes the Makefiles associated
with this target */ with this target */
virtual void WriteRuleFiles(); virtual void WriteRuleFiles();

View File

@ -26,6 +26,12 @@
#include <memory> // auto_ptr #include <memory> // auto_ptr
//----------------------------------------------------------------------------
cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator()
{
this->DriveCustomCommandsOnDepends = true;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefileLibraryTargetGenerator::WriteRuleFiles() void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
{ {

View File

@ -23,6 +23,8 @@ class cmMakefileLibraryTargetGenerator:
public cmMakefileTargetGenerator public cmMakefileTargetGenerator
{ {
public: public:
cmMakefileLibraryTargetGenerator();
/* the main entry point for this class. Writes the Makefiles associated /* the main entry point for this class. Writes the Makefiles associated
with this target */ with this target */
virtual void WriteRuleFiles(); virtual void WriteRuleFiles();

View File

@ -35,6 +35,7 @@ cmMakefileTargetGenerator::cmMakefileTargetGenerator()
this->BuildFileStream = 0; this->BuildFileStream = 0;
this->InfoFileStream = 0; this->InfoFileStream = 0;
this->FlagFileStream = 0; this->FlagFileStream = 0;
this->DriveCustomCommandsOnDepends = false;
} }
cmMakefileTargetGenerator * cmMakefileTargetGenerator *
@ -775,6 +776,23 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
commands.push_back(depCmd.str()); commands.push_back(depCmd.str());
// Make sure all custom command outputs in this target are built. // Make sure all custom command outputs in this target are built.
if(this->DriveCustomCommandsOnDepends)
{
this->DriveCustomCommands(depends);
}
// Write the rule.
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
depMark.c_str(),
depends, commands, false);
}
//----------------------------------------------------------------------------
void
cmMakefileTargetGenerator
::DriveCustomCommands(std::vector<std::string>& depends)
{
// Depend on all custom command outputs.
const std::vector<cmSourceFile*>& sources = const std::vector<cmSourceFile*>& sources =
this->Target->GetSourceFiles(); this->Target->GetSourceFiles();
for(std::vector<cmSourceFile*>::const_iterator source = sources.begin(); for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
@ -790,11 +808,6 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
} }
} }
} }
// Write the rule.
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
depMark.c_str(),
depends, commands, false);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -1040,6 +1053,12 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule(const char* main_output,
{ {
// Setup the comment for the main build driver. // Setup the comment for the main build driver.
comment = "Rule to build all files generated by this target."; comment = "Rule to build all files generated by this target.";
// Make sure all custom command outputs in this target are built.
if(!this->DriveCustomCommandsOnDepends)
{
this->DriveCustomCommands(depends);
}
} }
// Write the driver rule. // Write the driver rule.

View File

@ -107,6 +107,8 @@ protected:
// write the driver rule to build target outputs // write the driver rule to build target outputs
void WriteTargetDriverRule(const char* main_output, bool relink); void WriteTargetDriverRule(const char* main_output, bool relink);
void DriveCustomCommands(std::vector<std::string>& depends);
// Return the a string with -F flags on apple // Return the a string with -F flags on apple
std::string GetFrameworkFlags(); std::string GetFrameworkFlags();
@ -122,6 +124,8 @@ protected:
cmGlobalGenerator *GlobalGenerator; cmGlobalGenerator *GlobalGenerator;
cmMakefile *Makefile; cmMakefile *Makefile;
bool DriveCustomCommandsOnDepends;
// the full path to the build file // the full path to the build file
std::string BuildFileName; std::string BuildFileName;
std::string BuildFileNameFull; std::string BuildFileNameFull;