summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-10-10 14:23:45 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2016-10-10 14:23:45 (GMT)
commit1e6aaefdeebbf09eaf7fa0e9dbc6a7faa2f9132a (patch)
treedc995bdb1701c8c8088620a5ca343c71087287e0 /Source/cmMakefile.cxx
parentea533eb71516a92e1528e358ffa374b16864eac6 (diff)
parenta1cfc4fe3deed4d642773d0ae63dd524c3f2eba1 (diff)
downloadCMake-1e6aaefdeebbf09eaf7fa0e9dbc6a7faa2f9132a.zip
CMake-1e6aaefdeebbf09eaf7fa0e9dbc6a7faa2f9132a.tar.gz
CMake-1e6aaefdeebbf09eaf7fa0e9dbc6a7faa2f9132a.tar.bz2
Merge topic 'clean-up-link-configuration'
a1cfc4fe cmMakefile: Simplify programmer error to an assert 4079ba20 cmMakefile: Implement LinkLibraries as an internal property 17ab8e33 cmMakefile: Inline method into only remaining caller 7edfcd0e cmMakefile: Inline method into caller 6c8dc7f1 cmake: Simplify find-package mode library addition 1efca9f4 cmMakefile: Remove obsolete parameter d9b5f0a3 cmTarget: Remove target name from parameter list 1c70c6cc cmMakefile: Use public API to find a target 2b7baed7 cmMakefile: Inline method into only caller 7ba95492 cmMakefile: Use public API to find a target 6d98b15f cmMakefile: Invert if() condition to remove else 869037ee cmMakefile: Remove ALIAS check 2f6462a6 cmMakefile: Collapse two consecutive if()s into one 148b83a1 cmMakefile: DeMorgan-invert condition 4457a9f1 cmMakefile: Return after error and remove else condition 4d039c5b cmMakefile: Invert handling of error condition ...
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx147
1 files changed, 55 insertions, 92 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index a9ef9cd..c3111c0 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1207,71 +1207,6 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
return true;
}
-void cmMakefile::AddLinkLibrary(const std::string& lib,
- cmTargetLinkLibraryType llt)
-{
- cmTarget::LibraryID tmp;
- tmp.first = lib;
- tmp.second = llt;
- this->LinkLibraries.push_back(tmp);
-}
-
-void cmMakefile::AddLinkLibraryForTarget(const std::string& target,
- const std::string& lib,
- cmTargetLinkLibraryType llt)
-{
- cmTargets::iterator i = this->Targets.find(target);
- if (i != this->Targets.end()) {
- cmTarget* tgt = this->GetGlobalGenerator()->FindTarget(lib);
- if (tgt) {
- // if it is not a static or shared library then you can not link to it
- if (!((tgt->GetType() == cmState::STATIC_LIBRARY) ||
- (tgt->GetType() == cmState::SHARED_LIBRARY) ||
- (tgt->GetType() == cmState::INTERFACE_LIBRARY) ||
- tgt->IsExecutableWithExports())) {
- std::ostringstream e;
- e << "Target \"" << lib << "\" of type "
- << cmState::GetTargetTypeName(tgt->GetType())
- << " may not be linked into another target. "
- << "One may link only to STATIC or SHARED libraries, or "
- << "to executables with the ENABLE_EXPORTS property set.";
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
- }
- }
- i->second.AddLinkLibrary(*this, target, lib, llt);
- } else {
- std::ostringstream e;
- e << "Attempt to add link library \"" << lib << "\" to target \"" << target
- << "\" which is not built in this directory.";
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
- }
-}
-
-void cmMakefile::AddLinkDirectoryForTarget(const std::string& target,
- const std::string& d)
-{
- cmTargets::iterator i = this->Targets.find(target);
- if (i != this->Targets.end()) {
- if (this->IsAlias(target)) {
- std::ostringstream e;
- e << "ALIAS target \"" << target << "\" "
- << "may not be linked into another target.";
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
- return;
- }
- i->second.AddLinkDirectory(d);
- } else {
- cmSystemTools::Error(
- "Attempt to add link directories to non-existent target: ",
- target.c_str(), " for directory ", d.c_str());
- }
-}
-
-void cmMakefile::AddLinkLibrary(const std::string& lib)
-{
- this->AddLinkLibrary(lib, GENERAL_LibraryType);
-}
-
void cmMakefile::InitializeFromParent(cmMakefile* parent)
{
this->SystemIncludeDirectories = parent->SystemIncludeDirectories;
@@ -1303,7 +1238,7 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
}
// link libraries
- this->LinkLibraries = parent->LinkLibraries;
+ this->SetProperty("LINK_LIBRARIES", parent->GetProperty("LINK_LIBRARIES"));
// link directories
this->SetProperty("LINK_DIRECTORIES",
@@ -1835,8 +1770,7 @@ void cmMakefile::SetProjectName(std::string const& p)
this->StateSnapshot.SetProjectName(p);
}
-void cmMakefile::AddGlobalLinkInformation(const std::string& name,
- cmTarget& target)
+void cmMakefile::AddGlobalLinkInformation(cmTarget& target)
{
// for these targets do not add anything
switch (target.GetType()) {
@@ -1857,13 +1791,34 @@ void cmMakefile::AddGlobalLinkInformation(const std::string& name,
if (*j->rbegin() == '/') {
newdir = j->substr(0, j->size() - 1);
}
- if (std::find(this->LinkDirectories.begin(), this->LinkDirectories.end(),
- newdir) == this->LinkDirectories.end()) {
- target.AddLinkDirectory(*j);
+ target.AddLinkDirectory(*j);
+ }
+ }
+
+ if (const char* linkLibsProp = this->GetProperty("LINK_LIBRARIES")) {
+ std::vector<std::string> linkLibs;
+ cmSystemTools::ExpandListArgument(linkLibsProp, linkLibs);
+
+ for (std::vector<std::string>::iterator j = linkLibs.begin();
+ j != linkLibs.end(); ++j) {
+ std::string libraryName = *j;
+ cmTargetLinkLibraryType libType = GENERAL_LibraryType;
+ if (libraryName == "optimized") {
+ libType = OPTIMIZED_LibraryType;
+ ++j;
+ libraryName = *j;
+ } else if (libraryName == "debug") {
+ libType = DEBUG_LibraryType;
+ ++j;
+ libraryName = *j;
}
+ // This is equivalent to the target_link_libraries plain signature.
+ target.AddLinkLibrary(*this, libraryName, libType);
+ target.AppendProperty(
+ "INTERFACE_LINK_LIBRARIES",
+ target.GetDebugGeneratorExpressions(libraryName, libType).c_str());
}
}
- target.MergeLinkLibraries(*this, name, this->LinkLibraries);
}
void cmMakefile::AddAlias(const std::string& lname, std::string const& tgtName)
@@ -1877,14 +1832,9 @@ cmTarget* cmMakefile::AddLibrary(const std::string& lname,
const std::vector<std::string>& srcs,
bool excludeFromAll)
{
- // wrong type ? default to STATIC
- if ((type != cmState::STATIC_LIBRARY) && (type != cmState::SHARED_LIBRARY) &&
- (type != cmState::MODULE_LIBRARY) && (type != cmState::OBJECT_LIBRARY) &&
- (type != cmState::INTERFACE_LIBRARY)) {
- this->IssueMessage(cmake::INTERNAL_ERROR,
- "cmMakefile::AddLibrary given invalid target type.");
- type = cmState::STATIC_LIBRARY;
- }
+ assert(type == cmState::STATIC_LIBRARY || type == cmState::SHARED_LIBRARY ||
+ type == cmState::MODULE_LIBRARY || type == cmState::OBJECT_LIBRARY ||
+ type == cmState::INTERFACE_LIBRARY);
cmTarget* target = this->AddNewTarget(type, lname);
// Clear its dependencies. Otherwise, dependencies might persist
@@ -1895,7 +1845,7 @@ cmTarget* cmMakefile::AddLibrary(const std::string& lname,
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
}
target->AddSources(srcs);
- this->AddGlobalLinkInformation(lname, *target);
+ this->AddGlobalLinkInformation(*target);
return target;
}
@@ -1908,7 +1858,7 @@ cmTarget* cmMakefile::AddExecutable(const char* exeName,
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
}
target->AddSources(srcs);
- this->AddGlobalLinkInformation(exeName, *target);
+ this->AddGlobalLinkInformation(*target);
return target;
}
@@ -2125,19 +2075,32 @@ void cmMakefile::ExpandVariablesCMP0019()
}
}
}
- for (cmTarget::LinkLibraryVectorType::iterator l =
- this->LinkLibraries.begin();
- l != this->LinkLibraries.end(); ++l) {
- if (mightExpandVariablesCMP0019(l->first.c_str())) {
- std::string orig = l->first;
- this->ExpandVariablesInString(l->first, true, true);
- if (pol == cmPolicies::WARN && l->first != orig) {
- /* clang-format off */
+
+ if (const char* linkLibsProp = this->GetProperty("LINK_LIBRARIES")) {
+ std::vector<std::string> linkLibs;
+ cmSystemTools::ExpandListArgument(linkLibsProp, linkLibs);
+
+ for (std::vector<std::string>::iterator l = linkLibs.begin();
+ l != linkLibs.end(); ++l) {
+ std::string libName = *l;
+ if (libName == "optimized") {
+ ++l;
+ libName = *l;
+ } else if (libName == "debug") {
+ ++l;
+ libName = *l;
+ }
+ if (mightExpandVariablesCMP0019(libName.c_str())) {
+ std::string orig = libName;
+ this->ExpandVariablesInString(libName, true, true);
+ if (pol == cmPolicies::WARN && libName != orig) {
+ /* clang-format off */
w << "Evaluated link library\n"
<< " " << orig << "\n"
<< "as\n"
- << " " << l->first << "\n";
- /* clang-format on */
+ << " " << libName << "\n";
+ /* clang-format on */
+ }
}
}
}