diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2003-06-04 17:42:42 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2003-06-04 17:42:42 (GMT) |
commit | fc0a916eee7068720bcaffc32ca5cc8e9414e9d1 (patch) | |
tree | 8f4eb45e612c646f6436e45891535582276bb126 /Source | |
parent | 3154a6649a12711068e54405f70cb4b224b13443 (diff) | |
download | CMake-fc0a916eee7068720bcaffc32ca5cc8e9414e9d1.zip CMake-fc0a916eee7068720bcaffc32ca5cc8e9414e9d1.tar.gz CMake-fc0a916eee7068720bcaffc32ca5cc8e9414e9d1.tar.bz2 |
ENH: allow duplicate commands with the same output to be reduced automatically to one command
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCustomCommand.cxx | 15 | ||||
-rw-r--r-- | Source/cmCustomCommand.h | 3 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 2 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 35 |
4 files changed, 43 insertions, 12 deletions
diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 5facc4c..fffa51d 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -65,3 +65,18 @@ void cmCustomCommand::ExpandVariables(const cmMakefile &mf) mf.ExpandVariablesInString(*i); } } + + +bool cmCustomCommand::IsEquivalent(const char* command, + const char* args) +{ + if(m_Command != command) + { + return false; + } + if(m_Arguments != args) + { + return false; + } + return true; +} diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index 79206ac..62b47fa 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -69,6 +69,9 @@ public: const std::vector<std::string> &GetDepends() const {return m_Depends;} std::vector<std::string> &GetDepends() {return m_Depends;} + ///! Return true if the command and args are equal to the ones here. + bool IsEquivalent(const char* command, + const char* args); private: std::string m_Command; std::string m_Arguments; diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index a3fcd7b..5e4b5cd 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -951,7 +951,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout) // look for custom rules on a target and collect them together void cmLocalVisualStudio7Generator::OutputTargetRules(std::ostream& fout, const cmTarget &target, - const char */* libName */) + const char * /* libName */) { if (target.GetType() > cmTarget::UTILITY) { diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 8c8d251..5678178 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -499,6 +499,16 @@ AddCustomCommandToOutput(const char* output, const char *comment, bool replace) { + std::string expandC; + std::string combinedArgs; + unsigned int i; + for (i = 0; i < commandArgs.size(); ++i) + { + expandC = commandArgs[i].c_str(); + this->ExpandVariablesInString(expandC); + combinedArgs += cmSystemTools::EscapeSpaces(expandC.c_str()); + combinedArgs += " "; + } cmSourceFile *file = 0; std::string outName = output; outName += ".rule"; @@ -524,7 +534,18 @@ AddCustomCommandToOutput(const char* output, file = this->GetSource(outName.c_str()); if (file && file->GetCustomCommand() && !replace) { - cmSystemTools::Error("Attempt to add a custom rule to an output that already has a custom rule. For output: ", output); + cmCustomCommand* cc = file->GetCustomCommand(); + // if the command and args are the same + // as the command already there, then silently skip + // this add command + if(cc->IsEquivalent(command, combinedArgs.c_str())) + { + return; + } + // produce error if two different commands are given to produce + // the same output + cmSystemTools::Error("Attempt to add a custom rule to an output that already" + " has a custom rule. For output: ", output); return; } // create a cmSourceFile for the output @@ -538,19 +559,11 @@ AddCustomCommandToOutput(const char* output, out->SetProperty("GENERATED","1"); // process the command - std::string expandC = command; + expandC = command; this->ExpandVariablesInString(expandC); std::string c = cmSystemTools::EscapeSpaces(expandC.c_str()); - std::string combinedArgs; - unsigned int i; - for (i = 0; i < commandArgs.size(); ++i) - { - expandC = commandArgs[i].c_str(); - this->ExpandVariablesInString(expandC); - combinedArgs += cmSystemTools::EscapeSpaces(expandC.c_str()); - combinedArgs += " "; - } + std::vector<std::string> depends2(depends); if (main_dependency && main_dependency[0] != '\0') { |