cmGeneratorTarget.h 35 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 cmGeneratorTarget_h
#define cmGeneratorTarget_h

6
#include "cmConfigure.h" // IWYU pragma: keep
7

8
#include "cmLinkItem.h"
9 10
#include "cmListFileCache.h"
#include "cmPolicies.h"
11
#include "cmStateTypes.h"
12 13 14

#include <map>
#include <set>
15
#include <stddef.h>
16 17 18
#include <string>
#include <utility>
#include <vector>
19

20
class cmComputeLinkInformation;
21 22 23 24 25 26 27 28 29 30
class cmCustomCommand;
class cmGlobalGenerator;
class cmLocalGenerator;
class cmMakefile;
class cmSourceFile;
class cmTarget;

class cmGeneratorTarget
{
public:
31
  cmGeneratorTarget(cmTarget*, cmLocalGenerator* lg);
32
  ~cmGeneratorTarget();
33

wahikihiki's avatar
wahikihiki committed
34 35 36
  cmGeneratorTarget(cmGeneratorTarget const&) = delete;
  cmGeneratorTarget& operator=(cmGeneratorTarget const&) = delete;

37 38
  cmLocalGenerator* GetLocalGenerator() const;

39 40
  cmGlobalGenerator* GetGlobalGenerator() const;

41
  bool IsImported() const;
42
  bool IsImportedGloballyVisible() const;
43
  const char* GetLocation(const std::string& config) const;
44

45 46 47
  std::vector<cmCustomCommand> const& GetPreBuildCommands() const;
  std::vector<cmCustomCommand> const& GetPreLinkCommands() const;
  std::vector<cmCustomCommand> const& GetPostBuildCommands() const;
48

49 50 51 52 53
#define DECLARE_TARGET_POLICY(POLICY)                                         \
  cmPolicies::PolicyStatus GetPolicyStatus##POLICY() const                    \
  {                                                                           \
    return this->PolicyMap.Get(cmPolicies::POLICY);                           \
  }
54 55 56 57 58

  CM_FOR_EACH_TARGET_POLICY(DECLARE_TARGET_POLICY)

#undef DECLARE_TARGET_POLICY

59 60 61 62 63
  /** Get the location of the target in the build tree with a placeholder
      referencing the configuration in the native build system.  This
      location is suitable for use as the LOCATION target property.  */
  const char* GetLocationForBuild() const;

64 65
  cmComputeLinkInformation* GetLinkInformation(
    const std::string& config) const;
66

67
  cmStateEnums::TargetType GetType() const;
68
  const std::string& GetName() const;
69 70
  std::string GetExportName() const;

71
  std::vector<std::string> GetPropertyKeys() const;
72
  //! Might return a nullptr if the property is not set or invalid
73
  const char* GetProperty(const std::string& prop) const;
74
  //! Always returns a valid pointer
75
  const char* GetSafeProperty(const std::string& prop) const;
76
  bool GetPropertyAsBool(const std::string& prop) const;
77 78
  void GetSourceFiles(std::vector<cmSourceFile*>& files,
                      const std::string& config) const;
79 80
  std::vector<BT<cmSourceFile*>> GetSourceFiles(
    std::string const& config) const;
81

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  /** Source file kinds (classifications).
      Generators use this to decide how to treat a source file.  */
  enum SourceKind
  {
    SourceKindAppManifest,
    SourceKindCertificate,
    SourceKindCustomCommand,
    SourceKindExternalObject,
    SourceKindExtra,
    SourceKindHeader,
    SourceKindIDL,
    SourceKindManifest,
    SourceKindModuleDefinition,
    SourceKindObjectSource,
    SourceKindResx,
    SourceKindXaml
  };

  /** A source file paired with a kind (classification).  */
  struct SourceAndKind
  {
103
    BT<cmSourceFile*> Source;
104 105 106 107 108 109 110 111 112 113
    SourceKind Kind;
  };

  /** All sources needed for a configuration with kinds assigned.  */
  struct KindedSources
  {
    std::vector<SourceAndKind> Sources;
    std::set<std::string> ExpectedResxHeaders;
    std::set<std::string> ExpectedXamlHeaders;
    std::set<std::string> ExpectedXamlSources;
114
    bool Initialized = false;
115 116 117 118 119
  };

  /** Get all sources needed for a configuration with kinds assigned.  */
  KindedSources const& GetKindedSources(std::string const& config) const;

120 121 122 123 124 125 126 127 128 129 130
  struct AllConfigSource
  {
    cmSourceFile const* Source;
    cmGeneratorTarget::SourceKind Kind;
    std::vector<size_t> Configs;
  };

