|
|
@@ -1495,17 +1495,16 @@ void cmLocalGenerator::GetTargetFlags(
|
|
|
libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
|
|
|
CM_FALLTHROUGH;
|
|
|
case cmStateEnums::SHARED_LIBRARY: {
|
|
|
- std::string sharedLibFlags;
|
|
|
if (this->IsSplitSwiftBuild() || linkLanguage != "Swift") {
|
|
|
- sharedLibFlags = cmStrCat(
|
|
|
- this->Makefile->GetSafeDefinition(libraryLinkVariable), ' ');
|
|
|
- if (!configUpper.empty()) {
|
|
|
- std::string build = cmStrCat(libraryLinkVariable, '_', configUpper);
|
|
|
- sharedLibFlags += this->Makefile->GetSafeDefinition(build);
|
|
|
- sharedLibFlags += " ";
|
|
|
+ std::string libFlags;
|
|
|
+ this->AddConfigVariableFlags(libFlags, libraryLinkVariable, target,
|
|
|
+ cmBuildStep::Link, linkLanguage, config);
|
|
|
+ if (!libFlags.empty()) {
|
|
|
+ linkFlags.emplace_back(std::move(libFlags));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ std::string sharedLibFlags;
|
|
|
cmValue targetLinkFlags = target->GetProperty("LINK_FLAGS");
|
|
|
if (targetLinkFlags) {
|
|
|
sharedLibFlags += *targetLinkFlags;
|
|
|
@@ -1538,7 +1537,6 @@ void cmLocalGenerator::GetTargetFlags(
|
|
|
}
|
|
|
} break;
|
|
|
case cmStateEnums::EXECUTABLE: {
|
|
|
- std::string exeFlags;
|
|
|
if (linkLanguage.empty()) {
|
|
|
cmSystemTools::Error(
|
|
|
"CMake can not determine linker language for target: " +
|
|
|
@@ -1547,15 +1545,16 @@ void cmLocalGenerator::GetTargetFlags(
|
|
|
}
|
|
|
|
|
|
if (linkLanguage != "Swift") {
|
|
|
- exeFlags = this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
|
|
|
- exeFlags += " ";
|
|
|
- if (!configUpper.empty()) {
|
|
|
- exeFlags += this->Makefile->GetSafeDefinition(
|
|
|
- cmStrCat("CMAKE_EXE_LINKER_FLAGS_", configUpper));
|
|
|
- exeFlags += " ";
|
|
|
+ std::string exeFlags;
|
|
|
+ this->AddConfigVariableFlags(exeFlags, "CMAKE_EXE_LINKER_FLAGS",
|
|
|
+ target, cmBuildStep::Link, linkLanguage,
|
|
|
+ config);
|
|
|
+ if (!exeFlags.empty()) {
|
|
|
+ linkFlags.emplace_back(std::move(exeFlags));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ std::string exeFlags;
|
|
|
if (target->IsWin32Executable(config)) {
|
|
|
exeFlags += this->Makefile->GetSafeDefinition(
|
|
|
cmStrCat("CMAKE_", linkLanguage, "_CREATE_WIN32_EXE"));
|
|
|
@@ -2621,6 +2620,19 @@ void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
|
|
|
this->AppendFlags(flags, this->Makefile->GetSafeDefinition(flagsVar));
|
|
|
}
|
|
|
}
|
|
|
+void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
|
|
|
+ const std::string& var,
|
|
|
+ cmGeneratorTarget const* target,
|
|
|
+ cmBuildStep compileOrLink,
|
|
|
+ const std::string& lang,
|
|
|
+ const std::string& config)
|
|
|
+{
|
|
|
+ std::string newFlags;
|
|
|
+ this->AddConfigVariableFlags(newFlags, var, config);
|
|
|
+ if (!newFlags.empty()) {
|
|
|
+ this->AppendFlags(flags, newFlags, var, target, compileOrLink, lang);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
void cmLocalGenerator::AppendFlags(std::string& flags,
|
|
|
const std::string& newFlags) const
|
|
|
@@ -2651,6 +2663,59 @@ void cmLocalGenerator::AppendFlagEscape(std::string& flags,
|
|
|
this->EscapeForShell(rawFlag, false, false, false, this->IsNinjaMulti()));
|
|
|
}
|
|
|
|
|
|
+void cmLocalGenerator::AppendFlags(std::string& flags,
|
|
|
+ std::string const& newFlags,
|
|
|
+ const std::string& name,
|
|
|
+ const cmGeneratorTarget* target,
|
|
|
+ cmBuildStep compileOrLink,
|
|
|
+ const std::string& language)
|
|
|
+{
|
|
|
+ switch (target->GetPolicyStatusCMP0181()) {
|
|
|
+ case cmPolicies::WARN:
|
|
|
+ if (!this->Makefile->GetCMakeInstance()->GetIsInTryCompile() &&
|
|
|
+ this->Makefile->PolicyOptionalWarningEnabled(
|
|
|
+ "CMAKE_POLICY_WARNING_CMP0181")) {
|
|
|
+ this->Makefile->GetCMakeInstance()->IssueMessage(
|
|
|
+ MessageType::AUTHOR_WARNING,
|
|
|
+ cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0181),
|
|
|
+ "\nSince the policy is not set, the contents of variable '",
|
|
|
+ name,
|
|
|
+ "' will "
|
|
|
+ "be used as is."),
|
|
|
+ target->GetBacktrace());
|
|
|
+ }
|
|
|
+ CM_FALLTHROUGH;
|
|
|
+ case cmPolicies::OLD:
|
|
|
+ this->AppendFlags(flags, newFlags);
|
|
|
+ break;
|
|
|
+ case cmPolicies::REQUIRED_IF_USED:
|
|
|
+ case cmPolicies::REQUIRED_ALWAYS:
|
|
|
+ this->Makefile->GetCMakeInstance()->IssueMessage(
|
|
|
+ MessageType::FATAL_ERROR,
|
|
|
+ cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0181),
|
|
|
+ target->GetBacktrace());
|
|
|
+ CM_FALLTHROUGH;
|
|
|
+ case cmPolicies::NEW:
|
|
|
+ if (compileOrLink == cmBuildStep::Link) {
|
|
|
+ std::vector<std::string> options;
|
|
|
+ cmSystemTools::ParseUnixCommandLine(newFlags.c_str(), options);
|
|
|
+ this->SetLinkScriptShell(this->GlobalGenerator->GetUseLinkScript());
|
|
|
+ std::vector<BT<std::string>> optionsWithBT{ options.size() };
|
|
|
+ std::transform(options.cbegin(), options.cend(), optionsWithBT.begin(),
|
|
|
+ [](const std::string& item) -> BT<std::string> {
|
|
|
+ return BT<std::string>{ item };
|
|
|
+ });
|
|
|
+ target->ResolveLinkerWrapper(optionsWithBT, language);
|
|
|
+ for (const auto& item : optionsWithBT) {
|
|
|
+ this->AppendFlagEscape(flags, item.Value);
|
|
|
+ }
|
|
|
+ this->SetLinkScriptShell(false);
|
|
|
+ } else {
|
|
|
+ this->AppendFlags(flags, newFlags);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void cmLocalGenerator::AddISPCDependencies(cmGeneratorTarget* target)
|
|
|
{
|
|
|
std::vector<std::string> enabledLanguages =
|