Process generator expressions in the COMPILE_DEFINITIONS target property.

This commit is contained in:
Stephen Kelly 2012-09-20 23:28:09 +02:00 committed by Brad King
parent 08cb4fa4c0
commit 083de7ed35
10 changed files with 67 additions and 1 deletions

View File

@ -342,5 +342,20 @@ std::string cmGeneratorTarget::GetCompileDefinitions(const char *config)
const char *prop = this->Target->GetProperty(defPropName.c_str()); 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);
} }

View File

@ -27,6 +27,15 @@ enum {
#endif #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) int main(int argc, char **argv)
{ {
return 0; return 0;

View File

@ -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_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 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>"
)

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:COMPILE_DEFINITIONS>
Self reference on target "TargetPropertyGeneratorExpressions".$

View File

@ -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 "$<TARGET_PROPERTY:COMPILE_DEFINITIONS>"
)

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,COMPILE_DEFINITIONS>
Self reference on target "TargetPropertyGeneratorExpressions".$

View File

@ -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
"$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,COMPILE_DEFINITIONS>"
)

View File

@ -4,3 +4,5 @@ run_cmake(BadSelfReference1)
run_cmake(BadSelfReference2) run_cmake(BadSelfReference2)
run_cmake(BadSelfReference3) run_cmake(BadSelfReference3)
run_cmake(BadSelfReference4) run_cmake(BadSelfReference4)
run_cmake(BadSelfReference5)
run_cmake(BadSelfReference6)