  /** Get all sources needed for all configurations with kinds and
      per-source configurations assigned.  */
  std::vector<AllConfigSource> const& GetAllConfigSources() const;

131
  void GetObjectSources(std::vector<cmSourceFile const*>&,
132
                        const std::string& config) const;
133
  const std::string& GetObjectName(cmSourceFile const* file);
134
  const char* GetCustomObjectExtension() const;
135 136

  bool HasExplicitObjectName(cmSourceFile const* file) const;
137
  void AddExplicitObjectName(cmSourceFile const* sf);
138

139 140
  void GetModuleDefinitionSources(std::vector<cmSourceFile const*>&,
                                  const std::string& config) const;
141 142 143 144 145 146 147 148 149 150 151 152
  void GetResxSources(std::vector<cmSourceFile const*>&,
                      const std::string& config) const;
  void GetExternalObjects(std::vector<cmSourceFile const*>&,
                          const std::string& config) const;
  void GetHeaderSources(std::vector<cmSourceFile const*>&,
                        const std::string& config) const;
  void GetExtraSources(std::vector<cmSourceFile const*>&,
                       const std::string& config) const;
  void GetCustomCommands(std::vector<cmSourceFile const*>&,
                         const std::string& config) const;
  void GetExpectedResxHeaders(std::set<std::string>&,
                              const std::string& config) const;
153 154
  void GetAppManifest(std::vector<cmSourceFile const*>&,
                      const std::string& config) const;
155 156
  void GetManifests(std::vector<cmSourceFile const*>&,
                    const std::string& config) const;
157 158
  void GetCertificates(std::vector<cmSourceFile const*>&,
                       const std::string& config) const;
159 160 161 162 163 164
  void GetXamlSources(std::vector<cmSourceFile const*>&,
                      const std::string& config) const;
  void GetExpectedXamlHeaders(std::set<std::string>&,
                              const std::string& config) const;
  void GetExpectedXamlSources(std::set<std::string>&,
                              const std::string& config) const;
165

166
  std::set<cmLinkItem> const& GetUtilityItems() const;
167

168 169
  void ComputeObjectMapping();

170 171
  const char* GetFeature(const std::string& feature,
                         const std::string& config) const;
172

173 174
  const char* GetLinkPIEProperty(const std::string& config) const;

175
  bool IsIPOEnabled(std::string const& lang, std::string const& config) const;
176

177 178 179 180 181 182 183 184
  bool IsLinkInterfaceDependentBoolProperty(const std::string& p,
                                            const std::string& config) const;
  bool IsLinkInterfaceDependentStringProperty(const std::string& p,
                                              const std::string& config) const;
  bool IsLinkInterfaceDependentNumberMinProperty(
    const std::string& p, const std::string& config) const;
  bool IsLinkInterfaceDependentNumberMaxProperty(
    const std::string& p, const std::string& config) const;
185

186
  bool GetLinkInterfaceDependentBoolProperty(const std::string& p,
187 188
                                             const std::string& config) const;

189 190 191 192 193 194
  const char* GetLinkInterfaceDependentStringProperty(
    const std::string& p, const std::string& config) const;
  const char* GetLinkInterfaceDependentNumberMinProperty(
    const std::string& p, const std::string& config) const;
  const char* GetLinkInterfaceDependentNumberMaxProperty(
    const std::string& p, const std::string& config) const;
195

196 197
  cmLinkInterface const* GetLinkInterface(
    const std::string& config, const cmGeneratorTarget* headTarget) const;
198 199
  void ComputeLinkInterface(const std::string& config,
                            cmOptionalLinkInterface& iface,
200
                            const cmGeneratorTarget* head) const;
201

202 203 204
  cmLinkInterfaceLibraries const* GetLinkInterfaceLibraries(
    const std::string& config, const cmGeneratorTarget* headTarget,
    bool usage_requirements_only) const;
205

206
  void ComputeLinkInterfaceLibraries(const std::string& config,
207
                                     cmOptionalLinkInterface& iface,
208
                                     const cmGeneratorTarget* head,
209 210
                                     bool usage_requirements_only) const;

211 212 213
  /** Get the library name for an imported interface library.  */
  std::string GetImportedLibName(std::string const& config) const;

214 215
  /** Get the full path to the target according to the settings in its
      makefile and the configuration type.  */
216 217 218 219 220 221
  std::string GetFullPath(
    const std::string& config = "",
    cmStateEnums::ArtifactType artifact = cmStateEnums::RuntimeBinaryArtifact,
    bool realname = false) const;
  std::string NormalGetFullPath(const std::string& config,
                                cmStateEnums::ArtifactType artifact,
222 223 224
                                bool realname) const;
  std::string NormalGetRealName(const std::string& config) const;

225 226 227 228 229
  /** Get the names of an object library's object files underneath
      its object file directory.  */
  void GetTargetObjectNames(std::string const& config,
                            std::vector<std::string>& objects) const;

230 231 232
  /** What hierarchy level should the reported directory contain */
  enum BundleDirectoryLevel
  {
233
    BundleDirLevel,
234 235 236 237
    ContentLevel,
    FullLevel
  };

238 239
  /** @return the Mac App directory without the base */
  std::string GetAppBundleDirectory(const std::string& config,
240
                                    BundleDirectoryLevel level) const;
241

242 243 244 245
  /** Return whether this target is an executable Bundle, a framework
      or CFBundle on Apple.  */
  bool IsBundleOnApple() const;

246 247
  /** Get the full name of the target according to the settings in its
      makefile.  */
248
  std::string GetFullName(const std::string& config = "",
249 250
                          cmStateEnums::ArtifactType artifact =
                            cmStateEnums::RuntimeBinaryArtifact) const;
251

252 253
  /** @return the Mac framework directory without the base. */
  std::string GetFrameworkDirectory(const std::string& config,
254
                                    BundleDirectoryLevel level) const;
255

256 257 258 259
  /** Return the framework version string.  Undefined if
      IsFrameworkOnApple returns false.  */
  std::string GetFrameworkVersion() const;

260 261
  /** @return the Mac CFBundle directory without the base */
  std::string GetCFBundleDirectory(const std::string& config,
262
                                   BundleDirectoryLevel level) const;
263

264
  /** Return the install name directory for the target in the
265 266
   * build tree.  For example: "\@rpath/", "\@loader_path/",
   * or "/full/path/to/library".  */
267 268 269
  std::string GetInstallNameDirForBuildTree(const std::string& config) const;

