summaryrefslogtreecommitdiffstats
path: root/Source/cmCoreTryCompile.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-01-16 16:08:47 (GMT)
committerBrad King <brad.king@kitware.com>2023-01-16 21:58:49 (GMT)
commit65ed5c2ca816f8ba4068b163a2dcdab079df0038 (patch)
tree3a78119b61d16b15e521926c2ef2962b356661dc /Source/cmCoreTryCompile.cxx
parent0418efb7added53ff83e0868d44ea8965ec15027 (diff)
downloadCMake-65ed5c2ca816f8ba4068b163a2dcdab079df0038.zip
CMake-65ed5c2ca816f8ba4068b163a2dcdab079df0038.tar.gz
CMake-65ed5c2ca816f8ba4068b163a2dcdab079df0038.tar.bz2
try_compile: Report underlying error when COPY_FILE fails
Diffstat (limited to 'Source/cmCoreTryCompile.cxx')
-rw-r--r--Source/cmCoreTryCompile.cxx36
1 files changed, 24 insertions, 12 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 2a4ea80..1883816 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -1099,23 +1099,35 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
if ((res == 0) && arguments.CopyFileTo) {
std::string const& copyFile = *arguments.CopyFileTo;
- if (this->OutputFile.empty() ||
- !cmSystemTools::CopyFileAlways(this->OutputFile, copyFile)) {
- std::ostringstream emsg;
+ cmsys::SystemTools::CopyStatus status =
+ cmSystemTools::CopyFileAlways(this->OutputFile, copyFile);
+ if (!status) {
+ std::string err = status.GetString();
+ switch (status.Path) {
+ case cmsys::SystemTools::CopyStatus::SourcePath:
+ err = cmStrCat(err, " (input)");
+ break;
+ case cmsys::SystemTools::CopyStatus::DestPath:
+ err = cmStrCat(err, " (output)");
+ break;
+ default:
+ break;
+ }
/* clang-format off */
- emsg << "Cannot copy output executable\n"
- << " '" << this->OutputFile << "'\n"
- << "to destination specified by COPY_FILE:\n"
- << " '" << copyFile << "'\n";
+ err = cmStrCat(
+ "Cannot copy output executable\n",
+ " '", this->OutputFile, "'\n",
+ "to destination specified by COPY_FILE:\n",
+ " '", copyFile, "'\n",
+ "because:\n",
+ " ", err, "\n",
+ this->FindErrorMessage);
/* clang-format on */
- if (!this->FindErrorMessage.empty()) {
- emsg << this->FindErrorMessage;
- }
if (!arguments.CopyFileError) {
- this->Makefile->IssueMessage(MessageType::FATAL_ERROR, emsg.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, err);
return cm::nullopt;
}
- copyFileErrorMessage = emsg.str();
+ copyFileErrorMessage = std::move(err);
}
}