Genex: Add a COMPILE_LANGUAGE generator expression.

This commit is contained in:
Stephen Kelly 2015-02-22 17:43:13 +01:00
parent 4a0128f42f
commit e387ce7d68
26 changed files with 162 additions and 6 deletions

View File

@ -52,14 +52,16 @@ cmGeneratorExpression::~cmGeneratorExpression()
const char *cmCompiledGeneratorExpression::Evaluate(
cmMakefile* mf, const std::string& config, bool quiet,
cmTarget const* headTarget,
cmGeneratorExpressionDAGChecker *dagChecker) const
cmGeneratorExpressionDAGChecker *dagChecker,
std::string const& language) const
{
return this->Evaluate(mf,
config,
quiet,
headTarget,
headTarget,
dagChecker);
dagChecker,
language);
}
//----------------------------------------------------------------------------
@ -67,7 +69,8 @@ const char *cmCompiledGeneratorExpression::Evaluate(
cmMakefile* mf, const std::string& config, bool quiet,
cmTarget const* headTarget,
cmTarget const* currentTarget,
cmGeneratorExpressionDAGChecker *dagChecker) const
cmGeneratorExpressionDAGChecker *dagChecker,
std::string const& language) const
{
if (!this->NeedsEvaluation)
{
@ -93,6 +96,7 @@ const char *cmCompiledGeneratorExpression::Evaluate(
context.EvaluateForBuildsystem = this->EvaluateForBuildsystem;
context.CurrentTarget = currentTarget ? currentTarget : headTarget;
context.Backtrace = this->Backtrace;
context.Language = language;
for ( ; it != end; ++it)
{

View File

@ -80,11 +80,13 @@ public:
bool quiet = false,
cmTarget const* headTarget = 0,
cmTarget const* currentTarget = 0,
cmGeneratorExpressionDAGChecker *dagChecker = 0) const;
cmGeneratorExpressionDAGChecker *dagChecker = 0,
std::string const& language = std::string()) const;
const char* Evaluate(cmMakefile* mf, const std::string& config,
bool quiet,
cmTarget const* headTarget,
cmGeneratorExpressionDAGChecker *dagChecker) const;
cmGeneratorExpressionDAGChecker *dagChecker,
std::string const& language = std::string()) const;
/** Get set of targets found during evaluations. */
std::set<cmTarget*> const& GetTargets() const

View File

@ -16,6 +16,7 @@
#include "cmGeneratorExpressionDAGChecker.h"
#include "cmGeneratorExpression.h"
#include "cmLocalGenerator.h"
#include "cmGlobalGenerator.h"
#include "cmSourceFile.h"
#include <cmsys/String.h>
@ -89,7 +90,8 @@ std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
context->Quiet,
headTarget,
currentTarget,
dagChecker);
dagChecker,
context->Language);
if (cge->GetHadContextSensitiveCondition())
{
context->HadContextSensitiveCondition = true;
@ -806,6 +808,33 @@ static const struct JoinNode : public cmGeneratorExpressionNode
}
} joinNode;
static const struct CompileLanguageNode : public cmGeneratorExpressionNode
{
CompileLanguageNode() {}
virtual int NumExpectedParameters() const { return OneOrZeroParameters; }
std::string Evaluate(const std::vector<std::string> &parameters,
cmGeneratorExpressionContext *context,
const GeneratorExpressionContent *content,
cmGeneratorExpressionDAGChecker *) const
{
if(context->Language.empty())
{
reportError(context, content->GetOriginalExpression(),
"$<COMPILE_LANGUAGE:...> may only be used to specify include "
"directories compile definitions, compile options and to evaluate "
"components of the file(GENERATE) command.");
return std::string();
}
if (parameters.empty())
{
return context->Language;
}
return context->Language == parameters.front() ? "1" : "0";
}
} languageNode;
#define TRANSITIVE_PROPERTY_NAME(PROPERTY) \
, "INTERFACE_" #PROPERTY
@ -1829,6 +1858,7 @@ cmGeneratorExpressionNode* GetNode(const std::string &identifier)
nodeMap["INSTALL_PREFIX"] = &installPrefixNode;
nodeMap["JOIN"] = &joinNode;
nodeMap["LINK_ONLY"] = &linkOnlyNode;
nodeMap["COMPILE_LANGUAGE"] = &languageNode;
}
NodeMap::const_iterator i = nodeMap.find(identifier);
if (i == nodeMap.end())

View File

@ -36,6 +36,7 @@ struct cmGeneratorExpressionContext
MaxLanguageStandard;
cmMakefile *Makefile;
std::string Config;
std::string Language;
cmTarget const* HeadTarget; // The target whose property is being evaluated.
cmTarget const* CurrentTarget; // The dependent of HeadTarget which appears
// directly or indirectly in the property.

View File

@ -0,0 +1,10 @@
CMake Error at COMPILE_LANGUAGE-add_custom_command.cmake:6 \(add_custom_command\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
\$<COMPILE_LANGUAGE:...> may only be used to specify include directories
compile definitions, compile options and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,8 @@
enable_language(C)
add_library(empty empty.c)
add_custom_command(TARGET empty PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo $<COMPILE_LANGUAGE>
)

View File

@ -0,0 +1,10 @@
CMake Error at COMPILE_LANGUAGE-add_custom_target.cmake:4 \(add_custom_target\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
\$<COMPILE_LANGUAGE:...> may only be used to specify include directories
compile definitions, compile options and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,6 @@
enable_language(C)
add_custom_target(empty
COMMAND ${CMAKE_COMMAND} -E echo $<COMPILE_LANGUAGE>
)

View File

@ -0,0 +1,10 @@
CMake Error at COMPILE_LANGUAGE-add_executable.cmake:4 \(add_executable\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
\$<COMPILE_LANGUAGE:...> may only be used to specify include directories
compile definitions, compile options and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,4 @@
enable_language(C)
add_executable(empty empty.$<COMPILE_LANGUAGE>)

View File

@ -0,0 +1,10 @@
CMake Error at COMPILE_LANGUAGE-add_library.cmake:4 \(add_library\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
\$<COMPILE_LANGUAGE:...> may only be used to specify include directories
compile definitions, compile options and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,4 @@
enable_language(C)
add_library(empty empty.$<COMPILE_LANGUAGE>)

View File

@ -0,0 +1,10 @@
CMake Error at COMPILE_LANGUAGE-add_test.cmake:5 \(add_test\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
\$<COMPILE_LANGUAGE:...> may only be used to specify include directories
compile definitions, compile options and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,5 @@
include(CTest)
enable_testing()
add_test(NAME dummy COMMAND ${CMAKE_COMMAND} -E echo $<COMPILE_LANGUAGE>)

View File

@ -0,0 +1,8 @@
CMake Error:
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
\$<COMPILE_LANGUAGE:...> may only be used to specify include directories
compile definitions, compile options and to evaluate components of the
file\(GENERATE\) command.

View File

@ -0,0 +1,5 @@
install(FILES
empty.$<COMPILE_LANGUAGE>
DESTINATION src
)

View File

@ -0,0 +1,10 @@
CMake Error at COMPILE_LANGUAGE-target_sources.cmake:5 \(target_sources\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
\$<COMPILE_LANGUAGE:...> may only be used to specify include directories
compile definitions, compile options and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,5 @@
enable_language(C)
add_library(empty empty.c)
target_sources(empty PRIVATE empty.$<COMPILE_LANGUAGE>)

View File

@ -16,6 +16,13 @@ run_cmake(NonValidTarget-C_COMPILER_VERSION)
run_cmake(NonValidTarget-CXX_COMPILER_VERSION)
run_cmake(NonValidTarget-TARGET_PROPERTY)
run_cmake(NonValidTarget-TARGET_POLICY)
run_cmake(COMPILE_LANGUAGE-add_custom_target)
run_cmake(COMPILE_LANGUAGE-add_custom_command)
run_cmake(COMPILE_LANGUAGE-install)
run_cmake(COMPILE_LANGUAGE-target_sources)
run_cmake(COMPILE_LANGUAGE-add_executable)
run_cmake(COMPILE_LANGUAGE-add_library)
run_cmake(COMPILE_LANGUAGE-add_test)
if(LINKER_SUPPORTS_PDB)
run_cmake(NonValidTarget-TARGET_PDB_FILE)