Ninja: support SWIFT_MODULE_NAME property

Add a new `SWIFT_MODULE_NAME` property that defaults to the target name.
This is needed as otherwise, the first source file determines the module
name.

Issue: #18800
This commit is contained in:
Saleem Abdulrasool 2019-01-16 11:42:10 -08:00 committed by Brad King
parent c59eae7ebc
commit 0ffe8f8844
3 changed files with 11 additions and 2 deletions

View File

@ -433,6 +433,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
vars.ObjectFileDir = "$OBJECT_FILE_DIR";
if (lang == "Swift") {
vars.SwiftAuxiliarySources = "$SWIFT_AUXILIARY_SOURCES";
vars.SwiftModuleName = "$SWIFT_MODULE_NAME";
}
// For some cases we do an explicit preprocessor invocation.
@ -904,9 +905,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
vars["DEFINES"] = this->ComputeDefines(source, language);
vars["INCLUDES"] = this->ComputeIncludes(source, language);
// The swift compiler needs all the sources besides the one being compiled in
// order to do the type checking. List all these "auxiliary" sources.
if (language == "Swift") {
// The swift compiler needs all the sources besides the one being compiled
// in order to do the type checking. List all these "auxiliary" sources.
std::string aux_sources;
cmGeneratorTarget::KindedSources const& sources =
this->GeneratorTarget->GetKindedSources(this->GetConfigName());
@ -917,6 +918,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
aux_sources += " " + this->GetSourceFilePath(src.Source.Value);
}
vars["SWIFT_AUXILIARY_SOURCES"] = aux_sources;
vars["SWIFT_MODULE_NAME"] = this->GeneratorTarget->GetName();
}
if (!this->NeedDepTypeMSVC(language)) {

View File

@ -167,6 +167,11 @@ std::string cmRulePlaceholderExpander::ExpandRuleVariable(
return replaceValues.SwiftAuxiliarySources;
}
}
if (replaceValues.SwiftModuleName) {
if (variable == "SWIFT_MODULE_NAME") {
return replaceValues.SwiftModuleName;
}
}
if (variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
variable == "TARGET_INSTALLNAME_DIR") {
// All these variables depend on TargetSOName

View File

@ -59,6 +59,7 @@ public:
const char* DependencyFile;
const char* FilterPrefix;
const char* SwiftAuxiliarySources;
const char* SwiftModuleName;
};
// Expand rule variables in CMake of the type found in language rules