  /** Return the install name directory for the target in the
270
   * install tree.  For example: "\@rpath/" or "\@loader_path/". */
271 272
  std::string GetInstallNameDirForInstallTree() const;

273 274
  cmListFileBacktrace GetBacktrace() const;

275
  std::set<BT<std::string>> const& GetUtilities() const;
276

277
  bool LinkLanguagePropagatesToDependents() const
278
  {
279
    return this->GetType() == cmStateEnums::STATIC_LIBRARY;
280
  }
281

282 283
  /** Get the macro to define when building sources in this target.
      If no macro should be defined null is returned.  */
284
  const std::string* GetExportMacro() const;
285

286 287 288
  /** Get the soname of the target.  Allowed only for a shared library.  */
  std::string GetSOName(const std::string& config) const;

289 290 291
  void GetFullNameComponents(std::string& prefix, std::string& base,
                             std::string& suffix,
                             const std::string& config = "",
292 293
                             cmStateEnums::ArtifactType artifact =
                               cmStateEnums::RuntimeBinaryArtifact) const;
294

295 296 297 298 299
  /** Append to @a base the bundle directory hierarchy up to a certain @a level
   * and return it. */
  std::string BuildBundleDirectory(const std::string& base,
                                   const std::string& config,
                                   BundleDirectoryLevel level) const;
300 301

  /** @return the mac content directory for this target. */
302 303
  std::string GetMacContentDirectory(
    const std::string& config, cmStateEnums::ArtifactType artifact) const;
304

305 306 307
  /** @return folder prefix for IDEs. */
  std::string GetEffectiveFolderName() const;

308 309 310
  cmTarget* Target;
  cmMakefile* Makefile;
  cmLocalGenerator* LocalGenerator;
311
  cmGlobalGenerator const* GlobalGenerator;
312

313 314 315
  struct ModuleDefinitionInfo
  {
    std::string DefFile;
316
    bool DefFileGenerated;
317
    bool WindowsExportAllSymbols;
318
    std::vector<cmSourceFile const*> Sources;
319 320 321
  };
  ModuleDefinitionInfo const* GetModuleDefinitionInfo(
    std::string const& config) const;
322

323 324 325
  /** Return whether or not the target is for a DLL platform.  */
  bool IsDLLPlatform() const;

326 327 328
  /** @return whether this target have a well defined output file name. */
  bool HaveWellDefinedOutputFiles() const;

329 330 331 332 333 334 335 336 337 338 339 340 341 342
  /** Link information from the transitive closure of the link
      implementation and the interfaces of its dependencies.  */
  struct LinkClosure
  {
    // The preferred linker language.
    std::string LinkerLanguage;

    // Languages whose runtime libraries must be linked.
    std::vector<std::string> Languages;
  };

  LinkClosure const* GetLinkClosure(const std::string& config) const;
  void ComputeLinkClosure(const std::string& config, LinkClosure& lc) const;

343 344
  cmLinkImplementation const* GetLinkImplementation(
    const std::string& config) const;
345

346 347
  void ComputeLinkImplementationLanguages(
    const std::string& config, cmOptionalLinkImplementation& impl) const;
348

349 350
  cmLinkImplementationLibraries const* GetLinkImplementationLibraries(
    const std::string& config) const;
351 352 353

