cmLinkItem.h 4.11 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3 4 5
#ifndef cmLinkItem_h
#define cmLinkItem_h

6 7 8 9 10 11 12
#include <cmConfigure.h>

#include <algorithm>
#include <map>
#include <string>
#include <vector>

13
#include "cmListFileCache.h"
14
#include "cmSystemTools.h"
15
#include "cmTargetLinkLibraryType.h"
16

17
class cmGeneratorTarget;
18 19

// Basic information about each link item.
20
class cmLinkItem : public std::string
21 22
{
  typedef std::string std_string;
23

24
public:
25 26
  cmLinkItem()
    : std_string()
Daniel Pfeifer's avatar
Daniel Pfeifer committed
27
    , Target(CM_NULLPTR)
28 29 30 31 32 33 34 35 36 37 38 39
  {
  }
  cmLinkItem(const std_string& n, cmGeneratorTarget const* t)
    : std_string(n)
    , Target(t)
  {
  }
  cmLinkItem(cmLinkItem const& r)
    : std_string(r)
    , Target(r.Target)
  {
  }
40
  cmGeneratorTarget const* Target;
41 42
};

43
class cmLinkImplItem : public cmLinkItem
44 45
{
public:
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  cmLinkImplItem()
    : cmLinkItem()
    , Backtrace()
    , FromGenex(false)
  {
  }
  cmLinkImplItem(std::string const& n, cmGeneratorTarget const* t,
                 cmListFileBacktrace const& bt, bool fromGenex)
    : cmLinkItem(n, t)
    , Backtrace(bt)
    , FromGenex(fromGenex)
  {
  }
  cmLinkImplItem(cmLinkImplItem const& r)
    : cmLinkItem(r)
    , Backtrace(r.Backtrace)
    , FromGenex(r.FromGenex)
  {
  }
65 66 67 68
  cmListFileBacktrace Backtrace;
  bool FromGenex;
};

69 70 71 72 73 74 75 76 77 78 79 80
/** The link implementation specifies the direct library
    dependencies needed by the object files of the target.  */
struct cmLinkImplementationLibraries
{
  // Libraries linked directly in this configuration.
  std::vector<cmLinkImplItem> Libraries;

  // Libraries linked directly in other configurations.
  // Needed only for OLD behavior of CMP0003.
  std::vector<cmLinkItem> WrongConfigLibraries;
};

81 82 83 84 85 86
struct cmLinkInterfaceLibraries
{
  // Libraries listed in the interface.
  std::vector<cmLinkItem> Libraries;
};

87
struct cmLinkInterface : public cmLinkInterfaceLibraries
88 89 90 91 92 93 94 95 96
{
  // Languages whose runtime libraries must be linked.
  std::vector<std::string> Languages;

  // Shared library dependencies needed for linking on some platforms.
  std::vector<cmLinkItem> SharedDeps;

  // Number of repetitions of a strongly connected component of two
  // or more static libraries.
97
  unsigned int Multiplicity;
98 99 100 101 102 103 104

  // Libraries listed for other configurations.
  // Needed only for OLD behavior of CMP0003.
  std::vector<cmLinkItem> WrongConfigLibraries;

  bool ImplementationIsInterface;

105 106 107 108 109
  cmLinkInterface()
    : Multiplicity(0)
    , ImplementationIsInterface(false)
  {
  }
110 111
};

112
struct cmOptionalLinkInterface : public cmLinkInterface
113
{
114 115 116 117 118
  cmOptionalLinkInterface()
    : LibrariesDone(false)
    , AllDone(false)
    , Exists(false)
    , HadHeadSensitiveCondition(false)
Daniel Pfeifer's avatar
Daniel Pfeifer committed
119
    , ExplicitLibraries(CM_NULLPTR)
120 121
  {
  }
122 123 124 125 126 127 128
  bool LibrariesDone;
  bool AllDone;
  bool Exists;
  bool HadHeadSensitiveCondition;
  const char* ExplicitLibraries;
};

129 130
struct cmHeadToLinkInterfaceMap
  : public std::map<cmGeneratorTarget const*, cmOptionalLinkInterface>
131 132 133
{
};

134
struct cmLinkImplementation : public cmLinkImplementationLibraries
135 136 137 138 139
{
  // Languages whose runtime libraries must be linked.
  std::vector<std::string> Languages;
};

140
// Cache link implementation computation from each configuration.
141
struct cmOptionalLinkImplementation : public cmLinkImplementation
142
{
143 144 145 146 147 148
  cmOptionalLinkImplementation()
    : LibrariesDone(false)
    , LanguagesDone(false)
    , HadHeadSensitiveCondition(false)
  {
  }
149 150 151 152 153
  bool LibrariesDone;
  bool LanguagesDone;
  bool HadHeadSensitiveCondition;
};

154
/** Compute the link type to use for the given configuration.  */
155 156
inline cmTargetLinkLibraryType CMP0003_ComputeLinkType(
  const std::string& config, std::vector<std::string> const& debugConfigs)
157 158
{
  // No configuration is always optimized.
159
  if (config.empty()) {
160
    return OPTIMIZED_LibraryType;
161
  }
162 163 164 165

  // Check if any entry in the list matches this configuration.
  std::string configUpper = cmSystemTools::UpperCase(config);
  if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
166
      debugConfigs.end()) {
167
    return DEBUG_LibraryType;
168
  }
169 170 171 172
  // The current configuration is not a debug configuration.
  return OPTIMIZED_LibraryType;
}

173
#endif