diff options
author | Evan Wilde <etceterawilde@gmail.com> | 2023-01-02 06:11:46 (GMT) |
---|---|---|
committer | Evan Wilde <etceterawilde@gmail.com> | 2023-01-21 18:37:09 (GMT) |
commit | d0b469b7e03e0d902b3d8e2bf2f0b694438f0bf1 (patch) | |
tree | 6cc429b316b4c9db309f1e20946a744e2221f67e | |
parent | 06c7e88b9148fce5721335409015892b6fa4faba (diff) | |
download | CMake-d0b469b7e03e0d902b3d8e2bf2f0b694438f0bf1.zip CMake-d0b469b7e03e0d902b3d8e2bf2f0b694438f0bf1.tar.gz CMake-d0b469b7e03e0d902b3d8e2bf2f0b694438f0bf1.tar.bz2 |
Ninja: NFC: refactor swift module name computations
In order to handle determining the swiftmodule name to add to the ninja
dependency graph, we'll need to be able to compute the swiftmodule name
for the dependency target, not just the current target. This patch
refactors the computation of the module name out of inaccessible lambdas
and into static functions that can compute the swiftmodule name from the
generator and the target.
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index d481b64..c427bde 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -940,6 +940,37 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkStatement( this->WriteNvidiaDeviceLinkRule(usedResponseFile, config); } +/// Get the target property if it exists, or return a default +static std::string GetTargetPropertyOrDefault(cmGeneratorTarget const* target, + std::string const& property, + std::string defaultValue) +{ + if (cmValue name = target->GetProperty(property)) { + return *name; + } + return defaultValue; +} + +/// Compute the swift module name for target +static std::string GetSwiftModuleName(cmGeneratorTarget const* target) +{ + return GetTargetPropertyOrDefault(target, "Swift_MODULE_NAME", + target->GetName()); +} + +/// Compute the swift module path for the target +/// The returned path will need to be converted to the generator path +static std::string GetSwiftModulePath(cmGeneratorTarget const* target) +{ + std::string moduleName = GetSwiftModuleName(target); + std::string moduleDirectory = GetTargetPropertyOrDefault( + target, "Swift_MODULE_DIRECTORY", + target->LocalGenerator->GetCurrentBinaryDirectory()); + std::string moduleFileName = GetTargetPropertyOrDefault( + target, "Swift_MODULE", moduleName + ".swiftmodule"); + return moduleDirectory + "/" + moduleFileName; +} + void cmNinjaNormalTargetGenerator::WriteLinkStatement( const std::string& config, const std::string& fileConfig, bool firstForConfig) @@ -1038,31 +1069,10 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( return targetNames.Base; }(); - vars["SWIFT_MODULE_NAME"] = [gt]() -> std::string { - if (cmValue name = gt->GetProperty("Swift_MODULE_NAME")) { - return *name; - } - return gt->GetName(); - }(); - - vars["SWIFT_MODULE"] = [this](const std::string& module) -> std::string { - std::string directory = - this->GetLocalGenerator()->GetCurrentBinaryDirectory(); - if (cmValue prop = this->GetGeneratorTarget()->GetProperty( - "Swift_MODULE_DIRECTORY")) { - directory = *prop; - } - - std::string name = module + ".swiftmodule"; - if (cmValue prop = - this->GetGeneratorTarget()->GetProperty("Swift_MODULE")) { - name = *prop; - } - - return this->GetLocalGenerator()->ConvertToOutputFormat( - this->ConvertToNinjaPath(directory + "/" + name), - cmOutputConverter::SHELL); - }(vars["SWIFT_MODULE_NAME"]); + vars["SWIFT_MODULE_NAME"] = GetSwiftModuleName(gt); + vars["SWIFT_MODULE"] = this->GetLocalGenerator()->ConvertToOutputFormat( + this->ConvertToNinjaPath(GetSwiftModulePath(gt)), + cmOutputConverter::SHELL); vars["SWIFT_SOURCES"] = [this, config]() -> std::string { std::vector<cmSourceFile const*> sources; |