2005-02-24 21:16:41 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#ifndef cmOrderLinkDirectories_h
|
|
|
|
#define cmOrderLinkDirectories_h
|
|
|
|
|
|
|
|
#include <cmStandardIncludes.h>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include "cmTarget.h"
|
|
|
|
#include "cmsys/RegularExpression.hxx"
|
|
|
|
|
|
|
|
|
|
|
|
/** \class cmOrderLinkDirectories
|
|
|
|
* \brief Compute the best -L path order
|
|
|
|
*
|
|
|
|
* This class computes the best order for -L paths.
|
|
|
|
* It tries to make sure full path specified libraries are
|
|
|
|
* used. For example if you have /usr/mylib/libfoo.a on as
|
|
|
|
* a link library for a target, and you also have /usr/lib/libbar.a
|
|
|
|
* and you also have /usr/lib/libfoo.a, then you would
|
|
|
|
* want -L/usr/mylib -L/usr/lib to make sure the correct libfoo.a is
|
|
|
|
* found by the linker. The algorithm is as follows:
|
|
|
|
* - foreach library create a vector of directories it exists in.
|
|
|
|
* - foreach directory create a vector of directories that must come
|
|
|
|
* after it, put this in a map<dir, vector<dir>> mapping from a directory
|
|
|
|
* to the vector of directories that it must be before.
|
|
|
|
* - put all directories into a vector
|
|
|
|
* - sort the vector with a compare function CanBeBefore
|
|
|
|
* CanBeBefore returns true if a directory is OK to be before
|
|
|
|
* another directory. This is determined by looking at the
|
|
|
|
* map<dir vector<dir>> and seeing if d1 is in the vector for d2.
|
|
|
|
*/
|
|
|
|
class cmOrderLinkDirectories
|
|
|
|
{
|
|
|
|
public:
|
2005-03-04 02:46:52 +03:00
|
|
|
cmOrderLinkDirectories();
|
2005-02-24 21:16:41 +03:00
|
|
|
///! set link information from the target
|
2006-01-14 02:18:32 +03:00
|
|
|
void SetLinkInformation(const char* targetName,
|
|
|
|
const std::vector<std::string>& linkLibraries,
|
|
|
|
const std::vector<std::string>& linkDirectories);
|
2005-02-24 21:16:41 +03:00
|
|
|
///! Compute the best order for -L paths from GetLinkLibraries
|
|
|
|
bool DetermineLibraryPathOrder();
|
|
|
|
///! Get the results from DetermineLibraryPathOrder
|
|
|
|
void GetLinkerInformation(std::vector<cmStdString>& searchPaths,
|
|
|
|
std::vector<cmStdString>& linkItems)
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
linkItems = this->LinkItems;
|
|
|
|
searchPaths = this->SortedSearchPaths;
|
2005-02-24 21:16:41 +03:00
|
|
|
}
|
|
|
|
// should be set from CMAKE_STATIC_LIBRARY_SUFFIX,
|
|
|
|
// CMAKE_SHARED_LIBRARY_SUFFIX
|
|
|
|
// CMAKE_LINK_LIBRARY_SUFFIX
|
|
|
|
void AddLinkExtension(const char* e)
|
2005-08-10 20:55:41 +04:00
|
|
|
{
|
2006-01-14 02:18:32 +03:00
|
|
|
if(e && *e)
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->LinkExtensions.push_back(e);
|
2006-01-14 02:18:32 +03:00
|
|
|
}
|
2005-08-10 20:55:41 +04:00
|
|
|
}
|
|
|
|
// should be set from CMAKE_STATIC_LIBRARY_PREFIX
|
|
|
|
void SetLinkPrefix(const char* s)
|
|
|
|
{
|
2006-01-14 02:18:32 +03:00
|
|
|
if(s)
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->LinkPrefix = s;
|
2006-01-14 02:18:32 +03:00
|
|
|
}
|
2005-08-10 20:55:41 +04:00
|
|
|
}
|
2005-02-24 21:16:41 +03:00
|
|
|
// Return any warnings if the exist
|
|
|
|
std::string GetWarnings();
|
2005-02-26 01:45:12 +03:00
|
|
|
// return a list of all full path libraries
|
|
|
|
void GetFullPathLibraries(std::vector<cmStdString>& libs);
|
2005-02-24 21:16:41 +03:00
|
|
|
|
|
|
|
// structure to hold a full path library link item
|
|
|
|
struct Library
|
|
|
|
{
|
|
|
|
cmStdString FullPath;
|
|
|
|
cmStdString File;
|
|
|
|
cmStdString Path;
|
|
|
|
};
|
|
|
|
friend struct cmOrderLinkDirectoriesCompare;
|
2005-03-04 02:46:52 +03:00
|
|
|
void DebugOn()
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Debug = true;
|
2005-03-04 02:46:52 +03:00
|
|
|
}
|
|
|
|
|
2005-02-24 21:16:41 +03:00
|
|
|
private:
|
|
|
|
void CreateRegularExpressions();
|
|
|
|
void DetermineLibraryPathOrder(std::vector<cmStdString>& searchPaths,
|
|
|
|
std::vector<cmStdString>& libs,
|
|
|
|
std::vector<cmStdString>& sortedPaths);
|
|
|
|
void PrepareLinkTargets();
|
|
|
|
bool LibraryInDirectory(const char* dir, const char* lib);
|
2006-04-01 06:43:11 +04:00
|
|
|
void FindLibrariesInSearchPaths();
|
2005-02-24 21:16:41 +03:00
|
|
|
void FindIndividualLibraryOrders();
|
|
|
|
void PrintMap(const char* name,
|
|
|
|
std::map<cmStdString, std::vector<cmStdString> >& m);
|
|
|
|
void OrderPaths(std::vector<cmStdString>& paths);
|
2005-03-04 02:16:00 +03:00
|
|
|
bool FindPathNotInDirectoryToAfterList(cmStdString& path);
|
2005-04-08 20:46:56 +04:00
|
|
|
std::string NoCaseExpression(const char* str);
|
2005-02-24 21:16:41 +03:00
|
|
|
private:
|
|
|
|
// map from library to directories that it is in other than its full path
|
2006-03-15 19:02:08 +03:00
|
|
|
std::map<cmStdString, std::vector<cmStdString> > LibraryToDirectories;
|
2005-02-24 21:16:41 +03:00
|
|
|
// map from directory to vector of directories that must be after it
|
2006-03-15 19:02:08 +03:00
|
|
|
std::map<cmStdString, std::vector<cmStdString> > DirectoryToAfterList;
|
2005-02-24 21:16:41 +03:00
|
|
|
// map from full path to a Library struct
|
2006-03-15 19:02:08 +03:00
|
|
|
std::map<cmStdString, Library> FullPathLibraries;
|
2005-02-24 21:16:41 +03:00
|
|
|
// libraries that are found in multiple directories
|
2006-03-15 19:02:08 +03:00
|
|
|
std::vector<Library> MultiDirectoryLibraries;
|
2005-02-24 21:16:41 +03:00
|
|
|
// libraries that are only found in one directory
|
2006-03-15 19:02:08 +03:00
|
|
|
std::vector<Library> SingleDirectoryLibraries;
|
2005-02-24 21:16:41 +03:00
|
|
|
// This is a vector of all the link objects -lm or m
|
2006-03-15 19:02:08 +03:00
|
|
|
std::vector<cmStdString> LinkItems;
|
2005-02-24 21:16:41 +03:00
|
|
|
// Unprocessed link items
|
2006-03-15 19:02:08 +03:00
|
|
|
std::vector<cmStdString> RawLinkItems;
|
2005-02-24 21:16:41 +03:00
|
|
|
// This vector holds the sorted -L paths
|
2006-03-15 19:02:08 +03:00
|
|
|
std::vector<cmStdString> SortedSearchPaths;
|
2005-12-26 21:14:19 +03:00
|
|
|
// This vector holds the -F paths
|
2006-03-15 19:02:08 +03:00
|
|
|
std::set<cmStdString> EmittedFrameworkPaths;
|
2005-02-24 21:16:41 +03:00
|
|
|
// This is the set of -L paths unsorted, but unique
|
2006-03-15 19:02:08 +03:00
|
|
|
std::set<cmStdString> LinkPathSet;
|
2005-02-24 21:16:41 +03:00
|
|
|
// the names of link extensions
|
2006-03-15 19:02:08 +03:00
|
|
|
std::vector<cmStdString> LinkExtensions;
|
2005-08-10 20:55:41 +04:00
|
|
|
// the names of link prefixes
|
2006-03-15 19:02:08 +03:00
|
|
|
cmStdString LinkPrefix;
|
2005-02-24 21:16:41 +03:00
|
|
|
// set of directories that can not be put in the correct order
|
2006-03-15 19:02:08 +03:00
|
|
|
std::set<cmStdString> ImpossibleDirectories;
|
2005-11-23 00:08:16 +03:00
|
|
|
// Name of target
|
2006-03-15 19:02:08 +03:00
|
|
|
cmStdString TargetName;
|
2005-02-24 21:16:41 +03:00
|
|
|
// library regular expressions
|
2006-03-15 19:02:08 +03:00
|
|
|
cmsys::RegularExpression RemoveLibraryExtension;
|
|
|
|
cmsys::RegularExpression ExtractBaseLibraryName;
|
|
|
|
cmsys::RegularExpression ExtractBaseLibraryNameNoPrefix;
|
|
|
|
cmsys::RegularExpression SplitFramework;
|
|
|
|
bool Debug;
|
2005-02-24 21:16:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|