summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2012-11-05 11:43:28 (GMT)
committerStephen Kelly <steveire@gmail.com>2013-01-31 16:34:20 (GMT)
commit77cecb778ff1882d87401c1055ec06585462f787 (patch)
tree7abf8c4ffc3839e6b2f8593757cd34119aea17a2 /Source
parent0b92602b816e2584db3781b120a1e5200da72ada (diff)
downloadCMake-77cecb778ff1882d87401c1055ec06585462f787.zip
CMake-77cecb778ff1882d87401c1055ec06585462f787.tar.gz
CMake-77cecb778ff1882d87401c1055ec06585462f787.tar.bz2
Add includes and compile definitions with target_link_libraries.
This establishes that linking is used to propagate usage-requirements between targets in CMake code. The use of the target_link_libraries command as the API for this is chosen because introducing a new command would introduce confusion due to multiple commands which differ only in a subtle way.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmTarget.h6
-rw-r--r--Source/cmTargetLinkLibrariesCommand.cxx53
-rw-r--r--Source/cmTargetLinkLibrariesCommand.h9
3 files changed, 65 insertions, 3 deletions
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index cf2d4c4..7577a59 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -514,6 +514,9 @@ public:
const char *GetLinkInterfaceDependentStringProperty(const std::string &p,
const char *config);
+
+ std::string GetDebugGeneratorExpressions(const std::string &value,
+ cmTarget::LinkLibraryType llt);
private:
/**
* A list of direct dependencies. Use in conjunction with DependencyMap.
@@ -659,9 +662,6 @@ private:
void ProcessSourceExpression(std::string const& expr);
- std::string GetDebugGeneratorExpressions(const std::string &value,
- cmTarget::LinkLibraryType llt);
-
// The cmMakefile instance that owns this target. This should
// always be set.
cmMakefile* Makefile;
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index f42b0f6..cb913f5 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -250,10 +250,51 @@ cmTargetLinkLibrariesCommand
}
//----------------------------------------------------------------------------
+static std::string compileProperty(cmTarget *tgt, const std::string &lib,
+ bool isGenex,
+ const std::string &property,
+ cmTarget::LinkLibraryType llt)
+{
+ std::string value = !isGenex ? "$<LINKED:" + lib + ">"
+ : "$<$<TARGET_DEFINED:" + lib + ">:" +
+ "$<TARGET_PROPERTY:" + lib +
+ ",INTERFACE_" + property + ">"
+ ">";
+
+ return tgt->GetDebugGeneratorExpressions(value, llt);
+}
+
+//----------------------------------------------------------------------------
+static bool isGeneratorExpression(const std::string &lib)
+{
+ const std::string::size_type openpos = lib.find("$<");
+ return (openpos != std::string::npos)
+ && (lib.find(">", openpos) != std::string::npos);
+}
+
+//----------------------------------------------------------------------------
void
cmTargetLinkLibrariesCommand::HandleLibrary(const char* lib,
cmTarget::LinkLibraryType llt)
{
+ const bool isGenex = isGeneratorExpression(lib);
+
+ cmsys::RegularExpression targetNameValidator;
+ targetNameValidator.compile("^[A-Za-z0-9_.:-]+$");
+ const bool potentialTargetName = targetNameValidator.find(lib);
+
+ if (potentialTargetName || isGenex)
+ {
+ this->Target->AppendProperty("INCLUDE_DIRECTORIES",
+ compileProperty(this->Target, lib,
+ isGenex,
+ "INCLUDE_DIRECTORIES", llt).c_str());
+ this->Target->AppendProperty("COMPILE_DEFINITIONS",
+ compileProperty(this->Target, lib,
+ isGenex,
+ "COMPILE_DEFINITIONS", llt).c_str());
+ }
+
// Handle normal case first.
if(this->CurrentProcessingState != ProcessingLinkInterface)
{
@@ -266,6 +307,18 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const char* lib,
}
}
+ if (potentialTargetName || isGenex)
+ {
+ this->Target->AppendProperty("INTERFACE_COMPILE_DEFINITIONS",
+ compileProperty(this->Target, lib,
+ isGenex,
+ "COMPILE_DEFINITIONS", llt).c_str());
+ this->Target->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
+ compileProperty(this->Target, lib,
+ isGenex,
+ "INCLUDE_DIRECTORIES", llt).c_str());
+ }
+
// Get the list of configurations considered to be DEBUG.
std::vector<std::string> const& debugConfigs =
this->Makefile->GetCMakeInstance()->GetDebugConfigs();
diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h
index 3da3950..aaabdfa 100644
--- a/Source/cmTargetLinkLibrariesCommand.h
+++ b/Source/cmTargetLinkLibrariesCommand.h
@@ -97,6 +97,15 @@ public:
"Calls to other signatures of this command may set the property "
"making any libraries linked exclusively by this signature private."
"\n"
+ "Target usage requirements are also consumed by this command. If the "
+ "<target> is linked to another target which has "
+ "a populated INTERFACE_INCLUDE_DIRECTORIES, the content of it is "
+ "appended to the INCLUDE_DIRECTORIES of <target>. Similarly, the "
+ "INTERFACE_COMPILE_DEFINITONS of a dependee are added to the "
+ "COMPILE_DEFINITONS of <target>, and the "
+ "INTERFACE_POSITION_INDEPENDENT_CODE property is used to determine the "
+ "POSITION_INDEPENDENT_CODE property of <target>."
+ "\n"
" target_link_libraries(<target> LINK_INTERFACE_LIBRARIES\n"
" [[debug|optimized|general] <lib>] ...)\n"
"The LINK_INTERFACE_LIBRARIES mode appends the libraries "