mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-13 17:47:49 +08:00
cmComputeLinkInformation: Improve type safety of item IsPath member
Use an enum to avoid implicit conversions to bool.
This commit is contained in:
@@ -659,14 +659,14 @@ void cmComputeLinkInformation::AddItem(BT<std::string> const& item,
|
||||
|
||||
std::string exe = tgt->GetFullPath(config, artifact, true);
|
||||
linkItem += exe;
|
||||
this->Items.emplace_back(BT<std::string>(linkItem, item.Backtrace), true,
|
||||
tgt);
|
||||
this->Items.emplace_back(BT<std::string>(linkItem, item.Backtrace),
|
||||
ItemIsPath::Yes, tgt);
|
||||
this->Depends.push_back(std::move(exe));
|
||||
} else if (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
|
||||
// Add the interface library as an item so it can be considered as part
|
||||
// of COMPATIBLE_INTERFACE_ enforcement. The generators will ignore
|
||||
// this for the actual link line.
|
||||
this->Items.emplace_back(std::string(), false, tgt);
|
||||
this->Items.emplace_back(std::string(), ItemIsPath::No, tgt);
|
||||
|
||||
// Also add the item the interface specifies to be used in its place.
|
||||
std::string const& libName = tgt->GetImportedLibName(config);
|
||||
@@ -1038,10 +1038,10 @@ void cmComputeLinkInformation::SetCurrentLinkType(LinkType lt)
|
||||
if (this->LinkTypeEnabled) {
|
||||
switch (this->CurrentLinkType) {
|
||||
case LinkStatic:
|
||||
this->Items.emplace_back(this->StaticLinkTypeFlag, false);
|
||||
this->Items.emplace_back(this->StaticLinkTypeFlag, ItemIsPath::No);
|
||||
break;
|
||||
case LinkShared:
|
||||
this->Items.emplace_back(this->SharedLinkTypeFlag, false);
|
||||
this->Items.emplace_back(this->SharedLinkTypeFlag, ItemIsPath::No);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -1084,7 +1084,7 @@ void cmComputeLinkInformation::AddTargetItem(BT<std::string> const& item,
|
||||
}
|
||||
|
||||
// Now add the full path to the library.
|
||||
this->Items.emplace_back(item, true, target);
|
||||
this->Items.emplace_back(item, ItemIsPath::Yes, target);
|
||||
}
|
||||
|
||||
void cmComputeLinkInformation::AddFullItem(BT<std::string> const& item)
|
||||
@@ -1138,7 +1138,7 @@ void cmComputeLinkInformation::AddFullItem(BT<std::string> const& item)
|
||||
}
|
||||
|
||||
// Now add the full path to the library.
|
||||
this->Items.emplace_back(item, true);
|
||||
this->Items.emplace_back(item, ItemIsPath::Yes);
|
||||
}
|
||||
|
||||
bool cmComputeLinkInformation::CheckImplicitDirItem(std::string const& item)
|
||||
@@ -1226,7 +1226,7 @@ void cmComputeLinkInformation::AddUserItem(BT<std::string> const& item,
|
||||
this->SetCurrentLinkType(this->StartLinkType);
|
||||
|
||||
// Use the item verbatim.
|
||||
this->Items.emplace_back(item, false);
|
||||
this->Items.emplace_back(item, ItemIsPath::No);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1296,7 +1296,8 @@ void cmComputeLinkInformation::AddUserItem(BT<std::string> const& item,
|
||||
|
||||
// Create an option to ask the linker to search for the library.
|
||||
std::string out = cmStrCat(this->LibLinkFlag, lib, this->LibLinkSuffix);
|
||||
this->Items.emplace_back(BT<std::string>(out, item.Backtrace), false);
|
||||
this->Items.emplace_back(BT<std::string>(out, item.Backtrace),
|
||||
ItemIsPath::No);
|
||||
|
||||
// Here we could try to find the library the linker will find and
|
||||
// add a runtime information entry for it. It would probably not be
|
||||
@@ -1328,13 +1329,13 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item)
|
||||
if (this->GlobalGenerator->IsXcode()) {
|
||||
// Add framework path - it will be handled by Xcode after it's added to
|
||||
// "Link Binary With Libraries" build phase
|
||||
this->Items.emplace_back(item, true);
|
||||
this->Items.emplace_back(item, ItemIsPath::Yes);
|
||||
} else {
|
||||
// Add the item using the -framework option.
|
||||
this->Items.emplace_back(std::string("-framework"), false);
|
||||
this->Items.emplace_back(std::string("-framework"), ItemIsPath::No);
|
||||
cmOutputConverter converter(this->Makefile->GetStateSnapshot());
|
||||
fw = converter.EscapeForShell(fw);
|
||||
this->Items.emplace_back(fw, false);
|
||||
this->Items.emplace_back(fw, ItemIsPath::No);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -35,17 +35,24 @@ public:
|
||||
~cmComputeLinkInformation();
|
||||
bool Compute();
|
||||
|
||||
enum class ItemIsPath
|
||||
{
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
struct Item
|
||||
{
|
||||
Item() = default;
|
||||
Item(BT<std::string> v, bool p, cmGeneratorTarget const* target = nullptr)
|
||||
Item(BT<std::string> v, ItemIsPath isPath,
|
||||
cmGeneratorTarget const* target = nullptr)
|
||||
: Value(std::move(v))
|
||||
, IsPath(p)
|
||||
, IsPath(isPath)
|
||||
, Target(target)
|
||||
{
|
||||
}
|
||||
BT<std::string> Value;
|
||||
bool IsPath = true;
|
||||
ItemIsPath IsPath = ItemIsPath::Yes;
|
||||
cmGeneratorTarget const* Target = nullptr;
|
||||
};
|
||||
using ItemVector = std::vector<Item>;
|
||||
|
@@ -3454,7 +3454,9 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
|
||||
libItem.Target->GetType() == cmStateEnums::SHARED_LIBRARY ||
|
||||
libItem.Target->GetType() == cmStateEnums::MODULE_LIBRARY ||
|
||||
libItem.Target->GetType() == cmStateEnums::UNKNOWN_LIBRARY)) ||
|
||||
(!libItem.Target && libItem.IsPath && forceLinkPhase))) {
|
||||
(!libItem.Target &&
|
||||
libItem.IsPath == cmComputeLinkInformation::ItemIsPath::Yes &&
|
||||
forceLinkPhase))) {
|
||||
std::string libName;
|
||||
bool canUseLinkPhase = true;
|
||||
if (libItem.Target) {
|
||||
@@ -3565,7 +3567,7 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
|
||||
auto* libTarget = FindXCodeTarget(libItem->Target);
|
||||
cmXCodeObject* buildFile;
|
||||
if (!libTarget) {
|
||||
if (libItem->IsPath) {
|
||||
if (libItem->IsPath == cmComputeLinkInformation::ItemIsPath::Yes) {
|
||||
// Get or create a direct file ref in the root project
|
||||
auto cleanPath = libItem->Value.Value;
|
||||
if (cmSystemTools::FileIsFullPath(cleanPath)) {
|
||||
@@ -3724,7 +3726,7 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
|
||||
BuildObjectListOrString libPaths(this, true);
|
||||
for (auto const& libItem : configItemMap[configName]) {
|
||||
auto const& libName = *libItem;
|
||||
if (libName.IsPath) {
|
||||
if (libName.IsPath == cmComputeLinkInformation::ItemIsPath::Yes) {
|
||||
auto cleanPath = libName.Value.Value;
|
||||
if (cmSystemTools::FileIsFullPath(cleanPath)) {
|
||||
cleanPath = cmSystemTools::CollapseFullPath(cleanPath);
|
||||
|
@@ -74,7 +74,7 @@ void cmLinkLineComputer::ComputeLinkLibs(
|
||||
}
|
||||
|
||||
BT<std::string> linkLib;
|
||||
if (item.IsPath) {
|
||||
if (item.IsPath == cmComputeLinkInformation::ItemIsPath::Yes) {
|
||||
linkLib.Value += cli.GetLibLinkFileFlag();
|
||||
linkLib.Value += this->ConvertToOutputFormat(
|
||||
this->ConvertToLinkReference(item.Value.Value));
|
||||
|
@@ -111,7 +111,7 @@ void cmLinkLineDeviceComputer::ComputeLinkLibraries(
|
||||
}
|
||||
|
||||
BT<std::string> linkLib;
|
||||
if (item.IsPath) {
|
||||
if (item.IsPath == cmComputeLinkInformation::ItemIsPath::Yes) {
|
||||
// nvcc understands absolute paths to libraries ending in '.a' or '.lib'.
|
||||
// These should be passed to nvlink. Other extensions need to be left
|
||||
// out because nvlink may not understand or need them. Even though it
|
||||
|
@@ -1254,7 +1254,7 @@ void cmLocalVisualStudio7GeneratorInternals::OutputLibraries(
|
||||
{
|
||||
cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
|
||||
for (auto const& lib : libs) {
|
||||
if (lib.IsPath) {
|
||||
if (lib.IsPath == cmComputeLinkInformation::ItemIsPath::Yes) {
|
||||
std::string rel = lg->MaybeRelativeToCurBinDir(lib.Value.Value);
|
||||
fout << lg->ConvertToXMLOutputPath(rel) << " ";
|
||||
} else if (!lib.Target ||
|
||||
|
@@ -3391,7 +3391,7 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
|
||||
}
|
||||
}
|
||||
|
||||
if (l.IsPath) {
|
||||
if (l.IsPath == cmComputeLinkInformation::ItemIsPath::Yes) {
|
||||
std::string path =
|
||||
this->LocalGenerator->MaybeRelativeToCurBinDir(l.Value.Value);
|
||||
ConvertToWindowsSlash(path);
|
||||
@@ -3945,7 +3945,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
|
||||
using ItemVector = cmComputeLinkInformation::ItemVector;
|
||||
const ItemVector& libs = cli.GetItems();
|
||||
for (cmComputeLinkInformation::Item const& l : libs) {
|
||||
if (l.IsPath && cmVS10IsTargetsFile(l.Value.Value)) {
|
||||
if (l.IsPath == cmComputeLinkInformation::ItemIsPath::Yes &&
|
||||
cmVS10IsTargetsFile(l.Value.Value)) {
|
||||
std::string path =
|
||||
this->LocalGenerator->MaybeRelativeToCurBinDir(l.Value.Value);
|
||||
ConvertToWindowsSlash(path);
|
||||
@@ -4028,7 +4029,7 @@ void cmVisualStudio10TargetGenerator::AddLibraries(
|
||||
}
|
||||
}
|
||||
|
||||
if (l.IsPath) {
|
||||
if (l.IsPath == cmComputeLinkInformation::ItemIsPath::Yes) {
|
||||
std::string path =
|
||||
this->LocalGenerator->MaybeRelativeToCurBinDir(l.Value.Value);
|
||||
ConvertToWindowsSlash(path);
|
||||
|
Reference in New Issue
Block a user