From 08cb4fa4c0378468fc2757666701617f6fe8270e Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 18 Sep 2012 13:57:07 +0200 Subject: Process generator expressions in the INCLUDE_DIRECTORIES property. This use of generator expressions, like all others to come which operate on target properties, must initalize the dag checker. --- Source/cmGeneratorTarget.cxx | 22 ++++++++++++++++++++-- Source/cmIncludeDirectoryCommand.cxx | 7 ++++++- .../TargetIncludeDirectories/CMakeLists.txt | 8 ++++++++ .../TargetIncludeDirectories/main.cpp | 4 ++++ .../TargetIncludeDirectories/sing/ting/ting.h | 1 + Tests/RunCMake/CMakeLists.txt | 1 + .../BadSelfReference1-result.txt | 1 + .../BadSelfReference1-stderr.txt | 6 ++++++ .../BadSelfReference1.cmake | 7 +++++++ .../BadSelfReference2-result.txt | 1 + .../BadSelfReference2-stderr.txt | 6 ++++++ .../BadSelfReference2.cmake | 9 +++++++++ .../BadSelfReference3-result.txt | 1 + .../BadSelfReference3-stderr.txt | 6 ++++++ .../BadSelfReference3.cmake | 8 ++++++++ .../BadSelfReference4-result.txt | 1 + .../BadSelfReference4-stderr.txt | 6 ++++++ .../BadSelfReference4.cmake | 10 ++++++++++ .../CMakeLists.txt | 8 ++++++++ .../RunCMakeTest.cmake | 6 ++++++ 20 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 Tests/IncludeDirectories/TargetIncludeDirectories/sing/ting/ting.h create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-result.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-stderr.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4.cmake create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/CMakeLists.txt create mode 100644 Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 3f58433..9093613 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -17,6 +17,8 @@ #include "cmComputeLinkInformation.h" #include "cmGlobalGenerator.h" #include "cmSourceFile.h" +#include "cmGeneratorExpression.h" +#include "cmGeneratorExpressionDAGChecker.h" #include @@ -289,11 +291,27 @@ std::vector cmGeneratorTarget::GetIncludeDirectories() { std::vector includes; const char *prop = this->Target->GetProperty("INCLUDE_DIRECTORIES"); - if(prop) + if(!prop) { - cmSystemTools::ExpandListArgument(prop, includes); + return includes; } + const char *config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"); + cmListFileBacktrace lfbt; + cmGeneratorExpression ge(lfbt); + + cmGeneratorExpressionDAGChecker dagChecker(lfbt, + this->GetName(), + "INCLUDE_DIRECTORIES", 0, 0); + + cmSystemTools::ExpandListArgument(ge.Parse(prop) + .Evaluate(this->Makefile, + config, + false, + this, + &dagChecker), + includes); + std::set uniqueIncludes; std::vector orderedAndUniqueIncludes; for(std::vector::const_iterator diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx index 11c5f4e..ba81849 100644 --- a/Source/cmIncludeDirectoryCommand.cxx +++ b/Source/cmIncludeDirectoryCommand.cxx @@ -55,6 +55,11 @@ bool cmIncludeDirectoryCommand return true; } +static bool StartsWithGeneratorExpression(const std::string &input) +{ + return input[0] == '$' && input[1] == '<'; +} + // do a lot of cleanup on the arguments because this is one place where folks // sometimes take the output of a program and pass it directly into this // command not thinking that a single argument could be filled with spaces @@ -105,7 +110,7 @@ void cmIncludeDirectoryCommand::AddDirectory(const char *i, cmSystemTools::ConvertToUnixSlashes(ret); if(!cmSystemTools::FileIsFullPath(ret.c_str())) { - if(ret[0] != '$' && ret[1] != '<') + if(!StartsWithGeneratorExpression(ret)) { std::string tmp = this->Makefile->GetStartDirectory(); tmp += "/"; diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt index 334b8be..4b6f682 100644 --- a/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt +++ b/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt @@ -12,13 +12,21 @@ create_header(bar) create_header(bat) create_header(foo) create_header(baz) +create_header(bang) +create_header(bing) +create_header(bung) set(CMAKE_INCLUDE_CURRENT_DIR ON) include_directories("${CMAKE_CURRENT_BINARY_DIR}/bar") +include_directories("$<1:${CMAKE_CURRENT_BINARY_DIR}/bang>") add_executable(TargetIncludeDirectories main.cpp) set_property(TARGET TargetIncludeDirectories APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/bat") set_property(TARGET TargetIncludeDirectories APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/foo") +set_property(TARGET TargetIncludeDirectories APPEND PROPERTY + INCLUDE_DIRECTORIES "$<1:${CMAKE_CURRENT_BINARY_DIR}/bing>") include_directories("${CMAKE_CURRENT_BINARY_DIR}/baz") +include_directories("$<1:${CMAKE_CURRENT_BINARY_DIR}/bung>") +include_directories("sing$<1:/ting>") diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp b/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp index 8aa3532..63217f4 100644 --- a/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp +++ b/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp @@ -3,6 +3,10 @@ #include "bat.h" #include "foo.h" #include "baz.h" +#include "bang.h" +#include "bing.h" +#include "bung.h" +#include "ting.h" int main(int, char**) { diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/sing/ting/ting.h b/Tests/IncludeDirectories/TargetIncludeDirectories/sing/ting/ting.h new file mode 100644 index 0000000..4fe01dd --- /dev/null +++ b/Tests/IncludeDirectories/TargetIncludeDirectories/sing/ting/ting.h @@ -0,0 +1 @@ +//ting.h diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 3ea54f1..2fa7141 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -46,6 +46,7 @@ macro(add_RunCMake_test test) endmacro() add_RunCMake_test(GeneratorExpression) +add_RunCMake_test(TargetPropertyGeneratorExpressions) add_RunCMake_test(Languages) add_RunCMake_test(ObjectLibrary) diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-stderr.txt new file mode 100644 index 0000000..791c4a9 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Self reference on target "TargetPropertyGeneratorExpressions".$ diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1.cmake new file mode 100644 index 0000000..a85731e --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference1.cmake @@ -0,0 +1,7 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +include_directories("$") diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-stderr.txt new file mode 100644 index 0000000..791c4a9 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Self reference on target "TargetPropertyGeneratorExpressions".$ diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2.cmake new file mode 100644 index 0000000..f1459b8 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference2.cmake @@ -0,0 +1,9 @@ + +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 + INCLUDE_DIRECTORIES "$" +) diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-stderr.txt new file mode 100644 index 0000000..f60d726 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Self reference on target "TargetPropertyGeneratorExpressions".$ diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3.cmake new file mode 100644 index 0000000..433b730 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference3.cmake @@ -0,0 +1,8 @@ + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "int main(int, char **) { return 0; }\n") + +add_executable(TargetPropertyGeneratorExpressions + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +include_directories( + "$") diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-result.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-stderr.txt new file mode 100644 index 0000000..f60d726 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Self reference on target "TargetPropertyGeneratorExpressions".$ diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4.cmake new file mode 100644 index 0000000..4b64459 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadSelfReference4.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 +INCLUDE_DIRECTORIES + "$" +) diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/CMakeLists.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/CMakeLists.txt new file mode 100644 index 0000000..22577da --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/CMakeLists.txt @@ -0,0 +1,8 @@ + +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} CXX) + +# MSVC creates extra targets which pollute the stderr unless we set this. +set(CMAKE_SUPPRESS_REGENERATION TRUE) + +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake new file mode 100644 index 0000000..211e6e7 --- /dev/null +++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake @@ -0,0 +1,6 @@ +include(RunCMake) + +run_cmake(BadSelfReference1) +run_cmake(BadSelfReference2) +run_cmake(BadSelfReference3) +run_cmake(BadSelfReference4) -- cgit v0.12