  void ComputeLinkImplementationLibraries(const std::string& config,
                                          cmOptionalLinkImplementation& impl,
354
                                          const cmGeneratorTarget* head) const;
355

356 357 358 359 360 361 362
  struct TargetOrString
  {
    std::string String;
    cmGeneratorTarget* Target = nullptr;
  };
  TargetOrString ResolveTargetReference(std::string const& name) const;

Brad King's avatar
Brad King committed
363 364
  cmLinkItem ResolveLinkItem(std::string const& name,
                             cmListFileBacktrace const& bt) const;
365

366 367 368 369 370 371 372 373
  // Compute the set of languages compiled by the target.  This is
  // computed every time it is called because the languages can change
  // when source file properties are changed and we do not have enough
  // information to forward these property changes to the targets
  // until we have per-target object file properties.
  void GetLanguages(std::set<std::string>& languages,
                    std::string const& config) const;

374
  bool IsCSharpOnly() const;
375

376 377
  void GetObjectLibrariesCMP0026(
    std::vector<cmGeneratorTarget*>& objlibs) const;
378

379
  std::string GetFullNameImported(const std::string& config,
380
                                  cmStateEnums::ArtifactType artifact) const;
381

382 383 384
  /** Get source files common to all configurations and diagnose cases
      with per-config sources.  Excludes sources added by a TARGET_OBJECTS
      generator expression.  */
385 386
  bool GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const;

387 388
  bool HaveBuildTreeRPATH(const std::string& config) const;

389 390 391 392 393
  /** Full path with trailing slash to the top-level directory
      holding object files for this target.  Includes the build
      time config name placeholder if needed for the generator.  */
  std::string ObjectDirectory;

394 395 396 397
  /** Full path with trailing slash to the top-level directory
      holding object files for the given configuration.  */
  std::string GetObjectDirectory(std::string const& config) const;

398
  void GetAppleArchs(const std::string& config,
399
                     std::vector<std::string>& archVec) const;
400

401
  std::string GetFeatureSpecificLinkRuleVariable(
402 403
    std::string const& var, std::string const& lang,
    std::string const& config) const;
404

405 406 407
  /** Return the rule variable used to create this type of target.  */
  std::string GetCreateRuleVariable(std::string const& lang,
                                    std::string const& config) const;
408

409
  /** Get the include directories for this target.  */
410
  std::vector<BT<std::string>> GetIncludeDirectories(
411
    const std::string& config, const std::string& lang) const;
412

413
  void GetCompileOptions(std::vector<std::string>& result,
414 415
                         const std::string& config,
                         const std::string& language) const;
416 417
  std::vector<BT<std::string>> GetCompileOptions(
    std::string const& config, std::string const& language) const;
418

419
  void GetCompileFeatures(std::vector<std::string>& features,
420
                          const std::string& config) const;
421 422
  std::vector<BT<std::string>> GetCompileFeatures(
    std::string const& config) const;
423

424
  void GetCompileDefinitions(std::vector<std::string>& result,
425 426
                             const std::string& config,
                             const std::string& language) const;
427 428
  std::vector<BT<std::string>> GetCompileDefinitions(
    std::string const& config, std::string const& language) const;
429

430 431 432
  void GetLinkOptions(std::vector<std::string>& result,
                      const std::string& config,
                      const std::string& language) const;
433 434 435
  std::vector<BT<std::string>> GetLinkOptions(
    std::string const& config, std::string const& language) const;

436 437 438
  void GetStaticLibraryLinkOptions(std::vector<std::string>& result,
                                   const std::string& config,
                                   const std::string& language) const;
439 440
  std::vector<BT<std::string>> GetStaticLibraryLinkOptions(
    std::string const& config, std::string const& language) const;
441

442 443 444
  void GetLinkDirectories(std::vector<std::string>& result,
                          const std::string& config,
                          const std::string& language) const;
445 446
  std::vector<BT<std::string>> GetLinkDirectories(
    std::string const& config, std::string const& language) const;
447

448 449 450
  void GetLinkDepends(std::vector<std::string>& result,
                      const std::string& config,
                      const std::string& language) const;
451 452
  std::vector<BT<std::string>> GetLinkDepends(
    std::string const& config, std::string const& language) const;
453

454
  bool IsSystemIncludeDirectory(const std::string& dir,
455 456
                                const std::string& config,
                                const std::string& language) const;
457

458
  /** Add the target output files to the global generator manifest.  */
459
  void ComputeTargetManifest(const std::string& config) const;
460

461 462
  bool ComputeCompileFeatures(std::string const& config) const;

463 464 465 466 467 468
  /**
   * Trace through the source files in this target and add al source files
   * that they depend on, used by all generators
   */
  void TraceDependencies();

469 470 471 472 473
  /** Get the directory in which this target will be built.  If the
      configuration name is given then the generator will add its
      subdirectory for that configuration.  Otherwise just the canonical
      output directory is given.  */
  std::string GetDirectory(const std::string& config = "",
474 475
                           cmStateEnums::ArtifactType artifact =
                             cmStateEnums::RuntimeBinaryArtifact) const;
476

477 478 479 480 481 482
  /** Get the directory in which to place the target compiler .pdb file.
      If the configuration name is given then the generator will add its
      subdirectory for that configuration.  Otherwise just the canonical
      compiler pdb output directory is given.  */
  std::string GetCompilePDBDirectory(const std::string& config = "") const;

483
  /** Get sources that must be built before the given source.  */
484 485
  std::vector<cmSourceFile*> const* GetSourceDepends(
    cmSourceFile const* sf) const;
486

487 488
  /** Return whether this target uses the default value for its output
      directory.  */
489 490
  bool UsesDefaultOutputDir(const std::string& config,
                            cmStateEnums::ArtifactType artifact) const;
491

492 493 494 495 496 497 498
  // Cache target output paths for each configuration.
  struct OutputInfo
  {
    std::string OutDir;
    std::string ImpDir;
    std::string PdbDir;
    bool empty() const
499 500 501
    {
      return OutDir.empty() && ImpDir.empty() && PdbDir.empty();
    }
502 503 504 505
  };

