| 3703 | |
| 3704 | namespace { |
| 3705 | bool 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 |
no test coverage detected
searching dependent graphs…