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.
This commit is contained in:
Stephen Kelly 2012-09-18 13:57:07 +02:00 committed by Brad King
parent 0ef091d986
commit 08cb4fa4c0
20 changed files with 116 additions and 3 deletions

View File

@ -17,6 +17,8 @@
#include "cmComputeLinkInformation.h" #include "cmComputeLinkInformation.h"
#include "cmGlobalGenerator.h" #include "cmGlobalGenerator.h"
#include "cmSourceFile.h" #include "cmSourceFile.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorExpressionDAGChecker.h"
#include <assert.h> #include <assert.h>
@ -289,11 +291,27 @@ std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories()
{ {
std::vector<std::string> includes; std::vector<std::string> includes;
const char *prop = this->Target->GetProperty("INCLUDE_DIRECTORIES"); 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<std::string> uniqueIncludes; std::set<std::string> uniqueIncludes;
std::vector<std::string> orderedAndUniqueIncludes; std::vector<std::string> orderedAndUniqueIncludes;
for(std::vector<std::string>::const_iterator for(std::vector<std::string>::const_iterator

View File

@ -55,6 +55,11 @@ bool cmIncludeDirectoryCommand
return true; 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 // 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 // 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 // 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); cmSystemTools::ConvertToUnixSlashes(ret);
if(!cmSystemTools::FileIsFullPath(ret.c_str())) if(!cmSystemTools::FileIsFullPath(ret.c_str()))
{ {
if(ret[0] != '$' && ret[1] != '<') if(!StartsWithGeneratorExpression(ret))
{ {
std::string tmp = this->Makefile->GetStartDirectory(); std::string tmp = this->Makefile->GetStartDirectory();
tmp += "/"; tmp += "/";

View File

@ -12,13 +12,21 @@ create_header(bar)
create_header(bat) create_header(bat)
create_header(foo) create_header(foo)
create_header(baz) create_header(baz)
create_header(bang)
create_header(bing)
create_header(bung)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories("${CMAKE_CURRENT_BINARY_DIR}/bar") include_directories("${CMAKE_CURRENT_BINARY_DIR}/bar")
include_directories("$<1:${CMAKE_CURRENT_BINARY_DIR}/bang>")
add_executable(TargetIncludeDirectories main.cpp) 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}/bat")
set_property(TARGET TargetIncludeDirectories APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/foo") 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("${CMAKE_CURRENT_BINARY_DIR}/baz")
include_directories("$<1:${CMAKE_CURRENT_BINARY_DIR}/bung>")
include_directories("sing$<1:/ting>")

View File

@ -3,6 +3,10 @@
#include "bat.h" #include "bat.h"
#include "foo.h" #include "foo.h"
#include "baz.h" #include "baz.h"
#include "bang.h"
#include "bing.h"
#include "bung.h"
#include "ting.h"
int main(int, char**) int main(int, char**)
{ {

View File

@ -0,0 +1 @@
//ting.h

View File

@ -46,6 +46,7 @@ macro(add_RunCMake_test test)
endmacro() endmacro()
add_RunCMake_test(GeneratorExpression) add_RunCMake_test(GeneratorExpression)
add_RunCMake_test(TargetPropertyGeneratorExpressions)
add_RunCMake_test(Languages) add_RunCMake_test(Languages)
add_RunCMake_test(ObjectLibrary) add_RunCMake_test(ObjectLibrary)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,INCLUDE_DIRECTORIES>
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
INCLUDE_DIRECTORIES
"$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,INCLUDE_DIRECTORIES>"
)

View File

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

View File

@ -0,0 +1,6 @@
include(RunCMake)
run_cmake(BadSelfReference1)
run_cmake(BadSelfReference2)
run_cmake(BadSelfReference3)
run_cmake(BadSelfReference4)