summaryrefslogtreecommitdiffstats
path: root/Source/cmcmd.cxx
diff options
context:
space:
mode:
authorAndrew Ng <andrew.ng@sony.com>2023-02-20 18:00:44 (GMT)
committerBrad King <brad.king@kitware.com>2023-02-23 19:35:08 (GMT)
commit0b552eb877b887638e8130bb6c982106a76827d8 (patch)
treea130f217a7239e77376007c1d928f2fd0a672abb /Source/cmcmd.cxx
parentdf5adfd5ab1f2ab30acf33031a75fc2c69dfd599 (diff)
downloadCMake-0b552eb877b887638e8130bb6c982106a76827d8.zip
CMake-0b552eb877b887638e8130bb6c982106a76827d8.tar.gz
CMake-0b552eb877b887638e8130bb6c982106a76827d8.tar.bz2
MSVC: Embed manifests directly for non-incremental vs_link_exe links
This avoids the need to separately execute `mt.exe` to perform the embedding of manifests into the output for non-incremental links. The primary motivation for this change is that this separate execution of `mt.exe` to embed manifests is known to cause intermittent failures due to AV/security scanning. The only change in behavior is that any linker generated manifest will no longer be output as a separate manifest file alongside the output file. Fixes: #24531
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r--Source/cmcmd.cxx42
1 files changed, 21 insertions, 21 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index d57b78b..a2a9e09 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -2329,6 +2329,9 @@ bool cmVSLink::Parse(std::vector<std::string>::const_iterator argBeg,
cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL") == 0 ||
cmSystemTools::Strucmp(arg->c_str(), "-INCREMENTAL") == 0) {
this->Incremental = true;
+ } else if (cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL:NO") == 0 ||
+ cmSystemTools::Strucmp(arg->c_str(), "-INCREMENTAL:NO") == 0) {
+ this->Incremental = false;
} else if (cmSystemTools::Strucmp(arg->c_str(), "/MANIFEST:NO") == 0 ||
cmSystemTools::Strucmp(arg->c_str(), "-MANIFEST:NO") == 0) {
this->LinkGeneratesManifest = false;
@@ -2353,17 +2356,11 @@ bool cmVSLink::Parse(std::vector<std::string>::const_iterator argBeg,
// pass it to the link command.
this->ManifestFileRC = intDir + "/manifest.rc";
this->ManifestFileRes = intDir + "/manifest.res";
- } else if (this->UserManifests.empty()) {
- // Prior to support for user-specified manifests CMake placed the
- // linker-generated manifest next to the binary (as if it were not to be
- // embedded) when not linking incrementally. Preserve this behavior.
- this->ManifestFile = this->TargetFile + ".manifest";
- this->LinkerManifestFile = this->ManifestFile;
- }
- if (this->LinkGeneratesManifest) {
- this->LinkCommand.emplace_back("/MANIFEST");
- this->LinkCommand.push_back("/MANIFESTFILE:" + this->LinkerManifestFile);
+ if (this->LinkGeneratesManifest) {
+ this->LinkCommand.emplace_back("/MANIFEST");
+ this->LinkCommand.push_back("/MANIFESTFILE:" + this->LinkerManifestFile);
+ }
}
return true;
@@ -2497,20 +2494,23 @@ int cmVSLink::LinkIncremental()
int cmVSLink::LinkNonIncremental()
{
- // Run the link command (possibly generates intermediate manifest).
- if (!RunCommand("LINK", this->LinkCommand, this->Verbose, FORMAT_DECIMAL)) {
- return -1;
- }
+ // Sort out any manifests.
+ if (this->LinkGeneratesManifest || !this->UserManifests.empty()) {
+ std::string opt =
+ std::string("/MANIFEST:EMBED,ID=") + (this->Type == 1 ? '1' : '2');
+ this->LinkCommand.emplace_back(opt);
- // If we have no manifest files we are done.
- if (!this->LinkGeneratesManifest && this->UserManifests.empty()) {
- return 0;
+ for (auto const& m : this->UserManifests) {
+ opt = "/MANIFESTINPUT:" + m;
+ this->LinkCommand.emplace_back(opt);
+ }
}
- // Run the manifest tool to embed the final manifest in the binary.
- std::string mtOut =
- "/outputresource:" + this->TargetFile + (this->Type == 1 ? ";#1" : ";#2");
- return this->RunMT(mtOut, false);
+ // Run the link command.
+ if (!RunCommand("LINK", this->LinkCommand, this->Verbose, FORMAT_DECIMAL)) {
+ return -1;
+ }
+ return 0;
}
int cmVSLink::RunMT(std::string const& out, bool notify)