LINKER_TYPE: Support MOLD only on GCC versions that support it

Fixes: #25748
This commit is contained in:
Marc Chevrier
2024-03-11 18:10:43 +01:00
committed by Brad King
parent 939ac5287e
commit 801ae06952
11 changed files with 51 additions and 14 deletions

View File

@@ -5,6 +5,7 @@
#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cstddef>
#include <cstdio>
@@ -5585,11 +5586,22 @@ std::string cmGeneratorTarget::GetLinkerTool(const std::string& lang,
linkerTool = this->Makefile->GetDefinition("CMAKE_LINKER");
if (linkerType != "DEFAULT"_s) {
this->LocalGenerator->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("LINKER_TYPE '", linkerType,
"' is unknown. Did you forget to define '", usingLinker,
"' variable?"));
auto isCMakeLinkerType = [](const std::string& type) -> bool {
return std::all_of(type.cbegin(), type.cend(),
[](char c) { return std::isupper(c); });
};
if (isCMakeLinkerType(linkerType)) {
this->LocalGenerator->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("LINKER_TYPE '", linkerType,
"' is unknown or not supported by this toolchain."));
} else {
this->LocalGenerator->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("LINKER_TYPE '", linkerType,
"' is unknown. Did you forget to define the '", usingLinker,
"' variable?"));
}
}
}

View File

@@ -5,6 +5,7 @@
#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <initializer_list>
@@ -3357,10 +3358,22 @@ void cmLocalGenerator::AppendLinkerTypeFlags(std::string& flags,
this->AppendFlags(flags, linkerFlags);
}
} else if (linkerType != "DEFAULT"_s) {
this->IssueMessage(MessageType::FATAL_ERROR,
cmStrCat("LINKER_TYPE '", linkerType,
"' is unknown. Did you forget to define '",
usingLinker, "' variable?"));
auto isCMakeLinkerType = [](const std::string& type) -> bool {
return std::all_of(type.cbegin(), type.cend(),
[](char c) { return std::isupper(c); });
};
if (isCMakeLinkerType(linkerType)) {
this->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("LINKER_TYPE '", linkerType,
"' is unknown or not supported by this toolchain."));
} else {
this->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("LINKER_TYPE '", linkerType,
"' is unknown. Did you forget to define the '", usingLinker,
"' variable?"));
}
}
}