diff options
author | friendlyanon <friendlyanon_@hotmail.com> | 2022-06-30 18:51:18 (GMT) |
---|---|---|
committer | friendlyanon <friendlyanon_@hotmail.com> | 2022-06-30 21:37:05 (GMT) |
commit | b4fd385c9b467182d3572854168e2afa037210bc (patch) | |
tree | cb60099c2540550c09f2023ac5663e4a733a0e10 /Source/cmMakefile.cxx | |
parent | 66bfe14309e9e8968a159d1eda7ed00322d5559d (diff) | |
download | CMake-b4fd385c9b467182d3572854168e2afa037210bc.zip CMake-b4fd385c9b467182d3572854168e2afa037210bc.tar.gz CMake-b4fd385c9b467182d3572854168e2afa037210bc.tar.bz2 |
cmMakefile: Dedupe languages when enabling them
cmMakefile::EnableLanguage() now deduplicates the languages argument and
emits an author warning listing the languages that were defined multiple
times in a single call.
Fixes: #23596
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r-- | Source/cmMakefile.cxx | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 79a56c1..208d907 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3491,13 +3491,35 @@ void cmMakefile::EnableLanguage(std::vector<std::string> const& languages, if (const char* def = this->GetGlobalGenerator()->GetCMakeCFGIntDir()) { this->AddDefinition("CMAKE_CFG_INTDIR", def); } + + std::vector<std::string> unique_languages; + { + std::vector<std::string> duplicate_languages; + for (std::string const& language : languages) { + if (!cm::contains(unique_languages, language)) { + unique_languages.push_back(language); + } else if (!cm::contains(duplicate_languages, language)) { + duplicate_languages.push_back(language); + } + } + if (!duplicate_languages.empty()) { + auto quantity = duplicate_languages.size() == 1 ? std::string(" has") + : std::string("s have"); + this->IssueMessage(MessageType::AUTHOR_WARNING, + "Languages to be enabled may not be specified more " + "than once at the same time. The following language" + + quantity + " been specified multiple times: " + + cmJoin(duplicate_languages, ", ")); + } + } + // If RC is explicitly listed we need to do it after other languages. // On some platforms we enable RC implicitly while enabling others. // Do not let that look like recursive enable_language(RC). std::vector<std::string> languages_without_RC; std::vector<std::string> languages_for_RC; - languages_without_RC.reserve(languages.size()); - for (std::string const& language : languages) { + languages_without_RC.reserve(unique_languages.size()); + for (std::string const& language : unique_languages) { if (language == "RC") { languages_for_RC.push_back(language); } else { |