| 313 | } |
| 314 | |
| 315 | cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode( |
| 316 | Arguments& arguments, cmStateEnums::TargetType targetType) |
| 317 | { |
| 318 | this->OutputFile.clear(); |
| 319 | // which signature were we called with ? |
| 320 | this->SrcFileSignature = true; |
| 321 | |
| 322 | bool useUniqueBinaryDirectory = false; |
| 323 | std::string sourceDirectory; |
| 324 | std::string projectName; |
| 325 | std::string targetName; |
| 326 | if (arguments.ProjectName) { |
| 327 | this->SrcFileSignature = false; |
| 328 | if (!arguments.SourceDirectoryOrFile || |
| 329 | arguments.SourceDirectoryOrFile->empty()) { |
| 330 | this->Makefile->IssueMessage(MessageType::FATAL_ERROR, |
| 331 | "No <srcdir> specified."); |
| 332 | return cm::nullopt; |
| 333 | } |
| 334 | sourceDirectory = *arguments.SourceDirectoryOrFile; |
| 335 | projectName = *arguments.ProjectName; |
| 336 | if (arguments.TargetName) { |
| 337 | targetName = *arguments.TargetName; |
| 338 | } |
| 339 | } else { |
| 340 | projectName = "CMAKE_TRY_COMPILE"; |
| 341 | /* Use a random file name to avoid rapid creation and deletion |
| 342 | of the same executable name (some filesystems fail on that). */ |
| 343 | char targetNameBuf[64]; |
| 344 | snprintf(targetNameBuf, sizeof(targetNameBuf), "cmTC_%05x", |
| 345 | cmSystemTools::RandomNumber() & 0xFFFFF); |
| 346 | targetName = targetNameBuf; |
| 347 | } |
| 348 | |
| 349 | if (!arguments.BinaryDirectory || arguments.BinaryDirectory->empty()) { |
| 350 | this->Makefile->IssueMessage(MessageType::FATAL_ERROR, |
| 351 | "No <bindir> specified."); |
| 352 | return cm::nullopt; |
| 353 | } |
| 354 | if (*arguments.BinaryDirectory == unique_binary_directory) { |
| 355 | // leave empty until we're ready to create it, so we don't try to remove |
| 356 | // a non-existing directory if we abort due to e.g. bad arguments |
| 357 | this->BinaryDirectory.clear(); |
| 358 | useUniqueBinaryDirectory = true; |
| 359 | } else { |
| 360 | if (!cmSystemTools::FileIsFullPath(*arguments.BinaryDirectory)) { |
| 361 | this->Makefile->IssueMessage( |
| 362 | MessageType::FATAL_ERROR, |
| 363 | cmStrCat("<bindir> is not an absolute path:\n '", |
| 364 | *arguments.BinaryDirectory, '\'')); |
| 365 | return cm::nullopt; |
| 366 | } |
| 367 | this->BinaryDirectory = *arguments.BinaryDirectory; |
| 368 | // compute the binary dir when TRY_COMPILE is called with a src file |
| 369 | // signature |
| 370 | if (this->SrcFileSignature) { |
| 371 | this->BinaryDirectory += "/CMakeFiles/CMakeTmp"; |
| 372 | } |
no test coverage detected