MCPcopy Create free account
hub / github.com/Kitware/CMake / TryCompileCode

Method TryCompileCode

Source/cmCoreTryCompile.cxx:315–1345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313}
314
315cm::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 }

Callers 2

cmTryCompileCommandFunction · 0.80
TryRunCodeMethod · 0.80

Calls 15

WriteSourceMethod · 0.95
FindOutputFileMethod · 0.95
moveFunction · 0.85
cmTrimWhitespaceFunction · 0.85
cmHasLiteralSuffixFunction · 0.85
FindTargetToUseMethod · 0.80
emplace_backMethod · 0.80
strMethod · 0.80
c_strMethod · 0.80
emplaceMethod · 0.80

Tested by

no test coverage detected