  OutputInfo const* GetOutputInfo(const std::string& config) const;

506
  /** Get the name of the pdb file for the target.  */
507
  std::string GetPDBName(const std::string& config = "") const;
508

509 510 511
  /** Whether this library has soname enabled and platform supports it.  */
  bool HasSOName(const std::string& config) const;

512 513 514 515 516 517 518 519 520 521
  struct CompileInfo
  {
    std::string CompilePdbDir;
  };

  CompileInfo const* GetCompileInfo(const std::string& config) const;

  typedef std::map<std::string, CompileInfo> CompileInfoMapType;
  mutable CompileInfoMapType CompileInfoMap;

522
  bool IsNullImpliedByLinkLibraries(const std::string& p) const;
523

524
  /** Get the name of the compiler pdb file for the target.  */
525
  std::string GetCompilePDBName(const std::string& config = "") const;
526 527

  /** Get the path for the MSVC /Fd option for this target.  */
528
  std::string GetCompilePDBPath(const std::string& config = "") const;
529

530
  // Get the target base name.
531 532
  std::string GetOutputName(const std::string& config,
                            cmStateEnums::ArtifactType artifact) const;
533

534
  /** Clears cached meta data for local and external source files.
535 536
   * The meta data will be recomputed on demand.
   */
537 538
  void ClearSourcesCache();

539
  void AddSource(const std::string& src, bool before = false);
540 541
  void AddTracedSources(std::vector<std::string> const& srcs);

542 543 544 545 546 547
  /**
   * Adds an entry to the INCLUDE_DIRECTORIES list.
   * If before is true the entry is pushed at the front.
   */
  void AddIncludeDirectory(const std::string& src, bool before = false);

548 549 550 551 552 553 554 555 556 557 558
  /**
   * Flags for a given source file as used in this target. Typically assigned
   * via SET_TARGET_PROPERTIES when the property is a list of source files.
   */
  enum SourceFileType
  {
    SourceFileTypeNormal,
    SourceFileTypePrivateHeader, // is in "PRIVATE_HEADER" target property
    SourceFileTypePublicHeader,  // is in "PUBLIC_HEADER" target property
    SourceFileTypeResource,      // is in "RESOURCE" target property *or*
                                 // has MACOSX_PACKAGE_LOCATION=="Resources"
559 560 561
    SourceFileTypeDeepResource,  // MACOSX_PACKAGE_LOCATION starts with
                                 // "Resources/"
    SourceFileTypeMacContent     // has MACOSX_PACKAGE_LOCATION!="Resources[/]"
562 563 564
  };
  struct SourceFileFlags
  {
565 566
    SourceFileType Type = SourceFileTypeNormal;
    const char* MacFolder = nullptr; // location inside Mac content folders
567
  };
568
  void GetAutoUicOptions(std::vector<std::string>& result,
569 570
                         const std::string& config) const;

571 572 573 574 575 576 577 578 579 580
  struct Names
  {
    std::string Base;
    std::string Output;
    std::string Real;
    std::string ImportLibrary;
    std::string PDB;
    std::string SharedObject;
  };

581 582 583
  /** Get the names of the executable needed to generate a build rule
      that takes into account executable version numbers.  This should
      be called only on an executable target.  */
584
  Names GetExecutableNames(const std::string& config) const;
585

586 587 588
  /** Get the names of the library needed to generate a build rule
      that takes into account shared library version numbers.  This
      should be called only on a library target.  */
589
  Names GetLibraryNames(const std::string& config) const;
590

591 592 593 594 595
  /**
   * Compute whether this target must be relinked before installing.
   */
  bool NeedRelinkBeforeInstall(const std::string& config) const;

596 597 598
  /** Return true if builtin chrpath will work for this target */
  bool IsChrpathUsed(const std::string& config) const;

599 600 601 602 603 604
  /** Get the directory in which this targets .pdb files will be placed.
      If the configuration name is given then the generator will add its
      subdirectory for that configuration.  Otherwise just the canonical
      pdb output directory is given.  */
  std::string GetPDBDirectory(const std::string& config) const;

605
  //! Return the preferred linker language for this target
606
  std::string GetLinkerLanguage(const std::string& config) const;
607

608
  /** Does this target have a GNU implib to convert to MS format?  */
609
  bool HasImplibGNUtoMS(std::string const& config) const;
610 611 612

