diff options
author | Evan Wilde <etceterawilde@gmail.com> | 2022-10-26 23:11:51 (GMT) |
---|---|---|
committer | Evan Wilde <etceterawilde@gmail.com> | 2022-10-28 23:44:26 (GMT) |
commit | e88509d0e87eaa6f41603bfd7b07b653527e88c0 (patch) | |
tree | b7d43db0ee99bc1a1a7d79640d434725820d949c /Source/cmNinjaTargetGenerator.cxx | |
parent | bcf203226a6877824b91f2ffa9b5cc0373900273 (diff) | |
download | CMake-e88509d0e87eaa6f41603bfd7b07b653527e88c0.zip CMake-e88509d0e87eaa6f41603bfd7b07b653527e88c0.tar.gz CMake-e88509d0e87eaa6f41603bfd7b07b653527e88c0.tar.bz2 |
Swift: Omit output-file-map when used as a linker
Swift is used as the linker for non-swift files because it needs to pull
files like swiftrt.o in when swift symbols are present to ensure that
the swift runtime is linked.
The swift driver uses clang as the underlying linker, which pulls in
crtbegin.o and friends when appropriate, so using Swift as a linker for
C/C++ libraries is fine.
The output-file-map was getting passed to all Swift invocations,
regardless of whether or not we generated one. This patch changes it so
that we only include the output-file-map in the Swift compiler
invocation if we have actually generated the file.
Diffstat (limited to 'Source/cmNinjaTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index e4427f5..ae6a510 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1177,30 +1177,42 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( } this->GetImplFileStream(fileConfig) << "\n"; +} - if (!this->Configs[config].SwiftOutputMap.empty()) { - std::string const mapFilePath = - cmStrCat(this->GeneratorTarget->GetSupportDirectory(), '/', config, '/', - "output-file-map.json"); - std::string const targetSwiftDepsPath = [this, config]() -> std::string { - cmGeneratorTarget const* target = this->GeneratorTarget; - if (cmValue name = target->GetProperty("Swift_DEPENDENCIES_FILE")) { - return *name; - } - return this->ConvertToNinjaPath( - cmStrCat(target->GetSupportDirectory(), '/', config, '/', - target->GetName(), ".swiftdeps")); - }(); +void cmNinjaTargetGenerator::GenerateSwiftOutputFileMap( + const std::string& config, std::string& flags) +{ + if (this->Configs[config].SwiftOutputMap.empty()) { + return; + } - // build the global target dependencies - // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps - Json::Value deps(Json::objectValue); - deps["swift-dependencies"] = targetSwiftDepsPath; - this->Configs[config].SwiftOutputMap[""] = deps; + std::string const targetSwiftDepsPath = [this, config]() -> std::string { + cmGeneratorTarget const* target = this->GeneratorTarget; + if (cmValue name = target->GetProperty("Swift_DEPENDENCIES_FILE")) { + return *name; + } + return this->ConvertToNinjaPath(cmStrCat(target->GetSupportDirectory(), + '/', config, '/', + target->GetName(), ".swiftdeps")); + }(); - cmGeneratedFileStream output(mapFilePath); - output << this->Configs[config].SwiftOutputMap; - } + std::string mapFilePath = + cmStrCat(this->GeneratorTarget->GetSupportDirectory(), '/', config, '/', + "output-file-map.json"); + + // build the global target dependencies + // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps + Json::Value deps(Json::objectValue); + deps["swift-dependencies"] = targetSwiftDepsPath; + this->Configs[config].SwiftOutputMap[""] = deps; + + cmGeneratedFileStream output(mapFilePath); + output << this->Configs[config].SwiftOutputMap; + + // Add flag + this->LocalGenerator->AppendFlags(flags, "-output-file-map"); + this->LocalGenerator->AppendFlagEscape(flags, + ConvertToNinjaPath(mapFilePath)); } namespace { |