From 9a1d4e92eb6347dbe6d03cc861e284f6a4da5a6a Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 Sep 2006 16:40:35 -0400 Subject: 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. --- Source/cmAddCustomCommandCommand.cxx | 14 +++++++------ Source/cmCustomCommand.cxx | 12 ++++++++--- Source/cmCustomCommand.h | 1 + Source/cmGlobalVisualStudio71Generator.cxx | 19 ++++++++--------- Source/cmGlobalVisualStudio71Generator.h | 4 ++-- Source/cmGlobalVisualStudio7Generator.cxx | 19 ++++++++--------- Source/cmGlobalVisualStudio7Generator.h | 4 ++-- Source/cmGlobalVisualStudio8Generator.cxx | 14 ++++++------- Source/cmGlobalVisualStudio8Generator.h | 3 ++- Source/cmLocalGenerator.cxx | 2 +- Source/cmLocalVisualStudio7Generator.cxx | 7 +++---- Source/cmLocalVisualStudio7Generator.h | 2 +- Source/cmMakefile.cxx | 18 ++++++++++++---- Source/cmMakefileExecutableTargetGenerator.cxx | 6 ++++++ Source/cmMakefileExecutableTargetGenerator.h | 2 ++ Source/cmMakefileLibraryTargetGenerator.cxx | 6 ++++++ Source/cmMakefileLibraryTargetGenerator.h | 2 ++ Source/cmMakefileTargetGenerator.cxx | 29 +++++++++++++++++++++----- Source/cmMakefileTargetGenerator.h | 4 ++++ 19 files changed, 112 insertions(+), 56 deletions(-) diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index 3c37d4b..3f0dd26 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -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 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 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; } diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 621f7ca..e3fc69a 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -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), @@ -41,13 +43,16 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r): cmCustomCommand::cmCustomCommand(const std::vector& outputs, const std::vector& depends, const cmCustomCommandLines& commandLines, - const char* comment, + const char* comment, const char* workingDirectory): 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; } //---------------------------------------------------------------------------- diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index e493c5d..8f34297 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -70,6 +70,7 @@ private: std::vector Outputs; std::vector Depends; cmCustomCommandLines CommandLines; + bool HaveComment; std::string Comment; std::string WorkingDirectory; bool EscapeAllowMakeVars; diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx index 78631d9..0ca3250 100644 --- a/Source/cmGlobalVisualStudio71Generator.cxx +++ b/Source/cmGlobalVisualStudio71Generator.cxx @@ -253,14 +253,14 @@ void cmGlobalVisualStudio71Generator cmCustomCommand cc = l->second.GetPostBuildCommands()[0]; const cmCustomCommandLines& cmds = cc.GetCommandLines(); std::string project = cmds[0][0]; - this->WriteProjectConfigurations(fout, project.c_str(), - l->second.IsInAll()); + this->WriteProjectConfigurations(fout, project.c_str(), + 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()); + this->WriteProjectConfigurations(fout, si->c_str(), + l->second.GetType()); ++si; } } @@ -415,19 +415,18 @@ 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::iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { - fout << "\t\t{" << guid << "}." << *i + fout << "\t\t{" << guid << "}." << *i << ".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"; } } diff --git a/Source/cmGlobalVisualStudio71Generator.h b/Source/cmGlobalVisualStudio71Generator.h index 6ccf06a..e730b36 100644 --- a/Source/cmGlobalVisualStudio71Generator.h +++ b/Source/cmGlobalVisualStudio71Generator.h @@ -53,9 +53,9 @@ protected: const char* name, const char* path, cmTarget &t); virtual void WriteProjectDepends(std::ostream& fout, const char* name, const char* path, cmTarget &t); - virtual void WriteProjectConfigurations(std::ostream& fout, + 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& depends); diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 03595a3..22c6647 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -536,14 +536,14 @@ void cmGlobalVisualStudio7Generator cmCustomCommand cc = l->second.GetPostBuildCommands()[0]; const cmCustomCommandLines& cmds = cc.GetCommandLines(); std::string name = cmds[0][0]; - this->WriteProjectConfigurations(fout, name.c_str(), - l->second.IsInAll()); + this->WriteProjectConfigurations(fout, name.c_str(), + 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()); + this->WriteProjectConfigurations(fout, si->c_str(), + l->second.GetType()); ++si; } } @@ -651,19 +651,18 @@ 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::iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { - fout << "\t\t{" << guid << "}." << *i + fout << "\t\t{" << guid << "}." << *i << ".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"; } } diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 9ff97da..c8902cf 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -105,9 +105,9 @@ protected: const char* name, const char* path, cmTarget &t); virtual void WriteProjectDepends(std::ostream& fout, const char* name, const char* path, cmTarget &t); - virtual void WriteProjectConfigurations(std::ostream& fout, + 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); diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 1b3236b..bb87489 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -227,20 +227,20 @@ 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::iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { - fout << "\t\t{" << guid << "}." << *i - << "|" << this->PlatformName << ".ActiveCfg = " + 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 = " + fout << "\t\t{" << guid << "}." << *i + << "|" << this->PlatformName << ".Build.0 = " << *i << "|" << this->PlatformName << "\n"; } } diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h index b7cf038..fdc8316 100644 --- a/Source/cmGlobalVisualStudio8Generator.h +++ b/Source/cmGlobalVisualStudio8Generator.h @@ -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 diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index bcd05c3..fe89580 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -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(); } diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 2cdca06..463f8db 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -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 no_depends; cmCustomCommandLine force_command; diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index c4ea004..d52cc63 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -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 &sgs); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d99182c..8ad4139 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -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 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 = diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 5473bd6..65e2877 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -25,6 +25,12 @@ #include "cmake.h" //---------------------------------------------------------------------------- +cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator() +{ + this->DriveCustomCommandsOnDepends = true; +} + +//---------------------------------------------------------------------------- void cmMakefileExecutableTargetGenerator::WriteRuleFiles() { // create the build.make file and directory, put in the common blocks diff --git a/Source/cmMakefileExecutableTargetGenerator.h b/Source/cmMakefileExecutableTargetGenerator.h index f6ffad2..269fd5f 100644 --- a/Source/cmMakefileExecutableTargetGenerator.h +++ b/Source/cmMakefileExecutableTargetGenerator.h @@ -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(); diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index c7c06ff..006caa7 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -27,6 +27,12 @@ #include // auto_ptr //---------------------------------------------------------------------------- +cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator() +{ + this->DriveCustomCommandsOnDepends = true; +} + +//---------------------------------------------------------------------------- void cmMakefileLibraryTargetGenerator::WriteRuleFiles() { // create the build.make file and directory, put in the common blocks diff --git a/Source/cmMakefileLibraryTargetGenerator.h b/Source/cmMakefileLibraryTargetGenerator.h index 502e35b..1194afe 100644 --- a/Source/cmMakefileLibraryTargetGenerator.h +++ b/Source/cmMakefileLibraryTargetGenerator.h @@ -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(); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index cd8239c..cc16069 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -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& depends) +{ + // Depend on all custom command outputs. const std::vector& sources = this->Target->GetSourceFiles(); for(std::vector::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. diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index 02223e6..dd6bbe6 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -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& 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; -- cgit v0.12