From 64b336784507f7b8c9117cf5367a6abfc78a8ba3 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Sat, 18 Nov 2023 15:51:13 -0800 Subject: cmGlobalGenerator: Allow passing language to GetLangaugeOutputExtension The original GetLanguageOutputExtension took a sourcefile instead of the name of the language itself. This implementation provided a convenient handler for when the SourceFile doesn't know what language it is, but there are times where we know the language, but don't necessarily have a source file. Adding an overload that takes the name of the language and returns the extension of that language, or empty string if no extension is registered. --- Source/cmGlobalGenerator.cxx | 32 +++++++++++++++++++------------- Source/cmGlobalGenerator.h | 2 ++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index ca1afab..e74a8b0 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1158,24 +1158,30 @@ std::string cmGlobalGenerator::GetLanguageOutputExtension( { const std::string& lang = source.GetLanguage(); if (!lang.empty()) { - auto const it = this->LanguageToOutputExtension.find(lang); - if (it != this->LanguageToOutputExtension.end()) { - return it->second; - } - } else { - // if no language is found then check to see if it is already an - // output extension for some language. In that case it should be ignored - // and in this map, so it will not be compiled but will just be used. - std::string const& ext = source.GetExtension(); - if (!ext.empty()) { - if (this->OutputExtensions.count(ext)) { - return ext; - } + return this->GetLanguageOutputExtension(lang); + } + // if no language is found then check to see if it is already an + // output extension for some language. In that case it should be ignored + // and in this map, so it will not be compiled but will just be used. + std::string const& ext = source.GetExtension(); + if (!ext.empty()) { + if (this->OutputExtensions.count(ext)) { + return ext; } } return ""; } +std::string cmGlobalGenerator::GetLanguageOutputExtension( + std::string const& lang) const +{ + auto const it = this->LanguageToOutputExtension.find(lang); + if (it != this->LanguageToOutputExtension.end()) { + return it->second; + } + return ""; +} + std::string cmGlobalGenerator::GetLanguageFromExtension(const char* ext) const { // if there is an extension and it starts with . then move past the diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index aa54f69..d83b669 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -349,6 +349,8 @@ public: int GetLinkerPreference(const std::string& lang) const; //! What is the object file extension for a given source file? std::string GetLanguageOutputExtension(cmSourceFile const&) const; + //! What is the object file extension for a given language? + std::string GetLanguageOutputExtension(std::string const& lang) const; //! What is the configurations directory variable called? virtual const char* GetCMakeCFGIntDir() const { return "."; } -- cgit v0.12