File(GENERATE): Process genex evaluation files for each language.

This commit is contained in:
Stephen Kelly 2015-02-22 17:44:59 +01:00
parent b734fa4471
commit 9e1689413f
7 changed files with 70 additions and 16 deletions

View File

@ -38,13 +38,15 @@ cmGeneratorExpressionEvaluationFile::cmGeneratorExpressionEvaluationFile(
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGeneratorExpressionEvaluationFile::Generate(const std::string& config, void cmGeneratorExpressionEvaluationFile::Generate(const std::string& config,
const std::string& lang,
cmCompiledGeneratorExpression* inputExpression, cmCompiledGeneratorExpression* inputExpression,
std::map<std::string, std::string> &outputFiles, mode_t perm) std::map<std::string, std::string> &outputFiles, mode_t perm)
{ {
std::string rawCondition = this->Condition->GetInput(); std::string rawCondition = this->Condition->GetInput();
if (!rawCondition.empty()) if (!rawCondition.empty())
{ {
std::string condResult = this->Condition->Evaluate(this->Makefile, config); std::string condResult = this->Condition->Evaluate(this->Makefile, config,
false, 0, 0, 0, lang);
if (condResult == "0") if (condResult == "0")
{ {
return; return;
@ -60,9 +62,11 @@ void cmGeneratorExpressionEvaluationFile::Generate(const std::string& config,
} }
const std::string outputFileName const std::string outputFileName
= this->OutputFileExpr->Evaluate(this->Makefile, config); = this->OutputFileExpr->Evaluate(this->Makefile, config,
false, 0, 0, 0, lang);
const std::string outputContent const std::string outputContent
= inputExpression->Evaluate(this->Makefile, config); = inputExpression->Evaluate(this->Makefile, config,
false, 0, 0, 0, lang);
std::map<std::string, std::string>::iterator it std::map<std::string, std::string>::iterator it
= outputFiles.find(outputFileName); = outputFiles.find(outputFileName);
@ -75,7 +79,8 @@ void cmGeneratorExpressionEvaluationFile::Generate(const std::string& config,
} }
std::ostringstream e; std::ostringstream e;
e << "Evaluation file to be written multiple times for different " e << "Evaluation file to be written multiple times for different "
"configurations with different content:\n " << outputFileName; "configurations or languages with different content:\n "
<< outputFileName;
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return; return;
} }
@ -97,15 +102,23 @@ void cmGeneratorExpressionEvaluationFile::Generate(const std::string& config,
void cmGeneratorExpressionEvaluationFile::CreateOutputFile( void cmGeneratorExpressionEvaluationFile::CreateOutputFile(
std::string const& config) std::string const& config)
{ {
std::string name = this->OutputFileExpr->Evaluate(this->Makefile, config); std::vector<std::string> enabledLanguages;
cmGlobalGenerator *gg
= this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
gg->GetEnabledLanguages(enabledLanguages);
for(std::vector<std::string>::const_iterator le = enabledLanguages.begin();
le != enabledLanguages.end(); ++le)
{
std::string name = this->OutputFileExpr->Evaluate(this->Makefile, config,
false, 0, 0, 0, *le);
cmSourceFile* sf = this->Makefile->GetOrCreateSource(name); cmSourceFile* sf = this->Makefile->GetOrCreateSource(name);
sf->SetProperty("GENERATED", "1"); sf->SetProperty("GENERATED", "1");
cmGlobalGenerator *gg
= this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
gg->SetFilenameTargetDepends(sf, gg->SetFilenameTargetDepends(sf,
this->OutputFileExpr->GetSourceSensitiveTargets()); this->OutputFileExpr->GetSourceSensitiveTargets());
} }
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGeneratorExpressionEvaluationFile::Generate() void cmGeneratorExpressionEvaluationFile::Generate()
@ -153,13 +166,23 @@ void cmGeneratorExpressionEvaluationFile::Generate()
{ {
allConfigs.push_back(""); allConfigs.push_back("");
} }
std::vector<std::string> enabledLanguages;
cmGlobalGenerator *gg
= this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
gg->GetEnabledLanguages(enabledLanguages);
for(std::vector<std::string>::const_iterator le = enabledLanguages.begin();
le != enabledLanguages.end(); ++le)
{
for(std::vector<std::string>::const_iterator li = allConfigs.begin(); for(std::vector<std::string>::const_iterator li = allConfigs.begin();
li != allConfigs.end(); ++li) li != allConfigs.end(); ++li)
{ {
this->Generate(*li, inputExpression.get(), outputFiles, perm); this->Generate(*li, *le, inputExpression.get(), outputFiles, perm);
if(cmSystemTools::GetFatalErrorOccured()) if(cmSystemTools::GetFatalErrorOccured())
{ {
return; return;
} }
} }
} }
}

View File

@ -34,7 +34,7 @@ public:
void CreateOutputFile(std::string const& config); void CreateOutputFile(std::string const& config);
private: private:
void Generate(const std::string& config, void Generate(const std::string& config, const std::string& lang,
cmCompiledGeneratorExpression* inputExpression, cmCompiledGeneratorExpression* inputExpression,
std::map<std::string, std::string> &outputFiles, mode_t perm); std::map<std::string, std::string> &outputFiles, mode_t perm);

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,12 @@
enable_language(CXX C)
add_library(empty empty.cpp empty.c)
target_compile_options(empty
PRIVATE LANG_IS_$<COMPILE_LANGUAGE>
)
file(GENERATE
OUTPUT opts-$<COMPILE_LANGUAGE>.txt
CONTENT "$<TARGET_PROPERTY:empty,COMPILE_OPTIONS>\n"
)

View File

@ -1,5 +1,5 @@
CMake Error in CMakeLists.txt: CMake Error in CMakeLists.txt:
Evaluation file to be written multiple times for different configurations Evaluation file to be written multiple times for different configurations
with different content: or languages with different content:
.*output.txt .*output.txt

View File

@ -17,6 +17,16 @@ if (NOT file_contents MATCHES "generated.cpp.rule")
message(SEND_ERROR "Rule file not in target sources! ${file_contents}") message(SEND_ERROR "Rule file not in target sources! ${file_contents}")
endif() endif()
if (NOT RunCMake_GENERATOR MATCHES "Visual Studio")
run_cmake(COMPILE_LANGUAGE-genex)
foreach(l CXX C)
file(READ "${RunCMake_BINARY_DIR}/COMPILE_LANGUAGE-genex-build/opts-${l}.txt" l_defs)
if (NOT l_defs STREQUAL "LANG_IS_${l}\n")
message(FATAL_ERROR "File content does not match: ${l_defs}")
endif()
endforeach()
endif()
set(timeformat "%Y%j%H%M%S") set(timeformat "%Y%j%H%M%S")
file(REMOVE "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt") file(REMOVE "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt")

View File

@ -0,0 +1,8 @@
#ifdef _WIN32
__declspec(dllexport)
#endif
int empty_c()
{
return 0;
}