From 083de7ed35b26dceff6edeb4fc8f9d2500855a9b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 20 Sep 2012 23:28:09 +0200 Subject: [PATCH] Process generator expressions in the COMPILE_DEFINITIONS target property. --- Source/cmGeneratorTarget.cxx | 17 ++++++++++++++++- Tests/CompileDefinitions/compiletest.cpp | 9 +++++++++ .../target_prop/CMakeLists.txt | 6 ++++++ .../BadSelfReference5-result.txt | 1 + .../BadSelfReference5-stderr.txt | 6 ++++++ .../BadSelfReference5.cmake | 10 ++++++++++ .../BadSelfReference6-result.txt | 1 + .../BadSelfReference6-stderr.txt | 6 ++++++ .../BadSelfReference6.cmake | 10 ++++++++++ .../RunCMakeTest.cmake | 2 ++ 10 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6.cmake diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 9093613db..d4b57f4a0 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -342,5 +342,20 @@ std::string cmGeneratorTarget::GetCompileDefinitions(const char *config) const char *prop = this->Target->GetProperty(defPropName.c_str()); - return prop ? prop : ""; + if (!prop) + { + return ""; + } + + cmListFileBacktrace lfbt; + cmGeneratorExpression ge(lfbt); + + cmGeneratorExpressionDAGChecker dagChecker(lfbt, + this->GetName(), + defPropName, 0, 0); + return ge.Parse(prop).Evaluate(this->Makefile, + config, + false, + this, + &dagChecker); } diff --git a/Tests/CompileDefinitions/compiletest.cpp b/Tests/CompileDefinitions/compiletest.cpp index 6db6f3f96..4a68a0750 100644 --- a/Tests/CompileDefinitions/compiletest.cpp +++ b/Tests/CompileDefinitions/compiletest.cpp @@ -27,6 +27,15 @@ enum { #endif }; +#ifdef TEST_GENERATOR_EXPRESSIONS +#ifndef CMAKE_IS_DECLARATIVE +#error Expect declarative definition +#endif +#ifdef GE_NOT_DEFINED +#error Expect not defined generator expression +#endif +#endif + int main(int argc, char **argv) { return 0; diff --git a/Tests/CompileDefinitions/target_prop/CMakeLists.txt b/Tests/CompileDefinitions/target_prop/CMakeLists.txt index e2b6ba9b2..fcb22b019 100644 --- a/Tests/CompileDefinitions/target_prop/CMakeLists.txt +++ b/Tests/CompileDefinitions/target_prop/CMakeLists.txt @@ -7,3 +7,9 @@ set_target_properties(target_prop_executable PROPERTIES COMPILE_DEFINITIONS CMAK set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS CMAKE_IS_REALLY="Very Fun" CMAKE_IS=Fun) set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS CMAKE_IS_FUN CMAKE_IS_="Fun") + +set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS + TEST_GENERATOR_EXPRESSIONS + "$<1:CMAKE_IS_DECLARATIVE>" + "$<0:GE_NOT_DEFINED>" +) diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-stderr.txt new file mode 100644 index 000000000..2b22d0fc3 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Self reference on target "TargetPropertyGeneratorExpressions".$ diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5.cmake new file mode 100644 index 000000000..74fff674d --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference5.cmake @@ -0,0 +1,10 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +set_property(TARGET TargetPropertyGeneratorExpressions +PROPERTY + COMPILE_DEFINITIONS "$" +) diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-stderr.txt new file mode 100644 index 000000000..fe7caa3c3 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Self reference on target "TargetPropertyGeneratorExpressions".$ diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6.cmake new file mode 100644 index 000000000..d6650d3a5 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference6.cmake @@ -0,0 +1,10 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +set_property(TARGET TargetPropertyGeneratorExpressions PROPERTY +COMPILE_DEFINITIONS + "$" +) diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake index 211e6e727..f2ff05b4b 100644 --- a/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake @@ -4,3 +4,5 @@ run_cmake(BadSelfReference1) run_cmake(BadSelfReference2) run_cmake(BadSelfReference3) run_cmake(BadSelfReference4) +run_cmake(BadSelfReference5) +run_cmake(BadSelfReference6)