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

View File

@ -19,6 +19,7 @@
//----------------------------------------------------------------------------
cmCustomCommand::cmCustomCommand()
{
this->HaveComment = false;
this->EscapeOldStyle = true;
this->EscapeAllowMakeVars = false;
this->Used = false;
@ -29,6 +30,7 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
Outputs(r.Outputs),
Depends(r.Depends),
CommandLines(r.CommandLines),
HaveComment(r.HaveComment),
Comment(r.Comment),
WorkingDirectory(r.WorkingDirectory),
EscapeAllowMakeVars(r.EscapeAllowMakeVars),
@ -46,8 +48,11 @@ cmCustomCommand::cmCustomCommand(const std::vector<std::string>& outputs,
Outputs(outputs),
Depends(depends),
CommandLines(commandLines),
HaveComment(comment?true:false),
Comment(comment?comment:""),
WorkingDirectory(workingDirectory?workingDirectory:"")
WorkingDirectory(workingDirectory?workingDirectory:""),
EscapeAllowMakeVars(false),
EscapeOldStyle(true)
{
this->EscapeOldStyle = true;
this->EscapeAllowMakeVars = false;
@ -85,7 +90,8 @@ const cmCustomCommandLines& cmCustomCommand::GetCommandLines() 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> Depends;
cmCustomCommandLines CommandLines;
bool HaveComment;
std::string Comment;
std::string WorkingDirectory;
bool EscapeAllowMakeVars;

View File

@ -254,13 +254,13 @@ void cmGlobalVisualStudio71Generator
const cmCustomCommandLines& cmds = cc.GetCommandLines();
std::string project = cmds[0][0];
this->WriteProjectConfigurations(fout, project.c_str(),
l->second.IsInAll());
l->second.GetType());
}
else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
&& (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
{
this->WriteProjectConfigurations(fout, si->c_str(),
l->second.IsInAll());
l->second.GetType());
++si;
}
}
@ -415,9 +415,8 @@ void cmGlobalVisualStudio71Generator
// Write a dsp file into the SLN file, Note, that dependencies from
// executables to the libraries it uses are also done here
void cmGlobalVisualStudio71Generator
::WriteProjectConfigurations(std::ostream& fout,
const char* name,
bool in_all_build)
::WriteProjectConfigurations(std::ostream& fout, const char* name,
int targetType)
{
std::string guid = this->GetGUID(name);
for(std::vector<std::string>::iterator i = this->Configurations.begin();
@ -425,7 +424,7 @@ void cmGlobalVisualStudio71Generator
{
fout << "\t\t{" << guid << "}." << *i
<< ".ActiveCfg = " << *i << "|Win32\n";
if (in_all_build)
if(targetType != cmTarget::GLOBAL_TARGET)
{
fout << "\t\t{" << guid << "}." << *i
<< ".Build.0 = " << *i << "|Win32\n";

View File

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

View File

@ -537,13 +537,13 @@ void cmGlobalVisualStudio7Generator
const cmCustomCommandLines& cmds = cc.GetCommandLines();
std::string name = cmds[0][0];
this->WriteProjectConfigurations(fout, name.c_str(),
l->second.IsInAll());
l->second.GetType());
}
else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
&& (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
{
this->WriteProjectConfigurations(fout, si->c_str(),
l->second.IsInAll());
l->second.GetType());
++si;
}
}
@ -651,9 +651,8 @@ cmGlobalVisualStudio7Generator
// Write a dsp file into the SLN file, Note, that dependencies from
// executables to the libraries it uses are also done here
void cmGlobalVisualStudio7Generator
::WriteProjectConfigurations(std::ostream& fout,
const char* name,
bool in_all_build)
::WriteProjectConfigurations(std::ostream& fout, const char* name,
int targetType)
{
std::string guid = this->GetGUID(name);
for(std::vector<std::string>::iterator i = this->Configurations.begin();
@ -661,7 +660,7 @@ void cmGlobalVisualStudio7Generator
{
fout << "\t\t{" << guid << "}." << *i
<< ".ActiveCfg = " << *i << "|Win32\n";
if (in_all_build)
if(targetType != cmTarget::GLOBAL_TARGET)
{
fout << "\t\t{" << guid << "}." << *i
<< ".Build.0 = " << *i << "|Win32\n";

View File

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

View File

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

View File

@ -56,7 +56,8 @@ protected:
virtual void WriteSLNHeader(std::ostream& fout);
virtual void WriteSolutionConfigurations(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
};
#endif

View File

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

View File

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

View File

@ -71,7 +71,7 @@ private:
std::string& flags);
std::string GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
const char* configName);
void FixTargets();
void FixGlobalTargets();
void OutputVCProjFile();
void WriteVCProjHeader(std::ostream& fout, const char *libName,
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.SetInAll(all);
target.SetMakefile(this);
// Store the custom command in the target.
std::vector<std::string> outputs;
cmCustomCommand cc(outputs, depends, commandLines, 0, workingDirectory);
cc.SetEscapeOldStyle(escapeOldStyle);
target.GetPostBuildCommands().push_back(cc);
std::string force = this->GetStartOutputDirectory();
force += cmake::GetCMakeFilesDirectory();
force += "/";
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.
cmTargets::iterator it =

View File

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

View File

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

View File

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

View File

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

View File

@ -35,6 +35,7 @@ cmMakefileTargetGenerator::cmMakefileTargetGenerator()
this->BuildFileStream = 0;
this->InfoFileStream = 0;
this->FlagFileStream = 0;
this->DriveCustomCommandsOnDepends = false;
}
cmMakefileTargetGenerator *
@ -775,6 +776,23 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
commands.push_back(depCmd.str());
// 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 =
this->Target->GetSourceFiles();
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.
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.

View File

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