diff options
author | Robert Maynard <rmaynard@nvidia.com> | 2022-04-27 17:54:42 (GMT) |
---|---|---|
committer | Robert Maynard <rmaynard@nvidia.com> | 2022-05-04 13:33:35 (GMT) |
commit | 627ef4c1d002cf642ef0ef9048c5e3fa24069516 (patch) | |
tree | 810f7b1cd4c27b9e20fee545147b25192fcd3de9 /Source/cmCommonTargetGenerator.cxx | |
parent | 1d82670bd4daff26d0d0169820b289bc401f4943 (diff) | |
download | CMake-627ef4c1d002cf642ef0ef9048c5e3fa24069516.zip CMake-627ef4c1d002cf642ef0ef9048c5e3fa24069516.tar.gz CMake-627ef4c1d002cf642ef0ef9048c5e3fa24069516.tar.bz2 |
Provide guidance when trying to use non-enabled language
Fixes #23463
Diffstat (limited to 'Source/cmCommonTargetGenerator.cxx')
-rw-r--r-- | Source/cmCommonTargetGenerator.cxx | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index 129ef4b..b172c20 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -2,7 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCommonTargetGenerator.h" -#include <set> +#include <algorithm> #include <sstream> #include <utility> @@ -13,9 +13,11 @@ #include "cmLocalCommonGenerator.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmRange.h" #include "cmSourceFile.h" +#include "cmState.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmTarget.h" @@ -321,3 +323,29 @@ std::string cmCommonTargetGenerator::GetLinkerLauncher( } return std::string(); } + +bool cmCommonTargetGenerator::HaveRequiredLanguages( + const std::vector<cmSourceFile const*>& sources, + std::set<std::string>& languagesNeeded) const +{ + for (cmSourceFile const* sf : sources) { + languagesNeeded.insert(sf->GetLanguage()); + } + + auto* makefile = this->Makefile; + auto* state = makefile->GetState(); + auto unary = [&state, &makefile](const std::string& lang) -> bool { + const bool valid = state->GetLanguageEnabled(lang); + if (!valid) { + makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("The language ", lang, + " was requested for compilation but was not enabled." + " To enable a language it needs to be specified in a" + " 'project' or 'enable_language' command in the root" + " CMakeLists.txt")); + } + return valid; + }; + return std::all_of(languagesNeeded.cbegin(), languagesNeeded.cend(), unary); +} |