summaryrefslogtreecommitdiffstats
path: root/Source/cmNinjaNormalTargetGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-05-20 14:55:11 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-05-20 14:55:27 (GMT)
commita9fb9a8774a7b1dd411542d1d14fb537968e32f1 (patch)
tree2d74dc351b298a5317d05634170c91a8b43bc07e /Source/cmNinjaNormalTargetGenerator.cxx
parent28ee31149030c75c32ebbf134502a9d020dbd54b (diff)
parenta9180ccf9a9e845658ba455e2dbc2447b18d2654 (diff)
downloadCMake-a9fb9a8774a7b1dd411542d1d14fb537968e32f1.zip
CMake-a9fb9a8774a7b1dd411542d1d14fb537968e32f1.tar.gz
CMake-a9fb9a8774a7b1dd411542d1d14fb537968e32f1.tar.bz2
Merge topic 'ninja-swift'
a9180ccf9a Tests: add a check for the Swift compiler d745551fb6 Help: add some initial documentation for Swift support 9a182c9e5b Auxiliary: update vim syntax highlighting e9b0063e8e Modules: add build rules for Swift Ninja support b6412e3e38 Ninja: add placeholders to support Swift build 7d7f31161d Ninja: add support for Swift's output-file-map.json d688c4c19d Swift: remove unnecessary unreleased Ninja infrastructure 0723582208 Swift: Detect compiler version ... Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3297
Diffstat (limited to 'Source/cmNinjaNormalTargetGenerator.cxx')
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx102
1 files changed, 76 insertions, 26 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index dd63a54..06063b2 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -281,10 +281,13 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType());
vars.Language = this->TargetLinkLanguage.c_str();
+
if (this->TargetLinkLanguage == "Swift") {
- vars.SwiftPartialModules = "$SWIFT_PARTIAL_MODULES";
- vars.TargetSwiftModule = "$TARGET_SWIFT_MODULE";
- vars.TargetSwiftDoc = "$TARGET_SWIFT_DOC";
+ 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;
@@ -805,35 +808,82 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
outputs.push_back(targetOutputReal);
if (this->TargetLinkLanguage == "Swift") {
- if (const char* name = gt.GetProperty("SWIFT_MODULE_NAME")) {
- vars["TARGET_SWIFT_DOC"] = std::string(name) + ".swiftdoc";
- vars["TARGET_SWIFT_MODULE"] = std::string(name) + ".swiftmodule";
- } else {
- vars["TARGET_SWIFT_DOC"] = gt.GetName() + ".swiftdoc";
- vars["TARGET_SWIFT_MODULE"] = gt.GetName() + ".swiftmodule";
- }
- outputs.push_back(vars["TARGET_SWIFT_DOC"]);
- outputs.push_back(vars["TARGET_SWIFT_MODULE"]);
+ 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;
+ }
- cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
+ return this->GetLocalGenerator()->ConvertToOutputFormat(
+ this->ConvertToNinjaPath(directory + "/" + name),
+ cmOutputConverter::SHELL);
+ }();
- std::string partials;
- std::vector<cmSourceFile const*> sources;
- gt.GetObjectSources(sources, this->GetConfigName());
- for (cmSourceFile const* source : sources) {
- partials += " ";
- if (const char* partial = source->GetProperty("SWIFT_PARTIAL_MODULE")) {
- partials += partial;
- } else {
- partials += localGen.GetTargetDirectory(&gt) + "/" +
- gt.GetObjectName(source) + ".swiftmodule";
+ vars["SWIFT_MODULE_NAME"] = [this]() -> std::string {
+ if (const char* name =
+ this->GetGeneratorTarget()->GetProperty("Swift_MODULE_NAME")) {
+ return name;
}
- }
- vars["SWIFT_PARTIAL_MODULES"] = partials;
+ 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()) {