mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Refactor some swift only logic to be re-used by other languages
The logic in AddSwiftInterfaceIncludeDirectories is something that other languages will want going forward
This commit is contained in:
@@ -1333,18 +1333,18 @@ std::string cmGeneratorTarget::EvaluateInterfaceProperty(
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::string AddSwiftInterfaceIncludeDirectories(
|
||||
|
||||
std::string AddLangSpecificInterfaceIncludeDirectories(
|
||||
const cmGeneratorTarget* root, const cmGeneratorTarget* target,
|
||||
const std::string& config, cmGeneratorExpressionDAGChecker* context)
|
||||
const std::string& lang, const std::string& config,
|
||||
const std::string& propertyName, cmGeneratorExpressionDAGChecker* context)
|
||||
{
|
||||
cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
|
||||
"Swift_MODULE_DIRECTORY", nullptr,
|
||||
context };
|
||||
propertyName, nullptr, context };
|
||||
switch (dag.Check()) {
|
||||
case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
|
||||
dag.ReportError(nullptr,
|
||||
"$<TARGET_PROPERTY:" + target->GetName() +
|
||||
",Swift_MODULE_DIRECTORY>");
|
||||
dag.ReportError(
|
||||
nullptr, "$<TARGET_PROPERTY:" + target->GetName() + ",propertyName");
|
||||
CM_FALLTHROUGH;
|
||||
case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
|
||||
// No error. We just skip cyclic references.
|
||||
@@ -1360,13 +1360,11 @@ std::string AddSwiftInterfaceIncludeDirectories(
|
||||
target->GetLinkInterfaceLibraries(config, root, true)) {
|
||||
for (const cmLinkItem& library : interface->Libraries) {
|
||||
if (const cmGeneratorTarget* dependency = library.Target) {
|
||||
if (cm::contains(dependency->GetAllConfigCompileLanguages(),
|
||||
"Swift")) {
|
||||
std::string value =
|
||||
dependency->GetSafeProperty("Swift_MODULE_DIRECTORY");
|
||||
if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
|
||||
auto* lg = dependency->GetLocalGenerator();
|
||||
std::string value = dependency->GetSafeProperty(propertyName);
|
||||
if (value.empty()) {
|
||||
value =
|
||||
dependency->GetLocalGenerator()->GetCurrentBinaryDirectory();
|
||||
value = lg->GetCurrentBinaryDirectory();
|
||||
}
|
||||
|
||||
if (!directories.empty()) {
|
||||
@@ -1380,35 +1378,33 @@ std::string AddSwiftInterfaceIncludeDirectories(
|
||||
return directories;
|
||||
}
|
||||
|
||||
void AddSwiftImplicitIncludeDirectories(
|
||||
const cmGeneratorTarget* target, const std::string& config,
|
||||
void AddLangSpecificImplicitIncludeDirectories(
|
||||
const cmGeneratorTarget* target, const std::string& lang,
|
||||
const std::string& config, const std::string& propertyName,
|
||||
EvaluatedTargetPropertyEntries& entries)
|
||||
{
|
||||
if (const auto* libraries = target->GetLinkImplementationLibraries(config)) {
|
||||
cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
|
||||
"Swift_MODULE_DIRECTORY", nullptr,
|
||||
nullptr };
|
||||
propertyName, nullptr, nullptr };
|
||||
|
||||
for (const cmLinkImplItem& library : libraries->Libraries) {
|
||||
if (const cmGeneratorTarget* dependency = library.Target) {
|
||||
if (!dependency->IsInBuildSystem()) {
|
||||
continue;
|
||||
}
|
||||
if (cm::contains(dependency->GetAllConfigCompileLanguages(),
|
||||
"Swift")) {
|
||||
if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
|
||||
auto* lg = dependency->GetLocalGenerator();
|
||||
EvaluatedTargetPropertyEntry entry{ library, library.Backtrace };
|
||||
|
||||
if (cmProp val = dependency->GetProperty("Swift_MODULE_DIRECTORY")) {
|
||||
if (cmProp val = dependency->GetProperty(propertyName)) {
|
||||
entry.Values.emplace_back(*val);
|
||||
} else {
|
||||
entry.Values.emplace_back(
|
||||
dependency->GetLocalGenerator()->GetCurrentBinaryDirectory());
|
||||
entry.Values.emplace_back(lg->GetCurrentBinaryDirectory());
|
||||
}
|
||||
|
||||
cmExpandList(AddSwiftInterfaceIncludeDirectories(target, dependency,
|
||||
config, &dag),
|
||||
cmExpandList(AddLangSpecificInterfaceIncludeDirectories(
|
||||
target, dependency, lang, config, propertyName, &dag),
|
||||
entry.Values);
|
||||
|
||||
entries.Entries.emplace_back(std::move(entry));
|
||||
}
|
||||
}
|
||||
@@ -3442,7 +3438,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
|
||||
this, config, lang, &dagChecker, this->IncludeDirectoriesEntries);
|
||||
|
||||
if (lang == "Swift") {
|
||||
AddSwiftImplicitIncludeDirectories(this, config, entries);
|
||||
AddLangSpecificImplicitIncludeDirectories(
|
||||
this, lang, config, "Swift_MODULE_DIRECTORY", entries);
|
||||
}
|
||||
|
||||
AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES", lang,
|
||||
|
Reference in New Issue
Block a user