mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-09 15:20:56 -06:00
cmGeneratorTarget: Factor LINK_DIRECTORIES impl into own source
This commit is contained in:
@@ -286,6 +286,7 @@ add_library(
|
||||
cmGeneratorTarget.cxx
|
||||
cmGeneratorTarget.h
|
||||
cmGeneratorTarget_IncludeDirectories.cxx
|
||||
cmGeneratorTarget_LinkDirectories.cxx
|
||||
cmGeneratorTarget_Sources.cxx
|
||||
cmGeneratorTarget_TargetPropertyEntry.cxx
|
||||
cmLinkItemGraphVisitor.cxx
|
||||
|
||||
@@ -3697,131 +3697,6 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace {
|
||||
void processLinkDirectories(cmGeneratorTarget const* tgt,
|
||||
EvaluatedTargetPropertyEntries& entries,
|
||||
std::vector<BT<std::string>>& directories,
|
||||
std::unordered_set<std::string>& uniqueDirectories,
|
||||
bool debugDirectories)
|
||||
{
|
||||
for (EvaluatedTargetPropertyEntry& entry : entries.Entries) {
|
||||
cmLinkImplItem const& item = entry.LinkImplItem;
|
||||
std::string const& targetName = item.AsStr();
|
||||
|
||||
std::string usedDirectories;
|
||||
for (std::string& entryDirectory : entry.Values) {
|
||||
if (!cmSystemTools::FileIsFullPath(entryDirectory)) {
|
||||
std::ostringstream e;
|
||||
bool noMessage = false;
|
||||
MessageType messageType = MessageType::FATAL_ERROR;
|
||||
if (!targetName.empty()) {
|
||||
/* clang-format off */
|
||||
e << "Target \"" << targetName << "\" contains relative "
|
||||
"path in its INTERFACE_LINK_DIRECTORIES:\n"
|
||||
" \"" << entryDirectory << "\"";
|
||||
/* clang-format on */
|
||||
} else {
|
||||
switch (tgt->GetPolicyStatusCMP0081()) {
|
||||
case cmPolicies::WARN: {
|
||||
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0081) << "\n";
|
||||
messageType = MessageType::AUTHOR_WARNING;
|
||||
} break;
|
||||
case cmPolicies::OLD:
|
||||
noMessage = true;
|
||||
break;
|
||||
case cmPolicies::REQUIRED_IF_USED:
|
||||
case cmPolicies::REQUIRED_ALWAYS:
|
||||
case cmPolicies::NEW:
|
||||
// Issue the fatal message.
|
||||
break;
|
||||
}
|
||||
e << "Found relative path while evaluating link directories of "
|
||||
"\""
|
||||
<< tgt->GetName() << "\":\n \"" << entryDirectory << "\"\n";
|
||||
}
|
||||
if (!noMessage) {
|
||||
tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
|
||||
if (messageType == MessageType::FATAL_ERROR) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sanitize the path the same way the link_directories command does
|
||||
// in case projects set the LINK_DIRECTORIES property directly.
|
||||
cmSystemTools::ConvertToUnixSlashes(entryDirectory);
|
||||
if (uniqueDirectories.insert(entryDirectory).second) {
|
||||
directories.emplace_back(entryDirectory, entry.Backtrace);
|
||||
if (debugDirectories) {
|
||||
usedDirectories += " * " + entryDirectory + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!usedDirectories.empty()) {
|
||||
tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
|
||||
MessageType::LOG,
|
||||
std::string("Used link directories for target ") + tgt->GetName() +
|
||||
":\n" + usedDirectories,
|
||||
entry.Backtrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::GetLinkDirectories(std::vector<std::string>& result,
|
||||
const std::string& config,
|
||||
const std::string& language) const
|
||||
{
|
||||
std::vector<BT<std::string>> tmp =
|
||||
this->GetLinkDirectories(config, language);
|
||||
result.reserve(tmp.size());
|
||||
for (BT<std::string>& v : tmp) {
|
||||
result.emplace_back(std::move(v.Value));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
|
||||
std::string const& config, std::string const& language) const
|
||||
{
|
||||
ConfigAndLanguage cacheKey(
|
||||
config, cmStrCat(language, this->IsDeviceLink() ? "-device" : ""));
|
||||
{
|
||||
auto it = this->LinkDirectoriesCache.find(cacheKey);
|
||||
if (it != this->LinkDirectoriesCache.end()) {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
std::vector<BT<std::string>> result;
|
||||
std::unordered_set<std::string> uniqueDirectories;
|
||||
|
||||
cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DIRECTORIES", nullptr,
|
||||
nullptr, this->LocalGenerator);
|
||||
|
||||
cmList debugProperties{ this->Makefile->GetDefinition(
|
||||
"CMAKE_DEBUG_TARGET_PROPERTIES") };
|
||||
bool debugDirectories = !this->DebugLinkDirectoriesDone &&
|
||||
cm::contains(debugProperties, "LINK_DIRECTORIES");
|
||||
|
||||
if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
|
||||
this->DebugLinkDirectoriesDone = true;
|
||||
}
|
||||
|
||||
EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
|
||||
this, config, language, &dagChecker, this->LinkDirectoriesEntries);
|
||||
|
||||
AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES", language,
|
||||
&dagChecker, entries, IncludeRuntimeInterface::Yes,
|
||||
this->GetPolicyStatusCMP0099() == cmPolicies::NEW
|
||||
? UseTo::Link
|
||||
: UseTo::Compile);
|
||||
|
||||
processLinkDirectories(this, entries, result, uniqueDirectories,
|
||||
debugDirectories);
|
||||
|
||||
this->LinkDirectoriesCache.emplace(cacheKey, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::GetLinkDepends(std::vector<std::string>& result,
|
||||
const std::string& config,
|
||||
const std::string& language) const
|
||||
|
||||
154
Source/cmGeneratorTarget_LinkDirectories.cxx
Normal file
154
Source/cmGeneratorTarget_LinkDirectories.cxx
Normal file
@@ -0,0 +1,154 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
/* clang-format off */
|
||||
#include "cmGeneratorTarget.h"
|
||||
/* clang-format on */
|
||||
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <cmext/algorithm>
|
||||
|
||||
#include "cmEvaluatedTargetProperty.h"
|
||||
#include "cmGeneratorExpressionDAGChecker.h"
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmLinkItem.h"
|
||||
#include "cmList.h"
|
||||
#include "cmListFileCache.h"
|
||||
#include "cmLocalGenerator.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmMessageType.h"
|
||||
#include "cmPolicies.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmValue.h"
|
||||
#include "cmake.h"
|
||||
|
||||
namespace {
|
||||
void processLinkDirectories(cmGeneratorTarget const* tgt,
|
||||
EvaluatedTargetPropertyEntries& entries,
|
||||
std::vector<BT<std::string>>& directories,
|
||||
std::unordered_set<std::string>& uniqueDirectories,
|
||||
bool debugDirectories)
|
||||
{
|
||||
for (EvaluatedTargetPropertyEntry& entry : entries.Entries) {
|
||||
cmLinkImplItem const& item = entry.LinkImplItem;
|
||||
std::string const& targetName = item.AsStr();
|
||||
|
||||
std::string usedDirectories;
|
||||
for (std::string& entryDirectory : entry.Values) {
|
||||
if (!cmSystemTools::FileIsFullPath(entryDirectory)) {
|
||||
std::ostringstream e;
|
||||
bool noMessage = false;
|
||||
MessageType messageType = MessageType::FATAL_ERROR;
|
||||
if (!targetName.empty()) {
|
||||
/* clang-format off */
|
||||
e << "Target \"" << targetName << "\" contains relative "
|
||||
"path in its INTERFACE_LINK_DIRECTORIES:\n"
|
||||
" \"" << entryDirectory << "\"";
|
||||
/* clang-format on */
|
||||
} else {
|
||||
switch (tgt->GetPolicyStatusCMP0081()) {
|
||||
case cmPolicies::WARN: {
|
||||
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0081) << "\n";
|
||||
messageType = MessageType::AUTHOR_WARNING;
|
||||
} break;
|
||||
case cmPolicies::OLD:
|
||||
noMessage = true;
|
||||
break;
|
||||
case cmPolicies::REQUIRED_IF_USED:
|
||||
case cmPolicies::REQUIRED_ALWAYS:
|
||||
case cmPolicies::NEW:
|
||||
// Issue the fatal message.
|
||||
break;
|
||||
}
|
||||
e << "Found relative path while evaluating link directories of "
|
||||
"\""
|
||||
<< tgt->GetName() << "\":\n \"" << entryDirectory << "\"\n";
|
||||
}
|
||||
if (!noMessage) {
|
||||
tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
|
||||
if (messageType == MessageType::FATAL_ERROR) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sanitize the path the same way the link_directories command does
|
||||
// in case projects set the LINK_DIRECTORIES property directly.
|
||||
cmSystemTools::ConvertToUnixSlashes(entryDirectory);
|
||||
if (uniqueDirectories.insert(entryDirectory).second) {
|
||||
directories.emplace_back(entryDirectory, entry.Backtrace);
|
||||
if (debugDirectories) {
|
||||
usedDirectories += " * " + entryDirectory + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!usedDirectories.empty()) {
|
||||
tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
|
||||
MessageType::LOG,
|
||||
std::string("Used link directories for target ") + tgt->GetName() +
|
||||
":\n" + usedDirectories,
|
||||
entry.Backtrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::GetLinkDirectories(std::vector<std::string>& result,
|
||||
const std::string& config,
|
||||
const std::string& language) const
|
||||
{
|
||||
std::vector<BT<std::string>> tmp =
|
||||
this->GetLinkDirectories(config, language);
|
||||
result.reserve(tmp.size());
|
||||
for (BT<std::string>& v : tmp) {
|
||||
result.emplace_back(std::move(v.Value));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
|
||||
std::string const& config, std::string const& language) const
|
||||
{
|
||||
ConfigAndLanguage cacheKey(
|
||||
config, cmStrCat(language, this->IsDeviceLink() ? "-device" : ""));
|
||||
{
|
||||
auto it = this->LinkDirectoriesCache.find(cacheKey);
|
||||
if (it != this->LinkDirectoriesCache.end()) {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
std::vector<BT<std::string>> result;
|
||||
std::unordered_set<std::string> uniqueDirectories;
|
||||
|
||||
cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DIRECTORIES", nullptr,
|
||||
nullptr, this->LocalGenerator);
|
||||
|
||||
cmList debugProperties{ this->Makefile->GetDefinition(
|
||||
"CMAKE_DEBUG_TARGET_PROPERTIES") };
|
||||
bool debugDirectories = !this->DebugLinkDirectoriesDone &&
|
||||
cm::contains(debugProperties, "LINK_DIRECTORIES");
|
||||
|
||||
if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
|
||||
this->DebugLinkDirectoriesDone = true;
|
||||
}
|
||||
|
||||
EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
|
||||
this, config, language, &dagChecker, this->LinkDirectoriesEntries);
|
||||
|
||||
AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES", language,
|
||||
&dagChecker, entries, IncludeRuntimeInterface::Yes,
|
||||
this->GetPolicyStatusCMP0099() == cmPolicies::NEW
|
||||
? UseTo::Link
|
||||
: UseTo::Compile);
|
||||
|
||||
processLinkDirectories(this, entries, result, uniqueDirectories,
|
||||
debugDirectories);
|
||||
|
||||
this->LinkDirectoriesCache.emplace(cacheKey, result);
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user