Genex: Allow relative paths in INSTALL_INTERFACE.

These paths can be prepended with the ${_IMPORT_PREFIX} generated
in the export file.

Such relative paths were previously an error.
This commit is contained in:
Stephen Kelly 2013-07-25 09:05:03 +02:00
parent 650e61f833
commit d777b8e716
5 changed files with 44 additions and 6 deletions

View File

@ -302,7 +302,8 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
const char* sep = input ? ";" : ""; const char* sep = input ? ";" : "";
includes += sep + tei->InterfaceIncludeDirectories; includes += sep + tei->InterfaceIncludeDirectories;
std::string prepro = cmGeneratorExpression::Preprocess(includes, std::string prepro = cmGeneratorExpression::Preprocess(includes,
preprocessRule); preprocessRule,
true);
if (!prepro.empty()) if (!prepro.empty())
{ {
this->ResolveTargetsInGeneratorExpressions(prepro, target, this->ResolveTargetsInGeneratorExpressions(prepro, target,

View File

@ -228,9 +228,28 @@ static std::string stripAllGeneratorExpressions(const std::string &input)
return cmGeneratorExpression::StripEmptyListElements(result); return cmGeneratorExpression::StripEmptyListElements(result);
} }
//----------------------------------------------------------------------------
static void prefixItems(const std::string &content, std::string &result,
const std::string &prefix)
{
std::vector<std::string> entries;
cmGeneratorExpression::Split(content, entries);
for(std::vector<std::string>::const_iterator ei = entries.begin();
ei != entries.end(); ++ei)
{
if (!cmSystemTools::FileIsFullPath(ei->c_str())
&& cmGeneratorExpression::Find(*ei) == std::string::npos)
{
result += prefix;
}
result += *ei;
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
static std::string stripExportInterface(const std::string &input, static std::string stripExportInterface(const std::string &input,
cmGeneratorExpression::PreprocessContext context) cmGeneratorExpression::PreprocessContext context,
bool resolveRelative)
{ {
std::string result; std::string result;
@ -289,7 +308,15 @@ static std::string stripExportInterface(const std::string &input,
else if(context == cmGeneratorExpression::InstallInterface else if(context == cmGeneratorExpression::InstallInterface
&& gotInstallInterface) && gotInstallInterface)
{ {
result += input.substr(pos, c - cStart); const std::string content = input.substr(pos, c - cStart);
if (resolveRelative)
{
prefixItems(content, result, "${_IMPORT_PREFIX}/");
}
else
{
result += content;
}
} }
break; break;
} }
@ -380,7 +407,8 @@ void cmGeneratorExpression::Split(const std::string &input,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmGeneratorExpression::Preprocess(const std::string &input, std::string cmGeneratorExpression::Preprocess(const std::string &input,
PreprocessContext context) PreprocessContext context,
bool resolveRelative)
{ {
if (context == StripAllGeneratorExpressions) if (context == StripAllGeneratorExpressions)
{ {
@ -388,7 +416,7 @@ std::string cmGeneratorExpression::Preprocess(const std::string &input,
} }
else if (context == BuildInterface || context == InstallInterface) else if (context == BuildInterface || context == InstallInterface)
{ {
return stripExportInterface(input, context); return stripExportInterface(input, context, resolveRelative);
} }
assert(!"cmGeneratorExpression::Preprocess called with invalid args"); assert(!"cmGeneratorExpression::Preprocess called with invalid args");

View File

@ -57,7 +57,8 @@ public:
}; };
static std::string Preprocess(const std::string &input, static std::string Preprocess(const std::string &input,
PreprocessContext context); PreprocessContext context,
bool resolveRelative = false);
static void Split(const std::string &input, static void Split(const std::string &input,
std::vector<std::string> &output); std::vector<std::string> &output);

View File

@ -140,6 +140,12 @@ install(FILES
) )
add_include_lib(testLibIncludeRequired6) add_include_lib(testLibIncludeRequired6)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired7/testLibIncludeRequired7.h" "// No content\n")
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired7/testLibIncludeRequired7.h"
DESTINATION include/testLibIncludeRequired7
)
set_property(TARGET testLibRequired APPEND PROPERTY set_property(TARGET testLibRequired APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES INTERFACE_INCLUDE_DIRECTORIES
$<TARGET_PROPERTY:testLibIncludeRequired1,INTERFACE_INCLUDE_DIRECTORIES> $<TARGET_PROPERTY:testLibIncludeRequired1,INTERFACE_INCLUDE_DIRECTORIES>
@ -154,6 +160,7 @@ set_property(TARGET testLibRequired APPEND PROPERTY
$<BUILD_INTERFACE:$<TARGET_PROPERTY:testLibIncludeRequired5,INTERFACE_INCLUDE_DIRECTORIES>> $<BUILD_INTERFACE:$<TARGET_PROPERTY:testLibIncludeRequired5,INTERFACE_INCLUDE_DIRECTORIES>>
# Test that the below is non-fatal # Test that the below is non-fatal
$<$<STREQUAL:one,two>:$<TARGET_PROPERTY:not_a_target,INTERFACE_INCLUDE_DIRECTORIES>> $<$<STREQUAL:one,two>:$<TARGET_PROPERTY:not_a_target,INTERFACE_INCLUDE_DIRECTORIES>>
$<INSTALL_INTERFACE:include/testLibIncludeRequired7>
) )
set_property(TARGET testLibRequired APPEND PROPERTY set_property(TARGET testLibRequired APPEND PROPERTY

View File

@ -2,6 +2,7 @@
#include "testLibIncludeRequired1.h" #include "testLibIncludeRequired1.h"
#include "testLibIncludeRequired2.h" #include "testLibIncludeRequired2.h"
#include "testLibIncludeRequired6.h" #include "testLibIncludeRequired6.h"
#include "testLibIncludeRequired7.h"
#include "installIncludesTest.h" #include "installIncludesTest.h"
#include "installIncludesTest2.h" #include "installIncludesTest2.h"