| 386 | } |
| 387 | |
| 388 | static void populateTargets(ProjectFolderItem* folder, const QHash<KDevelop::Path, QVector<CMakeTarget>>& targets) |
| 389 | { |
| 390 | auto isValidTarget = [](const CMakeTarget& target) -> bool { |
| 391 | if (target.type != CMakeTarget::Custom) |
| 392 | return true; |
| 393 | |
| 394 | // utility targets with empty sources are strange (e.g. _QCH) -> skip them |
| 395 | if (target.sources.isEmpty()) |
| 396 | return false; |
| 397 | |
| 398 | auto match |
| 399 | = [](const auto& needles, auto&& op) { return std::any_of(std::begin(needles), std::end(needles), op); }; |
| 400 | auto startsWith = [&](const auto& needle) { return target.name.startsWith(needle); }; |
| 401 | auto endsWith = [&](const auto& needle) { return target.name.endsWith(needle); }; |
| 402 | auto equals = [&](const auto& needle) { return target.name == needle; }; |
| 403 | |
| 404 | const auto invalidPrefixes = { QLatin1String("install/") }; |
| 405 | const auto invalidSuffixes |
| 406 | = { QLatin1String("_automoc"), QLatin1String("_autogen"), QLatin1String("_autogen_timestamp_deps") }; |
| 407 | const auto standardTargets |
| 408 | = { QLatin1String("edit_cache"), QLatin1String("rebuild_cache"), QLatin1String("list_install_components"), |
| 409 | QLatin1String("test"), // not really standard, but applicable for make and ninja |
| 410 | QLatin1String("install") }; |
| 411 | return !match(invalidPrefixes, startsWith) && !match(invalidSuffixes, endsWith) |
| 412 | && !match(standardTargets, equals); |
| 413 | }; |
| 414 | |
| 415 | auto isValidTargetSource = [](const Path& source) { |
| 416 | const auto& segments = source.segments(); |
| 417 | const auto lastSegment = source.lastPathSegment(); |
| 418 | // skip non-existent cmake internal rule files |
| 419 | if (lastSegment.endsWith(QLatin1String(".rule"))) { |
| 420 | return false; |
| 421 | } |
| 422 | |
| 423 | const auto secondToLastSegment = segments.value(segments.size() - 2); |
| 424 | // ignore generated cmake-internal files |
| 425 | if (secondToLastSegment == QLatin1String("CMakeFiles")) { |
| 426 | return false; |
| 427 | } |
| 428 | |
| 429 | // also skip *_autogen/timestamp files |
| 430 | if (lastSegment == QLatin1String("timestamp") && secondToLastSegment.endsWith(QLatin1String("_autogen"))) { |
| 431 | return false; |
| 432 | } |
| 433 | |
| 434 | return true; |
| 435 | }; |
| 436 | |
| 437 | // start by deleting all targets, the type may have changed anyways |
| 438 | const auto tl = folder->targetList(); |
| 439 | for (ProjectTargetItem* item : tl) { |
| 440 | delete item; |
| 441 | } |
| 442 | |
| 443 | QHash<QString, ProjectBaseItem*> folderItems; |
| 444 | folderItems[{}] = folder; |
| 445 | auto findOrCreateFolderItem = [&folderItems, folder](const QString& targetFolder) |
no test coverage detected