mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 15:32:10 +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 {
|
namespace {
|
||||||
std::string AddSwiftInterfaceIncludeDirectories(
|
|
||||||
|
std::string AddLangSpecificInterfaceIncludeDirectories(
|
||||||
const cmGeneratorTarget* root, const cmGeneratorTarget* target,
|
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,
|
cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
|
||||||
"Swift_MODULE_DIRECTORY", nullptr,
|
propertyName, nullptr, context };
|
||||||
context };
|
|
||||||
switch (dag.Check()) {
|
switch (dag.Check()) {
|
||||||
case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
|
case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
|
||||||
dag.ReportError(nullptr,
|
dag.ReportError(
|
||||||
"$<TARGET_PROPERTY:" + target->GetName() +
|
nullptr, "$<TARGET_PROPERTY:" + target->GetName() + ",propertyName");
|
||||||
",Swift_MODULE_DIRECTORY>");
|
|
||||||
CM_FALLTHROUGH;
|
CM_FALLTHROUGH;
|
||||||
case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
|
case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
|
||||||
// No error. We just skip cyclic references.
|
// No error. We just skip cyclic references.
|
||||||
@@ -1360,13 +1360,11 @@ std::string AddSwiftInterfaceIncludeDirectories(
|
|||||||
target->GetLinkInterfaceLibraries(config, root, true)) {
|
target->GetLinkInterfaceLibraries(config, root, true)) {
|
||||||
for (const cmLinkItem& library : interface->Libraries) {
|
for (const cmLinkItem& library : interface->Libraries) {
|
||||||
if (const cmGeneratorTarget* dependency = library.Target) {
|
if (const cmGeneratorTarget* dependency = library.Target) {
|
||||||
if (cm::contains(dependency->GetAllConfigCompileLanguages(),
|
if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
|
||||||
"Swift")) {
|
auto* lg = dependency->GetLocalGenerator();
|
||||||
std::string value =
|
std::string value = dependency->GetSafeProperty(propertyName);
|
||||||
dependency->GetSafeProperty("Swift_MODULE_DIRECTORY");
|
|
||||||
if (value.empty()) {
|
if (value.empty()) {
|
||||||
value =
|
value = lg->GetCurrentBinaryDirectory();
|
||||||
dependency->GetLocalGenerator()->GetCurrentBinaryDirectory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!directories.empty()) {
|
if (!directories.empty()) {
|
||||||
@@ -1380,35 +1378,33 @@ std::string AddSwiftInterfaceIncludeDirectories(
|
|||||||
return directories;
|
return directories;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddSwiftImplicitIncludeDirectories(
|
void AddLangSpecificImplicitIncludeDirectories(
|
||||||
const cmGeneratorTarget* target, const std::string& config,
|
const cmGeneratorTarget* target, const std::string& lang,
|
||||||
|
const std::string& config, const std::string& propertyName,
|
||||||
EvaluatedTargetPropertyEntries& entries)
|
EvaluatedTargetPropertyEntries& entries)
|
||||||
{
|
{
|
||||||
if (const auto* libraries = target->GetLinkImplementationLibraries(config)) {
|
if (const auto* libraries = target->GetLinkImplementationLibraries(config)) {
|
||||||
cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
|
cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
|
||||||
"Swift_MODULE_DIRECTORY", nullptr,
|
propertyName, nullptr, nullptr };
|
||||||
nullptr };
|
|
||||||
|
|
||||||
for (const cmLinkImplItem& library : libraries->Libraries) {
|
for (const cmLinkImplItem& library : libraries->Libraries) {
|
||||||
if (const cmGeneratorTarget* dependency = library.Target) {
|
if (const cmGeneratorTarget* dependency = library.Target) {
|
||||||
if (!dependency->IsInBuildSystem()) {
|
if (!dependency->IsInBuildSystem()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cm::contains(dependency->GetAllConfigCompileLanguages(),
|
if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
|
||||||
"Swift")) {
|
auto* lg = dependency->GetLocalGenerator();
|
||||||
EvaluatedTargetPropertyEntry entry{ library, library.Backtrace };
|
EvaluatedTargetPropertyEntry entry{ library, library.Backtrace };
|
||||||
|
|
||||||
if (cmProp val = dependency->GetProperty("Swift_MODULE_DIRECTORY")) {
|
if (cmProp val = dependency->GetProperty(propertyName)) {
|
||||||
entry.Values.emplace_back(*val);
|
entry.Values.emplace_back(*val);
|
||||||
} else {
|
} else {
|
||||||
entry.Values.emplace_back(
|
entry.Values.emplace_back(lg->GetCurrentBinaryDirectory());
|
||||||
dependency->GetLocalGenerator()->GetCurrentBinaryDirectory());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmExpandList(AddSwiftInterfaceIncludeDirectories(target, dependency,
|
cmExpandList(AddLangSpecificInterfaceIncludeDirectories(
|
||||||
config, &dag),
|
target, dependency, lang, config, propertyName, &dag),
|
||||||
entry.Values);
|
entry.Values);
|
||||||
|
|
||||||
entries.Entries.emplace_back(std::move(entry));
|
entries.Entries.emplace_back(std::move(entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3442,7 +3438,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
|
|||||||
this, config, lang, &dagChecker, this->IncludeDirectoriesEntries);
|
this, config, lang, &dagChecker, this->IncludeDirectoriesEntries);
|
||||||
|
|
||||||
if (lang == "Swift") {
|
if (lang == "Swift") {
|
||||||
AddSwiftImplicitIncludeDirectories(this, config, entries);
|
AddLangSpecificImplicitIncludeDirectories(
|
||||||
|
this, lang, config, "Swift_MODULE_DIRECTORY", entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES", lang,
|
AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES", lang,
|
||||||
|
Reference in New Issue
Block a user