  /** Convert the given GNU import library name (.dll.a) to a name with a new
      extension (.lib or ${CMAKE_IMPORT_LIBRARY_SUFFIX}).  */
613 614
  bool GetImplibGNUtoMS(std::string const& config, std::string const& gnuName,
                        std::string& out, const char* newExt = nullptr) const;
615

616 617
  bool IsExecutableWithExports() const;

618
  /** Return whether or not the target has a DLL import library.  */
619
  bool HasImportLibrary(std::string const& config) const;
620

621 622 623
  /** Get a build-tree directory in which to place target support files.  */
  std::string GetSupportDirectory() const;

624 625 626
  /** Return whether this target may be used to link another target.  */
  bool IsLinkable() const;

627 628 629 630
  /** Return whether this target is a shared library Framework on
      Apple.  */
  bool IsFrameworkOnApple() const;

631 632 633
  /** Return whether this target is an executable Bundle on Apple.  */
  bool IsAppBundleOnApple() const;

634 635 636
  /** Return whether this target is a XCTest on Apple.  */
  bool IsXCTestOnApple() const;

637 638 639
  /** Return whether this target is a CFBundle (plugin) on Apple.  */
  bool IsCFBundleOnApple() const;

640 641 642 643 644 645 646 647 648 649 650 651 652
  /** Assembly types. The order of the values of this enum is relevant
      because of smaller/larger comparison operations! */
  enum ManagedType
  {
    Undefined = 0, // target is no lib or executable
    Native,        // target compiles to unmanaged binary.
    Mixed,         // target compiles to mixed (managed and unmanaged) binary.
    Managed        // target compiles to managed binary.
  };

  /** Return the type of assembly this target compiles to. */
  ManagedType GetManagedType(const std::string& config) const;

653 654
  struct SourceFileFlags GetTargetSourceFileFlags(
    const cmSourceFile* sf) const;
655

656 657 658
  void ReportPropertyOrigin(const std::string& p, const std::string& result,
                            const std::string& report,
                            const std::string& compatibilityType) const;
659

660 661
  class TargetPropertyEntry;

662 663
  bool HaveInstallTreeRPATH() const;

664 665 666 667 668 669
  /** Whether this library has \@rpath and platform supports it.  */
  bool HasMacOSXRpathInstallNameDir(const std::string& config) const;

  /** Whether this library defaults to \@rpath.  */
  bool MacOSXRpathInstallNameDirDefault() const;

670 671 672 673 674 675 676 677 678 679
  enum InstallNameType
  {
    INSTALL_NAME_FOR_BUILD,
    INSTALL_NAME_FOR_INSTALL
  };
  /** Whether to use INSTALL_NAME_DIR. */
  bool MacOSXUseInstallNameDir() const;
  /** Whether to generate an install_name. */
  bool CanGenerateInstallNameDir(InstallNameType t) const;

680 681 682 683
  /** Test for special case of a third-party shared library that has
      no soname at all.  */
  bool IsImportedSharedLibWithoutSOName(const std::string& config) const;

684
  std::string ImportedGetLocation(const std::string& config) const;
685

686 687 688 689 690 691 692 693
  /** Get the target major and minor version numbers interpreted from
      the VERSION property.  Version 0 is returned if the property is
      not set or cannot be parsed.  */
  void GetTargetVersion(int& major, int& minor) const;

