From 7a5b1b6010d9f3f2bf979a505eb4c698b994bf26 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 27 Jun 2022 15:17:18 -0400 Subject: cmCoreTryCompile: Select source-file signature project/target names earlier --- Source/cmCoreTryCompile.cxx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 8d41f00..d90b574 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -283,7 +283,6 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, std::vector 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 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 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 const& argv, libsToLink.c_str()); } fclose(fout); - projectName = "CMAKE_TRY_COMPILE"; } // Forward a set of variables to the inner project cache. -- cgit v0.12