MCPcopy Create free account
hub / github.com/KDE/kdevelop / populateTargets

Function populateTargets

plugins/cmake/cmakemanager.cpp:388–482  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386}
387
388static 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)

Callers 5

populateTargetsMethod · 0.85
createImportJobMethod · 0.85
integrateDataMethod · 0.85
folderAddedMethod · 0.85

Calls 12

endsWithMethod · 0.80
lastPathSegmentMethod · 0.80
targetListMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
matchFunction · 0.50
isEmptyMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45
projectMethod · 0.45
setPathMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected