diff options
26 files changed, 162 insertions, 6 deletions
diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index bf96951..0a27016 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -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) { diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index 57f78c5..55d9691 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -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 diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index ba18faa..63a46f2 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -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> ¶meters, + 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()) diff --git a/Source/cmGeneratorExpressionEvaluator.h b/Source/cmGeneratorExpressionEvaluator.h index 0bf1797..b1fec0b 100644 --- a/Source/cmGeneratorExpressionEvaluator.h +++ b/Source/cmGeneratorExpressionEvaluator.h @@ -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. diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt new file mode 100644 index 0000000..789b4d0 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command.cmake new file mode 100644 index 0000000..f4ba261 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command.cmake @@ -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> +) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt new file mode 100644 index 0000000..400fbc0 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target.cmake new file mode 100644 index 0000000..4102623 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target.cmake @@ -0,0 +1,6 @@ + +enable_language(C) + +add_custom_target(empty + COMMAND ${CMAKE_COMMAND} -E echo $<COMPILE_LANGUAGE> +) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt new file mode 100644 index 0000000..e45bb02 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable.cmake new file mode 100644 index 0000000..5c2ff35 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable.cmake @@ -0,0 +1,4 @@ + +enable_language(C) + +add_executable(empty empty.$<COMPILE_LANGUAGE>) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt new file mode 100644 index 0000000..c9ee6fe --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library.cmake new file mode 100644 index 0000000..dd9f824 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library.cmake @@ -0,0 +1,4 @@ + +enable_language(C) + +add_library(empty empty.$<COMPILE_LANGUAGE>) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt new file mode 100644 index 0000000..9955f5d --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test.cmake new file mode 100644 index 0000000..deedf65 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test.cmake @@ -0,0 +1,5 @@ + +include(CTest) +enable_testing() + +add_test(NAME dummy COMMAND ${CMAKE_COMMAND} -E echo $<COMPILE_LANGUAGE>) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt new file mode 100644 index 0000000..eca700f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt @@ -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. diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install.cmake new file mode 100644 index 0000000..92c20e3 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install.cmake @@ -0,0 +1,5 @@ + +install(FILES + empty.$<COMPILE_LANGUAGE> + DESTINATION src +) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt new file mode 100644 index 0000000..2d324e2 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources.cmake new file mode 100644 index 0000000..0c78acd --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources.cmake @@ -0,0 +1,5 @@ + +enable_language(C) + +add_library(empty empty.c) +target_sources(empty PRIVATE empty.$<COMPILE_LANGUAGE>) diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake index 6c32393..f591c3d 100644 --- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake @@ -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) |