From 4079ba20d9d9c8d15fd28d9440d56c907dda811c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 7 Oct 2016 20:13:37 +0200 Subject: 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. --- Source/cmLinkLibrariesCommand.cxx | 7 ++-- Source/cmMakefile.cxx | 75 ++++++++++++++++++++++++--------------- Source/cmMakefile.h | 7 ---- 3 files changed, 50 insertions(+), 39 deletions(-) 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 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 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..47d9b47 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,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", @@ -1804,14 +1795,29 @@ 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 linkLibs; + cmSystemTools::ExpandListArgument(linkLibsProp, linkLibs); + + for (std::vector::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,19 +2080,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 linkLibs; + cmSystemTools::ExpandListArgument(linkLibsProp, linkLibs); + + for (std::vector::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 */ + } } } } 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 ListFiles; std::vector OutputFiles; - cmTarget::LinkLibraryVectorType LinkLibraries; - std::vector InstallGenerators; std::vector TestGenerators; -- cgit v0.12