cmCoreTryCompile: Select source-file signature project/target names earlier

This commit is contained in:
Brad King
2022-06-27 15:17:18 -04:00
parent 8b0ee799e4
commit 7a5b1b6010

View File

@@ -283,7 +283,6 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
std::vector<std::string> linkOptions;
std::string libsToLink = " ";
bool useOldLinkLibs = true;
char targetNameBuf[64];
bool didOutputVariable = false;
bool didCopyFile = false;
bool didCopyFileError = false;
@@ -419,6 +418,16 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
return -1;
}
if (this->SrcFileSignature) {
projectName = "CMAKE_TRY_COMPILE";
/* Use a random file name to avoid rapid creation and deletion
of the same executable name (some filesystems fail on that). */
char targetNameBuf[64];
snprintf(targetNameBuf, sizeof(targetNameBuf), "cmTC_%05x",
cmSystemTools::RandomSeed() & 0xFFFFF);
targetName = targetNameBuf;
}
if (didCopyFile && copyFile.empty()) {
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"COPY_FILE must be followed by a file path");
@@ -733,12 +742,6 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
cmJoin(compileDefs, "]==] [==[").c_str());
}
/* Use a random file name to avoid rapid creation and deletion
of the same executable name (some filesystems fail on that). */
snprintf(targetNameBuf, sizeof(targetNameBuf), "cmTC_%05x",
cmSystemTools::RandomSeed() & 0xFFFFF);
targetName = targetNameBuf;
if (!targets.empty()) {
std::string fname = "/" + std::string(targetName) + "Targets.cmake";
cmExportTryCompileFileGenerator tcfg(gg, targets, this->Makefile,
@@ -895,7 +898,6 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
libsToLink.c_str());
}
fclose(fout);
projectName = "CMAKE_TRY_COMPILE";
}
// Forward a set of variables to the inner project cache.