parent
1d82670bd4
commit
627ef4c1d0
@ -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);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -74,6 +75,9 @@ protected:
|
||||
|
||||
std::string GetLinkerLauncher(const std::string& config);
|
||||
|
||||
bool HaveRequiredLanguages(const std::vector<cmSourceFile const*>& sources,
|
||||
std::set<std::string>& languagesNeeded) const;
|
||||
|
||||
private:
|
||||
using ByLanguageMap = std::map<std::string, std::string>;
|
||||
struct ByConfig
|
||||
|
@ -305,9 +305,14 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
|
||||
std::vector<cmSourceFile const*> objectSources;
|
||||
this->GeneratorTarget->GetObjectSources(objectSources,
|
||||
this->GetConfigName());
|
||||
for (cmSourceFile const* sf : objectSources) {
|
||||
// Generate this object file's rule file.
|
||||
this->WriteObjectRuleFiles(*sf);
|
||||
|
||||
// validate that all languages requested are enabled.
|
||||
std::set<std::string> requiredLangs;
|
||||
if (this->HaveRequiredLanguages(objectSources, requiredLangs)) {
|
||||
for (cmSourceFile const* sf : objectSources) {
|
||||
// Generate this object file's rule file.
|
||||
this->WriteObjectRuleFiles(*sf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -532,8 +537,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
|
||||
cmSourceFile const& source)
|
||||
{
|
||||
// Identify the language of the source file.
|
||||
const std::string& lang =
|
||||
this->LocalGenerator->GetSourceFileLanguage(source);
|
||||
const std::string& lang = source.GetLanguage();
|
||||
if (lang.empty()) {
|
||||
// don't know anything about this file so skip it
|
||||
return;
|
||||
|
@ -126,15 +126,11 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules(
|
||||
std::set<std::string> languages;
|
||||
std::vector<cmSourceFile const*> sourceFiles;
|
||||
this->GetGeneratorTarget()->GetObjectSources(sourceFiles, config);
|
||||
for (cmSourceFile const* sf : sourceFiles) {
|
||||
std::string const lang = sf->GetLanguage();
|
||||
if (!lang.empty()) {
|
||||
languages.insert(lang);
|
||||
if (this->HaveRequiredLanguages(sourceFiles, languages)) {
|
||||
for (std::string const& language : languages) {
|
||||
this->WriteLanguageRules(language, config);
|
||||
}
|
||||
}
|
||||
for (std::string const& language : languages) {
|
||||
this->WriteLanguageRules(language, config);
|
||||
}
|
||||
}
|
||||
|
||||
const char* cmNinjaNormalTargetGenerator::GetVisibleTypeName() const
|
||||
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,4 @@
|
||||
CMake Error in CMakeLists.txt:
|
||||
The language CXX 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
|
3
Tests/RunCMake/project/LanguagesUsedButNotEnabled.cmake
Normal file
3
Tests/RunCMake/project/LanguagesUsedButNotEnabled.cmake
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
add_executable(UsesCXXLang empty.cxx)
|
||||
set_source_files_properties(empty.cxx PROPERTIES GENERATED TRUE LANGUAGE CXX )
|
@ -8,6 +8,9 @@ run_cmake(LanguagesEmpty)
|
||||
run_cmake(LanguagesNONE)
|
||||
run_cmake(LanguagesTwice)
|
||||
run_cmake(LanguagesUnordered)
|
||||
if(RunCMake_GENERATOR MATCHES "Make|Ninja")
|
||||
run_cmake(LanguagesUsedButNotEnabled)
|
||||
endif()
|
||||
run_cmake(ProjectDescription)
|
||||
run_cmake(ProjectDescription2)
|
||||
run_cmake(ProjectDescriptionNoArg)
|
||||
|
Loading…
Reference in New Issue
Block a user