ENH: When preserving potentially static portions of original user link lines recognize shared library names by their extension and skip them.

This commit is contained in:
Brad King 2008-04-30 18:04:48 -04:00
parent 9631c499dc
commit 3a5bdaa213
4 changed files with 24 additions and 3 deletions

View File

@ -24,6 +24,7 @@
#include "cmake.h"
#include <cmsys/stl/algorithm>
#include <cmsys/RegularExpression.hxx>
#include <assert.h>
@ -197,6 +198,12 @@ void cmComputeLinkDepends::SetOldLinkDirMode(bool b)
this->OldLinkDirMode = b;
}
//----------------------------------------------------------------------------
void cmComputeLinkDepends::SetSharedRegex(std::string const& regex)
{
this->SharedRegexString = regex;
}
//----------------------------------------------------------------------------
std::vector<cmComputeLinkDepends::LinkEntry> const&
cmComputeLinkDepends::Compute()
@ -874,6 +881,9 @@ void cmComputeLinkDepends::CheckWrongConfigItem(std::string const& item)
//----------------------------------------------------------------------------
void cmComputeLinkDepends::PreserveOriginalEntries()
{
// Regular expression to match shared libraries.
cmsys::RegularExpression shared_lib(this->SharedRegexString.c_str());
// Skip the part of the input sequence that already appears in the
// output.
std::vector<int>::const_iterator in = this->OriginalEntries.begin();
@ -882,7 +892,8 @@ void cmComputeLinkDepends::PreserveOriginalEntries()
out != this->FinalLinkOrder.end())
{
cmTarget* tgt = this->EntryList[*in].Target;
if(tgt && tgt->GetType() != cmTarget::STATIC_LIBRARY)
if((tgt && tgt->GetType() != cmTarget::STATIC_LIBRARY) ||
(!tgt && shared_lib.find(this->EntryList[*in].Item)))
{
// Skip input items known to not be static libraries.
++in;
@ -905,7 +916,8 @@ void cmComputeLinkDepends::PreserveOriginalEntries()
while(in != this->OriginalEntries.end())
{
cmTarget* tgt = this->EntryList[*in].Target;
if(tgt && tgt->GetType() != cmTarget::STATIC_LIBRARY)
if((tgt && tgt->GetType() != cmTarget::STATIC_LIBRARY) ||
(!tgt && shared_lib.find(this->EntryList[*in].Item)))
{
// Skip input items known to not be static libraries.
++in;

View File

@ -58,6 +58,10 @@ public:
std::set<cmTarget*> const& GetOldWrongConfigItems() const
{ return this->OldWrongConfigItems; }
/** Set a regular expression that matches strings ending in a shared
library extension. */
void SetSharedRegex(std::string const& regex);
private:
// Context information.
@ -137,6 +141,7 @@ private:
// Preservation of original link line.
std::vector<int> OriginalEntries;
void PreserveOriginalEntries();
std::string SharedRegexString;
// Compatibility help.
bool OldLinkDirMode;

View File

@ -511,6 +511,7 @@ bool cmComputeLinkInformation::Compute()
// Compute the ordered link line items.
cmComputeLinkDepends cld(this->Target, this->Config);
cld.SetOldLinkDirMode(this->OldLinkDirMode);
cld.SetSharedRegex(this->SharedRegexString);
cmComputeLinkDepends::EntryVector const& linkEntries = cld.Compute();
// Add the link line items.
@ -864,7 +865,9 @@ void cmComputeLinkInformation::ComputeItemParserInfo()
if(!this->SharedLinkExtensions.empty())
{
std::string reg_shared = reg;
reg_shared += this->CreateExtensionRegex(this->SharedLinkExtensions);
this->SharedRegexString =
this->CreateExtensionRegex(this->SharedLinkExtensions);
reg_shared += this->SharedRegexString;
#ifdef CM_COMPUTE_LINK_INFO_DEBUG
fprintf(stderr, "shared regex [%s]\n", reg_shared.c_str());
#endif

View File

@ -129,6 +129,7 @@ private:
cmsys::RegularExpression ExtractStaticLibraryName;
cmsys::RegularExpression ExtractSharedLibraryName;
cmsys::RegularExpression ExtractAnyLibraryName;
std::string SharedRegexString;
void AddLinkPrefix(const char* p);
void AddLinkExtension(const char* e, LinkType type);
std::string CreateExtensionRegex(std::vector<std::string> const& exts);