Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmTarget.h
blob2d4d0dfc47fa318d45801c284119111e62a9ed9b
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmTarget.h,v $
5 Language: C++
6 Date: $Date: 2009-02-10 13:50:09 $
7 Version: $Revision: 1.121 $
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 cmTarget_h
18 #define cmTarget_h
20 #include "cmCustomCommand.h"
21 #include "cmPropertyMap.h"
22 #include "cmPolicies.h"
24 class cmake;
25 class cmMakefile;
26 class cmSourceFile;
27 class cmGlobalGenerator;
28 class cmComputeLinkInformation;
29 class cmListFileBacktrace;
31 struct cmTargetLinkInformationMap:
32 public std::map<cmStdString, cmComputeLinkInformation*>
34 typedef std::map<cmStdString, cmComputeLinkInformation*> derived;
35 cmTargetLinkInformationMap() {}
36 cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r);
37 ~cmTargetLinkInformationMap();
40 struct cmTargetLinkInterface
42 // Libraries listed in the interface.
43 std::vector<std::string> Libraries;
45 // Shared library dependencies needed for linking on some platforms.
46 std::vector<std::string> SharedDeps;
49 struct cmTargetLinkInterfaceMap:
50 public std::map<cmStdString, cmTargetLinkInterface*>
52 typedef std::map<cmStdString, cmTargetLinkInterface*> derived;
53 cmTargetLinkInterfaceMap() {}
54 cmTargetLinkInterfaceMap(cmTargetLinkInterfaceMap const& r);
55 ~cmTargetLinkInterfaceMap();
58 class cmTargetInternals;
59 class cmTargetInternalPointer
61 public:
62 cmTargetInternalPointer();
63 cmTargetInternalPointer(cmTargetInternalPointer const& r);
64 ~cmTargetInternalPointer();
65 cmTargetInternalPointer& operator=(cmTargetInternalPointer const& r);
66 cmTargetInternals* operator->() const { return this->Pointer; }
67 private:
68 cmTargetInternals* Pointer;
71 /** \class cmTarget
72 * \brief Represent a library or executable target loaded from a makefile.
74 * cmTarget represents a target loaded from
75 * a makefile.
77 class cmTarget
79 public:
80 cmTarget();
81 enum TargetType { EXECUTABLE, STATIC_LIBRARY,
82 SHARED_LIBRARY, MODULE_LIBRARY, UTILITY, GLOBAL_TARGET,
83 INSTALL_FILES, INSTALL_PROGRAMS, INSTALL_DIRECTORY,
84 UNKNOWN_LIBRARY};
85 static const char* TargetTypeNames[];
86 enum CustomCommandType { PRE_BUILD, PRE_LINK, POST_BUILD };
88 /**
89 * Return the type of target.
91 TargetType GetType() const
93 return this->TargetTypeValue;
96 /**
97 * Set the target type
99 void SetType(TargetType f, const char* name);
101 void MarkAsImported();
103 ///! Set/Get the name of the target
104 const char* GetName() const {return this->Name.c_str();}
106 ///! Set the cmMakefile that owns this target
107 void SetMakefile(cmMakefile *mf);
108 cmMakefile *GetMakefile() const { return this->Makefile;};
110 /** Get the status of policy CMP0003 when the target was created. */
111 cmPolicies::PolicyStatus GetPolicyStatusCMP0003() const
112 { return this->PolicyStatusCMP0003; }
114 /** Get the status of policy CMP0004 when the target was created. */
115 cmPolicies::PolicyStatus GetPolicyStatusCMP0004() const
116 { return this->PolicyStatusCMP0004; }
118 /** Get the status of policy CMP0008 when the target was created. */
119 cmPolicies::PolicyStatus GetPolicyStatusCMP0008() const
120 { return this->PolicyStatusCMP0008; }
123 * Get the list of the custom commands for this target
125 std::vector<cmCustomCommand> &GetPreBuildCommands()
126 {return this->PreBuildCommands;}
127 std::vector<cmCustomCommand> &GetPreLinkCommands()
128 {return this->PreLinkCommands;}
129 std::vector<cmCustomCommand> &GetPostBuildCommands()
130 {return this->PostBuildCommands;}
132 ///! Return the list of frameworks being linked to this target
133 std::vector<std::string> &GetFrameworks() {return this->Frameworks;}
136 * Get the list of the source files used by this target
138 std::vector<cmSourceFile*> const &GetSourceFiles()
139 {return this->SourceFiles;}
140 void AddSourceFile(cmSourceFile* sf) { this->SourceFiles.push_back(sf); }
143 * Flags for a given source file as used in this target. Typically assigned
144 * via SET_TARGET_PROPERTIES when the property is a list of source files.
146 enum SourceFileType
148 SourceFileTypeNormal,
149 SourceFileTypePrivateHeader, // is in "PRIVATE_HEADER" target property
150 SourceFileTypePublicHeader, // is in "PUBLIC_HEADER" target property
151 SourceFileTypeResource, // is in "RESOURCE" target property *or*
152 // has MACOSX_PACKAGE_LOCATION=="Resources"
153 SourceFileTypeMacContent // has MACOSX_PACKAGE_LOCATION!="Resources"
155 struct SourceFileFlags
157 SourceFileFlags(): Type(SourceFileTypeNormal), MacFolder(0) {}
158 SourceFileFlags(SourceFileFlags const& r):
159 Type(r.Type), MacFolder(r.MacFolder) {}
160 SourceFileType Type;
161 const char* MacFolder; // location inside Mac content folders
165 * Get the flags for a given source file as used in this target
167 struct SourceFileFlags GetTargetSourceFileFlags(const cmSourceFile* sf);
170 * Add sources to the target.
172 void AddSources(std::vector<std::string> const& srcs);
173 cmSourceFile* AddSource(const char* src);
176 * Get the list of the source files used by this target
178 enum LinkLibraryType {GENERAL, DEBUG, OPTIMIZED};
180 //* how we identify a library, by name and type
181 typedef std::pair<cmStdString, LinkLibraryType> LibraryID;
183 typedef std::vector<LibraryID > LinkLibraryVectorType;
184 const LinkLibraryVectorType &GetLinkLibraries() const {
185 return this->LinkLibraries;}
186 const LinkLibraryVectorType &GetOriginalLinkLibraries() const
187 {return this->OriginalLinkLibraries;}
189 /** Compute the link type to use for the given configuration. */
190 LinkLibraryType ComputeLinkType(const char* config);
193 * Clear the dependency information recorded for this target, if any.
195 void ClearDependencyInformation(cmMakefile& mf, const char* target);
197 // Check to see if a library is a framework and treat it different on Mac
198 bool NameResolvesToFramework(const std::string& libname);
199 bool AddFramework(const std::string& lib, LinkLibraryType llt);
200 void AddLinkLibrary(cmMakefile& mf,
201 const char *target, const char* lib,
202 LinkLibraryType llt);
204 void AddLinkLibrary(const std::string& lib,
205 LinkLibraryType llt);
207 void MergeLinkLibraries( cmMakefile& mf, const char* selfname,
208 const LinkLibraryVectorType& libs );
210 const std::vector<std::string>& GetLinkDirectories();
212 void AddLinkDirectory(const char* d);
215 * Set the path where this target should be installed. This is relative to
216 * INSTALL_PREFIX
218 std::string GetInstallPath() {return this->InstallPath;}
219 void SetInstallPath(const char *name) {this->InstallPath = name;}
222 * Set the path where this target (if it has a runtime part) should be
223 * installed. This is relative to INSTALL_PREFIX
225 std::string GetRuntimeInstallPath() {return this->RuntimeInstallPath;}
226 void SetRuntimeInstallPath(const char *name) {
227 this->RuntimeInstallPath = name; }
230 * Get/Set whether there is an install rule for this target.
232 bool GetHaveInstallRule() { return this->HaveInstallRule; }
233 void SetHaveInstallRule(bool h) { this->HaveInstallRule = h; }
235 /** Add a utility on which this project depends. A utility is an executable
236 * name as would be specified to the ADD_EXECUTABLE or UTILITY_SOURCE
237 * commands. It is not a full path nor does it have an extension.
239 void AddUtility(const char* u) { this->Utilities.insert(u);}
240 ///! Get the utilities used by this target
241 std::set<cmStdString>const& GetUtilities() const { return this->Utilities; }
243 void AnalyzeLibDependencies( const cmMakefile& mf );
245 ///! Set/Get a property of this target file
246 void SetProperty(const char *prop, const char *value);
247 void AppendProperty(const char* prop, const char* value);
248 const char *GetProperty(const char *prop);
249 const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
250 bool GetPropertyAsBool(const char *prop);
251 void CheckProperty(const char* prop, cmMakefile* context);
253 bool IsImported() const {return this->IsImportedTarget;}
255 /** Get the library interface dependencies. This is the set of
256 libraries from which something that links to this target may
257 also receive symbols. Returns 0 if the user has not specified
258 such dependencies or for static libraries. */
259 cmTargetLinkInterface const* GetLinkInterface(const char* config);
261 /** Get the directory in which this target will be built. If the
262 configuration name is given then the generator will add its
263 subdirectory for that configuration. Otherwise just the canonical
264 output directory is given. */
265 std::string GetDirectory(const char* config = 0, bool implib = false);
267 /** Get the location of the target in the build tree for the given
268 configuration. This location is suitable for use as the LOCATION
269 target property. */
270 const char* GetLocation(const char* config);
272 /** Get the target major and minor version numbers interpreted from
273 the VERSION property. Version 0 is returned if the property is
274 not set or cannot be parsed. */
275 void GetTargetVersion(int& major, int& minor);
277 /** Get the target major, minor, and patch version numbers
278 interpreted from the VERSION or SOVERSION property. Version 0
279 is returned if the property is not set or cannot be parsed. */
280 void GetTargetVersion(bool soversion, int& major, int& minor, int& patch);
283 * Trace through the source files in this target and add al source files
284 * that they depend on, used by all generators
286 void TraceDependencies(const char* vsProjectFile);
289 * Make sure the full path to all source files is known.
291 bool FindSourceFiles();
293 ///! Return the prefered linker language for this target
294 const char* GetLinkerLanguage(cmGlobalGenerator*);
296 ///! Return the rule variable used to create this type of target,
297 // need to add CMAKE_(LANG) for full name.
298 const char* GetCreateRuleVariable();
300 /** Get the full name of the target according to the settings in its
301 makefile. */
302 std::string GetFullName(const char* config=0, bool implib = false);
303 void GetFullNameComponents(std::string& prefix,
304 std::string& base, std::string& suffix,
305 const char* config=0, bool implib = false);
307 /** Get the name of the pdb file for the target. */
308 std::string GetPDBName(const char* config=0);
310 /** Get the soname of the target. Allowed only for a shared library. */
311 std::string GetSOName(const char* config);
313 /** Test for special case of a third-party shared library that has
314 no soname at all. */
315 bool IsImportedSharedLibWithoutSOName(const char* config);
317 /** Get the full path to the target according to the settings in its
318 makefile and the configuration type. */
319 std::string GetFullPath(const char* config=0, bool implib = false,
320 bool realname = false);
322 /** Get the names of the library needed to generate a build rule
323 that takes into account shared library version numbers. This
324 should be called only on a library target. */
325 void GetLibraryNames(std::string& name, std::string& soName,
326 std::string& realName, std::string& impName,
327 std::string& pdbName, const char* config);
329 /** Get the names of the library used to remove existing copies of
330 the library from the build tree either before linking or during
331 a clean step. This should be called only on a library
332 target. */
333 void GetLibraryCleanNames(std::string& staticName,
334 std::string& sharedName,
335 std::string& sharedSOName,
336 std::string& sharedRealName,
337 std::string& importName,
338 std::string& pdbName,
339 const char* config);
341 /** Get the names of the executable needed to generate a build rule
342 that takes into account executable version numbers. This should
343 be called only on an executable target. */
344 void GetExecutableNames(std::string& name, std::string& realName,
345 std::string& impName,
346 std::string& pdbName, const char* config);
348 /** Get the names of the executable used to remove existing copies
349 of the executable from the build tree either before linking or
350 during a clean step. This should be called only on an
351 executable target. */
352 void GetExecutableCleanNames(std::string& name, std::string& realName,
353 std::string& impName,
354 std::string& pdbName, const char* config);
356 /** Add the target output files to the global generator manifest. */
357 void GenerateTargetManifest(const char* config);
360 * Compute whether this target must be relinked before installing.
362 bool NeedRelinkBeforeInstall();
364 bool HaveBuildTreeRPATH();
365 bool HaveInstallTreeRPATH();
367 /** Return true if builtin chrpath will work for this target */
368 bool IsChrpathUsed();
370 std::string GetInstallNameDirForBuildTree(const char* config,
371 bool for_xcode = false);
372 std::string GetInstallNameDirForInstallTree(const char* config,
373 bool for_xcode = false);
375 cmComputeLinkInformation* GetLinkInformation(const char* config);
377 // Get the properties
378 cmPropertyMap &GetProperties() { return this->Properties; };
380 // Define the properties
381 static void DefineProperties(cmake *cm);
383 // Compute the OBJECT_FILES property only when requested
384 void ComputeObjectFiles();
386 /** Get the macro to define when building sources in this target.
387 If no macro should be defined null is returned. */
388 const char* GetExportMacro();
390 // Compute the set of languages compiled by the target. This is
391 // computed every time it is called because the languages can change
392 // when source file properties are changed and we do not have enough
393 // information to forward these property changes to the targets
394 // until we have per-target object file properties.
395 void GetLanguages(std::set<cmStdString>& languages) const;
397 /** Return whether this target is an executable with symbol exports
398 enabled. */
399 bool IsExecutableWithExports();
401 /** Return whether this target may be used to link another target. */
402 bool IsLinkable();
404 /** Return whether this target is a shared library Framework on
405 Apple. */
406 bool IsFrameworkOnApple();
408 /** Return whether this target is an executable Bundle on Apple. */
409 bool IsAppBundleOnApple();
411 /** Return the framework version string. Undefined if
412 IsFrameworkOnApple returns false. */
413 std::string GetFrameworkVersion();
415 /** Get a backtrace from the creation of the target. */
416 cmListFileBacktrace const& GetBacktrace() const;
418 /** Get a build-tree directory in which to place target support files. */
419 std::string GetSupportDirectory() const;
421 private:
423 * A list of direct dependencies. Use in conjunction with DependencyMap.
425 typedef std::vector< LibraryID > DependencyList;
428 * This map holds the dependency graph. map[x] returns a set of
429 * direct dependencies of x. Note that the direct depenencies are
430 * ordered. This is necessary to handle direct dependencies that
431 * themselves have no dependency information.
433 typedef std::map< LibraryID, DependencyList > DependencyMap;
436 * Inserts \a dep at the end of the dependency list of \a lib.
438 void InsertDependency( DependencyMap& depMap,
439 const LibraryID& lib,
440 const LibraryID& dep);
443 * Deletes \a dep from the dependency list of \a lib.
445 void DeleteDependency( DependencyMap& depMap,
446 const LibraryID& lib,
447 const LibraryID& dep);
450 * Emits the library \a lib and all its dependencies into link_line.
451 * \a emitted keeps track of the libraries that have been emitted to
452 * avoid duplicates--it is more efficient than searching
453 * link_line. \a visited is used detect cycles. Note that \a
454 * link_line is in reverse order, in that the dependencies of a
455 * library are listed before the library itself.
457 void Emit( const LibraryID lib,
458 const DependencyMap& dep_map,
459 std::set<LibraryID>& emitted,
460 std::set<LibraryID>& visited,
461 DependencyList& link_line);
464 * Finds the dependencies for \a lib and inserts them into \a
465 * dep_map.
467 void GatherDependencies( const cmMakefile& mf,
468 const LibraryID& lib,
469 DependencyMap& dep_map);
471 const char* GetSuffixVariableInternal(TargetType type, bool implib);
472 const char* GetPrefixVariableInternal(TargetType type, bool implib);
473 std::string GetFullNameInternal(TargetType type, const char* config,
474 bool implib);
475 void GetFullNameInternal(TargetType type, const char* config, bool implib,
476 std::string& outPrefix, std::string& outBase,
477 std::string& outSuffix);
479 void GetLibraryNamesInternal(std::string& name,
480 std::string& soName,
481 std::string& realName,
482 std::string& impName,
483 std::string& pdbName,
484 TargetType type,
485 const char* config);
486 void GetExecutableNamesInternal(std::string& name,
487 std::string& realName,
488 std::string& impName,
489 std::string& pdbName,
490 TargetType type,
491 const char* config);
493 // Use a makefile variable to set a default for the given property.
494 // If the variable is not defined use the given default instead.
495 void SetPropertyDefault(const char* property, const char* default_value);
497 // Get the full path to the target output directory.
498 std::string GetOutputDir(bool implib);
499 std::string const& ComputeBaseOutputDir(bool implib);
501 const char* ImportedGetLocation(const char* config);
502 const char* NormalGetLocation(const char* config);
504 std::string GetFullNameImported(const char* config, bool implib);
506 std::string ImportedGetFullPath(const char* config, bool implib);
507 std::string NormalGetFullPath(const char* config, bool implib,
508 bool realname);
510 /** Get the real name of the target. Allowed only for non-imported
511 targets. When a library or executable file is versioned this is
512 the full versioned name. If the target is not versioned this is
513 the same as GetFullName. */
514 std::string NormalGetRealName(const char* config);
516 private:
517 std::string Name;
518 std::vector<cmCustomCommand> PreBuildCommands;
519 std::vector<cmCustomCommand> PreLinkCommands;
520 std::vector<cmCustomCommand> PostBuildCommands;
521 TargetType TargetTypeValue;
522 std::vector<cmSourceFile*> SourceFiles;
523 LinkLibraryVectorType LinkLibraries;
524 LinkLibraryVectorType PrevLinkedLibraries;
525 bool LinkLibrariesAnalyzed;
526 std::vector<std::string> Frameworks;
527 std::vector<std::string> LinkDirectories;
528 std::set<cmStdString> LinkDirectoriesEmmitted;
529 bool HaveInstallRule;
530 std::string InstallPath;
531 std::string RuntimeInstallPath;
532 std::string BaseOutputDir;
533 std::string BaseOutputDirImplib;
534 std::string Location;
535 std::string ExportMacro;
536 std::set<cmStdString> Utilities;
537 bool RecordDependencies;
538 cmPropertyMap Properties;
539 LinkLibraryVectorType OriginalLinkLibraries;
540 bool DLLPlatform;
541 bool IsImportedTarget;
543 // Cache import information from properties for each configuration.
544 struct ImportInfo
546 bool NoSOName;
547 std::string Location;
548 std::string SOName;
549 std::string ImportLibrary;
550 cmTargetLinkInterface LinkInterface;
552 typedef std::map<cmStdString, ImportInfo> ImportInfoMapType;
553 ImportInfoMapType ImportInfoMap;
554 ImportInfo const* GetImportInfo(const char* config);
555 void ComputeImportInfo(std::string const& desired_config, ImportInfo& info);
557 cmTargetLinkInformationMap LinkInformation;
559 // Link interface.
560 cmTargetLinkInterface* ComputeLinkInterface(const char* config);
561 cmTargetLinkInterfaceMap LinkInterface;
563 // The cmMakefile instance that owns this target. This should
564 // always be set.
565 cmMakefile* Makefile;
567 // Policy status recorded when target was created.
568 cmPolicies::PolicyStatus PolicyStatusCMP0003;
569 cmPolicies::PolicyStatus PolicyStatusCMP0004;
570 cmPolicies::PolicyStatus PolicyStatusCMP0008;
572 // Internal representation details.
573 friend class cmTargetInternals;
574 cmTargetInternalPointer Internal;
576 void ConstructSourceFileFlags();
579 typedef std::map<cmStdString,cmTarget> cmTargets;
581 class cmTargetSet: public std::set<cmStdString> {};
582 class cmTargetManifest: public std::map<cmStdString, cmTargetSet> {};
584 #endif