diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2019-05-08 06:11:52 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-05-16 18:41:05 (GMT) |
commit | b6412e3e38ba22bf816445f19394e7c8027c186f (patch) | |
tree | 7227811201094f5ffd37ce57def6a6ef95449422 /Source/cmNinjaNormalTargetGenerator.cxx | |
parent | 7d7f31161d65d8b1f460eaf23e1b092bdaf7c238 (diff) | |
download | CMake-b6412e3e38ba22bf816445f19394e7c8027c186f.zip CMake-b6412e3e38ba22bf816445f19394e7c8027c186f.tar.gz CMake-b6412e3e38ba22bf816445f19394e7c8027c186f.tar.bz2 |
Ninja: add placeholders to support Swift build
Add the placeholders needed to support compiling Swift code.
Diffstat (limited to 'Source/cmNinjaNormalTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 770d80c..146ef79 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -282,6 +282,14 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) vars.Language = this->TargetLinkLanguage.c_str(); + if (this->TargetLinkLanguage == "Swift") { + vars.SwiftLibraryName = "$SWIFT_LIBRARY_NAME"; + vars.SwiftModule = "$SWIFT_MODULE"; + vars.SwiftModuleName = "$SWIFT_MODULE_NAME"; + vars.SwiftOutputFileMap = "$SWIFT_OUTPUT_FILE_MAP"; + vars.SwiftSources = "$SWIFT_SOURCES"; + } + std::string responseFlag; if (!useResponseFile) { vars.Objects = "$in"; @@ -799,8 +807,83 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() cmNinjaDeps outputs; outputs.push_back(targetOutputReal); + if (this->TargetLinkLanguage == "Swift") { + vars["SWIFT_LIBRARY_NAME"] = [this]() -> std::string { + cmGeneratorTarget::Names targetNames = + this->GetGeneratorTarget()->GetLibraryNames(this->GetConfigName()); + return targetNames.Base; + }(); + + vars["SWIFT_MODULE"] = [this]() -> std::string { + cmGeneratorTarget::Names targetNames = + this->GetGeneratorTarget()->GetLibraryNames(this->GetConfigName()); + + std::string directory = + this->GetLocalGenerator()->GetCurrentBinaryDirectory(); + if (const char* prop = this->GetGeneratorTarget()->GetProperty( + "Swift_MODULE_DIRECTORY")) { + directory = prop; + } + + std::string name = targetNames.Base + ".swiftmodule"; + if (const char* prop = + this->GetGeneratorTarget()->GetProperty("Swift_MODULE")) { + name = prop; + } + + return this->GetLocalGenerator()->ConvertToOutputFormat( + this->ConvertToNinjaPath(directory + "/" + name), + cmOutputConverter::SHELL); + }(); + + vars["SWIFT_MODULE_NAME"] = [this]() -> std::string { + if (const char* name = + this->GetGeneratorTarget()->GetProperty("Swift_MODULE_NAME")) { + return name; + } + return this->GetGeneratorTarget()->GetName(); + }(); + + vars["SWIFT_OUTPUT_FILE_MAP"] = + this->GetLocalGenerator()->ConvertToOutputFormat( + this->ConvertToNinjaPath(gt.GetSupportDirectory() + + "/output-file-map.json"), + cmOutputConverter::SHELL); + + vars["SWIFT_SOURCES"] = [this]() -> std::string { + std::vector<cmSourceFile const*> sources; + std::stringstream oss; + + this->GetGeneratorTarget()->GetObjectSources(sources, + this->GetConfigName()); + cmLocalGenerator const* LocalGen = this->GetLocalGenerator(); + for (const auto& source : sources) { + oss << " " + << LocalGen->ConvertToOutputFormat( + this->ConvertToNinjaPath(this->GetSourceFilePath(source)), + cmOutputConverter::SHELL); + } + return oss.str(); + }(); + } + // Compute specific libraries to link with. - cmNinjaDeps explicitDeps = this->GetObjects(); + cmNinjaDeps explicitDeps; + if (this->TargetLinkLanguage == "Swift") { + std::vector<cmSourceFile const*> sources; + this->GetGeneratorTarget()->GetObjectSources(sources, + this->GetConfigName()); + for (const auto& source : sources) { + outputs.push_back( + this->ConvertToNinjaPath(this->GetObjectFilePath(source))); + explicitDeps.push_back( + this->ConvertToNinjaPath(this->GetSourceFilePath(source))); + } + + outputs.push_back(vars["SWIFT_MODULE"]); + } else { + explicitDeps = this->GetObjects(); + } cmNinjaDeps implicitDeps = this->ComputeLinkDeps(this->TargetLinkLanguage); if (!this->DeviceLinkObject.empty()) { |