BUG: Preserve all non-targets on user link lines
In CMake 2.4 the generated link line for a target always preserved the originally specified libraries in their original order. Dependencies were satisfied by inserting extra libraries into the line, though it had some bugs. In CMake 2.6.0 we preserved only the items on the link line that are not known to be shared libraries. This reduced excess libraries on the link line. However, since we link to system libraries (such as /usr/lib/libm.so) by asking the linker to search (-lm), some linkers secretly replace the library with a static library in another implicit search directory (developers can override this by using an imported target to force linking by full path). When this happens the order still matters. To avoid this and other potential subtle issues this commit restores preservation of all non-target items and static library targets. This will create cases of unnecessary, duplicate shared libraries on the link line if the user specifies them, but at least it will work. In the future we can attempt a more advanced analysis to safely remove duplicate shared libraries from the link line.
This commit is contained in:
parent
96c9e7de7e
commit
08221c2a49
|
@ -24,7 +24,6 @@
|
|||
#include "cmake.h"
|
||||
|
||||
#include <cmsys/stl/algorithm>
|
||||
#include <cmsys/RegularExpression.hxx>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
@ -198,12 +197,6 @@ 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()
|
||||
|
@ -881,14 +874,6 @@ void cmComputeLinkDepends::CheckWrongConfigItem(std::string const& item)
|
|||
//----------------------------------------------------------------------------
|
||||
void cmComputeLinkDepends::PreserveOriginalEntries()
|
||||
{
|
||||
// In CMake 2.4 and below all link items were included in order
|
||||
// preservation. In CMake 2.6 and above we know it is safe to skip
|
||||
// shared libraries.
|
||||
bool skipShared = !this->LocalGenerator->NeedBackwardsCompatibility(2,4);
|
||||
|
||||
// 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();
|
||||
|
@ -897,8 +882,7 @@ void cmComputeLinkDepends::PreserveOriginalEntries()
|
|||
out != this->FinalLinkOrder.end())
|
||||
{
|
||||
cmTarget* tgt = this->EntryList[*in].Target;
|
||||
if((tgt && tgt->GetType() != cmTarget::STATIC_LIBRARY) ||
|
||||
(skipShared && !tgt && shared_lib.find(this->EntryList[*in].Item)))
|
||||
if(tgt && tgt->GetType() != cmTarget::STATIC_LIBRARY)
|
||||
{
|
||||
// Skip input items known to not be static libraries.
|
||||
++in;
|
||||
|
@ -921,8 +905,7 @@ void cmComputeLinkDepends::PreserveOriginalEntries()
|
|||
while(in != this->OriginalEntries.end())
|
||||
{
|
||||
cmTarget* tgt = this->EntryList[*in].Target;
|
||||
if((tgt && tgt->GetType() != cmTarget::STATIC_LIBRARY) ||
|
||||
(skipShared && !tgt && shared_lib.find(this->EntryList[*in].Item)))
|
||||
if(tgt && tgt->GetType() != cmTarget::STATIC_LIBRARY)
|
||||
{
|
||||
// Skip input items known to not be static libraries.
|
||||
++in;
|
||||
|
|
|
@ -58,10 +58,6 @@ 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.
|
||||
|
@ -141,7 +137,6 @@ private:
|
|||
// Preservation of original link line.
|
||||
std::vector<int> OriginalEntries;
|
||||
void PreserveOriginalEntries();
|
||||
std::string SharedRegexString;
|
||||
|
||||
// Compatibility help.
|
||||
bool OldLinkDirMode;
|
||||
|
|
|
@ -511,7 +511,6 @@ 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.
|
||||
|
|
Loading…
Reference in New Issue