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

Method ExportSwiftObjectCompileCommand

Source/cmNinjaTargetGenerator.cxx:2354–2426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2352}
2353
2354void cmNinjaTargetGenerator::ExportSwiftObjectCompileCommand(
2355 std::vector<cmSourceFile const*> const& moduleSourceFiles,
2356 std::string const& moduleObjectFilename, std::string const& flags,
2357 std::string const& defines, std::string const& includes,
2358 std::string const& outputConfig, bool singleOutput)
2359{
2360 if (!this->GeneratorTarget->GetPropertyAsBool("EXPORT_COMPILE_COMMANDS")) {
2361 return;
2362 }
2363
2364 auto escapeSourceFileName = [this](std::string srcFilename) -> std::string {
2365 if (!cmSystemTools::FileIsFullPath(srcFilename)) {
2366 srcFilename =
2367 cmSystemTools::CollapseFullPath(srcFilename,
2368 this->GetGlobalGenerator()
2369 ->GetCMakeInstance()
2370 ->GetHomeOutputDirectory());
2371 }
2372
2373 return this->LocalGenerator->ConvertToOutputFormat(
2374 srcFilename, cmOutputConverter::SHELL);
2375 };
2376 auto escapedModuleObjectFilename =
2377 this->ConvertToNinjaPath(moduleObjectFilename);
2378
2379 cmRulePlaceholderExpander::RuleVariables compileObjectVars;
2380 compileObjectVars.Language = "Swift";
2381 compileObjectVars.Flags = flags.c_str();
2382 compileObjectVars.Defines = defines.c_str();
2383 compileObjectVars.Includes = includes.c_str();
2384
2385 // Build up the list of source files in the module
2386 std::vector<std::string> filenames;
2387 filenames.reserve(moduleSourceFiles.size());
2388 for (cmSourceFile const* sf : moduleSourceFiles) {
2389 filenames.emplace_back(
2390 escapeSourceFileName(this->GetCompiledSourceNinjaPath(sf)));
2391 }
2392 // Note that `escapedSourceFilenames` must remain alive until the
2393 // compileObjectVars is consumed or Source will be a dangling pointer.
2394 std::string const escapedSourceFilenames = cmJoin(filenames, " ");
2395 compileObjectVars.Source = escapedSourceFilenames.c_str();
2396
2397 std::string const& compileCommand =
2398 this->Makefile->GetRequiredDefinition("CMAKE_Swift_COMPILE_OBJECT");
2399 cmList compileCmds(compileCommand);
2400
2401 auto rulePlaceholderExpander =
2402 this->GetLocalGenerator()->CreateRulePlaceholderExpander();
2403
2404 for (cmSourceFile const* sf : moduleSourceFiles) {
2405 std::string const sourceFilename = this->GetCompiledSourceNinjaPath(sf);
2406 std::string objectFilename = escapedModuleObjectFilename;
2407
2408 if (!singleOutput) {
2409 // If it's not single-output, each source file gets a separate object
2410 objectFilename =
2411 this->ConvertToNinjaPath(this->GetObjectFilePath(sf, outputConfig));

Callers 1

Calls 15

GetGlobalGeneratorMethod · 0.95
GetLocalGeneratorMethod · 0.95
GetObjectFilePathMethod · 0.95
c_strMethod · 0.80
reserveMethod · 0.80
emplace_backMethod · 0.80
ExpandRuleVariablesMethod · 0.80
BuildCommandLineMethod · 0.80
cmJoinFunction · 0.70
GetPropertyAsBoolMethod · 0.45
GetCMakeInstanceMethod · 0.45

Tested by

no test coverage detected