  /** Get the target major, minor, and patch version numbers
      interpreted from the VERSION or SOVERSION property.  Version 0
      is returned if the property is not set or cannot be parsed.  */
694 695
  void GetTargetVersion(bool soversion, int& major, int& minor,
                        int& patch) const;
696

697
  std::string GetFortranModuleDirectory(std::string const& working_dir) const;
698

699 700
  const char* GetSourcesProperty() const;

701
private:
702
  void AddSourceCommon(const std::string& src, bool before = false);
703

704 705
  std::string CreateFortranModuleDirectory(
    std::string const& working_dir) const;
706 707 708
  mutable bool FortranModuleDirectoryCreated;
  mutable std::string FortranModuleDirectory;

709
  friend class cmTargetTraceDependencies;
710 711 712 713
  struct SourceEntry
  {
    std::vector<cmSourceFile*> Depends;
  };
714
  typedef std::map<cmSourceFile const*, SourceEntry> SourceEntriesType;
715
  SourceEntriesType SourceDepends;
716
  mutable std::map<cmSourceFile const*, std::string> Objects;
717
  std::set<cmSourceFile const*> ExplicitObjectName;
718
  mutable std::map<std::string, std::vector<std::string>> SystemIncludesCache;
719

720 721
  mutable std::string ExportMacro;

722 723 724 725
  void ConstructSourceFileFlags() const;
  mutable bool SourceFileFlagsConstructed;
  mutable std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;

726 727
  mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;

728
  std::string GetFullNameInternal(const std::string& config,
729 730 731
                                  cmStateEnums::ArtifactType artifact) const;
  void GetFullNameInternal(const std::string& config,
                           cmStateEnums::ArtifactType artifact,
732 733 734
                           std::string& outPrefix, std::string& outBase,
                           std::string& outSuffix) const;

735 736 737
  typedef std::map<std::string, LinkClosure> LinkClosureMapType;
  mutable LinkClosureMapType LinkClosureMap;

738
  // Returns ARCHIVE, LIBRARY, or RUNTIME based on platform and type.
739
  const char* GetOutputTargetType(cmStateEnums::ArtifactType artifact) const;
740

741 742
  void ComputeVersionedName(std::string& vName, std::string const& prefix,
                            std::string const& base, std::string const& suffix,
743 744 745
                            std::string const& name,
                            const char* version) const;

746 747 748 749 750 751 752
  struct CompatibleInterfacesBase
  {
    std::set<std::string> PropsBool;
    std::set<std::string> PropsString;
    std::set<std::string> PropsNumberMax;
    std::set<std::string> PropsNumberMin;
  };
753 754
  CompatibleInterfacesBase const& GetCompatibleInterfaces(
    std::string const& config) const;
755

756
  struct CompatibleInterfaces : public CompatibleInterfacesBase
757
  {
758
    bool Done = false;
759 760 761
  };
  mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;

762
  typedef std::map<std::string, cmComputeLinkInformation*>
763
    cmTargetLinkInformationMap;
764 765
  mutable cmTargetLinkInformationMap LinkInformation;

766
  void CheckPropertyCompatibility(cmComputeLinkInformation* info,
767 768
                                  const std::string& config) const;

769
  struct LinkImplClosure : public std::vector<cmGeneratorTarget const*>
770
  {
771
    bool Done = false;
772 773 774
  };
  mutable std::map<std::string, LinkImplClosure> LinkImplClosureMap;

775
  typedef std::map<std::string, cmHeadToLinkInterfaceMap> LinkInterfaceMapType;
776 777 778
  mutable LinkInterfaceMapType LinkInterfaceMap;
  mutable LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap;

779 780
  cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceMap(
    std::string const& config) const;
781
  cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap(
782
    std::string const& config) const;
783

784 785 786
  std::string GetLinkInterfaceDependentStringAsBoolProperty(
    const std::string& p, const std::string& config) const;

787 788 789
  // Cache import information from properties for each configuration.
  struct ImportInfo
  {
790 791 792
    bool NoSOName = false;
    ManagedType Managed = Native;
    unsigned int Multiplicity = 0;
793 794 795
    std::string Location;
    std::string SOName;
    std::string ImportLibrary;
796
    std::string LibName;
797 798 799 800 801 802 803 804 805 806 807 808
    std::string Languages;
    std::string Libraries;
    std::string LibrariesProp;
    std::string SharedDeps;
  };

