| 2352 | } |
| 2353 | |
| 2354 | void 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)); |
no test coverage detected