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

Function GetSourceFile

Source/cmGeneratorExpressionNode.cxx:3705–3765  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3703
3704namespace {
3705bool GetSourceFile(
3706 cmRange<std::vector<std::string>::const_iterator> parameters,
3707 cm::GenEx::Evaluation* eval, GeneratorExpressionContent const* content,
3708 cmSourceFile*& sourceFile)
3709{
3710 auto sourceName = *parameters.begin();
3711 auto* makefile = eval->Context.LG->GetMakefile();
3712 sourceFile = nullptr;
3713
3714 if (parameters.size() == 2) {
3715 auto const& option = *parameters.advance(1).begin();
3716 auto const DIRECTORY = "DIRECTORY:"_s;
3717 auto const TARGET_DIRECTORY = "TARGET_DIRECTORY:"_s;
3718 if (cmHasPrefix(option, DIRECTORY)) {
3719 auto dir = option.substr(DIRECTORY.length());
3720 if (dir.empty()) {
3721 reportError(
3722 eval, content->GetOriginalExpression(),
3723 cmStrCat("No value provided for the ", DIRECTORY, " option."));
3724 return false;
3725 }
3726 dir = cmSystemTools::CollapseFullPath(
3727 dir, makefile->GetCurrentSourceDirectory());
3728 makefile = makefile->GetGlobalGenerator()->FindMakefile(dir);
3729 if (!makefile) {
3730 reportError(
3731 eval, content->GetOriginalExpression(),
3732 cmStrCat("Directory \"", dir, "\" is not known from CMake."));
3733 return false;
3734 }
3735 } else if (cmHasPrefix(option, TARGET_DIRECTORY)) {
3736 auto targetName = option.substr(TARGET_DIRECTORY.length());
3737 if (targetName.empty()) {
3738 reportError(eval, content->GetOriginalExpression(),
3739 cmStrCat("No value provided for the ", TARGET_DIRECTORY,
3740 " option."));
3741 return false;
3742 }
3743 auto* target = makefile->FindTargetToUse(targetName);
3744 if (!target) {
3745 reportError(eval, content->GetOriginalExpression(),
3746 cmStrCat("Non-existent target: ", targetName));
3747 return false;
3748 }
3749 makefile = makefile->GetGlobalGenerator()->FindMakefile(
3750 target->GetProperty("BINARY_DIR"));
3751 } else {
3752 reportError(eval, content->GetOriginalExpression(),
3753 cmStrCat("Invalid option. ", DIRECTORY, " or ",
3754 TARGET_DIRECTORY, " expected."));
3755 return false;
3756 }
3757
3758 sourceName = cmSystemTools::CollapseFullPath(
3759 sourceName,
3760 eval->Context.LG->GetMakefile()->GetCurrentSourceDirectory());
3761 }
3762

Callers 2

EvaluateMethod · 0.85
EvaluateMethod · 0.85

Calls 15

cmHasPrefixFunction · 0.85
reportErrorFunction · 0.85
lengthMethod · 0.80
GetOriginalExpressionMethod · 0.80
FindMakefileMethod · 0.80
FindTargetToUseMethod · 0.80
GetSourceMethod · 0.80
cmStrCatFunction · 0.70
beginMethod · 0.45
GetMakefileMethod · 0.45
sizeMethod · 0.45
advanceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…