1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmComputeLinkInformation.h,v $
6 Date: $Date: 2008-01-23 18:30:55 $
7 Version: $Revision: 1.3 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmComputeLinkInformation_h
18 #define cmComputeLinkInformation_h
20 #include "cmStandardIncludes.h"
22 #include <cmsys/RegularExpression.hxx>
24 class cmGlobalGenerator
;
25 class cmLocalGenerator
;
29 /** \class cmComputeLinkInformation
30 * \brief Compute link information for a target in one configuration.
32 class cmComputeLinkInformation
35 cmComputeLinkInformation(cmTarget
* target
, const char* config
);
40 Item(): Value(), IsPath(true) {}
41 Item(Item
const& item
): Value(item
.Value
), IsPath(item
.IsPath
) {}
42 Item(std::string
const& v
, bool p
): Value(v
), IsPath(p
) {}
46 typedef std::vector
<Item
> ItemVector
;
47 ItemVector
const& GetItems();
48 std::vector
<std::string
> const& GetDirectories();
49 std::vector
<std::string
> const& GetDepends();
50 std::vector
<std::string
> const& GetFrameworkPaths();
51 const char* GetLinkLanguage() const { return this->LinkLanguage
; }
52 std::vector
<std::string
> const& GetRuntimeSearchPath();
54 void AddItem(std::string
const& item
);
56 // Output information.
58 std::vector
<std::string
> Directories
;
59 std::vector
<std::string
> Depends
;
60 std::vector
<std::string
> FrameworkPaths
;
61 std::vector
<std::string
> RuntimeSearchPath
;
63 // Context information.
66 cmLocalGenerator
* LocalGenerator
;
67 cmGlobalGenerator
* GlobalGenerator
;
69 // Configuration information.
71 const char* LinkLanguage
;
74 bool UseImportLibrary
;
75 const char* LoaderFlag
;
76 std::string LibLinkFlag
;
77 std::string LibLinkFileFlag
;
78 std::string LibLinkSuffix
;
80 // Link type adjustment.
81 void ComputeLinkTypeInfo();
82 enum LinkType
{ LinkUnknown
, LinkStatic
, LinkShared
};
83 LinkType StartLinkType
;
84 LinkType CurrentLinkType
;
85 std::string StaticLinkTypeFlag
;
86 std::string SharedLinkTypeFlag
;
88 void SetCurrentLinkType(LinkType lt
);
91 void ComputeItemParserInfo();
92 std::vector
<std::string
> StaticLinkExtensions
;
93 std::vector
<std::string
> SharedLinkExtensions
;
94 std::vector
<std::string
> LinkExtensions
;
95 std::set
<cmStdString
> LinkPrefixes
;
96 cmsys::RegularExpression RemoveLibraryExtension
;
97 cmsys::RegularExpression ExtractStaticLibraryName
;
98 cmsys::RegularExpression ExtractSharedLibraryName
;
99 cmsys::RegularExpression ExtractAnyLibraryName
;
100 void AddLinkPrefix(const char* p
);
101 void AddLinkExtension(const char* e
, LinkType type
);
102 std::string
CreateExtensionRegex(std::vector
<std::string
> const& exts
);
103 std::string
NoCaseExpression(const char* str
);
105 // Handling of link items that are not targets or full file paths.
106 void AddTargetItem(std::string
const& item
, cmTarget
* target
);
107 void AddFullItem(std::string
const& item
);
108 void AddUserItem(std::string
const& item
);
109 void AddDirectoryItem(std::string
const& item
);
110 void AddFrameworkItem(std::string
const& item
);
111 void DropDirectoryItem(std::string
const& item
);
114 void ComputeFrameworkInfo();
115 void AddFrameworkPath(std::string
const& p
);
116 std::set
<cmStdString
> FrameworkPathsEmmitted
;
117 cmsys::RegularExpression SplitFramework
;
119 // Linker search path computation.
120 void ComputeLinkerSearchDirectories();
121 void AddLinkerSearchDirectories(std::vector
<std::string
> const& dirs
);
122 std::set
<cmStdString
> DirectoriesEmmitted
;
124 // Runtime path computation.
125 struct LibraryRuntimeEntry
127 // The file name of the library.
128 std::string FileName
;
130 // The soname of the shared library if it is known.
133 // The directory in which the library is supposed to be found.
134 std::string Directory
;
136 // The index assigned to the directory.
139 bool RuntimeSearchPathComputed
;
140 std::vector
<LibraryRuntimeEntry
> LibraryRuntimeInfo
;
141 std::set
<cmStdString
> LibraryRuntimeInfoEmmitted
;
142 std::vector
<std::string
> RuntimeDirectories
;
143 std::map
<cmStdString
, int> RuntimeDirectoryIndex
;
144 std::vector
<char> RuntimeDirectoryVisited
;
145 void AddLibraryRuntimeInfo(std::string
const& fullPath
, cmTarget
* target
);
146 void AddLibraryRuntimeInfo(std::string
const& fullPath
,
147 const char* soname
= 0);
148 void CollectRuntimeDirectories();
149 int AddRuntimeDirectory(std::string
const& dir
);
150 void FindConflictingLibraries();
151 void FindDirectoriesForLib(unsigned int lri
);
152 void OrderRuntimeSearchPath();
153 void VisitRuntimeDirectory(unsigned int i
, bool top
);
154 void DiagnoseCycle();
157 // Adjacency-list representation of runtime path ordering graph.
158 // This maps from directory to those that must come *before* it.
159 // Each entry that must come before is a pair. The first element is
160 // the index of the directory that must come first. The second
161 // element is the index of the runtime library that added the
163 typedef std::pair
<int, int> RuntimeConflictPair
;
164 struct RuntimeConflictList
: public std::vector
<RuntimeConflictPair
> {};
165 std::vector
<RuntimeConflictList
> RuntimeConflictGraph
;