Resync.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmTarget.h
bloba2a96d38f7cc208ca321ee4b2a36ccc1b304b3b8
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmTarget.h,v $
5 Language: C++
6 Date: $Date: 2008-03-13 20:35:39 $
7 Version: $Revision: 1.111 $
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 static const char* TargetTypeNames[];
85 enum CustomCommandType { PRE_BUILD, PRE_LINK, POST_BUILD };
87 /**
88 * Return the type of target.
90 TargetType GetType() const
92 return this->TargetTypeValue;
95 /**
96 * Set the target type
98 void SetType(TargetType f, const char* name);
100 void MarkAsImported();
102 ///! Set/Get the name of the target
103 const char* GetName() const {return this->Name.c_str();}
105 ///! Set the cmMakefile that owns this target
106 void SetMakefile(cmMakefile *mf);
107 cmMakefile *GetMakefile() const { return this->Makefile;};
109 /** Get the status of policy CMP0003 when the target was created. */
110 cmPolicies::PolicyStatus GetPolicyStatusCMP0003() const
111 { return this->PolicyStatusCMP0003; }
113 /** Get the status of policy CMP0004 when the target was created. */
114 cmPolicies::PolicyStatus GetPolicyStatusCMP0004() const
115 { return this->PolicyStatusCMP0004; }
118 * Get the list of the custom commands for this target
120 std::vector<cmCustomCommand> &GetPreBuildCommands()
121 {return this->PreBuildCommands;}
122 std::vector<cmCustomCommand> &GetPreLinkCommands()
123 {return this->PreLinkCommands;}
124 std::vector<cmCustomCommand> &GetPostBuildCommands()
125 {return this->PostBuildCommands;}
127 ///! Return the list of frameworks being linked to this target
128 std::vector<std::string> &GetFrameworks() {return this->Frameworks;}
131 * Get the list of the source files used by this target
133 std::vector<cmSourceFile*> const &GetSourceFiles()
134 {return this->SourceFiles;}
135 void AddSourceFile(cmSourceFile* sf) { this->SourceFiles.push_back(sf); }
138 * Flags for a given source file as used in this target. Typically assigned
139 * via SET_TARGET_PROPERTIES when the property is a list of source files.
141 enum SourceFileType
143 SourceFileTypeNormal,
144 SourceFileTypePrivateHeader, // is in "PRIVATE_HEADER" target property
145 SourceFileTypePublicHeader, // is in "PUBLIC_HEADER" target property
146 SourceFileTypeResource, // is in "RESOURCE" target property *or*
147 // has MACOSX_PACKAGE_LOCATION=="Resources"
148 SourceFileTypeMacContent // has MACOSX_PACKAGE_LOCATION!="Resources"
150 struct SourceFileFlags
152 SourceFileFlags(): Type(SourceFileTypeNormal), MacFolder(0) {}
153 SourceFileFlags(SourceFileFlags const& r):
154 Type(r.Type), MacFolder(r.MacFolder) {}
155 SourceFileType Type;
156 const char* MacFolder; // location inside Mac content folders
160 * Get the flags for a given source file as used in this target
162 struct SourceFileFlags GetTargetSourceFileFlags(const cmSourceFile* sf);
165 * Add sources to the target.
167 void AddSources(std::vector<std::string> const& srcs);
168 cmSourceFile* AddSource(const char* src);
171 * Get the list of the source files used by this target
173 enum LinkLibraryType {GENERAL, DEBUG, OPTIMIZED};
175 //* how we identify a library, by name and type
176 typedef std::pair<cmStdString, LinkLibraryType> LibraryID;
178 typedef std::vector<LibraryID > LinkLibraryVectorType;
179 const LinkLibraryVectorType &GetLinkLibraries() const {
180 return this->LinkLibraries;}
181 const LinkLibraryVectorType &GetOriginalLinkLibraries() const
182 {return this->OriginalLinkLibraries;}
185 * Clear the dependency information recorded for this target, if any.
187 void ClearDependencyInformation(cmMakefile& mf, const char* target);
189 // Check to see if a library is a framework and treat it different on Mac
190 bool NameResolvesToFramework(const std::string& libname);
191 bool AddFramework(const std::string& lib, LinkLibraryType llt);
192 void AddLinkLibrary(cmMakefile& mf,
193 const char *target, const char* lib,
194 LinkLibraryType llt);
196 void AddLinkLibrary(const std::string& lib,
197 LinkLibraryType llt);
199 void MergeLinkLibraries( cmMakefile& mf, const char* selfname,
200 const LinkLibraryVectorType& libs );
202 const std::vector<std::string>& GetLinkDirectories();
204 void AddLinkDirectory(const char* d);
207 * Set the path where this target should be installed. This is relative to
208 * INSTALL_PREFIX
210 std::string GetInstallPath() {return this->InstallPath;}
211 void SetInstallPath(const char *name) {this->InstallPath = name;}
214 * Set the path where this target (if it has a runtime part) should be
215 * installed. This is relative to INSTALL_PREFIX
217 std::string GetRuntimeInstallPath() {return this->RuntimeInstallPath;}
218 void SetRuntimeInstallPath(const char *name) {
219 this->RuntimeInstallPath = name; }
222 * Get/Set whether there is an install rule for this target.
224 bool GetHaveInstallRule() { return this->HaveInstallRule; }
225 void SetHaveInstallRule(bool h) { this->HaveInstallRule = h; }
227 /** Add a utility on which this project depends. A utility is an executable
228 * name as would be specified to the ADD_EXECUTABLE or UTILITY_SOURCE
229 * commands. It is not a full path nor does it have an extension.
231 void AddUtility(const char* u) { this->Utilities.insert(u);}
232 ///! Get the utilities used by this target
233 std::set<cmStdString>const& GetUtilities() const { return this->Utilities; }
235 void AnalyzeLibDependencies( const cmMakefile& mf );
237 ///! Set/Get a property of this target file
238 void SetProperty(const char *prop, const char *value);
239 void AppendProperty(const char* prop, const char* value);
240 const char *GetProperty(const char *prop);
241 const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
242 bool GetPropertyAsBool(const char *prop);
244 bool IsImported() const {return this->IsImportedTarget;}
246 /** Get the library interface dependencies. This is the set of
247 libraries from which something that links to this target may
248 also receive symbols. Returns 0 if the user has not specified
249 such dependencies or for static libraries. */
250 cmTargetLinkInterface const* GetLinkInterface(const char* config);
252 /** Get the directory in which this target will be built. If the
253 configuration name is given then the generator will add its
254 subdirectory for that configuration. Otherwise just the canonical
255 output directory is given. */
256 const char* GetDirectory(const char* config = 0, bool implib = false);
258 /** Get the location of the target in the build tree for the given
259 configuration. This location is suitable for use as the LOCATION
260 target property. */
261 const char* GetLocation(const char* config);
263 /** Get the target major and minor version numbers interpreted from
264 the VERSION property. Version 0 is returned if the property is
265 not set or cannot be parsed. */
266 void GetTargetVersion(int& major, int& minor);
269 * Trace through the source files in this target and add al source files
270 * that they depend on, used by all generators
272 void TraceDependencies(const char* vsProjectFile);
274 ///! Return the prefered linker language for this target
275 const char* GetLinkerLanguage(cmGlobalGenerator*);
277 ///! Return the rule variable used to create this type of target,
278 // need to add CMAKE_(LANG) for full name.
279 const char* GetCreateRuleVariable();
281 /** Get the full name of the target according to the settings in its
282 makefile. */
283 std::string GetFullName(const char* config=0, bool implib = false);
284 void GetFullNameComponents(std::string& prefix,
285 std::string& base, std::string& suffix,
286 const char* config=0, bool implib = false);
288 /** Get the name of the pdb file for the target. */
289 std::string GetPDBName(const char* config=0);
291 /** Get the soname of the target. Allowed only for a shared library. */
292 std::string GetSOName(const char* config);
294 /** Test for special case of a third-party shared library that has
295 no soname at all. */
296 bool IsImportedSharedLibWithoutSOName(const char* config);
298 /** Get the full path to the target according to the settings in its
299 makefile and the configuration type. */
300 std::string GetFullPath(const char* config=0, bool implib = false,
301 bool realname = false);
303 /** Get the names of the library needed to generate a build rule
304 that takes into account shared library version numbers. This
305 should be called only on a library target. */
306 void GetLibraryNames(std::string& name, std::string& soName,
307 std::string& realName, std::string& impName,
308 std::string& pdbName, const char* config);
310 /** Get the names of the library used to remove existing copies of
311 the library from the build tree either before linking or during
312 a clean step. This should be called only on a library
313 target. */
314 void GetLibraryCleanNames(std::string& staticName,
315 std::string& sharedName,
316 std::string& sharedSOName,
317 std::string& sharedRealName,
318 std::string& importName,
319 std::string& pdbName,
320 const char* config);
322 /** Get the names of the executable needed to generate a build rule
323 that takes into account executable version numbers. This should
324 be called only on an executable target. */
325 void GetExecutableNames(std::string& name, std::string& realName,
326 std::string& impName,
327 std::string& pdbName, const char* config);
329 /** Get the names of the executable used to remove existing copies
330 of the executable from the build tree either before linking or
331 during a clean step. This should be called only on an
332 executable target. */
333 void GetExecutableCleanNames(std::string& name, std::string& realName,
334 std::string& impName,
335 std::string& pdbName, const char* config);
337 /** Add the target output files to the global generator manifest. */
338 void GenerateTargetManifest(const char* config);
341 * Compute whether this target must be relinked before installing.
343 bool NeedRelinkBeforeInstall();
345 bool HaveBuildTreeRPATH();
346 bool HaveInstallTreeRPATH();
348 /** Return true if builtin chrpath will work for this target */
349 bool IsChrpathUsed();
351 std::string GetInstallNameDirForBuildTree(const char* config);
352 std::string GetInstallNameDirForInstallTree(const char* config);
354 cmComputeLinkInformation* GetLinkInformation(const char* config);
356 // Get the properties
357 cmPropertyMap &GetProperties() { return this->Properties; };
359 // Define the properties
360 static void DefineProperties(cmake *cm);
362 // Compute the OBJECT_FILES property only when requested
363 void ComputeObjectFiles();
365 /** Get the macro to define when building sources in this target.
366 If no macro should be defined null is returned. */
367 const char* GetExportMacro();
369 // Compute the set of languages compiled by the target. This is
370 // computed every time it is called because the languages can change
371 // when source file properties are changed and we do not have enough
372 // information to forward these property changes to the targets
373 // until we have per-target object file properties.
374 void GetLanguages(std::set<cmStdString>& languages) const;
376 /** Return whether this target is an executable with symbol exports
377 enabled. */
378 bool IsExecutableWithExports();
380 /** Return whether this target is a shared library Framework on
381 Apple. */
382 bool IsFrameworkOnApple();
384 /** Return whether this target is an executable Bundle on Apple. */
385 bool IsAppBundleOnApple();
387 /** Get a backtrace from the creation of the target. */
388 cmListFileBacktrace const& GetBacktrace() const;
390 private:
392 * A list of direct dependencies. Use in conjunction with DependencyMap.
394 typedef std::vector< LibraryID > DependencyList;
397 * This map holds the dependency graph. map[x] returns a set of
398 * direct dependencies of x. Note that the direct depenencies are
399 * ordered. This is necessary to handle direct dependencies that
400 * themselves have no dependency information.
402 typedef std::map< LibraryID, DependencyList > DependencyMap;
405 * Inserts \a dep at the end of the dependency list of \a lib.
407 void InsertDependency( DependencyMap& depMap,
408 const LibraryID& lib,
409 const LibraryID& dep);
412 * Deletes \a dep from the dependency list of \a lib.
414 void DeleteDependency( DependencyMap& depMap,
415 const LibraryID& lib,
416 const LibraryID& dep);
419 * Emits the library \a lib and all its dependencies into link_line.
420 * \a emitted keeps track of the libraries that have been emitted to
421 * avoid duplicates--it is more efficient than searching
422 * link_line. \a visited is used detect cycles. Note that \a
423 * link_line is in reverse order, in that the dependencies of a
424 * library are listed before the library itself.
426 void Emit( const LibraryID lib,
427 const DependencyMap& dep_map,
428 std::set<LibraryID>& emitted,
429 std::set<LibraryID>& visited,
430 DependencyList& link_line);
433 * Finds the dependencies for \a lib and inserts them into \a
434 * dep_map.
436 void GatherDependencies( const cmMakefile& mf,
437 const LibraryID& lib,
438 DependencyMap& dep_map);
440 const char* GetSuffixVariableInternal(TargetType type, bool implib);
441 const char* GetPrefixVariableInternal(TargetType type, bool implib);
442 std::string GetFullNameInternal(TargetType type, const char* config,
443 bool implib);
444 void GetFullNameInternal(TargetType type, const char* config, bool implib,
445 std::string& outPrefix, std::string& outBase,
446 std::string& outSuffix);
448 void GetLibraryNamesInternal(std::string& name,
449 std::string& soName,
450 std::string& realName,
451 std::string& impName,
452 std::string& pdbName,
453 TargetType type,
454 const char* config);
455 void GetExecutableNamesInternal(std::string& name,
456 std::string& realName,
457 std::string& impName,
458 std::string& pdbName,
459 TargetType type,
460 const char* config);
462 // Use a makefile variable to set a default for the given property.
463 // If the variable is not defined use the given default instead.
464 void SetPropertyDefault(const char* property, const char* default_value);
466 // Get the full path to the target output directory.
467 const char* GetAndCreateOutputDir(bool implib, bool create);
469 // Get the full path to the target output directory.
470 const char* GetOutputDir(bool implib);
472 const char* ImportedGetLocation(const char* config);
473 const char* NormalGetLocation(const char* config);
475 std::string GetFullNameImported(const char* config, bool implib);
477 const char* ImportedGetDirectory(const char* config, bool implib);
478 const char* NormalGetDirectory(const char* config, bool implib);
480 std::string ImportedGetFullPath(const char* config, bool implib);
481 std::string NormalGetFullPath(const char* config, bool implib,
482 bool realname);
484 /** Get the real name of the target. Allowed only for non-imported
485 targets. When a library or executable file is versioned this is
486 the full versioned name. If the target is not versioned this is
487 the same as GetFullName. */
488 std::string NormalGetRealName(const char* config);
490 private:
491 std::string Name;
492 std::vector<cmCustomCommand> PreBuildCommands;
493 std::vector<cmCustomCommand> PreLinkCommands;
494 std::vector<cmCustomCommand> PostBuildCommands;
495 TargetType TargetTypeValue;
496 std::vector<cmSourceFile*> SourceFiles;
497 LinkLibraryVectorType LinkLibraries;
498 LinkLibraryVectorType PrevLinkedLibraries;
499 bool LinkLibrariesAnalyzed;
500 std::vector<std::string> Frameworks;
501 std::vector<std::string> LinkDirectories;
502 std::set<cmStdString> LinkDirectoriesEmmitted;
503 bool HaveInstallRule;
504 std::string InstallPath;
505 std::string RuntimeInstallPath;
506 std::string OutputDir;
507 std::string OutputDirImplib;
508 std::string Directory;
509 std::string Location;
510 std::string ExportMacro;
511 std::set<cmStdString> Utilities;
512 bool RecordDependencies;
513 cmPropertyMap Properties;
514 LinkLibraryVectorType OriginalLinkLibraries;
515 bool DLLPlatform;
516 bool IsImportedTarget;
518 // Cache import information from properties for each configuration.
519 struct ImportInfo
521 bool NoSOName;
522 std::string Location;
523 std::string SOName;
524 std::string ImportLibrary;
525 cmTargetLinkInterface LinkInterface;
527 typedef std::map<cmStdString, ImportInfo> ImportInfoMapType;
528 ImportInfoMapType ImportInfoMap;
529 ImportInfo const* GetImportInfo(const char* config);
530 void ComputeImportInfo(std::string const& desired_config, ImportInfo& info);
532 cmTargetLinkInformationMap LinkInformation;
534 // Link interface.
535 cmTargetLinkInterface* ComputeLinkInterface(const char* config);
536 cmTargetLinkInterfaceMap LinkInterface;
538 // The cmMakefile instance that owns this target. This should
539 // always be set.
540 cmMakefile* Makefile;
542 // Policy status recorded when target was created.
543 cmPolicies::PolicyStatus PolicyStatusCMP0003;
544 cmPolicies::PolicyStatus PolicyStatusCMP0004;
546 // Internal representation details.
547 friend class cmTargetInternals;
548 cmTargetInternalPointer Internal;
550 void ConstructSourceFileFlags();
553 typedef std::map<cmStdString,cmTarget> cmTargets;
555 class cmTargetSet: public std::set<cmStdString> {};
556 class cmTargetManifest: public std::map<cmStdString, cmTargetSet> {};
558 #endif