  typedef std::map<std::string, ImportInfo> ImportInfoMapType;
  mutable ImportInfoMapType ImportInfoMap;
  void ComputeImportInfo(std::string const& desired_config,
                         ImportInfo& info) const;
  ImportInfo const* GetImportInfo(const std::string& config) const;

809 810 811
  /** Strip off leading and trailing whitespace from an item named in
      the link dependencies of this target.  */
  std::string CheckCMP0004(std::string const& item) const;
812

813 814 815
  cmLinkInterface const* GetImportLinkInterface(
    const std::string& config, const cmGeneratorTarget* head,
    bool usage_requirements_only) const;
816

817 818 819 820
  typedef std::map<std::string, KindedSources> KindedSourcesMapType;
  mutable KindedSourcesMapType KindedSourcesMap;
  void ComputeKindedSources(KindedSources& files,
                            std::string const& config) const;
821

822 823 824
  mutable std::vector<AllConfigSource> AllConfigSources;
  void ComputeAllConfigSources() const;

825
  std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
826
  std::vector<TargetPropertyEntry*> CompileOptionsEntries;
827
  std::vector<TargetPropertyEntry*> CompileFeaturesEntries;
828
  std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
829
  std::vector<TargetPropertyEntry*> LinkOptionsEntries;
830
  std::vector<TargetPropertyEntry*> LinkDirectoriesEntries;
831
  std::vector<TargetPropertyEntry*> SourceEntries;
832
  mutable std::set<std::string> LinkImplicitNullProperties;
833

834
  void ExpandLinkItems(std::string const& prop, std::string const& value,
835 836
                       std::string const& config,
                       const cmGeneratorTarget* headTarget,
837 838 839 840
                       bool usage_requirements_only,
                       std::vector<cmLinkItem>& items,
                       bool& hadHeadSensitiveCondition) const;
  void LookupLinkItems(std::vector<std::string> const& names,
Brad King's avatar
Brad King committed
841
                       cmListFileBacktrace const& bt,
842 843
                       std::vector<cmLinkItem>& items) const;

844 845 846 847 848 849
  std::vector<BT<std::string>> GetSourceFilePaths(
    std::string const& config) const;
  std::vector<BT<cmSourceFile*>> GetSourceFilesWithoutObjectLibraries(
    std::string const& config) const;
  void GetSourceFilesWithoutObjectLibraries(std::vector<cmSourceFile*>& files,
                                            const std::string& config) const;
850

851 852 853 854 855
  struct HeadToLinkImplementationMap
    : public std::map<cmGeneratorTarget const*, cmOptionalLinkImplementation>
  {
  };
  typedef std::map<std::string, HeadToLinkImplementationMap> LinkImplMapType;
856 857
  mutable LinkImplMapType LinkImplMap;

858 859
  cmLinkImplementationLibraries const* GetLinkImplementationLibrariesInternal(
    const std::string& config, const cmGeneratorTarget* head) const;
860 861
  bool ComputeOutputDir(const std::string& config,
                        cmStateEnums::ArtifactType artifact,
862
                        std::string& out) const;
863 864 865

  typedef std::map<std::string, OutputInfo> OutputInfoMapType;
  mutable OutputInfoMapType OutputInfoMap;
866

867 868 869 870 871 872
  typedef std::map<std::string, ModuleDefinitionInfo>
    ModuleDefinitionInfoMapType;
  mutable ModuleDefinitionInfoMapType ModuleDefinitionInfoMap;
  void ComputeModuleDefinitionInfo(std::string const& config,
                                   ModuleDefinitionInfo& info) const;

873
  typedef std::pair<std::string, cmStateEnums::ArtifactType> OutputNameKey;
874 875
  typedef std::map<OutputNameKey, std::string> OutputNameMapType;
  mutable OutputNameMapType OutputNameMap;
876
  mutable std::set<cmLinkItem> UtilityItems;
877
  cmPolicies::PolicyMap PolicyMap;
878
  mutable bool PolicyWarnedCMP0022;
879
  mutable bool PolicyReportedCMP0069;
880
  mutable bool DebugIncludesDone;
881
  mutable bool DebugCompileOptionsDone;
882
  mutable bool DebugCompileFeaturesDone;
883
  mutable bool DebugCompileDefinitionsDone;
884
  mutable bool DebugLinkOptionsDone;
885
  mutable bool DebugLinkDirectoriesDone;
886 887
  mutable bool DebugSourcesDone;
  mutable bool LinkImplementationLanguageIsContextDependent;
888
  mutable bool UtilityItemsDone;
889
  bool DLLPlatform;
890

891 892 893
  bool ComputePDBOutputDir(const std::string& kind, const std::string& config,
                           std::string& out) const;

894 895
  ManagedType CheckManagedType(std::string const& propval) const;

896
public:
897 898
  const std::vector<const cmGeneratorTarget*>& GetLinkImplementationClosure(
    const std::string& config) const;
899

900
  mutable std::map<std::string, std::string> MaxLanguageStandards;
901
  std::map<std::string, std::string> const& GetMaxLanguageStandards() const
902 903 904
  {
    return this->MaxLanguageStandards;
  }
905

906 907
  struct StrictTargetComparison
  {
908 909 910
    bool operator()(cmGeneratorTarget const* t1,
                    cmGeneratorTarget const* t2) const;
  };
911 912 913
};

#endif