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

Method WriteSource

Source/cmCoreTryCompile.cxx:1454–1483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1452}
1453
1454std::string cmCoreTryCompile::WriteSource(std::string const& filename,
1455 std::string const& content,
1456 char const* command) const
1457{
1458 if (!cmSystemTools::GetFilenamePath(filename).empty()) {
1459 auto const& msg =
1460 cmStrCat(command, " given invalid filename \"", filename, '"');
1461 this->Makefile->IssueMessage(MessageType::FATAL_ERROR, msg);
1462 return {};
1463 }
1464
1465 auto filepath = cmStrCat(this->BinaryDirectory, '/', filename);
1466 cmsys::ofstream file{ filepath.c_str(), std::ios::out };
1467 if (!file) {
1468 auto const& msg =
1469 cmStrCat(command, " failed to open \"", filename, "\" for writing");
1470 this->Makefile->IssueMessage(MessageType::FATAL_ERROR, msg);
1471 return {};
1472 }
1473
1474 file << content;
1475 if (!file) {
1476 auto const& msg = cmStrCat(command, " failed to write \"", filename, '"');
1477 this->Makefile->IssueMessage(MessageType::FATAL_ERROR, msg);
1478 return {};
1479 }
1480
1481 file.close();
1482 return filepath;
1483}
1484
1485void cmCoreTryCompile::WriteTryCompileEventFields(
1486 cmConfigureLog& log, cmTryCompileResult const& compileResult)

Callers 1

TryCompileCodeMethod · 0.95

Calls 5

c_strMethod · 0.80
cmStrCatFunction · 0.70
emptyMethod · 0.45
IssueMessageMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected