diff options
author | Robert Goulet <robert.goulet@autodesk.com> | 2015-08-14 20:35:58 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-08-20 13:56:45 (GMT) |
commit | 3c37d2642d9000a2d01bc46ad0ea74a741bdb658 (patch) | |
tree | c1bb63b2a35fbb0de0691c88e1c4535cee6d0f4e /Source/cmGeneratorTarget.cxx | |
parent | a38ea312c02eec6e4ee61015f70920999bf79ff9 (diff) | |
download | CMake-3c37d2642d9000a2d01bc46ad0ea74a741bdb658.zip CMake-3c37d2642d9000a2d01bc46ad0ea74a741bdb658.tar.gz CMake-3c37d2642d9000a2d01bc46ad0ea74a741bdb658.tar.bz2 |
cmGeneratorTarget: Avoid recursion in GetOutputName method
Since support for generator expressions was added to OUTPUT_NAME it is
possible for project code to cause recursion in this method by using a
$<TARGET_FILE> genex. Detect and reject such cases.
Diffstat (limited to 'Source/cmGeneratorTarget.cxx')
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 93 |
1 files changed, 58 insertions, 35 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 299c112..530acfe 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -270,48 +270,71 @@ const char *cmGeneratorTarget::GetProperty(const std::string& prop) const std::string cmGeneratorTarget::GetOutputName(const std::string& config, bool implib) const { - std::vector<std::string> props; - std::string type = this->Target->GetOutputTargetType(implib); - std::string configUpper = cmSystemTools::UpperCase(config); - if(!type.empty() && !configUpper.empty()) - { - // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG> - props.push_back(type + "_OUTPUT_NAME_" + configUpper); - } - if(!type.empty()) + // Lookup/compute/cache the output name for this configuration. + OutputNameKey key(config, implib); + cmGeneratorTarget::OutputNameMapType::iterator i = + this->OutputNameMap.find(key); + if(i == this->OutputNameMap.end()) { - // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME - props.push_back(type + "_OUTPUT_NAME"); - } - if(!configUpper.empty()) - { - // OUTPUT_NAME_<CONFIG> - props.push_back("OUTPUT_NAME_" + configUpper); - // <CONFIG>_OUTPUT_NAME - props.push_back(configUpper + "_OUTPUT_NAME"); - } - // OUTPUT_NAME - props.push_back("OUTPUT_NAME"); + // Add empty name in map to detect potential recursion. + OutputNameMapType::value_type entry(key, ""); + i = this->OutputNameMap.insert(entry).first; - std::string outName; - for(std::vector<std::string>::const_iterator i = props.begin(); - i != props.end(); ++i) - { - if (const char* outNameProp = this->Target->GetProperty(*i)) + // Compute output name. + std::vector<std::string> props; + std::string type = this->Target->GetOutputTargetType(implib); + std::string configUpper = cmSystemTools::UpperCase(config); + if(!type.empty() && !configUpper.empty()) { - outName = outNameProp; - break; + // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG> + props.push_back(type + "_OUTPUT_NAME_" + configUpper); + } + if(!type.empty()) + { + // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME + props.push_back(type + "_OUTPUT_NAME"); + } + if(!configUpper.empty()) + { + // OUTPUT_NAME_<CONFIG> + props.push_back("OUTPUT_NAME_" + configUpper); + // <CONFIG>_OUTPUT_NAME + props.push_back(configUpper + "_OUTPUT_NAME"); + } + // OUTPUT_NAME + props.push_back("OUTPUT_NAME"); + + std::string outName; + for(std::vector<std::string>::const_iterator it = props.begin(); + it != props.end(); ++it) + { + if (const char* outNameProp = this->Target->GetProperty(*it)) + { + outName = outNameProp; + break; + } } - } - if (outName.empty()) + if(outName.empty()) + { + outName = this->GetName(); + } + + // Now evaluate genex and update the previously-prepared map entry. + cmGeneratorExpression ge; + cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName); + i->second = cge->Evaluate(this->Makefile, config); + } + else if(i->second.empty()) { - outName = this->GetName(); + // An empty map entry indicates we have been called recursively + // from the above block. + this->Makefile->GetCMakeInstance()->IssueMessage( + cmake::FATAL_ERROR, + "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.", + this->Target->GetBacktrace()); } - - cmGeneratorExpression ge; - cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName); - return cge->Evaluate(this->Makefile, config); + return i->second; } //---------------------------------------------------------------------------- |