This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake".
The branch, next has been updated via 9f667ee9f52f436a3d43121d43c8efe4e05709e1 (commit) via 87bde938fe3c66fc6298108c7594578005bbb2a6 (commit) via 9723f4ddb9cc0767b7b963aa31def62c11b05c50 (commit) via cd04ce0a7f6317169f6d8738f56b46c658314bd0 (commit) via d89821cdd61896d7500f8ca2378294d9cf7aa27e (commit) via 7edfcd0e834a4dc8d3da9cada6ad6b9b46dfb4dd (commit) via 6c8dc7f1df6d3492d11ad994a35ee2f0b8a4e60b (commit) via 1efca9f427a5c537afc034aadf0c29073bfdfa22 (commit) via d9b5f0a301c23c2c0e56ad3fcb696de71c3d6365 (commit) via 1c70c6cc09f0f8be087db2aeae5ee6a3f1b47bda (commit) via 2b7baed719e4a6eb918ed6f22ee6031a40b7f316 (commit) via 7ba954925a876f4c753a4296236bc7d2f18eb0b8 (commit) via 6d98b15fc8b9a065325e3683afe94efce17dd162 (commit) via 869037ee86d1c0ab757840adf499ea270d4301e1 (commit) via 2f6462a634726d9d0ea8d8552454839d67183016 (commit) via 148b83a12185d7611ff7576464087430c3f2719c (commit) via 4457a9f181663701961dc209740974f48213e6e7 (commit) via 4d039c5b46e3cac29ff1d9ce3e768af1bca6b69a (commit) via c8ec8d6a7ec6c176bc14e7026dc755a9be8689cb (commit) via 3e8d47d18b4db6b4621ee5e4864dde234ad8a282 (commit) via 3b4895fa35e4a96022abd99b07002a7d2ab3a968 (commit) via 2232e97a6ed4a338b814d1ba3d62a7ffa9ef6e7f (commit) via 9a1d4e4ba170f4ac34c80593bd2fe8e1481a1181 (commit) via 8391b3015a82909828b7ada98e76d45aa11b892b (commit) from befbf7ad51059b6077de1fa34a59bde28284731a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9f667ee9f52f436a3d43121d43c8efe4e05709e1 commit 9f667ee9f52f436a3d43121d43c8efe4e05709e1 Merge: befbf7a 87bde93 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 15:49:21 2016 -0400 Commit: CMake Topic Stage <kwro...@kitware.com> CommitDate: Fri Oct 7 15:49:21 2016 -0400 Merge topic 'clean-up-link-configuration' into next 87bde938 cmMakefile: Simplify programmer error to an assert 9723f4dd cmMakefile: Move link_libraries() related code out cd04ce0a cmMakefile: Implement LinkLibraries as an internal property d89821cd 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 ... https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=87bde938fe3c66fc6298108c7594578005bbb2a6 commit 87bde938fe3c66fc6298108c7594578005bbb2a6 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:37 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 21:33:25 2016 +0200 cmMakefile: Simplify programmer error to an assert diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 12f971f..c4d6103 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1782,14 +1782,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 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9723f4ddb9cc0767b7b963aa31def62c11b05c50 commit 9723f4ddb9cc0767b7b963aa31def62c11b05c50 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:37 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 21:33:25 2016 +0200 cmMakefile: Move link_libraries() related code out AddGlobalLinkInformation has an important-sounding name, but in reality, it is only used by the link_libraries() command. Keep behaviors which are specific to the current language out of the core of CMake. diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx index 96ad82a..10b4b76 100644 --- a/Source/cmAddExecutableCommand.cxx +++ b/Source/cmAddExecutableCommand.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmAddExecutableCommand.h" +#include "cmLinkLibrariesCommand.h" + // cmExecutableCommand bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) @@ -188,6 +190,9 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args, std::vector<std::string> srclists(s, args.end()); cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists, excludeFromAll); + + cmLinkLibrariesCommand::PopulateTarget(*tgt, this->Makefile); + if (use_win32) { tgt->SetProperty("WIN32_EXECUTABLE", "ON"); } diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index 26e38b8..8c02f75 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -4,6 +4,7 @@ #include "cmState.h" #include "cmake.h" +#include "cmLinkLibrariesCommand.h" // cmLibraryCommand bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args, @@ -355,7 +356,9 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args, srclists.insert(srclists.end(), s, args.end()); - this->Makefile->AddLibrary(libName, type, srclists, excludeFromAll); + cmTarget* tgt = this->Makefile->AddLibrary(libName, type, srclists, excludeFromAll); + + cmLinkLibrariesCommand::PopulateTarget(*tgt, this->Makefile); return true; } diff --git a/Source/cmLinkLibrariesCommand.cxx b/Source/cmLinkLibrariesCommand.cxx index 4202cf5..ecf3f57 100644 --- a/Source/cmLinkLibrariesCommand.cxx +++ b/Source/cmLinkLibrariesCommand.cxx @@ -35,3 +35,57 @@ bool cmLinkLibrariesCommand::InitialPass(std::vector<std::string> const& args, return true; } + +void cmLinkLibrariesCommand::PopulateTarget(cmTarget& target, cmMakefile* mf) +{ + // for these targets do not add anything + switch (target.GetType()) { + case cmState::UTILITY: + case cmState::GLOBAL_TARGET: + case cmState::INTERFACE_LIBRARY: + return; + default:; + } + if (const char* linkDirsProp = mf->GetProperty("LINK_DIRECTORIES")) { + std::vector<std::string> linkDirs; + cmSystemTools::ExpandListArgument(linkDirsProp, linkDirs); + + for (std::vector<std::string>::iterator j = linkDirs.begin(); + j != linkDirs.end(); ++j) { + std::string newdir = *j; + // remove trailing slashes + if (*j->rbegin() == '/') { + newdir = j->substr(0, j->size() - 1); + } + target.AddLinkDirectory(*j); + } + } + + if (const char* linkLibsProp = mf->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(*mf, libraryName, libType); + target.AppendProperty( + "INTERFACE_LINK_LIBRARIES", + target.GetDebugGeneratorExpressions(libraryName, libType).c_str()); + } + } +} diff --git a/Source/cmLinkLibrariesCommand.h b/Source/cmLinkLibrariesCommand.h index b4943b6..5170f03 100644 --- a/Source/cmLinkLibrariesCommand.h +++ b/Source/cmLinkLibrariesCommand.h @@ -27,6 +27,8 @@ public: bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) CM_OVERRIDE; + static void PopulateTarget(cmTarget& target, cmMakefile* mf); + /** * The name of the command as specified in CMakeList.txt. */ diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 2414b32..12f971f 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1771,60 +1771,6 @@ void cmMakefile::SetProjectName(std::string const& p) this->StateSnapshot.SetProjectName(p); } -void cmMakefile::AddGlobalLinkInformation(cmTarget& target) -{ - // for these targets do not add anything - switch (target.GetType()) { - case cmState::UTILITY: - case cmState::GLOBAL_TARGET: - case cmState::INTERFACE_LIBRARY: - return; - default:; - } - if (const char* linkDirsProp = this->GetProperty("LINK_DIRECTORIES")) { - std::vector<std::string> linkDirs; - cmSystemTools::ExpandListArgument(linkDirsProp, linkDirs); - - for (std::vector<std::string>::iterator j = linkDirs.begin(); - j != linkDirs.end(); ++j) { - std::string newdir = *j; - // remove trailing slashes - if (*j->rbegin() == '/') { - newdir = j->substr(0, j->size() - 1); - } - 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()); - } - } -} - void cmMakefile::AddAlias(const std::string& lname, std::string const& tgtName) { this->AliasTargets[lname] = tgtName; @@ -1854,7 +1800,6 @@ cmTarget* cmMakefile::AddLibrary(const std::string& lname, target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } target->AddSources(srcs); - this->AddGlobalLinkInformation(*target); return target; } @@ -1867,7 +1812,6 @@ cmTarget* cmMakefile::AddExecutable(const char* exeName, target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } target->AddSources(srcs); - this->AddGlobalLinkInformation(*target); return target; } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 8fef38b..c9ab3ba 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -771,9 +771,6 @@ public: void AddExportBuildFileGenerator(cmExportBuildFileGenerator* gen); protected: - // add link libraries and directories to the target - void AddGlobalLinkInformation(cmTarget& target); - // Check for a an unused variable void LogUnused(const char* reason, const std::string& name) const; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cd04ce0a7f6317169f6d8738f56b46c658314bd0 commit cd04ce0a7f6317169f6d8738f56b46c658314bd0 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:37 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 21:33:24 2016 +0200 cmMakefile: Implement LinkLibraries as an internal property cmMakefile should not have logic particular to individual cmake commands. The link_libraries() command is generally obsolete in favor of target_link_libraries(). An alternative language for CMake probably would not offer the former. The quirks and historical behaviors of the current language should be separate from the core classes of CMake to allow replacing the language. diff --git a/Source/cmLinkLibrariesCommand.cxx b/Source/cmLinkLibrariesCommand.cxx index 3fc7bd9..4202cf5 100644 --- a/Source/cmLinkLibrariesCommand.cxx +++ b/Source/cmLinkLibrariesCommand.cxx @@ -20,7 +20,7 @@ bool cmLinkLibrariesCommand::InitialPass(std::vector<std::string> const& args, "a library"); return false; } - this->Makefile->AddLinkLibrary(*i, DEBUG_LibraryType); + this->Makefile->AppendProperty("LINK_LIBRARIES", "debug"); } else if (*i == "optimized") { ++i; if (i == args.end()) { @@ -28,10 +28,9 @@ bool cmLinkLibrariesCommand::InitialPass(std::vector<std::string> const& args, "a library"); return false; } - this->Makefile->AddLinkLibrary(*i, OPTIMIZED_LibraryType); - } else { - this->Makefile->AddLinkLibrary(*i, GENERAL_LibraryType); + this->Makefile->AppendProperty("LINK_LIBRARIES", "optimized"); } + this->Makefile->AppendProperty("LINK_LIBRARIES", i->c_str()); } return true; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 6e451b6..2414b32 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1207,15 +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::InitializeFromParent(cmMakefile* parent) { this->SystemIncludeDirectories = parent->SystemIncludeDirectories; @@ -1247,7 +1238,8 @@ 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", @@ -1804,14 +1796,32 @@ void cmMakefile::AddGlobalLinkInformation(cmTarget& target) } } - cmTarget::LinkLibraryVectorType::const_iterator i = - this->LinkLibraries.begin(); - for (; i != this->LinkLibraries.end(); ++i) { - // This is equivalent to the target_link_libraries plain signature. - target.AddLinkLibrary(*this, i->first, i->second); - target.AppendProperty( - "INTERFACE_LINK_LIBRARIES", - target.GetDebugGeneratorExpressions(i->first, i->second).c_str()); + 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()); + } } } @@ -2074,21 +2084,37 @@ 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) { + + 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"; + << " " << libName << "\n"; /* clang-format on */ } } + } } if (!w.str().empty()) { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index a16c6bb..8fef38b 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -197,11 +197,6 @@ public: const char* comment = CM_NULLPTR, bool uses_terminal = false); /** - * Add a link library to the build. - */ - void AddLinkLibrary(const std::string&, cmTargetLinkLibraryType type); - - /** * Add a subdirectory to the build. */ void AddSubDirectory(const std::string& fullSrcDir, @@ -808,8 +803,6 @@ protected: std::vector<std::string> ListFiles; std::vector<std::string> OutputFiles; - cmTarget::LinkLibraryVectorType LinkLibraries; - std::vector<cmInstallGenerator*> InstallGenerators; std::vector<cmTestGenerator*> TestGenerators; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d89821cdd61896d7500f8ca2378294d9cf7aa27e commit d89821cdd61896d7500f8ca2378294d9cf7aa27e Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:36 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 21:25:46 2016 +0200 cmMakefile: Inline method into only remaining caller diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 2498ecb..b2da329 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -337,6 +337,38 @@ void CCONV cmAddCustomCommandToTarget(void* arg, const char* target, cctype, no_comment, no_working_dir); } +static void addLinkLibrary(cmMakefile* mf, std::string const& target, + std::string const& lib, cmTargetLinkLibraryType llt) +{ + cmTarget* t = mf->FindLocalNonAliasTarget(target); + if (!t) + { + std::ostringstream e; + e << "Attempt to add link library \"" + << lib << "\" to target \"" + << target << "\" which is not built in this directory."; + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + return; + } + + cmTarget* tgt = mf->GetGlobalGenerator()->FindTarget(lib); + if(tgt && (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."; + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + } + + t->AddLinkLibrary( *mf, lib, llt ); +} + void CCONV cmAddLinkLibraryForTarget(void* arg, const char* tgt, const char* value, int libtype) { @@ -344,13 +376,13 @@ void CCONV cmAddLinkLibraryForTarget(void* arg, const char* tgt, switch (libtype) { case CM_LIBRARY_GENERAL: - mf->AddLinkLibraryForTarget(tgt, value, GENERAL_LibraryType); + addLinkLibrary(mf, tgt,value, GENERAL_LibraryType); break; case CM_LIBRARY_DEBUG: - mf->AddLinkLibraryForTarget(tgt, value, DEBUG_LibraryType); + addLinkLibrary(mf, tgt,value, DEBUG_LibraryType); break; case CM_LIBRARY_OPTIMIZED: - mf->AddLinkLibraryForTarget(tgt, value, OPTIMIZED_LibraryType); + addLinkLibrary(mf, tgt,value, OPTIMIZED_LibraryType); break; } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index eda08c0..6e451b6 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1216,35 +1216,6 @@ void cmMakefile::AddLinkLibrary(const std::string& lib, this->LinkLibraries.push_back(tmp); } -void cmMakefile::AddLinkLibraryForTarget(const std::string& target, - const std::string& lib, - cmTargetLinkLibraryType llt) -{ - cmTarget* t = this->FindLocalNonAliasTarget(target); - if (!t) { - 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()); - return; - } - - cmTarget* tgt = this->GetGlobalGenerator()->FindTarget(lib); - if (tgt && (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()); - } - t->AddLinkLibrary(*this, lib, llt); -} - void cmMakefile::InitializeFromParent(cmMakefile* parent) { this->SystemIncludeDirectories = parent->SystemIncludeDirectories; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 9f5f8ee..a16c6bb 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -200,8 +200,6 @@ public: * Add a link library to the build. */ void AddLinkLibrary(const std::string&, cmTargetLinkLibraryType type); - void AddLinkLibraryForTarget(const std::string& tgt, const std::string&, - cmTargetLinkLibraryType type); /** * Add a subdirectory to the build. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7edfcd0e834a4dc8d3da9cada6ad6b9b46dfb4dd commit 7edfcd0e834a4dc8d3da9cada6ad6b9b46dfb4dd Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:36 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 21:25:41 2016 +0200 cmMakefile: Inline method into caller The various uses of AddLinkLibraryForTarget are going away. This is the only remaining non-deprecated use. diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index e714309..d1de7ef 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -338,7 +338,35 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, // Handle normal case first. if (this->CurrentProcessingState != ProcessingKeywordLinkInterface && this->CurrentProcessingState != ProcessingPlainLinkInterface) { - this->Makefile->AddLinkLibraryForTarget(this->Target->GetName(), lib, llt); + + cmTarget* t = + this->Makefile->FindLocalNonAliasTarget(this->Target->GetName()); + if (!t) { + std::ostringstream e; + e << "Attempt to add link library \"" << lib << "\" to target \"" + << this->Target->GetName() + << "\" which is not built in this directory."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + } else { + + cmTarget* tgt = this->Makefile->GetGlobalGenerator()->FindTarget(lib); + + if (tgt && (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->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + } + + this->Target->AddLinkLibrary(*this->Makefile, lib, llt); + } + if (this->CurrentProcessingState == ProcessingLinkLibraries) { this->Target->AppendProperty( "INTERFACE_LINK_LIBRARIES", https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6c8dc7f1df6d3492d11ad994a35ee2f0b8a4e60b commit 6c8dc7f1df6d3492d11ad994a35ee2f0b8a4e60b Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:36 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:23:19 2016 +0200 cmake: Simplify find-package mode library addition It does not need the cmMakefile version. diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 14124f8..dad8717 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -568,7 +568,7 @@ bool cmake::FindPackage(const std::vector<std::string>& args) cmSystemTools::ExpandListArgument(libs, libList); for (std::vector<std::string>::const_iterator libIt = libList.begin(); libIt != libList.end(); ++libIt) { - mf->AddLinkLibraryForTarget(targetName, *libIt, GENERAL_LibraryType); + tgt->AddLinkLibrary(*mf, *libIt, GENERAL_LibraryType); } std::string buildType = mf->GetSafeDefinition("CMAKE_BUILD_TYPE"); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1efca9f427a5c537afc034aadf0c29073bfdfa22 commit 1efca9f427a5c537afc034aadf0c29073bfdfa22 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:36 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:36 2016 +0200 cmMakefile: Remove obsolete parameter diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 4763d83..eda08c0 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1808,8 +1808,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()) { @@ -1874,7 +1873,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; } @@ -1887,7 +1886,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; } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 76afcbc..9f5f8ee 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -779,7 +779,7 @@ public: protected: // add link libraries and directories to the target - void AddGlobalLinkInformation(const std::string& name, cmTarget& target); + void AddGlobalLinkInformation(cmTarget& target); // Check for a an unused variable void LogUnused(const char* reason, const std::string& name) const; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d9b5f0a301c23c2c0e56ad3fcb696de71c3d6365 commit d9b5f0a301c23c2c0e56ad3fcb696de71c3d6365 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:36 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:36 2016 +0200 cmTarget: Remove target name from parameter list Use the member state instead. diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index ae2d776..4763d83 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1242,7 +1242,7 @@ void cmMakefile::AddLinkLibraryForTarget(const std::string& target, << "to executables with the ENABLE_EXPORTS property set."; this->IssueMessage(cmake::FATAL_ERROR, e.str()); } - t->AddLinkLibrary(*this, target, lib, llt); + t->AddLinkLibrary(*this, lib, llt); } void cmMakefile::InitializeFromParent(cmMakefile* parent) @@ -1808,7 +1808,7 @@ void cmMakefile::SetProjectName(std::string const& p) this->StateSnapshot.SetProjectName(p); } -void cmMakefile::AddGlobalLinkInformation(const std::string& name, +void cmMakefile::AddGlobalLinkInformation(const std::string& /* name */, cmTarget& target) { // for these targets do not add anything @@ -1838,7 +1838,7 @@ void cmMakefile::AddGlobalLinkInformation(const std::string& name, this->LinkLibraries.begin(); for (; i != this->LinkLibraries.end(); ++i) { // This is equivalent to the target_link_libraries plain signature. - target.AddLinkLibrary(*this, name, i->first, i->second); + target.AddLinkLibrary(*this, i->first, i->second); target.AppendProperty( "INTERFACE_LINK_LIBRARIES", target.GetDebugGeneratorExpressions(i->first, i->second).c_str()); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 86a2777..651bcc8 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -578,8 +578,7 @@ void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const } } -void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& target, - const std::string& lib, +void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& lib, cmTargetLinkLibraryType llt) { cmTarget* tgt = this->Makefile->FindTargetToUse(lib); @@ -597,7 +596,7 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& target, if (cmGeneratorExpression::Find(lib) != std::string::npos || (tgt && tgt->GetType() == cmState::INTERFACE_LIBRARY) || - (target == lib)) { + (this->Name == lib)) { return; } @@ -615,7 +614,7 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& target, // and we removing one instance will break the link line. Duplicates // will be appropriately eliminated at emit time. if (this->RecordDependencies) { - std::string targetEntry = target; + std::string targetEntry = this->Name; targetEntry += "_LIB_DEPENDS"; std::string dependencies; const char* old_val = mf.GetDefinition(targetEntry); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 8fbb42f..3d88688 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -142,8 +142,8 @@ public: */ void ClearDependencyInformation(cmMakefile& mf, const std::string& target); - void AddLinkLibrary(cmMakefile& mf, const std::string& target, - const std::string& lib, cmTargetLinkLibraryType llt); + void AddLinkLibrary(cmMakefile& mf, const std::string& lib, + cmTargetLinkLibraryType llt); enum TLLSignature { KeywordTLLSignature, https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1c70c6cc09f0f8be087db2aeae5ee6a3f1b47bda commit 1c70c6cc09f0f8be087db2aeae5ee6a3f1b47bda Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:35 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:35 2016 +0200 cmMakefile: Use public API to find a target diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index f2db37e..ae2d776 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1220,8 +1220,8 @@ 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* t = this->FindLocalNonAliasTarget(target); + if (!t) { std::ostringstream e; e << "Attempt to add link library \"" << lib << "\" to target \"" << target << "\" which is not built in this directory."; @@ -1242,7 +1242,7 @@ void cmMakefile::AddLinkLibraryForTarget(const std::string& target, << "to executables with the ENABLE_EXPORTS property set."; this->IssueMessage(cmake::FATAL_ERROR, e.str()); } - i->second.AddLinkLibrary(*this, target, lib, llt); + t->AddLinkLibrary(*this, target, lib, llt); } void cmMakefile::InitializeFromParent(cmMakefile* parent) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2b7baed719e4a6eb918ed6f22ee6031a40b7f316 commit 2b7baed719e4a6eb918ed6f22ee6031a40b7f316 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:35 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:35 2016 +0200 cmMakefile: Inline method into only caller cmMakefile should not have API which is only useful for deprecated systems like cmPluginAPI. diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 3a08aea..2498ecb 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -162,7 +162,14 @@ void CCONV cmAddLinkDirectoryForTarget(void* arg, const char* tgt, const char* d) { cmMakefile* mf = static_cast<cmMakefile*>(arg); - mf->AddLinkDirectoryForTarget(tgt, d); + cmTarget* t = mf->FindLocalNonAliasTarget(tgt); + if (!t) { + cmSystemTools::Error( + "Attempt to add link directories to non-existent target: ", tgt, + " for directory ", d); + return; + } + t->AddLinkDirectory(d); } void CCONV cmAddExecutable(void* arg, const char* exename, int numSrcs, diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d2be29c..f2db37e 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1245,20 +1245,6 @@ void cmMakefile::AddLinkLibraryForTarget(const std::string& target, i->second.AddLinkLibrary(*this, target, lib, llt); } -void cmMakefile::AddLinkDirectoryForTarget(const std::string& target, - const std::string& d) -{ - cmTarget* t = this->FindLocalNonAliasTarget(target); - if (!t) { - cmSystemTools::Error( - "Attempt to add link directories to non-existent target: ", - target.c_str(), " for directory ", d.c_str()); - return; - } - - t->AddLinkDirectory(d); -} - void cmMakefile::InitializeFromParent(cmMakefile* parent) { this->SystemIncludeDirectories = parent->SystemIncludeDirectories; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 9ffdd9d..76afcbc 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -202,7 +202,6 @@ public: void AddLinkLibrary(const std::string&, cmTargetLinkLibraryType type); void AddLinkLibraryForTarget(const std::string& tgt, const std::string&, cmTargetLinkLibraryType type); - void AddLinkDirectoryForTarget(const std::string& tgt, const std::string& d); /** * Add a subdirectory to the build. https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7ba954925a876f4c753a4296236bc7d2f18eb0b8 commit 7ba954925a876f4c753a4296236bc7d2f18eb0b8 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:35 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:35 2016 +0200 cmMakefile: Use public API to find a target diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7e26bff..d2be29c 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1248,14 +1248,15 @@ void cmMakefile::AddLinkLibraryForTarget(const std::string& target, void cmMakefile::AddLinkDirectoryForTarget(const std::string& target, const std::string& d) { - cmTargets::iterator i = this->Targets.find(target); - if (i == this->Targets.end()) { + cmTarget* t = this->FindLocalNonAliasTarget(target); + if (!t) { cmSystemTools::Error( "Attempt to add link directories to non-existent target: ", target.c_str(), " for directory ", d.c_str()); return; } - i->second.AddLinkDirectory(d); + + t->AddLinkDirectory(d); } void cmMakefile::InitializeFromParent(cmMakefile* parent) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6d98b15fc8b9a065325e3683afe94efce17dd162 commit 6d98b15fc8b9a065325e3683afe94efce17dd162 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:35 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:35 2016 +0200 cmMakefile: Invert if() condition to remove else diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 57bab7a..7e26bff 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1249,13 +1249,13 @@ void cmMakefile::AddLinkDirectoryForTarget(const std::string& target, const std::string& d) { cmTargets::iterator i = this->Targets.find(target); - if (i != this->Targets.end()) { - i->second.AddLinkDirectory(d); - } else { + if (i == this->Targets.end()) { cmSystemTools::Error( "Attempt to add link directories to non-existent target: ", target.c_str(), " for directory ", d.c_str()); + return; } + i->second.AddLinkDirectory(d); } void cmMakefile::InitializeFromParent(cmMakefile* parent) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=869037ee86d1c0ab757840adf499ea270d4301e1 commit 869037ee86d1c0ab757840adf499ea270d4301e1 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:35 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:35 2016 +0200 cmMakefile: Remove ALIAS check This method is only called from the cmPlugin API, which predates ALIAS targets and is obsolete. diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index c8446ac..57bab7a 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1250,13 +1250,6 @@ void cmMakefile::AddLinkDirectoryForTarget(const std::string& target, { 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( https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2f6462a634726d9d0ea8d8552454839d67183016 commit 2f6462a634726d9d0ea8d8552454839d67183016 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:34 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:34 2016 +0200 cmMakefile: Collapse two consecutive if()s into one diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 8716696..c8446ac 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1230,20 +1230,17 @@ void cmMakefile::AddLinkLibraryForTarget(const std::string& target, } 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()); - } + if (tgt && (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); } https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=148b83a12185d7611ff7576464087430c3f2719c commit 148b83a12185d7611ff7576464087430c3f2719c Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:34 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:34 2016 +0200 cmMakefile: DeMorgan-invert condition diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index f4ea8a9..8716696 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1232,10 +1232,10 @@ void cmMakefile::AddLinkLibraryForTarget(const std::string& target, 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())) { + 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()) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4457a9f181663701961dc209740974f48213e6e7 commit 4457a9f181663701961dc209740974f48213e6e7 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:34 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:34 2016 +0200 cmMakefile: Return after error and remove else condition diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7c4a2c2..f4ea8a9 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1226,25 +1226,26 @@ void cmMakefile::AddLinkLibraryForTarget(const std::string& target, e << "Attempt to add link library \"" << lib << "\" to target \"" << target << "\" which is not built in this directory."; this->IssueMessage(cmake::FATAL_ERROR, e.str()); - } else { - 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()); - } + return; + } + + 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); } + i->second.AddLinkLibrary(*this, target, lib, llt); } void cmMakefile::AddLinkDirectoryForTarget(const std::string& target, https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4d039c5b46e3cac29ff1d9ce3e768af1bca6b69a commit 4d039c5b46e3cac29ff1d9ce3e768af1bca6b69a Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:34 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:34 2016 +0200 cmMakefile: Invert handling of error condition diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 3e9837d..7c4a2c2 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1221,7 +1221,12 @@ void cmMakefile::AddLinkLibraryForTarget(const std::string& target, cmTargetLinkLibraryType llt) { cmTargets::iterator i = this->Targets.find(target); - if (i != this->Targets.end()) { + if (i == this->Targets.end()) { + 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()); + } else { cmTarget* tgt = this->GetGlobalGenerator()->FindTarget(lib); if (tgt) { // if it is not a static or shared library then you can not link to it @@ -1239,11 +1244,6 @@ void cmMakefile::AddLinkLibraryForTarget(const std::string& target, } } 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()); } } https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c8ec8d6a7ec6c176bc14e7026dc755a9be8689cb commit c8ec8d6a7ec6c176bc14e7026dc755a9be8689cb Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:34 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:34 2016 +0200 cmMakefile: Remove superfluous overload Explicit is better than implicit. diff --git a/Source/cmLinkLibrariesCommand.cxx b/Source/cmLinkLibrariesCommand.cxx index bb0e27b..3fc7bd9 100644 --- a/Source/cmLinkLibrariesCommand.cxx +++ b/Source/cmLinkLibrariesCommand.cxx @@ -30,7 +30,7 @@ bool cmLinkLibrariesCommand::InitialPass(std::vector<std::string> const& args, } this->Makefile->AddLinkLibrary(*i, OPTIMIZED_LibraryType); } else { - this->Makefile->AddLinkLibrary(*i); + this->Makefile->AddLinkLibrary(*i, GENERAL_LibraryType); } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0efd92c..3e9837d 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1267,11 +1267,6 @@ void cmMakefile::AddLinkDirectoryForTarget(const std::string& target, } } -void cmMakefile::AddLinkLibrary(const std::string& lib) -{ - this->AddLinkLibrary(lib, GENERAL_LibraryType); -} - void cmMakefile::InitializeFromParent(cmMakefile* parent) { this->SystemIncludeDirectories = parent->SystemIncludeDirectories; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 92907cd..9ffdd9d 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -199,7 +199,6 @@ public: /** * Add a link library to the build. */ - void AddLinkLibrary(const std::string&); void AddLinkLibrary(const std::string&, cmTargetLinkLibraryType type); void AddLinkLibraryForTarget(const std::string& tgt, const std::string&, cmTargetLinkLibraryType type); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3e8d47d18b4db6b4621ee5e4864dde234ad8a282 commit 3e8d47d18b4db6b4621ee5e4864dde234ad8a282 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:33 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:33 2016 +0200 cmMakefile: Remove useless link directory container It is never populated - a find will never find anything. diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index c022b44..0efd92c 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1857,10 +1857,7 @@ 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); } } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 40344ce..92907cd 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -805,9 +805,6 @@ protected: // Tests std::map<std::string, cmTest*> Tests; - // The link-library paths. Order matters, use std::vector (not std::set). - std::vector<std::string> LinkDirectories; - // The set of include directories that are marked as system include // directories. std::set<std::string> SystemIncludeDirectories; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3b4895fa35e4a96022abd99b07002a7d2ab3a968 commit 3b4895fa35e4a96022abd99b07002a7d2ab3a968 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:33 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:33 2016 +0200 cmTarget: Inline MergeLinkLibraries into only caller diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index df993ce..c022b44 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1863,7 +1863,16 @@ void cmMakefile::AddGlobalLinkInformation(const std::string& name, } } } - target.MergeLinkLibraries(*this, name, this->LinkLibraries); + + cmTarget::LinkLibraryVectorType::const_iterator i = + this->LinkLibraries.begin(); + for (; i != this->LinkLibraries.end(); ++i) { + // This is equivalent to the target_link_libraries plain signature. + target.AddLinkLibrary(*this, name, i->first, i->second); + target.AppendProperty( + "INTERFACE_LINK_LIBRARIES", + target.GetDebugGeneratorExpressions(i->first, i->second).c_str()); + } } void cmMakefile::AddAlias(const std::string& lname, std::string const& tgtName) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 0e7e2a5..86a2777 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -476,19 +476,6 @@ cmSourceFile* cmTarget::AddSource(const std::string& src) return this->Makefile->GetOrCreateSource(src); } -void cmTarget::MergeLinkLibraries(cmMakefile& mf, const std::string& selfname, - const LinkLibraryVectorType& libs) -{ - LinkLibraryVectorType::const_iterator i = libs.begin(); - for (; i != libs.end(); ++i) { - // This is equivalent to the target_link_libraries plain signature. - this->AddLinkLibrary(mf, selfname, i->first, i->second); - this->AppendProperty( - "INTERFACE_LINK_LIBRARIES", - this->GetDebugGeneratorExpressions(i->first, i->second).c_str()); - } -} - void cmTarget::AddLinkDirectory(const std::string& d) { // Make sure we don't add unnecessary search directories. diff --git a/Source/cmTarget.h b/Source/cmTarget.h index f062529..8fbb42f 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -153,9 +153,6 @@ public: cmListFileContext const& lfc); void GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const; - void MergeLinkLibraries(cmMakefile& mf, const std::string& selfname, - const LinkLibraryVectorType& libs); - const std::vector<std::string>& GetLinkDirectories() const; void AddLinkDirectory(const std::string& d); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2232e97a6ed4a338b814d1ba3d62a7ffa9ef6e7f commit 2232e97a6ed4a338b814d1ba3d62a7ffa9ef6e7f Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:33 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:33 2016 +0200 cmTarget: Remove useless link library state diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 5b878d3..0e7e2a5 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -479,9 +479,6 @@ cmSourceFile* cmTarget::AddSource(const std::string& src) void cmTarget::MergeLinkLibraries(cmMakefile& mf, const std::string& selfname, const LinkLibraryVectorType& libs) { - assert(this->PrevLinkedLibraries.empty()); - // Only add on libraries we haven't added on before. - // Assumption: the global link libraries could only grow, never shrink LinkLibraryVectorType::const_iterator i = libs.begin(); for (; i != libs.end(); ++i) { // This is equivalent to the target_link_libraries plain signature. @@ -490,7 +487,6 @@ void cmTarget::MergeLinkLibraries(cmMakefile& mf, const std::string& selfname, "INTERFACE_LINK_LIBRARIES", this->GetDebugGeneratorExpressions(i->first, i->second).c_str()); } - this->PrevLinkedLibraries = libs; } void cmTarget::AddLinkDirectory(const std::string& d) diff --git a/Source/cmTarget.h b/Source/cmTarget.h index dd9097a..f062529 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -299,7 +299,6 @@ private: std::vector<cmCustomCommand> PreLinkCommands; std::vector<cmCustomCommand> PostBuildCommands; std::vector<std::pair<TLLSignature, cmListFileContext> > TLLCommands; - LinkLibraryVectorType PrevLinkedLibraries; LinkLibraryVectorType OriginalLinkLibraries; cmMakefile* Makefile; cmTargetInternalPointer Internal; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9a1d4e4ba170f4ac34c80593bd2fe8e1481a1181 commit 9a1d4e4ba170f4ac34c80593bd2fe8e1481a1181 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:33 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:33 2016 +0200 cmTarget: Remove addition of zero when merging link libraries The size is always zero when this is called. diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 28ef04a..5b878d3 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -483,7 +483,6 @@ void cmTarget::MergeLinkLibraries(cmMakefile& mf, const std::string& selfname, // Only add on libraries we haven't added on before. // Assumption: the global link libraries could only grow, never shrink LinkLibraryVectorType::const_iterator i = libs.begin(); - i += this->PrevLinkedLibraries.size(); for (; i != libs.end(); ++i) { // This is equivalent to the target_link_libraries plain signature. this->AddLinkLibrary(mf, selfname, i->first, i->second); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8391b3015a82909828b7ada98e76d45aa11b892b commit 8391b3015a82909828b7ada98e76d45aa11b892b Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Fri Oct 7 20:13:32 2016 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Fri Oct 7 20:13:32 2016 +0200 cmTarget: Add assert about link data MergeLinkLibraries is called only from cmMakefile::AddGlobalLinkInformation which is only called immediately after creating a target. diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 13a4744..28ef04a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -479,6 +479,7 @@ cmSourceFile* cmTarget::AddSource(const std::string& src) void cmTarget::MergeLinkLibraries(cmMakefile& mf, const std::string& selfname, const LinkLibraryVectorType& libs) { + assert(this->PrevLinkedLibraries.empty()); // Only add on libraries we haven't added on before. // Assumption: the global link libraries could only grow, never shrink LinkLibraryVectorType::const_iterator i = libs.begin(); ----------------------------------------------------------------------- Summary of changes: Source/cmAddExecutableCommand.cxx | 5 ++ Source/cmAddLibraryCommand.cxx | 5 +- Source/cmCPluginAPI.cxx | 47 +++++++++- Source/cmLinkLibrariesCommand.cxx | 61 ++++++++++++- Source/cmLinkLibrariesCommand.h | 2 + Source/cmMakefile.cxx | 144 +++++++------------------------ Source/cmMakefile.h | 17 ---- Source/cmTarget.cxx | 24 +----- Source/cmTarget.h | 8 +- Source/cmTargetLinkLibrariesCommand.cxx | 30 ++++++- Source/cmake.cxx | 2 +- 11 files changed, 175 insertions(+), 170 deletions(-) hooks/post-receive -- CMake _______________________________________________ Cmake-commits mailing list Cmake-commits@cmake.org http://public.kitware.com/mailman/listinfo/cmake-commits