From 7e47f8496a3021a2b9a39a909514b7b20ff0d801 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 25 Aug 2006 22:56:41 -0400 Subject: [PATCH] BUG: Fix for VS.NET 2003 SP1 to make sure global target and utility target rules run every time. --- Source/cmLocalVisualStudio7Generator.cxx | 67 +++++++++++++++++++++--- Source/cmLocalVisualStudio7Generator.h | 1 + 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index e8a5dba34..5de5f2fc5 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -44,9 +44,46 @@ void cmLocalVisualStudio7Generator::Generate() lang.insert("IDL"); lang.insert("DEF"); this->CreateCustomTargetsAndCommands(lang); + this->FixTargets(); this->OutputVCProjFile(); } +void cmLocalVisualStudio7Generator::FixTargets() +{ + // Visual Studio .NET 2003 Service Pack 1 will not run post-build + // commands for targets in which no sources are built. Add dummy + // rules to force these targets to build. + cmTargets &tgts = this->Makefile->GetTargets(); + for(cmTargets::iterator l = tgts.begin(); + l != tgts.end(); l++) + { + cmTarget& tgt = l->second; + if(tgt.GetType() == cmTarget::GLOBAL_TARGET || + tgt.GetType() == cmTarget::UTILITY) + { + std::vector no_depends; + cmCustomCommandLine force_command; + force_command.push_back(";"); + cmCustomCommandLines force_commands; + force_commands.push_back(force_command); + const char* no_main_dependency = 0; + std::string force = this->Makefile->GetStartOutputDirectory(); + force += cmake::GetCMakeFilesDirectory(); + force += "/"; + force += tgt.GetName(); + force += "_force"; + this->Makefile->AddCustomCommandToOutput(force.c_str(), no_depends, + no_main_dependency, + force_commands, " ", 0, true); + if(cmSourceFile* file = + this->Makefile->GetSourceFileWithOutput(force.c_str())) + { + tgt.GetSourceFiles().push_back(file); + } + } + } +} + // TODO // for CommandLine= need to repleace quotes with " // write out configurations @@ -1268,15 +1305,29 @@ WriteCustomRule(std::ostream& fout, << "\t\t\t\t\tCommandLine=\"" << this->EscapeForXML(command) << "\"\n" << "\t\t\t\t\tAdditionalDependencies=\""; - // Write out the dependencies for the rule. - std::string temp; - for(std::vector::const_iterator d = depends.begin(); - d != depends.end(); ++d) + if(depends.empty()) { - // Lookup the real name of the dependency in case it is a CMake target. - std::string dep = this->GetRealDependency(d->c_str(), i->c_str()); - fout << this->ConvertToXMLOutputPath(dep.c_str()) - << ";"; + // There are no real dependencies. Produce an artificial one to + // make sure the rule runs reliably. + if(!cmSystemTools::FileExists(source)) + { + std::ofstream depout(source); + depout << "Artificial dependency for a custom command.\n"; + } + fout << this->ConvertToXMLOutputPath(source); + } + else + { + // Write out the dependencies for the rule. + std::string temp; + for(std::vector::const_iterator d = depends.begin(); + d != depends.end(); ++d) + { + // Lookup the real name of the dependency in case it is a CMake target. + std::string dep = this->GetRealDependency(d->c_str(), i->c_str()); + fout << this->ConvertToXMLOutputPath(dep.c_str()) + << ";"; + } } fout << "\"\n"; fout << "\t\t\t\t\tOutputs=\""; diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index ad81085e3..c4ea0049a 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -71,6 +71,7 @@ private: std::string& flags); std::string GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName); + void FixTargets(); void OutputVCProjFile(); void WriteVCProjHeader(std::ostream& fout, const char *libName, cmTarget &tgt, std::vector &sgs);