diff options
author | Brad King <brad.king@kitware.com> | 2006-04-11 15:06:19 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2006-04-11 15:06:19 (GMT) |
commit | d5719f22c1dca3e100f1e3b5dfaa4fe7d26796a0 (patch) | |
tree | 714a99bed97290f96ff8f846fa6864cebbdc0a28 /Source/cmGlobalUnixMakefileGenerator3.cxx | |
parent | b613cf0be806cc1d37d2b590f1a5ba7898236ae8 (diff) | |
download | CMake-d5719f22c1dca3e100f1e3b5dfaa4fe7d26796a0.zip CMake-d5719f22c1dca3e100f1e3b5dfaa4fe7d26796a0.tar.gz CMake-d5719f22c1dca3e100f1e3b5dfaa4fe7d26796a0.tar.bz2 |
ENH: Added support for multiple outputs generated by a single custom command. For Visual Studio generators the native tool provides support. For Xcode and Makefile generators a simple trick is used. The first output is considered primary and has the build rule attached. Other outputs simply depend on the first output with no build rule. During cmake_check_build_system CMake detects when a secondary output is missing and removes the primary output to make sure all outputs are regenerated. This approach always builds the custom command at the right time and only once even during parallel builds.
Diffstat (limited to 'Source/cmGlobalUnixMakefileGenerator3.cxx')
-rw-r--r-- | Source/cmGlobalUnixMakefileGenerator3.cxx | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 048ff50..4b17ded 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -99,6 +99,15 @@ void cmGlobalUnixMakefileGenerator3::GetDocumentation(cmDocumentationEntry& entr } //---------------------------------------------------------------------------- +void +cmGlobalUnixMakefileGenerator3 +::AddMultipleOutputPair(const char* depender, const char* dependee) +{ + MultipleOutputPairsType::value_type p(depender, dependee); + this->MultipleOutputPairs.insert(p); +} + +//---------------------------------------------------------------------------- void cmGlobalUnixMakefileGenerator3::Generate() { // first do superclass method @@ -298,8 +307,64 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile() cmakefileStream << " )\n\n"; this->WriteMainCMakefileLanguageRules(cmakefileStream, this->LocalGenerators); + + if(!this->MultipleOutputPairs.empty()) + { + cmakefileStream + << "\n" + << "SET(CMAKE_MULTIPLE_OUTPUT_PAIRS\n"; + for(MultipleOutputPairsType::const_iterator pi = + this->MultipleOutputPairs.begin(); + pi != this->MultipleOutputPairs.end(); ++pi) + { + cmakefileStream << " \"" << pi->first << "\" \"" + << pi->second << "\"\n"; + } + cmakefileStream << " )\n\n"; + } } - + +//---------------------------------------------------------------------------- +void cmGlobalUnixMakefileGenerator3::CheckMultipleOutputs(cmMakefile* mf, + bool verbose) +{ + // Get the string listing the multiple output pairs. + const char* pairs_string = mf->GetDefinition("CMAKE_MULTIPLE_OUTPUT_PAIRS"); + if(!pairs_string) + { + return; + } + + // Convert the string to a list and preserve empty entries. + std::vector<std::string> pairs; + cmSystemTools::ExpandListArgument(pairs_string, pairs, true); + for(std::vector<std::string>::const_iterator i = pairs.begin(); + i != pairs.end(); ++i) + { + const std::string& depender = *i; + if(++i != pairs.end()) + { + const std::string& dependee = *i; + + // If the depender is missing then delete the dependee to make + // sure both will be regenerated. + if(cmSystemTools::FileExists(dependee.c_str()) && + !cmSystemTools::FileExists(depender.c_str())) + { + if(verbose) + { + cmOStringStream msg; + msg << "Deleting primary custom command output \"" << dependee + << "\" because another output \"" + << depender << "\" does not exist." << std::endl; + cmSystemTools::Stdout(msg.str().c_str()); + } + cmSystemTools::RemoveFile(dependee.c_str()); + } + } + } +} + void cmGlobalUnixMakefileGenerator3 ::WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream, std::vector<cmLocalGenerator *> &lGenerators) |