Report an error on IMPORTED targets with a faulty INTERFACE

It is considered an error if the INTERFACE_INCLUDE_DIRECTORIES contains
a directory which does not exist, which indicates a programmer error
by the upstream, or a packaging error.

One of the RunCMake.CompatibleInterface tests also needs to be updated
due to this change. Non-existant includes were used in the test, but
are not needed.
This commit is contained in:
Stephen Kelly 2013-03-24 21:18:21 +01:00 committed by Brad King
parent af81a3c31b
commit 28051f1150
6 changed files with 52 additions and 5 deletions

View File

@ -131,11 +131,13 @@ public:
SourceEntriesType SourceEntries;
struct IncludeDirectoriesEntry {
IncludeDirectoriesEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge)
: ge(cge)
IncludeDirectoriesEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
const std::string &targetName = std::string())
: ge(cge), TargetName(targetName)
{}
const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
std::vector<std::string> CachedIncludes;
const std::string TargetName;
};
std::vector<IncludeDirectoriesEntry*> IncludeDirectoriesEntries;
std::vector<cmValueWithOrigin> LinkInterfaceIncludeDirectoriesEntries;
@ -2818,6 +2820,28 @@ static void processIncludeDirectories(cmTarget *tgt,
for(std::vector<std::string>::iterator
li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
{
cmTarget *dependentTarget =
mf->FindTargetToUse((*it)->TargetName.c_str());
const bool fromImported = dependentTarget
&& dependentTarget->IsImported();
if (fromImported && !cmSystemTools::FileExists(li->c_str()))
{
cmOStringStream e;
e << "Imported target \"" << (*it)->TargetName << "\" includes "
"non-existent path\n \"" << *li << "\"\nin its "
"INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
"* The path was deleted, renamed, or moved to another "
"location.\n"
"* An install or uninstall procedure did not complete "
"successfully.\n"
"* The installation package was faulty and references files it "
"does not provide.\n";
tgt->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
return;
}
if (testIsOff && !cmSystemTools::IsOff(li->c_str()))
{
cmSystemTools::ConvertToUnixSlashes(*li);
@ -2913,7 +2937,8 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
it->Value + ",INTERFACE_INCLUDE_DIRECTORIES>");
this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries.push_back(
new cmTargetInternals::IncludeDirectoriesEntry(cge));
new cmTargetInternals::IncludeDirectoriesEntry(cge,
it->Value));
}
}

View File

@ -3,8 +3,6 @@ add_library(foo UNKNOWN IMPORTED)
add_library(bar UNKNOWN IMPORTED)
set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_STRING INCLUDE_DIRECTORIES)
set_property(TARGET foo PROPERTY INTERFACE_INCLUDE_DIRECTORIES foo_inc)
set_property(TARGET bar PROPERTY INTERFACE_INCLUDE_DIRECTORIES bar_inc)
add_executable(user main.cpp)
set_property(TARGET user PROPERTY INCLUDE_DIRECTORIES bar_inc)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,13 @@
CMake Error in CMakeLists.txt:
Imported target "imported" includes non-existent path
"/does/not/exist"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
\* The path was deleted, renamed, or moved to another location.
\* An install or uninstall procedure did not complete successfully.
\* The installation package was faulty and references files it does not
provide.

View File

@ -0,0 +1,9 @@
project(ImportedTarget)
add_library(testTarget "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp")
add_library(imported UNKNOWN IMPORTED)
set_property(TARGET imported PROPERTY INTERFACE_INCLUDE_DIRECTORIES "/does/not/exist")
target_link_libraries(testTarget imported)

View File

@ -6,3 +6,4 @@ run_cmake(TID-bad-target)
run_cmake(SourceDirectoryInInterface)
run_cmake(BinaryDirectoryInInterface)
run_cmake(RelativePathInInterface)
run_cmake(ImportedTarget)