| 504 | } |
| 505 | |
| 506 | void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) |
| 507 | { |
| 508 | /* vector of all sources for this target */ |
| 509 | std::vector<cmSourceFile*> sources; |
| 510 | this->GeneratorTarget->GetSourceFiles(sources, this->ConfigName); |
| 511 | |
| 512 | /* for each source file assign it to its group */ |
| 513 | std::map<std::string, std::vector<cmSourceFile*>> groupFiles; |
| 514 | std::set<std::string> groupNames; |
| 515 | for (cmSourceFile* sf : sources) { |
| 516 | cmSourceGroup const* sourceGroup = |
| 517 | this->LocalGenerator->FindSourceGroup(sf->ResolveFullPath()); |
| 518 | std::string gn = sourceGroup->GetFullName(); |
| 519 | groupFiles[gn].push_back(sf); |
| 520 | groupNames.insert(std::move(gn)); |
| 521 | } |
| 522 | |
| 523 | /* list of known groups and the order they are displayed in a project file */ |
| 524 | std::vector<std::string> const standardGroups = { |
| 525 | "CMake Rules", "Header Files", "Source Files", |
| 526 | "Object Files", "Object Libraries", "Resources" |
| 527 | }; |
| 528 | |
| 529 | /* list of groups in the order they are displayed in a project file*/ |
| 530 | std::vector<std::string> groupFilesList(groupFiles.size()); |
| 531 | |
| 532 | /* put the groups in the order they should be listed |
| 533 | * - standard groups first, and then everything else |
| 534 | * in the order used by std::map. |
| 535 | */ |
| 536 | int i = 0; |
| 537 | for (std::string const& gn : standardGroups) { |
| 538 | auto n = groupNames.find(gn); |
| 539 | if (n != groupNames.end()) { |
| 540 | groupFilesList[i] = *n; |
| 541 | i += 1; |
| 542 | groupNames.erase(gn); |
| 543 | } else if (this->TagType == GhsMultiGpj::CUSTOM_TARGET && |
| 544 | gn == "CMake Rules") { |
| 545 | /* make sure that rules folder always exists in case of custom targets |
| 546 | * that have no custom commands except for pre or post build events. |
| 547 | */ |
| 548 | groupFilesList.resize(groupFilesList.size() + 1); |
| 549 | groupFilesList[i] = gn; |
| 550 | i += 1; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | { /* catch-all group - is last item */ |
| 555 | std::string gn; |
| 556 | auto n = groupNames.find(gn); |
| 557 | if (n != groupNames.end()) { |
| 558 | groupFilesList.back() = *n; |
| 559 | groupNames.erase(gn); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | for (auto const& n : groupNames) { |
no test coverage detected