Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmTarget.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmTarget.h"
13 #include "cmake.h"
14 #include "cmMakefile.h"
15 #include "cmSourceFile.h"
16 #include "cmLocalGenerator.h"
17 #include "cmGlobalGenerator.h"
18 #include "cmComputeLinkInformation.h"
19 #include "cmDocumentCompileDefinitions.h"
20 #include "cmDocumentGeneratorExpressions.h"
21 #include "cmDocumentLocationUndefined.h"
22 #include "cmListFileCache.h"
23 #include "cmGeneratorExpression.h"
24 #include "cmGeneratorExpressionDAGChecker.h"
25 #include <cmsys/RegularExpression.hxx>
26 #include <map>
27 #include <set>
28 #include <queue>
29 #include <stdlib.h> // required for atof
30 #include <assert.h>
31
32 const char* cmTarget::GetTargetTypeName(TargetType targetType)
33 {
34   switch( targetType )
35     {
36       case cmTarget::STATIC_LIBRARY:
37         return "STATIC_LIBRARY";
38       case cmTarget::MODULE_LIBRARY:
39         return "MODULE_LIBRARY";
40       case cmTarget::SHARED_LIBRARY:
41         return "SHARED_LIBRARY";
42       case cmTarget::OBJECT_LIBRARY:
43         return "OBJECT_LIBRARY";
44       case cmTarget::EXECUTABLE:
45         return "EXECUTABLE";
46       case cmTarget::UTILITY:
47         return "UTILITY";
48       case cmTarget::GLOBAL_TARGET:
49         return "GLOBAL_TARGET";
50       case cmTarget::UNKNOWN_LIBRARY:
51         return "UNKNOWN_LIBRARY";
52     }
53   assert(0 && "Unexpected target type");
54   return 0;
55 }
56
57 //----------------------------------------------------------------------------
58 struct cmTarget::OutputInfo
59 {
60   std::string OutDir;
61   std::string ImpDir;
62   std::string PdbDir;
63 };
64
65 //----------------------------------------------------------------------------
66 struct cmTarget::ImportInfo
67 {
68   bool NoSOName;
69   std::string Location;
70   std::string SOName;
71   std::string ImportLibrary;
72   cmTarget::LinkInterface LinkInterface;
73 };
74
75 struct TargetConfigPair : public std::pair<cmTarget*, std::string> {
76   TargetConfigPair(cmTarget* tgt, const std::string &config)
77     : std::pair<cmTarget*, std::string>(tgt, config) {}
78 };
79
80 //----------------------------------------------------------------------------
81 class cmTargetInternals
82 {
83 public:
84   cmTargetInternals()
85     {
86     this->PolicyWarnedCMP0022 = false;
87     this->SourceFileFlagsConstructed = false;
88     }
89   cmTargetInternals(cmTargetInternals const& r)
90     {
91     this->PolicyWarnedCMP0022 = false;
92     this->SourceFileFlagsConstructed = false;
93     // Only some of these entries are part of the object state.
94     // Others not copied here are result caches.
95     this->SourceEntries = r.SourceEntries;
96     }
97   ~cmTargetInternals();
98   typedef cmTarget::SourceFileFlags SourceFileFlags;
99   std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
100   bool SourceFileFlagsConstructed;
101
102   // The backtrace when the target was created.
103   cmListFileBacktrace Backtrace;
104
105   // Cache link interface computation from each configuration.
106   struct OptionalLinkInterface: public cmTarget::LinkInterface
107   {
108     OptionalLinkInterface(): Exists(false) {}
109     bool Exists;
110   };
111   typedef std::map<TargetConfigPair, OptionalLinkInterface>
112                                                           LinkInterfaceMapType;
113   LinkInterfaceMapType LinkInterfaceMap;
114   bool PolicyWarnedCMP0022;
115
116   typedef std::map<cmStdString, cmTarget::OutputInfo> OutputInfoMapType;
117   OutputInfoMapType OutputInfoMap;
118
119   typedef std::map<TargetConfigPair, cmTarget::ImportInfo>
120                                                             ImportInfoMapType;
121   ImportInfoMapType ImportInfoMap;
122
123   // Cache link implementation computation from each configuration.
124   typedef std::map<TargetConfigPair,
125                    cmTarget::LinkImplementation> LinkImplMapType;
126   LinkImplMapType LinkImplMap;
127
128   typedef std::map<TargetConfigPair, cmTarget::LinkClosure>
129                                                           LinkClosureMapType;
130   LinkClosureMapType LinkClosureMap;
131
132   struct SourceEntry { std::vector<cmSourceFile*> Depends; };
133   typedef std::map<cmSourceFile*, SourceEntry> SourceEntriesType;
134   SourceEntriesType SourceEntries;
135
136   struct TargetPropertyEntry {
137     TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
138       const std::string &targetName = std::string())
139       : ge(cge), TargetName(targetName)
140     {}
141     const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
142     std::vector<std::string> CachedEntries;
143     const std::string TargetName;
144   };
145   std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
146   std::vector<TargetPropertyEntry*> CompileOptionsEntries;
147   std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
148   std::vector<cmValueWithOrigin> LinkInterfacePropertyEntries;
149
150   std::map<std::string, std::vector<TargetPropertyEntry*> >
151                                 CachedLinkInterfaceIncludeDirectoriesEntries;
152   std::map<std::string, std::vector<TargetPropertyEntry*> >
153                                 CachedLinkInterfaceCompileOptionsEntries;
154   std::map<std::string, std::vector<TargetPropertyEntry*> >
155                                 CachedLinkInterfaceCompileDefinitionsEntries;
156
157   std::map<std::string, bool> CacheLinkInterfaceIncludeDirectoriesDone;
158   std::map<std::string, bool> CacheLinkInterfaceCompileDefinitionsDone;
159   std::map<std::string, bool> CacheLinkInterfaceCompileOptionsDone;
160 };
161
162 //----------------------------------------------------------------------------
163 void deleteAndClear(
164       std::vector<cmTargetInternals::TargetPropertyEntry*> &entries)
165 {
166   for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
167       it = entries.begin(),
168       end = entries.end();
169       it != end; ++it)
170     {
171       delete *it;
172     }
173   entries.clear();
174 }
175
176 //----------------------------------------------------------------------------
177 void deleteAndClear(
178   std::map<std::string,
179           std::vector<cmTargetInternals::TargetPropertyEntry*> > &entries)
180 {
181   for (std::map<std::string,
182           std::vector<cmTargetInternals::TargetPropertyEntry*> >::iterator
183         it = entries.begin(), end = entries.end(); it != end; ++it)
184     {
185     deleteAndClear(it->second);
186     }
187 }
188
189 //----------------------------------------------------------------------------
190 cmTargetInternals::~cmTargetInternals()
191 {
192   deleteAndClear(this->CachedLinkInterfaceIncludeDirectoriesEntries);
193   deleteAndClear(this->CachedLinkInterfaceCompileOptionsEntries);
194   deleteAndClear(this->CachedLinkInterfaceCompileDefinitionsEntries);
195 }
196
197 //----------------------------------------------------------------------------
198 cmTarget::cmTarget()
199 {
200 #define INITIALIZE_TARGET_POLICY_MEMBER(POLICY) \
201   this->PolicyStatus ## POLICY = cmPolicies::WARN;
202
203   CM_FOR_EACH_TARGET_POLICY(INITIALIZE_TARGET_POLICY_MEMBER)
204
205 #undef INITIALIZE_TARGET_POLICY_MEMBER
206
207   this->Makefile = 0;
208   this->LinkLibrariesAnalyzed = false;
209   this->HaveInstallRule = false;
210   this->DLLPlatform = false;
211   this->IsApple = false;
212   this->IsImportedTarget = false;
213   this->BuildInterfaceIncludesAppended = false;
214   this->DebugIncludesDone = false;
215   this->DebugCompileOptionsDone = false;
216   this->DebugCompileDefinitionsDone = false;
217 }
218
219 //----------------------------------------------------------------------------
220 void cmTarget::DefineProperties(cmake *cm)
221 {
222   cm->DefineProperty
223     ("AUTOMOC", cmProperty::TARGET,
224      "Should the target be processed with automoc (for Qt projects).",
225      "AUTOMOC is a boolean specifying whether CMake will handle "
226      "the Qt moc preprocessor automatically, i.e. without having to use "
227      "the QT4_WRAP_CPP() or QT5_WRAP_CPP() macro. Currently Qt4 and Qt5 are "
228      "supported.  "
229      "When this property is set to TRUE, CMake will scan the source files "
230      "at build time and invoke moc accordingly. "
231      "If an #include statement like #include \"moc_foo.cpp\" is found, "
232      "the Q_OBJECT class declaration is expected in the header, and moc is "
233      "run on the header file. "
234      "If an #include statement like #include \"foo.moc\" is found, "
235      "then a Q_OBJECT is expected in the current source file and moc "
236      "is run on the file itself. "
237      "Additionally, all header files are parsed for Q_OBJECT macros, "
238      "and if found, moc is also executed on those files. The resulting "
239      "moc files, which are not included as shown above in any of the source "
240      "files are included in a generated <targetname>_automoc.cpp file, "
241      "which is compiled as part of the target."
242      "This property is initialized by the value of the variable "
243      "CMAKE_AUTOMOC if it is set when a target is created.\n"
244      "Additional command line options for moc can be set via the "
245      "AUTOMOC_MOC_OPTIONS property.\n"
246      "By setting the CMAKE_AUTOMOC_RELAXED_MODE variable to TRUE the rules "
247      "for searching the files which will be processed by moc can be relaxed. "
248      "See the documentation for this variable for more details.\n"
249      "The global property AUTOMOC_TARGETS_FOLDER can be used to group the "
250      "automoc targets together in an IDE, e.g. in MSVS.");
251
252   cm->DefineProperty
253     ("AUTOMOC_MOC_OPTIONS", cmProperty::TARGET,
254     "Additional options for moc when using automoc (see the AUTOMOC property)",
255      "This property is only used if the AUTOMOC property is set to TRUE for "
256      "this target. In this case, it holds additional command line options "
257      "which will be used when moc is executed during the build, i.e. it is "
258      "equivalent to the optional OPTIONS argument of the qt4_wrap_cpp() "
259      "macro.\n"
260      "By default it is empty.");
261
262   cm->DefineProperty
263     ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
264      "Should build tree targets have install tree rpaths.",
265      "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
266      "the target in the build tree with the INSTALL_RPATH.  This takes "
267      "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
268      "before installation.  "
269      "This property is initialized by the value of the variable "
270      "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
271
272   cm->DefineProperty
273     ("COMPILE_FLAGS", cmProperty::TARGET,
274      "Additional flags to use when compiling this target's sources.",
275      "The COMPILE_FLAGS property sets additional compiler flags used "
276      "to build sources within the target.  Use COMPILE_DEFINITIONS "
277      "to pass additional preprocessor definitions.");
278
279   cm->DefineProperty
280     ("COMPILE_DEFINITIONS", cmProperty::TARGET,
281      "Preprocessor definitions for compiling a target's sources.",
282      "The COMPILE_DEFINITIONS property may be set to a "
283      "semicolon-separated list of preprocessor "
284      "definitions using the syntax VAR or VAR=value.  Function-style "
285      "definitions are not supported.  CMake will automatically escape "
286      "the value correctly for the native build system (note that CMake "
287      "language syntax may require escapes to specify some values).  "
288      "This property may be set on a per-configuration basis using the name "
289      "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
290      "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
291      "CMake will automatically drop some definitions that "
292      "are not supported by the native build tool.  "
293      "The VS6 IDE does not support definition values with spaces "
294      "(but NMake does).\n"
295      "Contents of COMPILE_DEFINITIONS may use \"generator expressions\" with "
296      "the syntax \"$<...>\".  "
297      CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS
298      CM_DOCUMENT_COMPILE_DEFINITIONS_DISCLAIMER);
299
300   cm->DefineProperty
301     ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
302      "Per-configuration preprocessor definitions on a target.",
303      "This is the configuration-specific version of COMPILE_DEFINITIONS.");
304
305   cm->DefineProperty
306     ("COMPILE_OPTIONS", cmProperty::TARGET,
307      "List of options to pass to the compiler.",
308      "This property specifies the list of options specified "
309      "so far for this property.  "
310      "This property exists on directories and targets."
311      "\n"
312      "The target property values are used by the generators to set "
313      "the options for the compiler.\n"
314      "Contents of COMPILE_OPTIONS may use \"generator expressions\" with "
315      "the syntax \"$<...>\".  "
316      CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
317
318   cm->DefineProperty
319     ("INTERFACE_COMPILE_OPTIONS", cmProperty::TARGET,
320      "List of interface options to pass to the compiler.",
321      "Targets may populate this property to publish the compile options "
322      "required to compile against the headers for the target.  Consuming "
323      "targets can add entries to their own COMPILE_OPTIONS property such "
324      "as $<TARGET_PROPERTY:foo,INTERFACE_COMPILE_OPTIONS> to use the "
325      "compile options specified in the interface of 'foo'."
326      "\n"
327      CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
328
329   cm->DefineProperty
330     ("DEFINE_SYMBOL", cmProperty::TARGET,
331      "Define a symbol when compiling this target's sources.",
332      "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
333      "compiling sources in a shared library. "
334      "If not set here then it is set to target_EXPORTS by default "
335      "(with some substitutions if the target is not a valid C "
336      "identifier). This is useful for headers to know whether they are "
337      "being included from inside their library or outside to properly "
338      "setup dllexport/dllimport decorations. ");
339
340   cm->DefineProperty
341     ("DEBUG_POSTFIX", cmProperty::TARGET,
342      "See target property <CONFIG>_POSTFIX.",
343      "This property is a special case of the more-general <CONFIG>_POSTFIX "
344      "property for the DEBUG configuration.");
345
346   cm->DefineProperty
347     ("<CONFIG>_POSTFIX", cmProperty::TARGET,
348      "Postfix to append to the target file name for configuration <CONFIG>.",
349      "When building with configuration <CONFIG> the value of this property "
350      "is appended to the target file name built on disk.  "
351      "For non-executable targets, this property is initialized by the value "
352      "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
353      "created.  "
354      "This property is ignored on the Mac for Frameworks and App Bundles.");
355
356   cm->DefineProperty
357     ("EchoString", cmProperty::TARGET,
358      "A message to be displayed when the target is built.",
359      "A message to display on some generators (such as makefiles) when "
360      "the target is built.");
361
362   cm->DefineProperty
363     ("BUNDLE", cmProperty::TARGET,
364      "This target is a CFBundle on the Mac.",
365      "If a module library target has this property set to true it will "
366      "be built as a CFBundle when built on the mac. It will have the "
367      "directory structure required for a CFBundle and will be suitable "
368      "to be used for creating Browser Plugins or other application "
369      "resources.");
370
371   cm->DefineProperty
372     ("BUNDLE_EXTENSION", cmProperty::TARGET,
373      "The file extension used to name a BUNDLE target on the Mac.",
374      "The default value is \"bundle\" - you can also use \"plugin\" or "
375      "whatever file extension is required by the host app for your "
376      "bundle.");
377
378   cm->DefineProperty
379     ("EXCLUDE_FROM_DEFAULT_BUILD", cmProperty::TARGET,
380      "Exclude target from \"Build Solution\".",
381      "This property is only used by Visual Studio generators 7 and above. "
382      "When set to TRUE, the target will not be built when you press "
383      "\"Build Solution\".");
384
385   cm->DefineProperty
386     ("EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG>", cmProperty::TARGET,
387      "Per-configuration version of target exclusion from \"Build Solution\". ",
388      "This is the configuration-specific version of "
389      "EXCLUDE_FROM_DEFAULT_BUILD. If the generic EXCLUDE_FROM_DEFAULT_BUILD "
390      "is also set on a target, EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG> takes "
391      "precedence in configurations for which it has a value.");
392
393   cm->DefineProperty
394     ("FRAMEWORK", cmProperty::TARGET,
395      "This target is a framework on the Mac.",
396      "If a shared library target has this property set to true it will "
397      "be built as a framework when built on the mac. It will have the "
398      "directory structure required for a framework and will be suitable "
399      "to be used with the -framework option");
400
401   cm->DefineProperty
402     ("HAS_CXX", cmProperty::TARGET,
403      "Link the target using the C++ linker tool (obsolete).",
404      "This is equivalent to setting the LINKER_LANGUAGE property to CXX.  "
405      "See that property's documentation for details.");
406
407   cm->DefineProperty
408     ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
409      "Specify #include line transforms for dependencies in a target.",
410      "This property specifies rules to transform macro-like #include lines "
411      "during implicit dependency scanning of C and C++ source files.  "
412      "The list of rules must be semicolon-separated with each entry of "
413      "the form \"A_MACRO(%)=value-with-%\" (the % must be literal).  "
414      "During dependency scanning occurrences of A_MACRO(...) on #include "
415      "lines will be replaced by the value given with the macro argument "
416      "substituted for '%'.  For example, the entry\n"
417      "  MYDIR(%)=<mydir/%>\n"
418      "will convert lines of the form\n"
419      "  #include MYDIR(myheader.h)\n"
420      "to\n"
421      "  #include <mydir/myheader.h>\n"
422      "allowing the dependency to be followed.\n"
423      "This property applies to sources in the target on which it is set.");
424
425   cm->DefineProperty
426     ("IMPORT_PREFIX", cmProperty::TARGET,
427      "What comes before the import library name.",
428      "Similar to the target property PREFIX, but used for import libraries "
429      "(typically corresponding to a DLL) instead of regular libraries. "
430      "A target property that can be set to override the prefix "
431      "(such as \"lib\") on an import library name.");
432
433   cm->DefineProperty
434     ("IMPORT_SUFFIX", cmProperty::TARGET,
435      "What comes after the import library name.",
436      "Similar to the target property SUFFIX, but used for import libraries "
437      "(typically corresponding to a DLL) instead of regular libraries. "
438      "A target property that can be set to override the suffix "
439      "(such as \".lib\") on an import library name.");
440
441   cm->DefineProperty
442     ("IMPORTED", cmProperty::TARGET,
443      "Read-only indication of whether a target is IMPORTED.",
444      "The boolean value of this property is true for targets created with "
445      "the IMPORTED option to add_executable or add_library.  "
446      "It is false for targets built within the project.");
447
448   cm->DefineProperty
449     ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
450      "Configurations provided for an IMPORTED target.",
451      "Set this to the list of configuration names available for an "
452      "IMPORTED target.  "
453      "The names correspond to configurations defined in the project from "
454      "which the target is imported.  "
455      "If the importing project uses a different set of configurations "
456      "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
457      "property.  "
458      "Ignored for non-imported targets.");
459
460   cm->DefineProperty
461     ("IMPORTED_IMPLIB", cmProperty::TARGET,
462      "Full path to the import library for an IMPORTED target.",
463      "Set this to the location of the \".lib\" part of a windows DLL.  "
464      "Ignored for non-imported targets.");
465
466   cm->DefineProperty
467     ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
468      "<CONFIG>-specific version of IMPORTED_IMPLIB property.",
469      "Configuration names correspond to those provided by the project "
470      "from which the target is imported.");
471
472   cm->DefineProperty
473     ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
474      "Dependent shared libraries of an imported shared library.",
475      "Shared libraries may be linked to other shared libraries as part "
476      "of their implementation.  On some platforms the linker searches "
477      "for the dependent libraries of shared libraries they are including "
478      "in the link.  "
479      "Set this property to the list of dependent shared libraries of an "
480      "imported library.  "
481      "The list "
482      "should be disjoint from the list of interface libraries in the "
483      "INTERFACE_LINK_LIBRARIES property.  On platforms requiring "
484      "dependent shared libraries to be found at link time CMake uses this "
485      "list to add appropriate files or paths to the link command line.  "
486      "Ignored for non-imported targets.");
487
488   cm->DefineProperty
489     ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
490      "<CONFIG>-specific version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
491      "Configuration names correspond to those provided by the project "
492      "from which the target is imported.  "
493      "If set, this property completely overrides the generic property "
494      "for the named configuration.");
495
496   cm->DefineProperty
497     ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
498      "Transitive link interface of an IMPORTED target.",
499      "Set this to the list of libraries whose interface is included when "
500      "an IMPORTED library target is linked to another target.  "
501      "The libraries will be included on the link line for the target.  "
502      "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
503      "to all imported target types, including STATIC libraries.  "
504      "This property is ignored for non-imported targets.\n"
505      "This property is ignored if the target also has a non-empty "
506      "INTERFACE_LINK_LIBRARIES property.\n"
507      "This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.");
508
509   cm->DefineProperty
510     ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
511      "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
512      "Configuration names correspond to those provided by the project "
513      "from which the target is imported.  "
514      "If set, this property completely overrides the generic property "
515      "for the named configuration.\n"
516      "This property is ignored if the target also has a non-empty "
517      "INTERFACE_LINK_LIBRARIES property.\n"
518      "This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.");
519
520   cm->DefineProperty
521     ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET,
522      "Languages compiled into an IMPORTED static library.",
523      "Set this to the list of languages of source files compiled to "
524      "produce a STATIC IMPORTED library (such as \"C\" or \"CXX\").  "
525      "CMake accounts for these languages when computing how to link a "
526      "target to the imported library.  "
527      "For example, when a C executable links to an imported C++ static "
528      "library CMake chooses the C++ linker to satisfy language runtime "
529      "dependencies of the static library.  "
530      "\n"
531      "This property is ignored for targets that are not STATIC libraries.  "
532      "This property is ignored for non-imported targets.");
533
534   cm->DefineProperty
535     ("IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>", cmProperty::TARGET,
536      "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LANGUAGES.",
537      "Configuration names correspond to those provided by the project "
538      "from which the target is imported.  "
539      "If set, this property completely overrides the generic property "
540      "for the named configuration.");
541
542   cm->DefineProperty
543     ("IMPORTED_LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
544      "Repetition count for cycles of IMPORTED static libraries.",
545      "This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.");
546   cm->DefineProperty
547     ("IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
548      "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_MULTIPLICITY.",
549      "If set, this property completely overrides the generic property "
550      "for the named configuration.");
551
552   cm->DefineProperty
553     ("IMPORTED_LOCATION", cmProperty::TARGET,
554      "Full path to the main file on disk for an IMPORTED target.",
555      "Set this to the location of an IMPORTED target file on disk.  "
556      "For executables this is the location of the executable file.  "
557      "For bundles on OS X this is the location of the executable file "
558      "inside Contents/MacOS under the application bundle folder.  "
559      "For static libraries and modules this is the location of the "
560      "library or module.  "
561      "For shared libraries on non-DLL platforms this is the location of "
562      "the shared library.  "
563      "For frameworks on OS X this is the location of the library file "
564      "symlink just inside the framework folder.  "
565      "For DLLs this is the location of the \".dll\" part of the library.  "
566      "For UNKNOWN libraries this is the location of the file to be linked.  "
567      "Ignored for non-imported targets."
568      "\n"
569      "Projects may skip IMPORTED_LOCATION if the configuration-specific "
570      "property IMPORTED_LOCATION_<CONFIG> is set.  "
571      "To get the location of an imported target read one of the "
572      "LOCATION or LOCATION_<CONFIG> properties.");
573
574   cm->DefineProperty
575     ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
576      "<CONFIG>-specific version of IMPORTED_LOCATION property.",
577      "Configuration names correspond to those provided by the project "
578      "from which the target is imported.");
579
580   cm->DefineProperty
581     ("IMPORTED_SONAME", cmProperty::TARGET,
582      "The \"soname\" of an IMPORTED target of shared library type.",
583      "Set this to the \"soname\" embedded in an imported shared library.  "
584      "This is meaningful only on platforms supporting the feature.  "
585      "Ignored for non-imported targets.");
586
587   cm->DefineProperty
588     ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
589      "<CONFIG>-specific version of IMPORTED_SONAME property.",
590      "Configuration names correspond to those provided by the project "
591      "from which the target is imported.");
592
593   cm->DefineProperty
594     ("IMPORTED_NO_SONAME", cmProperty::TARGET,
595      "Specifies that an IMPORTED shared library target has no \"soname\".  ",
596      "Set this property to true for an imported shared library file that "
597      "has no \"soname\" field.  "
598      "CMake may adjust generated link commands for some platforms to prevent "
599      "the linker from using the path to the library in place of its missing "
600      "soname.  "
601      "Ignored for non-imported targets.");
602
603   cm->DefineProperty
604     ("IMPORTED_NO_SONAME_<CONFIG>", cmProperty::TARGET,
605      "<CONFIG>-specific version of IMPORTED_NO_SONAME property.",
606      "Configuration names correspond to those provided by the project "
607      "from which the target is imported.");
608
609   cm->DefineProperty
610     ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
611      "Exclude the target from the all target.",
612      "A property on a target that indicates if the target is excluded "
613      "from the default build target. If it is not, then with a Makefile "
614      "for example typing make will cause this target to be built. "
615      "The same concept applies to the default build of other generators. "
616      "Installing a target with EXCLUDE_FROM_ALL set to true has "
617      "undefined behavior.");
618
619   cm->DefineProperty
620     ("LINK_LIBRARIES", cmProperty::TARGET,
621      "List of direct link dependencies.",
622      "This property specifies the list of libraries or targets which will be "
623      "used for linking. "
624      "In addition to accepting values from the target_link_libraries "
625      "command, values may be set directly on any target using the "
626      "set_property command. "
627      "\n"
628      "The target property values are used by the generators to set "
629      "the link libraries for the compiler.  "
630      "See also the target_link_libraries command.\n"
631      "Contents of LINK_LIBRARIES may use \"generator expressions\" with "
632      "the syntax \"$<...>\".  "
633      CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
634
635   cm->DefineProperty
636     ("INCLUDE_DIRECTORIES", cmProperty::TARGET,
637      "List of preprocessor include file search directories.",
638      "This property specifies the list of directories given "
639      "so far to the include_directories command. "
640      "This property exists on directories and targets. "
641      "In addition to accepting values from the include_directories "
642      "command, values may be set directly on any directory or any "
643      "target using the set_property command. "
644      "A target gets its initial value for this property from the value "
645      "of the directory property. "
646      "A directory gets its initial value from its parent directory if "
647      "it has one. "
648      "Both directory and target property values are adjusted by calls "
649      "to the include_directories command."
650      "\n"
651      "The target property values are used by the generators to set "
652      "the include paths for the compiler.  "
653      "See also the include_directories command.\n"
654      "Contents of INCLUDE_DIRECTORIES may use \"generator expressions\" with "
655      "the syntax \"$<...>\".  "
656      CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
657
658   cm->DefineProperty
659     ("INSTALL_NAME_DIR", cmProperty::TARGET,
660      "Mac OSX directory name for installed targets.",
661      "INSTALL_NAME_DIR is a string specifying the "
662      "directory portion of the \"install_name\" field of shared libraries "
663      "on Mac OSX to use in the installed targets. ");
664
665   cm->DefineProperty
666     ("INSTALL_RPATH", cmProperty::TARGET,
667      "The rpath to use for installed targets.",
668      "A semicolon-separated list specifying the rpath "
669      "to use in installed targets (for platforms that support it).  "
670      "This property is initialized by the value of the variable "
671      "CMAKE_INSTALL_RPATH if it is set when a target is created.");
672
673   cm->DefineProperty
674     ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
675      "Add paths to linker search and installed rpath.",
676      "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
677      "append directories in the linker search path and outside the "
678      "project to the INSTALL_RPATH.  "
679      "This property is initialized by the value of the variable "
680      "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
681      "created.");
682
683   cm->DefineProperty
684     ("INTERPROCEDURAL_OPTIMIZATION", cmProperty::TARGET,
685      "Enable interprocedural optimization for a target.",
686      "If set to true, enables interprocedural optimizations "
687      "if they are known to be supported by the compiler.");
688
689   cm->DefineProperty
690     ("INTERPROCEDURAL_OPTIMIZATION_<CONFIG>", cmProperty::TARGET,
691      "Per-configuration interprocedural optimization for a target.",
692      "This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION.  "
693      "If set, this property overrides the generic property "
694      "for the named configuration.");
695
696   cm->DefineProperty
697     ("LABELS", cmProperty::TARGET,
698      "Specify a list of text labels associated with a target.",
699      "Target label semantics are currently unspecified.");
700
701   cm->DefineProperty
702     ("LINK_FLAGS", cmProperty::TARGET,
703      "Additional flags to use when linking this target.",
704      "The LINK_FLAGS property can be used to add extra flags to the "
705      "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
706      "configuration <CONFIG>, "
707      "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
708
709   cm->DefineProperty
710     ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
711      "Per-configuration linker flags for a target.",
712      "This is the configuration-specific version of LINK_FLAGS.");
713
714 #define CM_LINK_SEARCH_SUMMARY \
715   "Some linkers support switches such as -Bstatic and -Bdynamic " \
716   "to determine whether to use static or shared libraries for -lXXX " \
717   "options.  CMake uses these options to set the link type for " \
718   "libraries whose full paths are not known or (in some cases) are in " \
719   "implicit link directories for the platform.  "
720
721   cm->DefineProperty
722     ("LINK_SEARCH_START_STATIC", cmProperty::TARGET,
723      "Assume the linker looks for static libraries by default.",
724      CM_LINK_SEARCH_SUMMARY
725      "By default the linker search type is assumed to be -Bdynamic at "
726      "the beginning of the library list.  This property switches the "
727      "assumption to -Bstatic.  It is intended for use when linking an "
728      "executable statically (e.g. with the GNU -static option).  "
729      "See also LINK_SEARCH_END_STATIC.");
730
731   cm->DefineProperty
732     ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
733      "End a link line such that static system libraries are used.",
734      CM_LINK_SEARCH_SUMMARY
735      "By default CMake adds an option at the end of the library list (if "
736      "necessary) to set the linker search type back to its starting type.  "
737      "This property switches the final linker search type to -Bstatic "
738      "regardless of how it started.  "
739      "See also LINK_SEARCH_START_STATIC.");
740
741   cm->DefineProperty
742     ("LINKER_LANGUAGE", cmProperty::TARGET,
743      "Specifies language whose compiler will invoke the linker.",
744      "For executables, shared libraries, and modules, this sets the "
745      "language whose compiler is used to link the target "
746      "(such as \"C\" or \"CXX\").  "
747      "A typical value for an executable is the language of the source "
748      "file providing the program entry point (main).  "
749      "If not set, the language with the highest linker preference "
750      "value is the default.  "
751      "See documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables."
752      "\n"
753      "If this property is not set by the user, it will be calculated at "
754      "generate-time by CMake."
755     );
756
757   cm->DefineProperty
758     ("LOCATION", cmProperty::TARGET,
759      "Read-only location of a target on disk.",
760      "For an imported target, this read-only property returns the value of "
761      "the LOCATION_<CONFIG> property for an unspecified configuration "
762      "<CONFIG> provided by the target.\n"
763      "For a non-imported target, this property is provided for compatibility "
764      "with CMake 2.4 and below.  "
765      "It was meant to get the location of an executable target's output file "
766      "for use in add_custom_command.  "
767      "The path may contain a build-system-specific portion that "
768      "is replaced at build time with the configuration getting built "
769      "(such as \"$(ConfigurationName)\" in VS). "
770      "In CMake 2.6 and above add_custom_command automatically recognizes a "
771      "target name in its COMMAND and DEPENDS options and computes the "
772      "target location.  "
773      "In CMake 2.8.4 and above add_custom_command recognizes generator "
774      "expressions to refer to target locations anywhere in the command.  "
775      "Therefore this property is not needed for creating custom commands."
776      CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
777
778   cm->DefineProperty
779     ("LOCATION_<CONFIG>", cmProperty::TARGET,
780      "Read-only property providing a target location on disk.",
781      "A read-only property that indicates where a target's main file is "
782      "located on disk for the configuration <CONFIG>.  "
783      "The property is defined only for library and executable targets.  "
784      "An imported target may provide a set of configurations different "
785      "from that of the importing project.  "
786      "By default CMake looks for an exact-match but otherwise uses an "
787      "arbitrary available configuration.  "
788      "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
789      "configurations explicitly."
790      CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
791
792   cm->DefineProperty
793     ("LINK_DEPENDS", cmProperty::TARGET,
794      "Additional files on which a target binary depends for linking.",
795      "Specifies a semicolon-separated list of full-paths to files on which "
796      "the link rule for this target depends.  "
797      "The target binary will be linked if any of the named files is newer "
798      "than it."
799      "\n"
800      "This property is ignored by non-Makefile generators.  "
801      "It is intended to specify dependencies on \"linker scripts\" for "
802      "custom Makefile link rules.");
803
804   cm->DefineProperty
805     ("LINK_DEPENDS_NO_SHARED", cmProperty::TARGET,
806      "Do not depend on linked shared library files.",
807      "Set this property to true to tell CMake generators not to add "
808      "file-level dependencies on the shared library files linked by "
809      "this target.  "
810      "Modification to the shared libraries will not be sufficient to "
811      "re-link this target.  "
812      "Logical target-level dependencies will not be affected so the "
813      "linked shared libraries will still be brought up to date before "
814      "this target is built."
815      "\n"
816      "This property is initialized by the value of the variable "
817      "CMAKE_LINK_DEPENDS_NO_SHARED if it is set when a target is "
818      "created.");
819
820   cm->DefineProperty
821     ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
822      "List public interface libraries for a shared library or executable.",
823      "By default linking to a shared library target transitively "
824      "links to targets with which the library itself was linked.  "
825      "For an executable with exports (see the ENABLE_EXPORTS property) "
826      "no default transitive link dependencies are used.  "
827      "This property replaces the default transitive link dependencies with "
828      "an explicit list.  "
829      "When the target is linked into another target the libraries "
830      "listed (and recursively their link interface libraries) will be "
831      "provided to the other target also.  "
832      "If the list is empty then no transitive link dependencies will be "
833      "incorporated when this target is linked into another target even if "
834      "the default set is non-empty.  "
835      "This property is initialized by the value of the variable "
836      "CMAKE_LINK_INTERFACE_LIBRARIES if it is set when a target is "
837      "created.  "
838      "This property is ignored for STATIC libraries.\n"
839      "This property is overridden by the INTERFACE_LINK_LIBRARIES property if "
840      "policy CMP0022 is NEW.\n"
841      "This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.");
842
843   cm->DefineProperty
844     ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
845      "Per-configuration list of public interface libraries for a target.",
846      "This is the configuration-specific version of "
847      "LINK_INTERFACE_LIBRARIES.  "
848      "If set, this property completely overrides the generic property "
849      "for the named configuration.\n"
850      "This property is overridden by the INTERFACE_LINK_LIBRARIES property if "
851      "policy CMP0022 is NEW.\n"
852      "This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.");
853
854   cm->DefineProperty
855     ("INTERFACE_LINK_LIBRARIES", cmProperty::TARGET,
856      "List public interface libraries for a library.",
857      "This property contains the list of transitive link dependencies.  "
858      "When the target is linked into another target the libraries "
859      "listed (and recursively their link interface libraries) will be "
860      "provided to the other target also.  "
861      "This property is overridden by the LINK_INTERFACE_LIBRARIES or "
862      "LINK_INTERFACE_LIBRARIES_<CONFIG> property if "
863      "policy CMP0022 is OLD or unset.\n"
864      "\n"
865      CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
866
867   cm->DefineProperty
868     ("INTERFACE_INCLUDE_DIRECTORIES", cmProperty::TARGET,
869      "List of public include directories for a library.",
870      "Targets may populate this property to publish the include directories "
871      "required to compile against the headers for the target.  Consuming "
872      "targets can add entries to their own INCLUDE_DIRECTORIES property such "
873      "as $<TARGET_PROPERTY:foo,INTERFACE_INCLUDE_DIRECTORIES> to use the "
874      "include directories specified in the interface of 'foo'."
875      "\n"
876      CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
877
878   cm->DefineProperty
879     ("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", cmProperty::TARGET,
880      "List of public system include directories for a library.",
881      "Targets may populate this property to publish the include directories "
882      "which contain system headers, and therefore should not result in "
883      "compiler warnings.  Consuming targets will then mark the same include "
884      "directories as system headers."
885      "\n"
886      CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
887
888   cm->DefineProperty
889     ("INTERFACE_COMPILE_DEFINITIONS", cmProperty::TARGET,
890      "List of public compile definitions for a library.",
891      "Targets may populate this property to publish the compile definitions "
892      "required to compile against the headers for the target.  Consuming "
893      "targets can add entries to their own COMPILE_DEFINITIONS property such "
894      "as $<TARGET_PROPERTY:foo,INTERFACE_COMPILE_DEFINITIONS> to use the "
895      "compile definitions specified in the interface of 'foo'."
896      "\n"
897      CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
898
899   cm->DefineProperty
900     ("LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
901      "Repetition count for STATIC libraries with cyclic dependencies.",
902      "When linking to a STATIC library target with cyclic dependencies the "
903      "linker may need to scan more than once through the archives in the "
904      "strongly connected component of the dependency graph.  "
905      "CMake by default constructs the link line so that the linker will "
906      "scan through the component at least twice.  "
907      "This property specifies the minimum number of scans if it is larger "
908      "than the default.  "
909      "CMake uses the largest value specified by any target in a component.");
910   cm->DefineProperty
911     ("LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
912      "Per-configuration repetition count for cycles of STATIC libraries.",
913      "This is the configuration-specific version of "
914      "LINK_INTERFACE_MULTIPLICITY.  "
915      "If set, this property completely overrides the generic property "
916      "for the named configuration.");
917
918   cm->DefineProperty
919     ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
920      "Map from project configuration to IMPORTED target's configuration.",
921      "Set this to the list of configurations of an imported target that "
922      "may be used for the current project's <CONFIG> configuration.  "
923      "Targets imported from another project may not provide the same set "
924      "of configuration names available in the current project.  "
925      "Setting this property tells CMake what imported configurations are "
926      "suitable for use when building the <CONFIG> configuration.  "
927      "The first configuration in the list found to be provided by the "
928      "imported target is selected.  If this property is set and no matching "
929      "configurations are available, then the imported target is considered "
930      "to be not found.  This property is ignored for non-imported targets.",
931      false /* TODO: make this chained */ );
932
933   cm->DefineProperty
934     ("OSX_ARCHITECTURES", cmProperty::TARGET,
935      "Target specific architectures for OS X.",
936      "The OSX_ARCHITECTURES property sets the target binary architecture "
937      "for targets on OS X.  "
938      "This property is initialized by the value of the variable "
939      "CMAKE_OSX_ARCHITECTURES if it is set when a target is created.  "
940      "Use OSX_ARCHITECTURES_<CONFIG> to set the binary architectures on a "
941      "per-configuration basis.  "
942      "<CONFIG> is an upper-case name (ex: \"OSX_ARCHITECTURES_DEBUG\").");
943
944   cm->DefineProperty
945     ("OSX_ARCHITECTURES_<CONFIG>", cmProperty::TARGET,
946      "Per-configuration OS X binary architectures for a target.",
947      "This property is the configuration-specific version of "
948      "OSX_ARCHITECTURES.");
949
950   cm->DefineProperty
951     ("NAME", cmProperty::TARGET,
952      "Logical name for the target.",
953      "Read-only logical name for the target as used by CMake.");
954
955   cm->DefineProperty
956     ("EXPORT_NAME", cmProperty::TARGET,
957      "Exported name for target files.",
958      "This sets the name for the IMPORTED target generated when it this "
959      "target is is exported.  "
960      "If not set, the logical target name is used by default.");
961
962   cm->DefineProperty
963     ("OUTPUT_NAME", cmProperty::TARGET,
964      "Output name for target files.",
965      "This sets the base name for output files created for an executable or "
966      "library target.  "
967      "If not set, the logical target name is used by default.");
968
969   cm->DefineProperty
970     ("OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
971      "Per-configuration target file base name.",
972      "This is the configuration-specific version of OUTPUT_NAME.");
973
974   cm->DefineProperty
975     ("ALIASED_TARGET", cmProperty::TARGET,
976      "Name of target aliased by this target.",
977      "If this is an ALIAS target, this property contains the name of the "
978      "target aliased.");
979
980   cm->DefineProperty
981     ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET,
982      "Old per-configuration target file base name.",
983      "This is a configuration-specific version of OUTPUT_NAME.  "
984      "Use OUTPUT_NAME_<CONFIG> instead.");
985
986   cm->DefineProperty
987     ("PDB_NAME", cmProperty::TARGET,
988      "Output name for MS debug symbols .pdb file from linker.",
989      "Set the base name for debug symbols file created for an "
990      "executable or shared library target.  "
991      "If not set, the logical target name is used by default.  "
992      "\n"
993      "This property is not implemented by the Visual Studio 6 generator.");
994
995   cm->DefineProperty
996     ("PDB_NAME_<CONFIG>", cmProperty::TARGET,
997      "Per-configuration name for MS debug symbols .pdb file.  ",
998      "This is the configuration-specific version of PDB_NAME.  "
999      "\n"
1000      "This property is not implemented by the Visual Studio 6 generator.");
1001
1002   cm->DefineProperty
1003     ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
1004      "Deprecated install support.",
1005      "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
1006      "old way to specify CMake scripts to run before and after "
1007      "installing a target.  They are used only when the old "
1008      "INSTALL_TARGETS command is used to install the target.  Use the "
1009      "INSTALL command instead.");
1010
1011   cm->DefineProperty
1012     ("PREFIX", cmProperty::TARGET,
1013      "What comes before the library name.",
1014      "A target property that can be set to override the prefix "
1015      "(such as \"lib\") on a library name.");
1016
1017   cm->DefineProperty
1018     ("<LANG>_VISIBILITY_PRESET", cmProperty::TARGET,
1019      "Value for symbol visibility compile flags",
1020      "The <LANG>_VISIBILITY_PRESET property determines the value passed in "
1021      "a visibility related compile option, such as -fvisibility= for <LANG>.  "
1022      "This property only has an affect for libraries and executables with "
1023      "exports.  This property is initialized by the value of the variable "
1024      "CMAKE_<LANG>_VISIBILITY_PRESET if it is set when a target is created.");
1025
1026   cm->DefineProperty
1027     ("VISIBILITY_INLINES_HIDDEN", cmProperty::TARGET,
1028      "Whether to add a compile flag to hide symbols of inline functions",
1029      "The VISIBILITY_INLINES_HIDDEN property determines whether a flag for "
1030      "hiding symbols for inline functions. the value passed used in "
1031      "a visibility related compile option, such as -fvisibility=.  This "
1032      "property only has an affect for libraries and executables with "
1033      "exports.  This property is initialized by the value of the variable "
1034      "CMAKE_VISIBILITY_INLINES_HIDDEN if it is set when a target is "
1035      "created.");
1036
1037   cm->DefineProperty
1038     ("POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
1039      "Whether to create a position-independent target",
1040      "The POSITION_INDEPENDENT_CODE property determines whether position "
1041      "independent executables or shared libraries will be created.  "
1042      "This property is true by default for SHARED and MODULE library "
1043      "targets and false otherwise.  "
1044      "This property is initialized by the value of the variable "
1045      "CMAKE_POSITION_INDEPENDENT_CODE if it is set when a target is "
1046      "created.");
1047
1048   cm->DefineProperty
1049     ("INTERFACE_POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
1050      "Whether consumers need to create a position-independent target",
1051      "The INTERFACE_POSITION_INDEPENDENT_CODE property informs consumers of "
1052      "this target whether they must set their POSITION_INDEPENDENT_CODE "
1053      "property to ON.  If this property is set to ON, then the "
1054      "POSITION_INDEPENDENT_CODE property on all consumers will be set to "
1055      "ON.  Similarly, if this property is set to OFF, then the "
1056      "POSITION_INDEPENDENT_CODE property on all consumers will be set to "
1057      "OFF.  If this property is undefined, then consumers will determine "
1058      "their POSITION_INDEPENDENT_CODE property by other means.  Consumers "
1059      "must ensure that the targets that they link to have a consistent "
1060      "requirement for their INTERFACE_POSITION_INDEPENDENT_CODE property.");
1061
1062   cm->DefineProperty
1063     ("COMPATIBLE_INTERFACE_BOOL", cmProperty::TARGET,
1064      "Properties which must be compatible with their link interface",
1065      "The COMPATIBLE_INTERFACE_BOOL property may contain a list of properties"
1066      "for this target which must be consistent when evaluated as a boolean "
1067      "in the INTERFACE of all linked dependees.  For example, if a "
1068      "property \"FOO\" appears in the list, then for each dependee, the "
1069      "\"INTERFACE_FOO\" property content in all of its dependencies must be "
1070      "consistent with each other, and with the \"FOO\" property in the "
1071      "dependee.  Consistency in this sense has the meaning that if the "
1072      "property is set, then it must have the same boolean value as all "
1073      "others, and if the property is not set, then it is ignored.  Note that "
1074      "for each dependee, the set of properties from this property must not "
1075      "intersect with the set of properties from the "
1076      "COMPATIBLE_INTERFACE_STRING property.");
1077
1078   cm->DefineProperty
1079     ("COMPATIBLE_INTERFACE_STRING", cmProperty::TARGET,
1080      "Properties which must be string-compatible with their link interface",
1081      "The COMPATIBLE_INTERFACE_STRING property may contain a list of "
1082      "properties for this target which must be the same when evaluated as "
1083      "a string in the INTERFACE of all linked dependees.  For example, "
1084      "if a property \"FOO\" appears in the list, then for each dependee, the "
1085      "\"INTERFACE_FOO\" property content in all of its dependencies must be "
1086      "equal with each other, and with the \"FOO\" property in the dependee.  "
1087      "If the property is not set, then it is ignored.  Note that for each "
1088      "dependee, the set of properties from this property must not intersect "
1089      "with the set of properties from the COMPATIBLE_INTERFACE_BOOL "
1090      "property.");
1091
1092   cm->DefineProperty
1093     ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
1094      "Deprecated install support.",
1095      "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
1096      "old way to specify CMake scripts to run before and after "
1097      "installing a target.  They are used only when the old "
1098      "INSTALL_TARGETS command is used to install the target.  Use the "
1099      "INSTALL command instead.");
1100
1101   cm->DefineProperty
1102     ("PRIVATE_HEADER", cmProperty::TARGET,
1103      "Specify private header files in a FRAMEWORK shared library target.",
1104      "Shared library targets marked with the FRAMEWORK property generate "
1105      "frameworks on OS X and normal shared libraries on other platforms.  "
1106      "This property may be set to a list of header files to be placed "
1107      "in the PrivateHeaders directory inside the framework folder.  "
1108      "On non-Apple platforms these headers may be installed using the "
1109      "PRIVATE_HEADER option to the install(TARGETS) command.");
1110
1111   cm->DefineProperty
1112     ("PUBLIC_HEADER", cmProperty::TARGET,
1113      "Specify public header files in a FRAMEWORK shared library target.",
1114      "Shared library targets marked with the FRAMEWORK property generate "
1115      "frameworks on OS X and normal shared libraries on other platforms.  "
1116      "This property may be set to a list of header files to be placed "
1117      "in the Headers directory inside the framework folder.  "
1118      "On non-Apple platforms these headers may be installed using the "
1119      "PUBLIC_HEADER option to the install(TARGETS) command.");
1120
1121   cm->DefineProperty
1122     ("RESOURCE", cmProperty::TARGET,
1123      "Specify resource files in a FRAMEWORK shared library target.",
1124      "Shared library targets marked with the FRAMEWORK property generate "
1125      "frameworks on OS X and normal shared libraries on other platforms.  "
1126      "This property may be set to a list of files to be placed "
1127      "in the Resources directory inside the framework folder.  "
1128      "On non-Apple platforms these files may be installed using the "
1129      "RESOURCE option to the install(TARGETS) command.");
1130
1131   cm->DefineProperty
1132     ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
1133      "Specify a launcher for compile rules.",
1134      "See the global property of the same name for details.  "
1135      "This overrides the global and directory property for a target.",
1136      true);
1137   cm->DefineProperty
1138     ("RULE_LAUNCH_LINK", cmProperty::TARGET,
1139      "Specify a launcher for link rules.",
1140      "See the global property of the same name for details.  "
1141      "This overrides the global and directory property for a target.",
1142      true);
1143   cm->DefineProperty
1144     ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
1145      "Specify a launcher for custom rules.",
1146      "See the global property of the same name for details.  "
1147      "This overrides the global and directory property for a target.",
1148      true);
1149
1150   cm->DefineProperty
1151     ("SKIP_BUILD_RPATH", cmProperty::TARGET,
1152      "Should rpaths be used for the build tree.",
1153      "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
1154      "generation of an rpath allowing the target to run from the "
1155      "build tree.  "
1156      "This property is initialized by the value of the variable "
1157      "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
1158
1159   cm->DefineProperty
1160     ("NO_SONAME", cmProperty::TARGET,
1161      "Whether to set \"soname\" when linking a shared library or module.",
1162      "Enable this boolean property if a generated shared library or module "
1163      "should not have \"soname\" set. Default is to set \"soname\" on all "
1164      "shared libraries and modules as long as the platform supports it. "
1165      "Generally, use this property only for leaf private libraries or "
1166      "plugins. If you use it on normal shared libraries which other targets "
1167      "link against, on some platforms a linker will insert a full path to "
1168      "the library (as specified at link time) into the dynamic section of "
1169      "the dependent binary. Therefore, once installed, dynamic loader may "
1170      "eventually fail to locate the library for the binary.");
1171
1172   cm->DefineProperty
1173     ("SOVERSION", cmProperty::TARGET,
1174      "What version number is this target.",
1175      "For shared libraries VERSION and SOVERSION can be used to specify "
1176      "the build version and API version respectively. When building or "
1177      "installing appropriate symlinks are created if the platform "
1178      "supports symlinks and the linker supports so-names. "
1179      "If only one of both is specified the missing is assumed to have "
1180      "the same version number. "
1181      "SOVERSION is ignored if NO_SONAME property is set. "
1182      "For shared libraries and executables on Windows the VERSION "
1183      "attribute is parsed to extract a \"major.minor\" version number. "
1184      "These numbers are used as the image version of the binary. ");
1185
1186   cm->DefineProperty
1187     ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
1188      "Extra flags to use when linking static libraries.",
1189      "Extra flags to use when linking a static library.");
1190
1191   cm->DefineProperty
1192     ("STATIC_LIBRARY_FLAGS_<CONFIG>", cmProperty::TARGET,
1193      "Per-configuration flags for creating a static library.",
1194      "This is the configuration-specific version of STATIC_LIBRARY_FLAGS.");
1195
1196   cm->DefineProperty
1197     ("SUFFIX", cmProperty::TARGET,
1198      "What comes after the target name.",
1199      "A target property that can be set to override the suffix "
1200      "(such as \".so\" or \".exe\") on the name of a library, module or "
1201      "executable.");
1202
1203   cm->DefineProperty
1204     ("TYPE", cmProperty::TARGET,
1205      "The type of the target.",
1206      "This read-only property can be used to test the type of the given "
1207      "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
1208      "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
1209
1210   cm->DefineProperty
1211     ("VERSION", cmProperty::TARGET,
1212      "What version number is this target.",
1213      "For shared libraries VERSION and SOVERSION can be used to specify "
1214      "the build version and API version respectively. When building or "
1215      "installing appropriate symlinks are created if the platform "
1216      "supports symlinks and the linker supports so-names. "
1217      "If only one of both is specified the missing is assumed to have "
1218      "the same version number. "
1219      "For executables VERSION can be used to specify the build version. "
1220      "When building or installing appropriate symlinks are created if "
1221      "the platform supports symlinks. "
1222      "For shared libraries and executables on Windows the VERSION "
1223      "attribute is parsed to extract a \"major.minor\" version number. "
1224      "These numbers are used as the image version of the binary. ");
1225
1226
1227   cm->DefineProperty
1228     ("WIN32_EXECUTABLE", cmProperty::TARGET,
1229      "Build an executable with a WinMain entry point on windows.",
1230      "When this property is set to true the executable when linked "
1231      "on Windows will be created with a WinMain() entry point instead "
1232      "of just main().  "
1233      "This makes it a GUI executable instead of a console application.  "
1234      "See the CMAKE_MFC_FLAG variable documentation to configure use "
1235      "of MFC for WinMain executables.  "
1236      "This property is initialized by the value of the variable "
1237      "CMAKE_WIN32_EXECUTABLE if it is set when a target is created.");
1238
1239   cm->DefineProperty
1240     ("MACOSX_BUNDLE", cmProperty::TARGET,
1241      "Build an executable as an application bundle on Mac OS X.",
1242      "When this property is set to true the executable when built "
1243      "on Mac OS X will be created as an application bundle.  "
1244      "This makes it a GUI executable that can be launched from "
1245      "the Finder.  "
1246      "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
1247      "about creation of the Info.plist file for the application bundle.  "
1248      "This property is initialized by the value of the variable "
1249      "CMAKE_MACOSX_BUNDLE if it is set when a target is created.");
1250
1251   cm->DefineProperty
1252     ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
1253      "Specify a custom Info.plist template for a Mac OS X App Bundle.",
1254      "An executable target with MACOSX_BUNDLE enabled will be built as an "
1255      "application bundle on Mac OS X.  "
1256      "By default its Info.plist file is created by configuring a template "
1257      "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH.  "
1258      "This property specifies an alternative template file name which "
1259      "may be a full path.\n"
1260      "The following target properties may be set to specify content to "
1261      "be configured into the file:\n"
1262      "  MACOSX_BUNDLE_INFO_STRING\n"
1263      "  MACOSX_BUNDLE_ICON_FILE\n"
1264      "  MACOSX_BUNDLE_GUI_IDENTIFIER\n"
1265      "  MACOSX_BUNDLE_LONG_VERSION_STRING\n"
1266      "  MACOSX_BUNDLE_BUNDLE_NAME\n"
1267      "  MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
1268      "  MACOSX_BUNDLE_BUNDLE_VERSION\n"
1269      "  MACOSX_BUNDLE_COPYRIGHT\n"
1270      "CMake variables of the same name may be set to affect all targets "
1271      "in a directory that do not have each specific property set.  "
1272      "If a custom Info.plist is specified by this property it may of course "
1273      "hard-code all the settings instead of using the target properties.");
1274
1275   cm->DefineProperty
1276     ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
1277      "Specify a custom Info.plist template for a Mac OS X Framework.",
1278      "A library target with FRAMEWORK enabled will be built as a "
1279      "framework on Mac OS X.  "
1280      "By default its Info.plist file is created by configuring a template "
1281      "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH.  "
1282      "This property specifies an alternative template file name which "
1283      "may be a full path.\n"
1284      "The following target properties may be set to specify content to "
1285      "be configured into the file:\n"
1286      "  MACOSX_FRAMEWORK_ICON_FILE\n"
1287      "  MACOSX_FRAMEWORK_IDENTIFIER\n"
1288      "  MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
1289      "  MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
1290      "CMake variables of the same name may be set to affect all targets "
1291      "in a directory that do not have each specific property set.  "
1292      "If a custom Info.plist is specified by this property it may of course "
1293      "hard-code all the settings instead of using the target properties.");
1294
1295   cm->DefineProperty
1296     ("MACOSX_RPATH", cmProperty::TARGET,
1297      "Whether to use rpaths on Mac OS X.",
1298      "When this property is set to true, the directory portion of the"
1299      "\"install_name\" field of shared libraries will default to \"@rpath\"."
1300      "Runtime paths will also be embedded in binaries using this target."
1301      "This property is initialized by the value of the variable "
1302      "CMAKE_MACOSX_RPATH if it is set when a target is created.");
1303
1304   cm->DefineProperty
1305     ("ENABLE_EXPORTS", cmProperty::TARGET,
1306      "Specify whether an executable exports symbols for loadable modules.",
1307      "Normally an executable does not export any symbols because it is "
1308      "the final program.  It is possible for an executable to export "
1309      "symbols to be used by loadable modules.  When this property is "
1310      "set to true CMake will allow other targets to \"link\" to the "
1311      "executable with the TARGET_LINK_LIBRARIES command.  "
1312      "On all platforms a target-level dependency on the executable is "
1313      "created for targets that link to it.  "
1314      "For DLL platforms an import library will be created for the "
1315      "exported symbols and then used for linking.  "
1316      "All Windows-based systems including Cygwin are DLL platforms.  "
1317      "For non-DLL platforms that require all symbols to be resolved at "
1318      "link time, such as Mac OS X, the module will \"link\" to the "
1319      "executable using a flag like \"-bundle_loader\".  "
1320      "For other non-DLL platforms the link rule is simply ignored since "
1321      "the dynamic loader will automatically bind symbols when the "
1322      "module is loaded.  "
1323       );
1324
1325   cm->DefineProperty
1326     ("Fortran_FORMAT", cmProperty::TARGET,
1327      "Set to FIXED or FREE to indicate the Fortran source layout.",
1328      "This property tells CMake whether the Fortran source files "
1329      "in a target use fixed-format or free-format.  "
1330      "CMake will pass the corresponding format flag to the compiler.  "
1331      "Use the source-specific Fortran_FORMAT property to change the "
1332      "format of a specific source file.  "
1333      "If the variable CMAKE_Fortran_FORMAT is set when a target "
1334      "is created its value is used to initialize this property.");
1335
1336   cm->DefineProperty
1337     ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
1338      "Specify output directory for Fortran modules provided by the target.",
1339      "If the target contains Fortran source files that provide modules "
1340      "and the compiler supports a module output directory this specifies "
1341      "the directory in which the modules will be placed.  "
1342      "When this property is not set the modules will be placed in the "
1343      "build directory corresponding to the target's source directory.  "
1344      "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
1345      "is created its value is used to initialize this property."
1346      "\n"
1347      "Note that some compilers will automatically search the module output "
1348      "directory for modules USEd during compilation but others will not.  "
1349      "If your sources USE modules their location must be specified by "
1350      "INCLUDE_DIRECTORIES regardless of this property.");
1351
1352   cm->DefineProperty
1353     ("GNUtoMS", cmProperty::TARGET,
1354      "Convert GNU import library (.dll.a) to MS format (.lib).",
1355      "When linking a shared library or executable that exports symbols "
1356      "using GNU tools on Windows (MinGW/MSYS) with Visual Studio installed "
1357      "convert the import library (.dll.a) from GNU to MS format (.lib).  "
1358      "Both import libraries will be installed by install(TARGETS) and "
1359      "exported by install(EXPORT) and export() to be linked by applications "
1360      "with either GNU- or MS-compatible tools."
1361      "\n"
1362      "If the variable CMAKE_GNUtoMS is set when a target "
1363      "is created its value is used to initialize this property.  "
1364      "The variable must be set prior to the first command that enables "
1365      "a language such as project() or enable_language().  "
1366      "CMake provides the variable as an option to the user automatically "
1367      "when configuring on Windows with GNU tools.");
1368
1369   cm->DefineProperty
1370     ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
1371      "Set Xcode target attributes directly.",
1372      "Tell the Xcode generator to set '<an-attribute>' to a given value "
1373      "in the generated Xcode project.  Ignored on other generators.");
1374
1375   cm->DefineProperty
1376     ("GENERATOR_FILE_NAME", cmProperty::TARGET,
1377      "Generator's file for this target.",
1378      "An internal property used by some generators to record the name of the "
1379      "project or dsp file associated with this target. Note that at configure "
1380      "time, this property is only set for targets created by "
1381      "include_external_msproject().");
1382
1383   cm->DefineProperty
1384     ("SOURCES", cmProperty::TARGET,
1385      "Source names specified for a target.",
1386      "Read-only list of sources specified for a target.  "
1387      "The names returned are suitable for passing to the "
1388      "set_source_files_properties command.");
1389
1390   cm->DefineProperty
1391     ("FOLDER", cmProperty::TARGET,
1392      "Set the folder name. Use to organize targets in an IDE.",
1393      "Targets with no FOLDER property will appear as top level "
1394      "entities in IDEs like Visual Studio. Targets with the same "
1395      "FOLDER property value will appear next to each other in a "
1396      "folder of that name. To nest folders, use FOLDER values such "
1397      "as 'GUI/Dialogs' with '/' characters separating folder levels.");
1398
1399   cm->DefineProperty
1400     ("PROJECT_LABEL", cmProperty::TARGET,
1401      "Change the name of a target in an IDE.",
1402      "Can be used to change the name of the target in an IDE "
1403      "like Visual Studio. ");
1404   cm->DefineProperty
1405     ("VS_KEYWORD", cmProperty::TARGET,
1406      "Visual Studio project keyword.",
1407      "Can be set to change the visual studio keyword, for example "
1408      "Qt integration works better if this is set to Qt4VSv1.0. ");
1409   cm->DefineProperty
1410     ("VS_SCC_PROVIDER", cmProperty::TARGET,
1411      "Visual Studio Source Code Control Provider.",
1412      "Can be set to change the visual studio source code control "
1413      "provider property.");
1414   cm->DefineProperty
1415     ("VS_SCC_LOCALPATH", cmProperty::TARGET,
1416      "Visual Studio Source Code Control Local Path.",
1417      "Can be set to change the visual studio source code control "
1418      "local path property.");
1419   cm->DefineProperty
1420     ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
1421      "Visual Studio Source Code Control Project.",
1422      "Can be set to change the visual studio source code control "
1423      "project name property.");
1424   cm->DefineProperty
1425     ("VS_SCC_AUXPATH", cmProperty::TARGET,
1426      "Visual Studio Source Code Control Aux Path.",
1427      "Can be set to change the visual studio source code control "
1428      "auxpath property.");
1429   cm->DefineProperty
1430     ("VS_GLOBAL_PROJECT_TYPES", cmProperty::TARGET,
1431      "Visual Studio project type(s).",
1432      "Can be set to one or more UUIDs recognized by Visual Studio "
1433      "to indicate the type of project. This value is copied "
1434      "verbatim into the generated project file. Example for a "
1435      "managed C++ unit testing project:\n"
1436      " {3AC096D0-A1C2-E12C-1390-A8335801FDAB};"
1437      "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\n"
1438      "UUIDs are semicolon-delimited.");
1439   cm->DefineProperty
1440     ("VS_GLOBAL_KEYWORD", cmProperty::TARGET,
1441      "Visual Studio project keyword.",
1442      "Sets the \"keyword\" attribute for a generated Visual Studio "
1443      "project. Defaults to \"Win32Proj\". You may wish to override "
1444      "this value with \"ManagedCProj\", for example, in a Visual "
1445      "Studio managed C++ unit test project.");
1446   cm->DefineProperty
1447     ("VS_GLOBAL_ROOTNAMESPACE", cmProperty::TARGET,
1448      "Visual Studio project root namespace.",
1449      "Sets the \"RootNamespace\" attribute for a generated Visual Studio "
1450      "project.  The attribute will be generated only if this is set.");
1451   cm->DefineProperty
1452     ("VS_DOTNET_TARGET_FRAMEWORK_VERSION", cmProperty::TARGET,
1453      "Specify the .NET target framework version.",
1454      "Used to specify the .NET target framework version for C++/CLI. "
1455      "For example, \"v4.5\".");
1456   cm->DefineProperty
1457     ("VS_DOTNET_REFERENCES", cmProperty::TARGET,
1458      "Visual Studio managed project .NET references",
1459      "Adds one or more semicolon-delimited .NET references to a "
1460      "generated Visual Studio project. For example, \"System;"
1461      "System.Windows.Forms\".");
1462   cm->DefineProperty
1463     ("VS_WINRT_EXTENSIONS", cmProperty::TARGET,
1464      "Visual Studio project C++/CX language extensions for Windows Runtime",
1465      "Can be set to enable C++/CX language extensions.");
1466   cm->DefineProperty
1467     ("VS_WINRT_REFERENCES", cmProperty::TARGET,
1468      "Visual Studio project Windows Runtime Metadata references",
1469      "Adds one or more semicolon-delimited WinRT references to a "
1470      "generated Visual Studio project. For example, \"Windows;"
1471      "Windows.UI.Core\".");
1472   cm->DefineProperty
1473     ("VS_GLOBAL_<variable>", cmProperty::TARGET,
1474      "Visual Studio project-specific global variable.",
1475      "Tell the Visual Studio generator to set the global variable "
1476      "'<variable>' to a given value in the generated Visual Studio "
1477      "project. Ignored on other generators. Qt integration works "
1478      "better if VS_GLOBAL_QtVersion is set to the version "
1479      "FindQt4.cmake found. For example, \"4.7.3\"");
1480
1481 #define CM_TARGET_FILE_TYPES_DOC                                            \
1482      "There are three kinds of target files that may be built: "            \
1483      "archive, library, and runtime.  "                                     \
1484      "Executables are always treated as runtime targets. "                  \
1485      "Static libraries are always treated as archive targets. "             \
1486      "Module libraries are always treated as library targets. "             \
1487      "For non-DLL platforms shared libraries are treated as library "       \
1488      "targets. "                                                            \
1489      "For DLL platforms the DLL part of a shared library is treated as "    \
1490      "a runtime target and the corresponding import library is treated as " \
1491      "an archive target. "                                                  \
1492      "All Windows-based systems including Cygwin are DLL platforms."
1493
1494 #define CM_TARGET_OUTDIR_DOC(TYPE, type)                                    \
1495      "This property specifies the directory into which " #type " target "   \
1496      "files should be built. "                                              \
1497      "Multi-configuration generators (VS, Xcode) append "                   \
1498      "a per-configuration subdirectory to the specified directory.  "       \
1499      CM_TARGET_FILE_TYPES_DOC "  "                                          \
1500      "This property is initialized by the value of the variable "           \
1501      "CMAKE_" #TYPE "_OUTPUT_DIRECTORY if it is set when a target is created."
1502
1503 #define CM_TARGET_OUTDIR_CONFIG_DOC(TYPE)                                   \
1504      "This is a per-configuration version of " #TYPE "_OUTPUT_DIRECTORY, "  \
1505      "but multi-configuration generators (VS, Xcode) do NOT append "        \
1506      "a per-configuration subdirectory to the specified directory.  "       \
1507      "This property is initialized by the value of the variable "           \
1508      "CMAKE_" #TYPE "_OUTPUT_DIRECTORY_<CONFIG> "                           \
1509      "if it is set when a target is created."
1510
1511   cm->DefineProperty
1512     ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
1513      "Output directory in which to build ARCHIVE target files.",
1514      CM_TARGET_OUTDIR_DOC(ARCHIVE, archive));
1515   cm->DefineProperty
1516     ("ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1517      "Per-configuration output directory for ARCHIVE target files.",
1518      CM_TARGET_OUTDIR_CONFIG_DOC(ARCHIVE));
1519   cm->DefineProperty
1520     ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
1521      "Output directory in which to build LIBRARY target files.",
1522      CM_TARGET_OUTDIR_DOC(LIBRARY, library));
1523   cm->DefineProperty
1524     ("LIBRARY_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1525      "Per-configuration output directory for LIBRARY target files.",
1526      CM_TARGET_OUTDIR_CONFIG_DOC(LIBRARY));
1527   cm->DefineProperty
1528     ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
1529      "Output directory in which to build RUNTIME target files.",
1530      CM_TARGET_OUTDIR_DOC(RUNTIME, runtime));
1531   cm->DefineProperty
1532     ("RUNTIME_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1533      "Per-configuration output directory for RUNTIME target files.",
1534      CM_TARGET_OUTDIR_CONFIG_DOC(RUNTIME));
1535
1536   cm->DefineProperty
1537     ("PDB_OUTPUT_DIRECTORY", cmProperty::TARGET,
1538      "Output directory for MS debug symbols .pdb file from linker.",
1539      "This property specifies the directory into which the MS debug symbols "
1540      "will be placed by the linker.  "
1541      "This property is initialized by the value of the variable "
1542      "CMAKE_PDB_OUTPUT_DIRECTORY if it is set when a target is created."
1543      "\n"
1544      "This property is not implemented by the Visual Studio 6 generator.");
1545   cm->DefineProperty
1546     ("PDB_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1547      "Per-configuration output directory for MS debug symbols .pdb files.",
1548      "This is a per-configuration version of PDB_OUTPUT_DIRECTORY, "
1549      "but multi-configuration generators (VS, Xcode) do NOT append "
1550      "a per-configuration subdirectory to the specified directory. "
1551      "This property is initialized by the value of the variable "
1552      "CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG> "
1553      "if it is set when a target is created."
1554      "\n"
1555      "This property is not implemented by the Visual Studio 6 generator.");
1556
1557   cm->DefineProperty
1558     ("ARCHIVE_OUTPUT_NAME", cmProperty::TARGET,
1559      "Output name for ARCHIVE target files.",
1560      "This property specifies the base name for archive target files. "
1561      "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties.  "
1562      CM_TARGET_FILE_TYPES_DOC);
1563   cm->DefineProperty
1564     ("ARCHIVE_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1565      "Per-configuration output name for ARCHIVE target files.",
1566      "This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.");
1567   cm->DefineProperty
1568     ("LIBRARY_OUTPUT_NAME", cmProperty::TARGET,
1569      "Output name for LIBRARY target files.",
1570      "This property specifies the base name for library target files. "
1571      "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties.  "
1572      CM_TARGET_FILE_TYPES_DOC);
1573   cm->DefineProperty
1574     ("LIBRARY_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1575      "Per-configuration output name for LIBRARY target files.",
1576      "This is the configuration-specific version of LIBRARY_OUTPUT_NAME.");
1577   cm->DefineProperty
1578     ("RUNTIME_OUTPUT_NAME", cmProperty::TARGET,
1579      "Output name for RUNTIME target files.",
1580      "This property specifies the base name for runtime target files.  "
1581      "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties.  "
1582      CM_TARGET_FILE_TYPES_DOC);
1583   cm->DefineProperty
1584     ("RUNTIME_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1585      "Per-configuration output name for RUNTIME target files.",
1586      "This is the configuration-specific version of RUNTIME_OUTPUT_NAME.");
1587 }
1588
1589 void cmTarget::SetType(TargetType type, const char* name)
1590 {
1591   this->Name = name;
1592   // only add dependency information for library targets
1593   this->TargetTypeValue = type;
1594   if(this->TargetTypeValue >= STATIC_LIBRARY
1595      && this->TargetTypeValue <= MODULE_LIBRARY)
1596     {
1597     this->RecordDependencies = true;
1598     }
1599   else
1600     {
1601     this->RecordDependencies = false;
1602     }
1603 }
1604
1605 //----------------------------------------------------------------------------
1606 void cmTarget::SetMakefile(cmMakefile* mf)
1607 {
1608   // Set our makefile.
1609   this->Makefile = mf;
1610
1611   // set the cmake instance of the properties
1612   this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
1613
1614   // Check whether this is a DLL platform.
1615   this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
1616                        this->Makefile->IsOn("CYGWIN") ||
1617                        this->Makefile->IsOn("MINGW"));
1618
1619   // Check whether we are targeting an Apple platform.
1620   this->IsApple = this->Makefile->IsOn("APPLE");
1621
1622   // Setup default property values.
1623   this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
1624   this->SetPropertyDefault("INSTALL_RPATH", "");
1625   this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
1626   this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
1627   this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
1628   this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
1629   this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
1630   this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
1631   this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
1632   this->SetPropertyDefault("Fortran_FORMAT", 0);
1633   this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
1634   this->SetPropertyDefault("GNUtoMS", 0);
1635   this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
1636   this->SetPropertyDefault("AUTOMOC", 0);
1637   this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
1638   this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
1639   this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
1640   this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
1641   this->SetPropertyDefault("MACOSX_BUNDLE", 0);
1642   this->SetPropertyDefault("MACOSX_RPATH", 0);
1643
1644
1645   // Collect the set of configuration types.
1646   std::vector<std::string> configNames;
1647   mf->GetConfigurations(configNames);
1648
1649   // Setup per-configuration property default values.
1650   const char* configProps[] = {
1651     "ARCHIVE_OUTPUT_DIRECTORY_",
1652     "LIBRARY_OUTPUT_DIRECTORY_",
1653     "RUNTIME_OUTPUT_DIRECTORY_",
1654     "PDB_OUTPUT_DIRECTORY_",
1655     0};
1656   for(std::vector<std::string>::iterator ci = configNames.begin();
1657       ci != configNames.end(); ++ci)
1658     {
1659     std::string configUpper = cmSystemTools::UpperCase(*ci);
1660     for(const char** p = configProps; *p; ++p)
1661       {
1662       std::string property = *p;
1663       property += configUpper;
1664       this->SetPropertyDefault(property.c_str(), 0);
1665       }
1666
1667     // Initialize per-configuration name postfix property from the
1668     // variable only for non-executable targets.  This preserves
1669     // compatibility with previous CMake versions in which executables
1670     // did not support this variable.  Projects may still specify the
1671     // property directly.  TODO: Make this depend on backwards
1672     // compatibility setting.
1673     if(this->TargetTypeValue != cmTarget::EXECUTABLE)
1674       {
1675       std::string property = cmSystemTools::UpperCase(*ci);
1676       property += "_POSTFIX";
1677       this->SetPropertyDefault(property.c_str(), 0);
1678       }
1679     }
1680
1681   // Save the backtrace of target construction.
1682   this->Makefile->GetBacktrace(this->Internal->Backtrace);
1683
1684   // Initialize the INCLUDE_DIRECTORIES property based on the current value
1685   // of the same directory property:
1686   const std::vector<cmValueWithOrigin> parentIncludes =
1687                               this->Makefile->GetIncludeDirectoriesEntries();
1688
1689   for (std::vector<cmValueWithOrigin>::const_iterator it
1690               = parentIncludes.begin(); it != parentIncludes.end(); ++it)
1691     {
1692     this->InsertInclude(*it);
1693     }
1694
1695   const std::set<cmStdString> parentSystemIncludes =
1696                               this->Makefile->GetSystemIncludeDirectories();
1697
1698   for (std::set<cmStdString>::const_iterator it
1699         = parentSystemIncludes.begin();
1700         it != parentSystemIncludes.end(); ++it)
1701     {
1702     this->SystemIncludeDirectories.insert(*it);
1703     }
1704
1705   const std::vector<cmValueWithOrigin> parentOptions =
1706                               this->Makefile->GetCompileOptionsEntries();
1707
1708   for (std::vector<cmValueWithOrigin>::const_iterator it
1709               = parentOptions.begin(); it != parentOptions.end(); ++it)
1710     {
1711     this->InsertCompileOption(*it);
1712     }
1713
1714   this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
1715   this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
1716   this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
1717
1718   if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
1719       || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
1720     {
1721     this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
1722     }
1723   this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
1724
1725   // Record current policies for later use.
1726 #define CAPTURE_TARGET_POLICY(POLICY) \
1727   this->PolicyStatus ## POLICY = \
1728     this->Makefile->GetPolicyStatus(cmPolicies::POLICY);
1729
1730   CM_FOR_EACH_TARGET_POLICY(CAPTURE_TARGET_POLICY)
1731
1732 #undef CAPTURE_TARGET_POLICY
1733 }
1734
1735 //----------------------------------------------------------------------------
1736 void cmTarget::FinishConfigure()
1737 {
1738   // Erase any cached link information that might have been comptued
1739   // on-demand during the configuration.  This ensures that build
1740   // system generation uses up-to-date information even if other cache
1741   // invalidation code in this source file is buggy.
1742   this->ClearLinkMaps();
1743
1744   // Do old-style link dependency analysis.
1745   this->AnalyzeLibDependencies(*this->Makefile);
1746 }
1747
1748 //----------------------------------------------------------------------------
1749 void cmTarget::ClearLinkMaps()
1750 {
1751   this->Internal->LinkImplMap.clear();
1752   this->Internal->LinkInterfaceMap.clear();
1753   this->Internal->LinkClosureMap.clear();
1754   for (cmTargetLinkInformationMap::const_iterator it
1755       = this->LinkInformation.begin();
1756       it != this->LinkInformation.end(); ++it)
1757     {
1758     delete it->second;
1759     }
1760   this->LinkInformation.clear();
1761 }
1762
1763 //----------------------------------------------------------------------------
1764 cmListFileBacktrace const& cmTarget::GetBacktrace() const
1765 {
1766   return this->Internal->Backtrace;
1767 }
1768
1769 //----------------------------------------------------------------------------
1770 std::string cmTarget::GetSupportDirectory() const
1771 {
1772   std::string dir = this->Makefile->GetCurrentOutputDirectory();
1773   dir += cmake::GetCMakeFilesDirectory();
1774   dir += "/";
1775   dir += this->Name;
1776 #if defined(__VMS)
1777   dir += "_dir";
1778 #else
1779   dir += ".dir";
1780 #endif
1781   return dir;
1782 }
1783
1784 //----------------------------------------------------------------------------
1785 bool cmTarget::IsExecutableWithExports()
1786 {
1787   return (this->GetType() == cmTarget::EXECUTABLE &&
1788           this->GetPropertyAsBool("ENABLE_EXPORTS"));
1789 }
1790
1791 //----------------------------------------------------------------------------
1792 bool cmTarget::IsLinkable()
1793 {
1794   return (this->GetType() == cmTarget::STATIC_LIBRARY ||
1795           this->GetType() == cmTarget::SHARED_LIBRARY ||
1796           this->GetType() == cmTarget::MODULE_LIBRARY ||
1797           this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
1798           this->IsExecutableWithExports());
1799 }
1800
1801 //----------------------------------------------------------------------------
1802 bool cmTarget::HasImportLibrary()
1803 {
1804   return (this->DLLPlatform &&
1805           (this->GetType() == cmTarget::SHARED_LIBRARY ||
1806            this->IsExecutableWithExports()));
1807 }
1808
1809 //----------------------------------------------------------------------------
1810 bool cmTarget::IsFrameworkOnApple()
1811 {
1812   return (this->GetType() == cmTarget::SHARED_LIBRARY &&
1813           this->Makefile->IsOn("APPLE") &&
1814           this->GetPropertyAsBool("FRAMEWORK"));
1815 }
1816
1817 //----------------------------------------------------------------------------
1818 bool cmTarget::IsAppBundleOnApple()
1819 {
1820   return (this->GetType() == cmTarget::EXECUTABLE &&
1821           this->Makefile->IsOn("APPLE") &&
1822           this->GetPropertyAsBool("MACOSX_BUNDLE"));
1823 }
1824
1825 //----------------------------------------------------------------------------
1826 bool cmTarget::IsCFBundleOnApple()
1827 {
1828   return (this->GetType() == cmTarget::MODULE_LIBRARY &&
1829           this->Makefile->IsOn("APPLE") &&
1830           this->GetPropertyAsBool("BUNDLE"));
1831 }
1832
1833 //----------------------------------------------------------------------------
1834 bool cmTarget::IsBundleOnApple()
1835 {
1836   return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
1837          this->IsCFBundleOnApple();
1838 }
1839
1840 //----------------------------------------------------------------------------
1841 class cmTargetTraceDependencies
1842 {
1843 public:
1844   cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal);
1845   void Trace();
1846 private:
1847   cmTarget* Target;
1848   cmTargetInternals* Internal;
1849   cmMakefile* Makefile;
1850   cmGlobalGenerator* GlobalGenerator;
1851   typedef cmTargetInternals::SourceEntry SourceEntry;
1852   SourceEntry* CurrentEntry;
1853   std::queue<cmSourceFile*> SourceQueue;
1854   std::set<cmSourceFile*> SourcesQueued;
1855   typedef std::map<cmStdString, cmSourceFile*> NameMapType;
1856   NameMapType NameMap;
1857
1858   void QueueSource(cmSourceFile* sf);
1859   void FollowName(std::string const& name);
1860   void FollowNames(std::vector<std::string> const& names);
1861   bool IsUtility(std::string const& dep);
1862   void CheckCustomCommand(cmCustomCommand const& cc);
1863   void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
1864 };
1865
1866 //----------------------------------------------------------------------------
1867 cmTargetTraceDependencies
1868 ::cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal):
1869   Target(target), Internal(internal)
1870 {
1871   // Convenience.
1872   this->Makefile = this->Target->GetMakefile();
1873   this->GlobalGenerator =
1874     this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
1875   this->CurrentEntry = 0;
1876
1877   // Queue all the source files already specified for the target.
1878   std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
1879   for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
1880       si != sources.end(); ++si)
1881     {
1882     this->QueueSource(*si);
1883     }
1884
1885   // Queue pre-build, pre-link, and post-build rule dependencies.
1886   this->CheckCustomCommands(this->Target->GetPreBuildCommands());
1887   this->CheckCustomCommands(this->Target->GetPreLinkCommands());
1888   this->CheckCustomCommands(this->Target->GetPostBuildCommands());
1889 }
1890
1891 //----------------------------------------------------------------------------
1892 void cmTargetTraceDependencies::Trace()
1893 {
1894   // Process one dependency at a time until the queue is empty.
1895   while(!this->SourceQueue.empty())
1896     {
1897     // Get the next source from the queue.
1898     cmSourceFile* sf = this->SourceQueue.front();
1899     this->SourceQueue.pop();
1900     this->CurrentEntry = &this->Internal->SourceEntries[sf];
1901
1902     // Queue dependencies added explicitly by the user.
1903     if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
1904       {
1905       std::vector<std::string> objDeps;
1906       cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
1907       this->FollowNames(objDeps);
1908       }
1909
1910     // Queue the source needed to generate this file, if any.
1911     this->FollowName(sf->GetFullPath());
1912
1913     // Queue dependencies added programatically by commands.
1914     this->FollowNames(sf->GetDepends());
1915
1916     // Queue custom command dependencies.
1917     if(cmCustomCommand const* cc = sf->GetCustomCommand())
1918       {
1919       this->CheckCustomCommand(*cc);
1920       }
1921     }
1922   this->CurrentEntry = 0;
1923 }
1924
1925 //----------------------------------------------------------------------------
1926 void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
1927 {
1928   if(this->SourcesQueued.insert(sf).second)
1929     {
1930     this->SourceQueue.push(sf);
1931
1932     // Make sure this file is in the target.
1933     this->Target->AddSourceFile(sf);
1934     }
1935 }
1936
1937 //----------------------------------------------------------------------------
1938 void cmTargetTraceDependencies::FollowName(std::string const& name)
1939 {
1940   NameMapType::iterator i = this->NameMap.find(name);
1941   if(i == this->NameMap.end())
1942     {
1943     // Check if we know how to generate this file.
1944     cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
1945     NameMapType::value_type entry(name, sf);
1946     i = this->NameMap.insert(entry).first;
1947     }
1948   if(cmSourceFile* sf = i->second)
1949     {
1950     // Record the dependency we just followed.
1951     if(this->CurrentEntry)
1952       {
1953       this->CurrentEntry->Depends.push_back(sf);
1954       }
1955
1956     this->QueueSource(sf);
1957     }
1958 }
1959
1960 //----------------------------------------------------------------------------
1961 void
1962 cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
1963 {
1964   for(std::vector<std::string>::const_iterator i = names.begin();
1965       i != names.end(); ++i)
1966     {
1967     this->FollowName(*i);
1968     }
1969 }
1970
1971 //----------------------------------------------------------------------------
1972 bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
1973 {
1974   // Dependencies on targets (utilities) are supposed to be named by
1975   // just the target name.  However for compatibility we support
1976   // naming the output file generated by the target (assuming there is
1977   // no output-name property which old code would not have set).  In
1978   // that case the target name will be the file basename of the
1979   // dependency.
1980   std::string util = cmSystemTools::GetFilenameName(dep);
1981   if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
1982     {
1983     util = cmSystemTools::GetFilenameWithoutLastExtension(util);
1984     }
1985
1986   // Check for a target with this name.
1987   if(cmTarget* t = this->Makefile->FindTargetToUse(util.c_str()))
1988     {
1989     // If we find the target and the dep was given as a full path,
1990     // then make sure it was not a full path to something else, and
1991     // the fact that the name matched a target was just a coincidence.
1992     if(cmSystemTools::FileIsFullPath(dep.c_str()))
1993       {
1994       if(t->GetType() >= cmTarget::EXECUTABLE &&
1995          t->GetType() <= cmTarget::MODULE_LIBRARY)
1996         {
1997         // This is really only for compatibility so we do not need to
1998         // worry about configuration names and output names.
1999         std::string tLocation = t->GetLocation(0);
2000         tLocation = cmSystemTools::GetFilenamePath(tLocation);
2001         std::string depLocation = cmSystemTools::GetFilenamePath(dep);
2002         depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
2003         tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
2004         if(depLocation == tLocation)
2005           {
2006           this->Target->AddUtility(util.c_str());
2007           return true;
2008           }
2009         }
2010       }
2011     else
2012       {
2013       // The original name of the dependency was not a full path.  It
2014       // must name a target, so add the target-level dependency.
2015       this->Target->AddUtility(util.c_str());
2016       return true;
2017       }
2018     }
2019
2020   // The dependency does not name a target built in this project.
2021   return false;
2022 }
2023
2024 //----------------------------------------------------------------------------
2025 void
2026 cmTargetTraceDependencies
2027 ::CheckCustomCommand(cmCustomCommand const& cc)
2028 {
2029   // Transform command names that reference targets built in this
2030   // project to corresponding target-level dependencies.
2031   cmGeneratorExpression ge(cc.GetBacktrace());
2032
2033   // Add target-level dependencies referenced by generator expressions.
2034   std::set<cmTarget*> targets;
2035
2036   for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
2037       cit != cc.GetCommandLines().end(); ++cit)
2038     {
2039     std::string const& command = *cit->begin();
2040     // Check for a target with this name.
2041     if(cmTarget* t = this->Makefile->FindTargetToUse(command.c_str()))
2042       {
2043       if(t->GetType() == cmTarget::EXECUTABLE)
2044         {
2045         // The command refers to an executable target built in
2046         // this project.  Add the target-level dependency to make
2047         // sure the executable is up to date before this custom
2048         // command possibly runs.
2049         this->Target->AddUtility(command.c_str());
2050         }
2051       }
2052
2053     // Check for target references in generator expressions.
2054     for(cmCustomCommandLine::const_iterator cli = cit->begin();
2055         cli != cit->end(); ++cli)
2056       {
2057       const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
2058                                                               = ge.Parse(*cli);
2059       cge->Evaluate(this->Makefile, 0, true);
2060       std::set<cmTarget*> geTargets = cge->GetTargets();
2061       for(std::set<cmTarget*>::const_iterator it = geTargets.begin();
2062           it != geTargets.end(); ++it)
2063         {
2064         targets.insert(*it);
2065         }
2066       }
2067     }
2068
2069   for(std::set<cmTarget*>::iterator ti = targets.begin();
2070       ti != targets.end(); ++ti)
2071     {
2072     this->Target->AddUtility((*ti)->GetName());
2073     }
2074
2075   // Queue the custom command dependencies.
2076   std::vector<std::string> const& depends = cc.GetDepends();
2077   for(std::vector<std::string>::const_iterator di = depends.begin();
2078       di != depends.end(); ++di)
2079     {
2080     std::string const& dep = *di;
2081     if(!this->IsUtility(dep))
2082       {
2083       // The dependency does not name a target and may be a file we
2084       // know how to generate.  Queue it.
2085       this->FollowName(dep);
2086       }
2087     }
2088 }
2089
2090 //----------------------------------------------------------------------------
2091 void
2092 cmTargetTraceDependencies
2093 ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
2094 {
2095   for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
2096       cli != commands.end(); ++cli)
2097     {
2098     this->CheckCustomCommand(*cli);
2099     }
2100 }
2101
2102 //----------------------------------------------------------------------------
2103 void cmTarget::TraceDependencies()
2104 {
2105   // CMake-generated targets have no dependencies to trace.  Normally tracing
2106   // would find nothing anyway, but when building CMake itself the "install"
2107   // target command ends up referencing the "cmake" target but we do not
2108   // really want the dependency because "install" depend on "all" anyway.
2109   if(this->GetType() == cmTarget::GLOBAL_TARGET)
2110     {
2111     return;
2112     }
2113
2114   // Use a helper object to trace the dependencies.
2115   cmTargetTraceDependencies tracer(this, this->Internal.Get());
2116   tracer.Trace();
2117 }
2118
2119 //----------------------------------------------------------------------------
2120 bool cmTarget::FindSourceFiles()
2121 {
2122   for(std::vector<cmSourceFile*>::const_iterator
2123         si = this->SourceFiles.begin();
2124       si != this->SourceFiles.end(); ++si)
2125     {
2126     std::string e;
2127     if((*si)->GetFullPath(&e).empty())
2128       {
2129       if(!e.empty())
2130         {
2131         cmake* cm = this->Makefile->GetCMakeInstance();
2132         cm->IssueMessage(cmake::FATAL_ERROR, e,
2133                          this->GetBacktrace());
2134         }
2135       return false;
2136       }
2137     }
2138   return true;
2139 }
2140
2141 //----------------------------------------------------------------------------
2142 std::vector<cmSourceFile*> const& cmTarget::GetSourceFiles()
2143 {
2144   return this->SourceFiles;
2145 }
2146
2147 //----------------------------------------------------------------------------
2148 void cmTarget::AddSourceFile(cmSourceFile* sf)
2149 {
2150   typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
2151   SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
2152   if(i == this->Internal->SourceEntries.end())
2153     {
2154     typedef cmTargetInternals::SourceEntry SourceEntry;
2155     SourceEntriesType::value_type entry(sf, SourceEntry());
2156     i = this->Internal->SourceEntries.insert(entry).first;
2157     this->SourceFiles.push_back(sf);
2158     }
2159 }
2160
2161 //----------------------------------------------------------------------------
2162 std::vector<cmSourceFile*> const*
2163 cmTarget::GetSourceDepends(cmSourceFile* sf)
2164 {
2165   typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
2166   SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
2167   if(i != this->Internal->SourceEntries.end())
2168     {
2169     return &i->second.Depends;
2170     }
2171   return 0;
2172 }
2173
2174 //----------------------------------------------------------------------------
2175 void cmTarget::AddSources(std::vector<std::string> const& srcs)
2176 {
2177   for(std::vector<std::string>::const_iterator i = srcs.begin();
2178       i != srcs.end(); ++i)
2179     {
2180     const char* src = i->c_str();
2181     if(src[0] == '$' && src[1] == '<')
2182       {
2183       this->ProcessSourceExpression(*i);
2184       }
2185     else
2186       {
2187       this->AddSource(src);
2188       }
2189     }
2190 }
2191
2192 //----------------------------------------------------------------------------
2193 cmSourceFile* cmTarget::AddSource(const char* s)
2194 {
2195   std::string src = s;
2196
2197   // For backwards compatibility replace varibles in source names.
2198   // This should eventually be removed.
2199   this->Makefile->ExpandVariablesInString(src);
2200
2201   cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
2202   this->AddSourceFile(sf);
2203   return sf;
2204 }
2205
2206 //----------------------------------------------------------------------------
2207 void cmTarget::ProcessSourceExpression(std::string const& expr)
2208 {
2209   if(strncmp(expr.c_str(), "$<TARGET_OBJECTS:", 17) == 0 &&
2210      expr[expr.size()-1] == '>')
2211     {
2212     std::string objLibName = expr.substr(17, expr.size()-18);
2213     this->ObjectLibraries.push_back(objLibName);
2214     }
2215   else
2216     {
2217     cmOStringStream e;
2218     e << "Unrecognized generator expression:\n"
2219       << "  " << expr;
2220     this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
2221     }
2222 }
2223
2224 //----------------------------------------------------------------------------
2225 struct cmTarget::SourceFileFlags
2226 cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
2227 {
2228   struct SourceFileFlags flags;
2229   this->ConstructSourceFileFlags();
2230   std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
2231     this->Internal->SourceFlagsMap.find(sf);
2232   if(si != this->Internal->SourceFlagsMap.end())
2233     {
2234     flags = si->second;
2235     }
2236   return flags;
2237 }
2238
2239 //----------------------------------------------------------------------------
2240 void cmTarget::ConstructSourceFileFlags()
2241 {
2242   if(this->Internal->SourceFileFlagsConstructed)
2243     {
2244     return;
2245     }
2246   this->Internal->SourceFileFlagsConstructed = true;
2247
2248   // Process public headers to mark the source files.
2249   if(const char* files = this->GetProperty("PUBLIC_HEADER"))
2250     {
2251     std::vector<std::string> relFiles;
2252     cmSystemTools::ExpandListArgument(files, relFiles);
2253     for(std::vector<std::string>::iterator it = relFiles.begin();
2254         it != relFiles.end(); ++it)
2255       {
2256       if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
2257         {
2258         SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
2259         flags.MacFolder = "Headers";
2260         flags.Type = cmTarget::SourceFileTypePublicHeader;
2261         }
2262       }
2263     }
2264
2265   // Process private headers after public headers so that they take
2266   // precedence if a file is listed in both.
2267   if(const char* files = this->GetProperty("PRIVATE_HEADER"))
2268     {
2269     std::vector<std::string> relFiles;
2270     cmSystemTools::ExpandListArgument(files, relFiles);
2271     for(std::vector<std::string>::iterator it = relFiles.begin();
2272         it != relFiles.end(); ++it)
2273       {
2274       if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
2275         {
2276         SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
2277         flags.MacFolder = "PrivateHeaders";
2278         flags.Type = cmTarget::SourceFileTypePrivateHeader;
2279         }
2280       }
2281     }
2282
2283   // Mark sources listed as resources.
2284   if(const char* files = this->GetProperty("RESOURCE"))
2285     {
2286     std::vector<std::string> relFiles;
2287     cmSystemTools::ExpandListArgument(files, relFiles);
2288     for(std::vector<std::string>::iterator it = relFiles.begin();
2289         it != relFiles.end(); ++it)
2290       {
2291       if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
2292         {
2293         SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
2294         flags.MacFolder = "Resources";
2295         flags.Type = cmTarget::SourceFileTypeResource;
2296         }
2297       }
2298     }
2299
2300   // Handle the MACOSX_PACKAGE_LOCATION property on source files that
2301   // were not listed in one of the other lists.
2302   std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
2303   for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
2304       si != sources.end(); ++si)
2305     {
2306     cmSourceFile* sf = *si;
2307     if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
2308       {
2309       SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
2310       if(flags.Type == cmTarget::SourceFileTypeNormal)
2311         {
2312         flags.MacFolder = location;
2313         if(strcmp(location, "Resources") == 0)
2314           {
2315           flags.Type = cmTarget::SourceFileTypeResource;
2316           }
2317         else
2318           {
2319           flags.Type = cmTarget::SourceFileTypeMacContent;
2320           }
2321         }
2322       }
2323     }
2324 }
2325
2326 //----------------------------------------------------------------------------
2327 void cmTarget::MergeLinkLibraries( cmMakefile& mf,
2328                                    const char *selfname,
2329                                    const LinkLibraryVectorType& libs )
2330 {
2331   // Only add on libraries we haven't added on before.
2332   // Assumption: the global link libraries could only grow, never shrink
2333   LinkLibraryVectorType::const_iterator i = libs.begin();
2334   i += this->PrevLinkedLibraries.size();
2335   for( ; i != libs.end(); ++i )
2336     {
2337     // This is equivalent to the target_link_libraries plain signature.
2338     this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
2339     this->AppendProperty("INTERFACE_LINK_LIBRARIES",
2340       this->GetDebugGeneratorExpressions(i->first.c_str(), i->second).c_str());
2341     }
2342   this->PrevLinkedLibraries = libs;
2343 }
2344
2345 //----------------------------------------------------------------------------
2346 void cmTarget::AddLinkDirectory(const char* d)
2347 {
2348   // Make sure we don't add unnecessary search directories.
2349   if(this->LinkDirectoriesEmmitted.insert(d).second)
2350     {
2351     this->LinkDirectories.push_back(d);
2352     }
2353 }
2354
2355 //----------------------------------------------------------------------------
2356 const std::vector<std::string>& cmTarget::GetLinkDirectories()
2357 {
2358   return this->LinkDirectories;
2359 }
2360
2361 //----------------------------------------------------------------------------
2362 cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
2363 {
2364   // No configuration is always optimized.
2365   if(!(config && *config))
2366     {
2367     return cmTarget::OPTIMIZED;
2368     }
2369
2370   // Get the list of configurations considered to be DEBUG.
2371   std::vector<std::string> const& debugConfigs =
2372     this->Makefile->GetCMakeInstance()->GetDebugConfigs();
2373
2374   // Check if any entry in the list matches this configuration.
2375   std::string configUpper = cmSystemTools::UpperCase(config);
2376   for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
2377       i != debugConfigs.end(); ++i)
2378     {
2379     if(*i == configUpper)
2380       {
2381       return cmTarget::DEBUG;
2382       }
2383     }
2384
2385   // The current configuration is not a debug configuration.
2386   return cmTarget::OPTIMIZED;
2387 }
2388
2389 //----------------------------------------------------------------------------
2390 void cmTarget::ClearDependencyInformation( cmMakefile& mf,
2391                                            const char* target )
2392 {
2393   // Clear the dependencies. The cache variable must exist iff we are
2394   // recording dependency information for this target.
2395   std::string depname = target;
2396   depname += "_LIB_DEPENDS";
2397   if (this->RecordDependencies)
2398     {
2399     mf.AddCacheDefinition(depname.c_str(), "",
2400                           "Dependencies for target", cmCacheManager::STATIC);
2401     }
2402   else
2403     {
2404     if (mf.GetDefinition( depname.c_str() ))
2405       {
2406       std::string message = "Target ";
2407       message += target;
2408       message += " has dependency information when it shouldn't.\n";
2409       message += "Your cache is probably stale. Please remove the entry\n  ";
2410       message += depname;
2411       message += "\nfrom the cache.";
2412       cmSystemTools::Error( message.c_str() );
2413       }
2414     }
2415 }
2416
2417 //----------------------------------------------------------------------------
2418 bool cmTarget::NameResolvesToFramework(const std::string& libname)
2419 {
2420   return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
2421     NameResolvesToFramework(libname);
2422 }
2423
2424 //----------------------------------------------------------------------------
2425 void cmTarget::GetDirectLinkLibraries(const char *config,
2426                             std::vector<std::string> &libs, cmTarget *head)
2427 {
2428   const char *prop = this->GetProperty("LINK_LIBRARIES");
2429   if (prop)
2430     {
2431     cmListFileBacktrace lfbt;
2432     cmGeneratorExpression ge(lfbt);
2433     const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
2434
2435     cmGeneratorExpressionDAGChecker dagChecker(lfbt,
2436                                         this->GetName(),
2437                                         "LINK_LIBRARIES", 0, 0);
2438     cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile,
2439                                         config,
2440                                         false,
2441                                         head,
2442                                         &dagChecker),
2443                                       libs);
2444
2445     std::set<cmStdString> seenProps = cge->GetSeenTargetProperties();
2446     for (std::set<cmStdString>::const_iterator it = seenProps.begin();
2447         it != seenProps.end(); ++it)
2448       {
2449       if (!this->GetProperty(it->c_str()))
2450         {
2451         this->LinkImplicitNullProperties.insert(*it);
2452         }
2453       }
2454     }
2455 }
2456
2457 //----------------------------------------------------------------------------
2458 std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
2459                                   cmTarget::LinkLibraryType llt)
2460 {
2461   if (llt == GENERAL)
2462     {
2463     return value;
2464     }
2465
2466   // Get the list of configurations considered to be DEBUG.
2467   std::vector<std::string> const& debugConfigs =
2468                       this->Makefile->GetCMakeInstance()->GetDebugConfigs();
2469
2470   std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
2471
2472   if (debugConfigs.size() > 1)
2473     {
2474     for(std::vector<std::string>::const_iterator
2475           li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
2476       {
2477       configString += ",$<CONFIG:" + *li + ">";
2478       }
2479     configString = "$<OR:" + configString + ">";
2480     }
2481
2482   if (llt == OPTIMIZED)
2483     {
2484     configString = "$<NOT:" + configString + ">";
2485     }
2486   return "$<" + configString + ":" + value + ">";
2487 }
2488
2489 //----------------------------------------------------------------------------
2490 static std::string targetNameGenex(const char *lib)
2491 {
2492   return std::string("$<TARGET_NAME:") + lib + ">";
2493 }
2494
2495 //----------------------------------------------------------------------------
2496 bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
2497 {
2498   bool ret = true;
2499   if (!this->TLLCommands.empty())
2500     {
2501     if (this->TLLCommands.back().first != signature)
2502       {
2503       ret = false;
2504       }
2505     }
2506   cmListFileBacktrace lfbt;
2507   this->Makefile->GetBacktrace(lfbt);
2508   this->TLLCommands.push_back(std::make_pair(signature, lfbt));
2509   return ret;
2510 }
2511
2512 //----------------------------------------------------------------------------
2513 void cmTarget::GetTllSignatureTraces(cmOStringStream &s,
2514                                      TLLSignature sig) const
2515 {
2516   std::vector<cmListFileBacktrace> sigs;
2517   typedef std::vector<std::pair<TLLSignature, cmListFileBacktrace> > Container;
2518   for(Container::const_iterator it = this->TLLCommands.begin();
2519       it != this->TLLCommands.end(); ++it)
2520     {
2521     if (it->first == sig)
2522       {
2523       sigs.push_back(it->second);
2524       }
2525     }
2526   if (!sigs.empty())
2527     {
2528     const char *sigString
2529                         = (sig == cmTarget::KeywordTLLSignature ? "keyword"
2530                                                                 : "plain");
2531     s << "The uses of the " << sigString << " signature are here:\n";
2532     std::set<cmStdString> emitted;
2533     for(std::vector<cmListFileBacktrace>::const_iterator it = sigs.begin();
2534         it != sigs.end(); ++it)
2535       {
2536       cmListFileBacktrace::const_iterator i = it->begin();
2537       if(i != it->end())
2538         {
2539         cmListFileContext const& lfc = *i;
2540         cmOStringStream line;
2541         line << " * " << (lfc.Line? "": " in ") << lfc << std::endl;
2542         if (emitted.insert(line.str()).second)
2543           {
2544           s << line.str();
2545           }
2546         ++i;
2547         }
2548       }
2549     }
2550 }
2551
2552 //----------------------------------------------------------------------------
2553 void cmTarget::AddLinkLibrary(cmMakefile& mf,
2554                               const char *target, const char* lib,
2555                               LinkLibraryType llt)
2556 {
2557   // Never add a self dependency, even if the user asks for it.
2558   if(strcmp( target, lib ) == 0)
2559     {
2560     return;
2561     }
2562
2563   {
2564   cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
2565   const bool isNonImportedTarget = tgt && !tgt->IsImported();
2566
2567   const std::string libName = (isNonImportedTarget && llt != GENERAL)
2568                                                         ? targetNameGenex(lib)
2569                                                         : std::string(lib);
2570   this->AppendProperty("LINK_LIBRARIES",
2571                        this->GetDebugGeneratorExpressions(libName,
2572                                                           llt).c_str());
2573   }
2574
2575   if (cmGeneratorExpression::Find(lib) != std::string::npos)
2576     {
2577     return;
2578     }
2579
2580   cmTarget::LibraryID tmp;
2581   tmp.first = lib;
2582   tmp.second = llt;
2583   this->LinkLibraries.push_back( tmp );
2584   this->OriginalLinkLibraries.push_back(tmp);
2585   this->ClearLinkMaps();
2586
2587   // Add the explicit dependency information for this target. This is
2588   // simply a set of libraries separated by ";". There should always
2589   // be a trailing ";". These library names are not canonical, in that
2590   // they may be "-framework x", "-ly", "/path/libz.a", etc.
2591   // We shouldn't remove duplicates here because external libraries
2592   // may be purposefully duplicated to handle recursive dependencies,
2593   // and we removing one instance will break the link line. Duplicates
2594   // will be appropriately eliminated at emit time.
2595   if(this->RecordDependencies)
2596     {
2597     std::string targetEntry = target;
2598     targetEntry += "_LIB_DEPENDS";
2599     std::string dependencies;
2600     const char* old_val = mf.GetDefinition( targetEntry.c_str() );
2601     if( old_val )
2602       {
2603       dependencies += old_val;
2604       }
2605     switch (llt)
2606       {
2607       case cmTarget::GENERAL:
2608         dependencies += "general";
2609         break;
2610       case cmTarget::DEBUG:
2611         dependencies += "debug";
2612         break;
2613       case cmTarget::OPTIMIZED:
2614         dependencies += "optimized";
2615         break;
2616       }
2617     dependencies += ";";
2618     dependencies += lib;
2619     dependencies += ";";
2620     mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
2621                            "Dependencies for the target",
2622                            cmCacheManager::STATIC );
2623     }
2624
2625 }
2626
2627 //----------------------------------------------------------------------------
2628 void
2629 cmTarget::AddSystemIncludeDirectories(const std::set<cmStdString> &incs)
2630 {
2631   for(std::set<cmStdString>::const_iterator li = incs.begin();
2632       li != incs.end(); ++li)
2633     {
2634     this->SystemIncludeDirectories.insert(*li);
2635     }
2636 }
2637
2638 //----------------------------------------------------------------------------
2639 void
2640 cmTarget::AddSystemIncludeDirectories(const std::vector<std::string> &incs)
2641 {
2642   for(std::vector<std::string>::const_iterator li = incs.begin();
2643       li != incs.end(); ++li)
2644     {
2645     this->SystemIncludeDirectories.insert(*li);
2646     }
2647 }
2648
2649 //----------------------------------------------------------------------------
2650 void cmTarget::FinalizeSystemIncludeDirectories()
2651 {
2652   for (std::vector<cmValueWithOrigin>::const_iterator
2653       it = this->Internal->LinkInterfacePropertyEntries.begin(),
2654       end = this->Internal->LinkInterfacePropertyEntries.end();
2655       it != end; ++it)
2656     {
2657     {
2658     cmListFileBacktrace lfbt;
2659     cmGeneratorExpression ge(lfbt);
2660     cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
2661                                                       ge.Parse(it->Value);
2662     std::string targetName = cge->Evaluate(this->Makefile, 0,
2663                                       false, this, 0, 0);
2664     if (!this->Makefile->FindTargetToUse(targetName.c_str()))
2665       {
2666       continue;
2667       }
2668     }
2669     std::string includeGenex = "$<TARGET_PROPERTY:" +
2670                         it->Value + ",INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>";
2671     if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
2672       {
2673       // Because it->Value is a generator expression, ensure that it
2674       // evaluates to the non-empty string before being used in the
2675       // TARGET_PROPERTY expression.
2676       includeGenex = "$<$<BOOL:" + it->Value + ">:" + includeGenex + ">";
2677       }
2678     this->SystemIncludeDirectories.insert(includeGenex);
2679     }
2680 }
2681
2682 //----------------------------------------------------------------------------
2683 void
2684 cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
2685 {
2686   // There are two key parts of the dependency analysis: (1)
2687   // determining the libraries in the link line, and (2) constructing
2688   // the dependency graph for those libraries.
2689   //
2690   // The latter is done using the cache entries that record the
2691   // dependencies of each library.
2692   //
2693   // The former is a more thorny issue, since it is not clear how to
2694   // determine if two libraries listed on the link line refer to the a
2695   // single library or not. For example, consider the link "libraries"
2696   //    /usr/lib/libtiff.so -ltiff
2697   // Is this one library or two? The solution implemented here is the
2698   // simplest (and probably the only practical) one: two libraries are
2699   // the same if their "link strings" are identical. Thus, the two
2700   // libraries above are considered distinct. This also means that for
2701   // dependency analysis to be effective, the CMake user must specify
2702   // libraries build by his project without using any linker flags or
2703   // file extensions. That is,
2704   //    LINK_LIBRARIES( One Two )
2705   // instead of
2706   //    LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
2707   // The former is probably what most users would do, but it never
2708   // hurts to document the assumptions. :-) Therefore, in the analysis
2709   // code, the "canonical name" of a library is simply its name as
2710   // given to a LINK_LIBRARIES command.
2711   //
2712   // Also, we will leave the original link line intact; we will just add any
2713   // dependencies that were missing.
2714   //
2715   // There is a problem with recursive external libraries
2716   // (i.e. libraries with no dependency information that are
2717   // recursively dependent). We must make sure that the we emit one of
2718   // the libraries twice to satisfy the recursion, but we shouldn't
2719   // emit it more times than necessary. In particular, we must make
2720   // sure that handling this improbable case doesn't cost us when
2721   // dealing with the common case of non-recursive libraries. The
2722   // solution is to assume that the recursion is satisfied at one node
2723   // of the dependency tree. To illustrate, assume libA and libB are
2724   // extrenal and mutually dependent. Suppose libX depends on
2725   // libA, and libY on libA and libX. Then
2726   //   TARGET_LINK_LIBRARIES( Y X A B A )
2727   //   TARGET_LINK_LIBRARIES( X A B A )
2728   //   TARGET_LINK_LIBRARIES( Exec Y )
2729   // would result in "-lY -lX -lA -lB -lA". This is the correct way to
2730   // specify the dependencies, since the mutual dependency of A and B
2731   // is resolved *every time libA is specified*.
2732   //
2733   // Something like
2734   //   TARGET_LINK_LIBRARIES( Y X A B A )
2735   //   TARGET_LINK_LIBRARIES( X A B )
2736   //   TARGET_LINK_LIBRARIES( Exec Y )
2737   // would result in "-lY -lX -lA -lB", and the mutual dependency
2738   // information is lost. This is because in some case (Y), the mutual
2739   // dependency of A and B is listed, while in another other case (X),
2740   // it is not. Depending on which line actually emits A, the mutual
2741   // dependency may or may not be on the final link line.  We can't
2742   // handle this pathalogical case cleanly without emitting extra
2743   // libraries for the normal cases. Besides, the dependency
2744   // information for X is wrong anyway: if we build an executable
2745   // depending on X alone, we would not have the mutual dependency on
2746   // A and B resolved.
2747   //
2748   // IMPROVEMENTS:
2749   // -- The current algorithm will not always pick the "optimal" link line
2750   //    when recursive dependencies are present. It will instead break the
2751   //    cycles at an aribtrary point. The majority of projects won't have
2752   //    cyclic dependencies, so this is probably not a big deal. Note that
2753   //    the link line is always correct, just not necessary optimal.
2754
2755  {
2756  // Expand variables in link library names.  This is for backwards
2757  // compatibility with very early CMake versions and should
2758  // eventually be removed.  This code was moved here from the end of
2759  // old source list processing code which was called just before this
2760  // method.
2761  for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
2762      p != this->LinkLibraries.end(); ++p)
2763    {
2764    this->Makefile->ExpandVariablesInString(p->first, true, true);
2765    }
2766  }
2767
2768  // The dependency map.
2769  DependencyMap dep_map;
2770
2771  // 1. Build the dependency graph
2772  //
2773  for(LinkLibraryVectorType::reverse_iterator lib
2774        = this->LinkLibraries.rbegin();
2775      lib != this->LinkLibraries.rend(); ++lib)
2776    {
2777    this->GatherDependencies( mf, *lib, dep_map);
2778    }
2779
2780  // 2. Remove any dependencies that are already satisfied in the original
2781  // link line.
2782  //
2783  for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
2784      lib != this->LinkLibraries.end(); ++lib)
2785    {
2786    for( LinkLibraryVectorType::iterator lib2 = lib;
2787         lib2 != this->LinkLibraries.end(); ++lib2)
2788      {
2789      this->DeleteDependency( dep_map, *lib, *lib2);
2790      }
2791    }
2792
2793
2794  // 3. Create the new link line by simply emitting any dependencies that are
2795  // missing.  Start from the back and keep adding.
2796  //
2797  std::set<DependencyMap::key_type> done, visited;
2798  std::vector<DependencyMap::key_type> newLinkLibraries;
2799  for(LinkLibraryVectorType::reverse_iterator lib =
2800        this->LinkLibraries.rbegin();
2801      lib != this->LinkLibraries.rend(); ++lib)
2802    {
2803    // skip zero size library entries, this may happen
2804    // if a variable expands to nothing.
2805    if (lib->first.size() != 0)
2806      {
2807      this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
2808      }
2809    }
2810
2811  // 4. Add the new libraries to the link line.
2812  //
2813  for( std::vector<DependencyMap::key_type>::reverse_iterator k =
2814         newLinkLibraries.rbegin();
2815       k != newLinkLibraries.rend(); ++k )
2816    {
2817    // get the llt from the dep_map
2818    this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
2819    }
2820  this->LinkLibrariesAnalyzed = true;
2821 }
2822
2823 //----------------------------------------------------------------------------
2824 void cmTarget::InsertDependency( DependencyMap& depMap,
2825                                  const LibraryID& lib,
2826                                  const LibraryID& dep)
2827 {
2828   depMap[lib].push_back(dep);
2829 }
2830
2831 //----------------------------------------------------------------------------
2832 void cmTarget::DeleteDependency( DependencyMap& depMap,
2833                                  const LibraryID& lib,
2834                                  const LibraryID& dep)
2835 {
2836   // Make sure there is an entry in the map for lib. If so, delete all
2837   // dependencies to dep. There may be repeated entries because of
2838   // external libraries that are specified multiple times.
2839   DependencyMap::iterator map_itr = depMap.find( lib );
2840   if( map_itr != depMap.end() )
2841     {
2842     DependencyList& depList = map_itr->second;
2843     DependencyList::iterator itr;
2844     while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
2845            depList.end() )
2846       {
2847       depList.erase( itr );
2848       }
2849     }
2850 }
2851
2852 //----------------------------------------------------------------------------
2853 void cmTarget::Emit(const LibraryID lib,
2854                     const DependencyMap& dep_map,
2855                     std::set<LibraryID>& emitted,
2856                     std::set<LibraryID>& visited,
2857                     DependencyList& link_line )
2858 {
2859   // It's already been emitted
2860   if( emitted.find(lib) != emitted.end() )
2861     {
2862     return;
2863     }
2864
2865   // Emit the dependencies only if this library node hasn't been
2866   // visited before. If it has, then we have a cycle. The recursion
2867   // that got us here should take care of everything.
2868
2869   if( visited.insert(lib).second )
2870     {
2871     if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
2872       {
2873       const DependencyList& dep_on = dep_map.find( lib )->second;
2874       DependencyList::const_reverse_iterator i;
2875
2876       // To cater for recursive external libraries, we must emit
2877       // duplicates on this link line *unless* they were emitted by
2878       // some other node, in which case we assume that the recursion
2879       // was resolved then. We making the simplifying assumption that
2880       // any duplicates on a single link line are on purpose, and must
2881       // be preserved.
2882
2883       // This variable will keep track of the libraries that were
2884       // emitted directly from the current node, and not from a
2885       // recursive call. This way, if we come across a library that
2886       // has already been emitted, we repeat it iff it has been
2887       // emitted here.
2888       std::set<DependencyMap::key_type> emitted_here;
2889       for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
2890         {
2891         if( emitted_here.find(*i) != emitted_here.end() )
2892           {
2893           // a repeat. Must emit.
2894           emitted.insert(*i);
2895           link_line.push_back( *i );
2896           }
2897         else
2898           {
2899           // Emit only if no-one else has
2900           if( emitted.find(*i) == emitted.end() )
2901             {
2902             // emit dependencies
2903             Emit( *i, dep_map, emitted, visited, link_line );
2904             // emit self
2905             emitted.insert(*i);
2906             emitted_here.insert(*i);
2907             link_line.push_back( *i );
2908             }
2909           }
2910         }
2911       }
2912     }
2913 }
2914
2915 //----------------------------------------------------------------------------
2916 void cmTarget::GatherDependencies( const cmMakefile& mf,
2917                                    const LibraryID& lib,
2918                                    DependencyMap& dep_map)
2919 {
2920   // If the library is already in the dependency map, then it has
2921   // already been fully processed.
2922   if( dep_map.find(lib) != dep_map.end() )
2923     {
2924     return;
2925     }
2926
2927   const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
2928   if( deps && strcmp(deps,"") != 0 )
2929     {
2930     // Make sure this library is in the map, even if it has an empty
2931     // set of dependencies. This distinguishes the case of explicitly
2932     // no dependencies with that of unspecified dependencies.
2933     dep_map[lib];
2934
2935     // Parse the dependency information, which is a set of
2936     // type, library pairs separated by ";". There is always a trailing ";".
2937     cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
2938     std::string depline = deps;
2939     std::string::size_type start = 0;
2940     std::string::size_type end;
2941     end = depline.find( ";", start );
2942     while( end != std::string::npos )
2943       {
2944       std::string l = depline.substr( start, end-start );
2945       if( l.size() != 0 )
2946         {
2947         if (l == "debug")
2948           {
2949           llt = cmTarget::DEBUG;
2950           }
2951         else if (l == "optimized")
2952           {
2953           llt = cmTarget::OPTIMIZED;
2954           }
2955         else if (l == "general")
2956           {
2957           llt = cmTarget::GENERAL;
2958           }
2959         else
2960           {
2961           LibraryID lib2(l,llt);
2962           this->InsertDependency( dep_map, lib, lib2);
2963           this->GatherDependencies( mf, lib2, dep_map);
2964           llt = cmTarget::GENERAL;
2965           }
2966         }
2967       start = end+1; // skip the ;
2968       end = depline.find( ";", start );
2969       }
2970     // cannot depend on itself
2971     this->DeleteDependency( dep_map, lib, lib);
2972     }
2973 }
2974
2975 //----------------------------------------------------------------------------
2976 void cmTarget::SetProperty(const char* prop, const char* value)
2977 {
2978   if (!prop)
2979     {
2980     return;
2981     }
2982   if (strcmp(prop, "NAME") == 0)
2983     {
2984     cmOStringStream e;
2985     e << "NAME property is read-only\n";
2986     this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
2987     return;
2988     }
2989   if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
2990     {
2991     cmListFileBacktrace lfbt;
2992     this->Makefile->GetBacktrace(lfbt);
2993     cmGeneratorExpression ge(lfbt);
2994     deleteAndClear(this->Internal->IncludeDirectoriesEntries);
2995     cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
2996     this->Internal->IncludeDirectoriesEntries.push_back(
2997                           new cmTargetInternals::TargetPropertyEntry(cge));
2998     return;
2999     }
3000   if(strcmp(prop,"COMPILE_OPTIONS") == 0)
3001     {
3002     cmListFileBacktrace lfbt;
3003     this->Makefile->GetBacktrace(lfbt);
3004     cmGeneratorExpression ge(lfbt);
3005     deleteAndClear(this->Internal->CompileOptionsEntries);
3006     cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
3007     this->Internal->CompileOptionsEntries.push_back(
3008                           new cmTargetInternals::TargetPropertyEntry(cge));
3009     return;
3010     }
3011   if(strcmp(prop,"COMPILE_DEFINITIONS") == 0)
3012     {
3013     cmListFileBacktrace lfbt;
3014     this->Makefile->GetBacktrace(lfbt);
3015     cmGeneratorExpression ge(lfbt);
3016     deleteAndClear(this->Internal->CompileDefinitionsEntries);
3017     cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
3018     this->Internal->CompileDefinitionsEntries.push_back(
3019                           new cmTargetInternals::TargetPropertyEntry(cge));
3020     return;
3021     }
3022   if(strcmp(prop,"EXPORT_NAME") == 0 && this->IsImported())
3023     {
3024     cmOStringStream e;
3025     e << "EXPORT_NAME property can't be set on imported targets (\""
3026           << this->Name << "\")\n";
3027     this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
3028     return;
3029     }
3030   if (strcmp(prop, "LINK_LIBRARIES") == 0)
3031     {
3032     this->Internal->LinkInterfacePropertyEntries.clear();
3033     if (cmGeneratorExpression::IsValidTargetName(value)
3034         || cmGeneratorExpression::Find(value) != std::string::npos)
3035       {
3036       cmListFileBacktrace lfbt;
3037       this->Makefile->GetBacktrace(lfbt);
3038       cmValueWithOrigin entry(value, lfbt);
3039       this->Internal->LinkInterfacePropertyEntries.push_back(entry);
3040       }
3041     // Fall through
3042     }
3043   this->Properties.SetProperty(prop, value, cmProperty::TARGET);
3044   this->MaybeInvalidatePropertyCache(prop);
3045 }
3046
3047 //----------------------------------------------------------------------------
3048 void cmTarget::AppendProperty(const char* prop, const char* value,
3049                               bool asString)
3050 {
3051   if (!prop)
3052     {
3053     return;
3054     }
3055   if (strcmp(prop, "NAME") == 0)
3056     {
3057     cmOStringStream e;
3058     e << "NAME property is read-only\n";
3059     this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
3060     return;
3061     }
3062   if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
3063     {
3064     cmListFileBacktrace lfbt;
3065     this->Makefile->GetBacktrace(lfbt);
3066     cmGeneratorExpression ge(lfbt);
3067     this->Internal->IncludeDirectoriesEntries.push_back(
3068               new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
3069     return;
3070     }
3071   if(strcmp(prop,"COMPILE_OPTIONS") == 0)
3072     {
3073     cmListFileBacktrace lfbt;
3074     this->Makefile->GetBacktrace(lfbt);
3075     cmGeneratorExpression ge(lfbt);
3076     this->Internal->CompileOptionsEntries.push_back(
3077               new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
3078     return;
3079     }
3080   if(strcmp(prop,"COMPILE_DEFINITIONS") == 0)
3081     {
3082     cmListFileBacktrace lfbt;
3083     this->Makefile->GetBacktrace(lfbt);
3084     cmGeneratorExpression ge(lfbt);
3085     this->Internal->CompileDefinitionsEntries.push_back(
3086               new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
3087     return;
3088     }
3089   if(strcmp(prop,"EXPORT_NAME") == 0 && this->IsImported())
3090     {
3091     cmOStringStream e;
3092     e << "EXPORT_NAME property can't be set on imported targets (\""
3093           << this->Name << "\")\n";
3094     this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
3095     return;
3096     }
3097   if (strcmp(prop, "LINK_LIBRARIES") == 0)
3098     {
3099     if (cmGeneratorExpression::IsValidTargetName(value)
3100         || cmGeneratorExpression::Find(value) != std::string::npos)
3101       {
3102       cmListFileBacktrace lfbt;
3103       this->Makefile->GetBacktrace(lfbt);
3104       cmValueWithOrigin entry(value, lfbt);
3105       this->Internal->LinkInterfacePropertyEntries.push_back(entry);
3106       }
3107     // Fall through
3108     }
3109   this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
3110   this->MaybeInvalidatePropertyCache(prop);
3111 }
3112
3113 //----------------------------------------------------------------------------
3114 const char* cmTarget::GetExportName()
3115 {
3116   const char *exportName = this->GetProperty("EXPORT_NAME");
3117
3118   if (exportName && *exportName)
3119     {
3120     if (!cmGeneratorExpression::IsValidTargetName(exportName))
3121       {
3122       cmOStringStream e;
3123       e << "EXPORT_NAME property \"" << exportName << "\" for \""
3124         << this->GetName() << "\": is not valid.";
3125       cmSystemTools::Error(e.str().c_str());
3126       return "";
3127       }
3128     return exportName;
3129     }
3130   return this->GetName();
3131 }
3132
3133 //----------------------------------------------------------------------------
3134 void cmTarget::AppendBuildInterfaceIncludes()
3135 {
3136   if(this->GetType() != cmTarget::SHARED_LIBRARY &&
3137      this->GetType() != cmTarget::STATIC_LIBRARY &&
3138      this->GetType() != cmTarget::MODULE_LIBRARY &&
3139      !this->IsExecutableWithExports())
3140     {
3141     return;
3142     }
3143   if (this->BuildInterfaceIncludesAppended)
3144     {
3145     return;
3146     }
3147   this->BuildInterfaceIncludesAppended = true;
3148
3149   if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
3150     {
3151     const char *binDir = this->Makefile->GetStartOutputDirectory();
3152     const char *srcDir = this->Makefile->GetStartDirectory();
3153     const std::string dirs = std::string(binDir ? binDir : "")
3154                             + std::string(binDir ? ";" : "")
3155                             + std::string(srcDir ? srcDir : "");
3156     if (!dirs.empty())
3157       {
3158       this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
3159                             ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
3160       }
3161     }
3162 }
3163
3164 //----------------------------------------------------------------------------
3165 void cmTarget::InsertInclude(const cmValueWithOrigin &entry,
3166                      bool before)
3167 {
3168   cmGeneratorExpression ge(entry.Backtrace);
3169
3170   std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
3171                 = before ? this->Internal->IncludeDirectoriesEntries.begin()
3172                          : this->Internal->IncludeDirectoriesEntries.end();
3173
3174   this->Internal->IncludeDirectoriesEntries.insert(position,
3175       new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
3176 }
3177
3178 //----------------------------------------------------------------------------
3179 void cmTarget::InsertCompileOption(const cmValueWithOrigin &entry,
3180                      bool before)
3181 {
3182   cmGeneratorExpression ge(entry.Backtrace);
3183
3184   std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
3185                 = before ? this->Internal->CompileOptionsEntries.begin()
3186                          : this->Internal->CompileOptionsEntries.end();
3187
3188   this->Internal->CompileOptionsEntries.insert(position,
3189       new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
3190 }
3191
3192 //----------------------------------------------------------------------------
3193 void cmTarget::InsertCompileDefinition(const cmValueWithOrigin &entry,
3194                      bool before)
3195 {
3196   cmGeneratorExpression ge(entry.Backtrace);
3197
3198   std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
3199                 = before ? this->Internal->CompileDefinitionsEntries.begin()
3200                          : this->Internal->CompileDefinitionsEntries.end();
3201
3202   this->Internal->CompileDefinitionsEntries.insert(position,
3203       new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
3204 }
3205
3206 //----------------------------------------------------------------------------
3207 static void processIncludeDirectories(cmTarget *tgt,
3208       const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
3209       std::vector<std::string> &includes,
3210       std::set<std::string> &uniqueIncludes,
3211       cmGeneratorExpressionDAGChecker *dagChecker,
3212       const char *config, bool debugIncludes)
3213 {
3214   cmMakefile *mf = tgt->GetMakefile();
3215
3216   for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
3217       it = entries.begin(), end = entries.end(); it != end; ++it)
3218     {
3219     bool testIsOff = true;
3220     bool cacheIncludes = false;
3221     std::vector<std::string> entryIncludes = (*it)->CachedEntries;
3222     if(!entryIncludes.empty())
3223       {
3224       testIsOff = false;
3225       }
3226     else
3227       {
3228       cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
3229                                                 config,
3230                                                 false,
3231                                                 tgt,
3232                                                 dagChecker),
3233                                       entryIncludes);
3234       if (mf->IsGeneratingBuildSystem()
3235           && !(*it)->ge->GetHadContextSensitiveCondition())
3236         {
3237         cacheIncludes = true;
3238         }
3239       }
3240     std::string usedIncludes;
3241     for(std::vector<std::string>::iterator
3242           li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
3243       {
3244       cmTarget *dependentTarget =
3245                               mf->FindTargetToUse((*it)->TargetName.c_str());
3246
3247       const bool fromImported = dependentTarget
3248                              && dependentTarget->IsImported();
3249
3250       if (fromImported && !cmSystemTools::FileExists(li->c_str()))
3251         {
3252         cmOStringStream e;
3253         e << "Imported target \"" << (*it)->TargetName << "\" includes "
3254              "non-existent path\n  \"" << *li << "\"\nin its "
3255              "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
3256              "* The path was deleted, renamed, or moved to another "
3257              "location.\n"
3258              "* An install or uninstall procedure did not complete "
3259              "successfully.\n"
3260              "* The installation package was faulty and references files it "
3261              "does not provide.\n";
3262         tgt->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
3263         return;
3264         }
3265
3266       if (!cmSystemTools::FileIsFullPath(li->c_str()))
3267         {
3268         cmOStringStream e;
3269         bool noMessage = false;
3270         cmake::MessageType messageType = cmake::FATAL_ERROR;
3271         if (!(*it)->TargetName.empty())
3272           {
3273           e << "Target \"" << (*it)->TargetName << "\" contains relative "
3274             "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
3275             "  \"" << *li << "\"";
3276           }
3277         else
3278           {
3279           switch(tgt->GetPolicyStatusCMP0021())
3280             {
3281             case cmPolicies::WARN:
3282               {
3283               cmOStringStream w;
3284               e << (mf->GetPolicies()
3285                     ->GetPolicyWarning(cmPolicies::CMP0021)) << "\n";
3286               messageType = cmake::AUTHOR_WARNING;
3287               }
3288               break;
3289             case cmPolicies::OLD:
3290               noMessage = true;
3291             case cmPolicies::REQUIRED_IF_USED:
3292             case cmPolicies::REQUIRED_ALWAYS:
3293             case cmPolicies::NEW:
3294               // Issue the fatal message.
3295               break;
3296             }
3297           e << "Found relative path while evaluating include directories of "
3298           "\"" << tgt->GetName() << "\":\n  \"" << *li << "\"\n";
3299           }
3300         if (!noMessage)
3301           {
3302           tgt->GetMakefile()->IssueMessage(messageType, e.str().c_str());
3303           if (messageType == cmake::FATAL_ERROR)
3304             {
3305             return;
3306             }
3307           }
3308         }
3309
3310       if (testIsOff && !cmSystemTools::IsOff(li->c_str()))
3311         {
3312         cmSystemTools::ConvertToUnixSlashes(*li);
3313         }
3314       std::string inc = *li;
3315
3316       if(uniqueIncludes.insert(inc).second)
3317         {
3318         includes.push_back(inc);
3319         if (debugIncludes)
3320           {
3321           usedIncludes += " * " + inc + "\n";
3322           }
3323         }
3324       }
3325     if (cacheIncludes)
3326       {
3327       (*it)->CachedEntries = entryIncludes;
3328       }
3329     if (!usedIncludes.empty())
3330       {
3331       mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
3332                             std::string("Used includes for target ")
3333                             + tgt->GetName() + ":\n"
3334                             + usedIncludes, (*it)->ge->GetBacktrace());
3335       }
3336     }
3337 }
3338
3339 //----------------------------------------------------------------------------
3340 std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
3341 {
3342   std::vector<std::string> includes;
3343   std::set<std::string> uniqueIncludes;
3344   cmListFileBacktrace lfbt;
3345
3346   cmGeneratorExpressionDAGChecker dagChecker(lfbt,
3347                                              this->GetName(),
3348                                              "INCLUDE_DIRECTORIES", 0, 0);
3349
3350   this->AppendBuildInterfaceIncludes();
3351
3352   std::vector<std::string> debugProperties;
3353   const char *debugProp =
3354               this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
3355   if (debugProp)
3356     {
3357     cmSystemTools::ExpandListArgument(debugProp, debugProperties);
3358     }
3359
3360   bool debugIncludes = !this->DebugIncludesDone
3361                     && std::find(debugProperties.begin(),
3362                                  debugProperties.end(),
3363                                  "INCLUDE_DIRECTORIES")
3364                         != debugProperties.end();
3365
3366   if (this->Makefile->IsGeneratingBuildSystem())
3367     {
3368     this->DebugIncludesDone = true;
3369     }
3370
3371   processIncludeDirectories(this,
3372                             this->Internal->IncludeDirectoriesEntries,
3373                             includes,
3374                             uniqueIncludes,
3375                             &dagChecker,
3376                             config,
3377                             debugIncludes);
3378
3379   std::string configString = config ? config : "";
3380   if (!this->Internal->CacheLinkInterfaceIncludeDirectoriesDone[configString])
3381     {
3382     for (std::vector<cmValueWithOrigin>::const_iterator
3383         it = this->Internal->LinkInterfacePropertyEntries.begin(),
3384         end = this->Internal->LinkInterfacePropertyEntries.end();
3385         it != end; ++it)
3386       {
3387       {
3388       cmGeneratorExpression ge(lfbt);
3389       cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
3390                                                         ge.Parse(it->Value);
3391       std::string result = cge->Evaluate(this->Makefile, config,
3392                                         false, this, 0, 0);
3393       if (!this->Makefile->FindTargetToUse(result.c_str()))
3394         {
3395         continue;
3396         }
3397       }
3398       std::string includeGenex = "$<TARGET_PROPERTY:" +
3399                               it->Value + ",INTERFACE_INCLUDE_DIRECTORIES>";
3400       if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
3401         {
3402         // Because it->Value is a generator expression, ensure that it
3403         // evaluates to the non-empty string before being used in the
3404         // TARGET_PROPERTY expression.
3405         includeGenex = "$<$<BOOL:" + it->Value + ">:" + includeGenex + ">";
3406         }
3407       cmGeneratorExpression ge(it->Backtrace);
3408       cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
3409                                                               includeGenex);
3410
3411       this->Internal
3412         ->CachedLinkInterfaceIncludeDirectoriesEntries[configString].push_back(
3413                         new cmTargetInternals::TargetPropertyEntry(cge,
3414                                                               it->Value));
3415       }
3416
3417     if(this->Makefile->IsOn("APPLE"))
3418       {
3419       LinkImplementation const* impl = this->GetLinkImplementation(config,
3420                                                                    this);
3421       for(std::vector<std::string>::const_iterator
3422           it = impl->Libraries.begin();
3423           it != impl->Libraries.end(); ++it)
3424         {
3425         std::string libDir = cmSystemTools::CollapseFullPath(it->c_str());
3426
3427         static cmsys::RegularExpression
3428           frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
3429         if(!frameworkCheck.find(libDir))
3430           {
3431           continue;
3432           }
3433
3434         libDir = frameworkCheck.match(1);
3435
3436         cmGeneratorExpression ge(lfbt);
3437         cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
3438                   ge.Parse(libDir.c_str());
3439         this->Internal
3440                 ->CachedLinkInterfaceIncludeDirectoriesEntries[configString]
3441                 .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
3442         }
3443       }
3444     }
3445
3446   processIncludeDirectories(this,
3447     this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries[configString],
3448                             includes,
3449                             uniqueIncludes,
3450                             &dagChecker,
3451                             config,
3452                             debugIncludes);
3453
3454   if (!this->Makefile->IsGeneratingBuildSystem())
3455     {
3456     deleteAndClear(
3457                 this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries);
3458     }
3459   else
3460     {
3461     this->Internal->CacheLinkInterfaceIncludeDirectoriesDone[configString]
3462                                                                       = true;
3463     }
3464
3465   return includes;
3466 }
3467
3468 //----------------------------------------------------------------------------
3469 static void processCompileOptionsInternal(cmTarget *tgt,
3470       const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
3471       std::vector<std::string> &options,
3472       std::set<std::string> &uniqueOptions,
3473       cmGeneratorExpressionDAGChecker *dagChecker,
3474       const char *config, bool debugOptions, const char *logName)
3475 {
3476   cmMakefile *mf = tgt->GetMakefile();
3477
3478   for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
3479       it = entries.begin(), end = entries.end(); it != end; ++it)
3480     {
3481     bool cacheOptions = false;
3482     std::vector<std::string> entryOptions = (*it)->CachedEntries;
3483     if(entryOptions.empty())
3484       {
3485       cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
3486                                                 config,
3487                                                 false,
3488                                                 tgt,
3489                                                 dagChecker),
3490                                       entryOptions);
3491       if (mf->IsGeneratingBuildSystem()
3492           && !(*it)->ge->GetHadContextSensitiveCondition())
3493         {
3494         cacheOptions = true;
3495         }
3496       }
3497     std::string usedOptions;
3498     for(std::vector<std::string>::iterator
3499           li = entryOptions.begin(); li != entryOptions.end(); ++li)
3500       {
3501       std::string opt = *li;
3502
3503       if(uniqueOptions.insert(opt).second)
3504         {
3505         options.push_back(opt);
3506         if (debugOptions)
3507           {
3508           usedOptions += " * " + opt + "\n";
3509           }
3510         }
3511       }
3512     if (cacheOptions)
3513       {
3514       (*it)->CachedEntries = entryOptions;
3515       }
3516     if (!usedOptions.empty())
3517       {
3518       mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
3519                             std::string("Used compile ") + logName
3520                             + std::string(" for target ")
3521                             + tgt->GetName() + ":\n"
3522                             + usedOptions, (*it)->ge->GetBacktrace());
3523       }
3524     }
3525 }
3526
3527 //----------------------------------------------------------------------------
3528 static void processCompileOptions(cmTarget *tgt,
3529       const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
3530       std::vector<std::string> &options,
3531       std::set<std::string> &uniqueOptions,
3532       cmGeneratorExpressionDAGChecker *dagChecker,
3533       const char *config, bool debugOptions)
3534 {
3535   processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
3536                                 dagChecker, config, debugOptions, "options");
3537 }
3538
3539 //----------------------------------------------------------------------------
3540 void cmTarget::GetCompileOptions(std::vector<std::string> &result,
3541                                  const char *config)
3542 {
3543   std::set<std::string> uniqueOptions;
3544   cmListFileBacktrace lfbt;
3545
3546   cmGeneratorExpressionDAGChecker dagChecker(lfbt,
3547                                               this->GetName(),
3548                                               "COMPILE_OPTIONS", 0, 0);
3549
3550   std::vector<std::string> debugProperties;
3551   const char *debugProp =
3552               this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
3553   if (debugProp)
3554     {
3555     cmSystemTools::ExpandListArgument(debugProp, debugProperties);
3556     }
3557
3558   bool debugOptions = !this->DebugCompileOptionsDone
3559                     && std::find(debugProperties.begin(),
3560                                  debugProperties.end(),
3561                                  "COMPILE_OPTIONS")
3562                         != debugProperties.end();
3563
3564   if (this->Makefile->IsGeneratingBuildSystem())
3565     {
3566     this->DebugCompileOptionsDone = true;
3567     }
3568
3569   processCompileOptions(this,
3570                             this->Internal->CompileOptionsEntries,
3571                             result,
3572                             uniqueOptions,
3573                             &dagChecker,
3574                             config,
3575                             debugOptions);
3576
3577   std::string configString = config ? config : "";
3578   if (!this->Internal->CacheLinkInterfaceCompileOptionsDone[configString])
3579     {
3580     for (std::vector<cmValueWithOrigin>::const_iterator
3581         it = this->Internal->LinkInterfacePropertyEntries.begin(),
3582         end = this->Internal->LinkInterfacePropertyEntries.end();
3583         it != end; ++it)
3584       {
3585       {
3586       cmGeneratorExpression ge(lfbt);
3587       cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
3588                                                         ge.Parse(it->Value);
3589       std::string targetResult = cge->Evaluate(this->Makefile, config,
3590                                         false, this, 0, 0);
3591       if (!this->Makefile->FindTargetToUse(targetResult.c_str()))
3592         {
3593         continue;
3594         }
3595       }
3596       std::string optionGenex = "$<TARGET_PROPERTY:" +
3597                               it->Value + ",INTERFACE_COMPILE_OPTIONS>";
3598       if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
3599         {
3600         // Because it->Value is a generator expression, ensure that it
3601         // evaluates to the non-empty string before being used in the
3602         // TARGET_PROPERTY expression.
3603         optionGenex = "$<$<BOOL:" + it->Value + ">:" + optionGenex + ">";
3604         }
3605       cmGeneratorExpression ge(it->Backtrace);
3606       cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
3607                                                                 optionGenex);
3608
3609       this->Internal
3610         ->CachedLinkInterfaceCompileOptionsEntries[configString].push_back(
3611                         new cmTargetInternals::TargetPropertyEntry(cge,
3612                                                               it->Value));
3613       }
3614     }
3615
3616   processCompileOptions(this,
3617     this->Internal->CachedLinkInterfaceCompileOptionsEntries[configString],
3618                             result,
3619                             uniqueOptions,
3620                             &dagChecker,
3621                             config,
3622                             debugOptions);
3623
3624   if (!this->Makefile->IsGeneratingBuildSystem())
3625     {
3626     deleteAndClear(this->Internal->CachedLinkInterfaceCompileOptionsEntries);
3627     }
3628   else
3629     {
3630     this->Internal->CacheLinkInterfaceCompileOptionsDone[configString] = true;
3631     }
3632 }
3633
3634 //----------------------------------------------------------------------------
3635 static void processCompileDefinitions(cmTarget *tgt,
3636       const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
3637       std::vector<std::string> &options,
3638       std::set<std::string> &uniqueOptions,
3639       cmGeneratorExpressionDAGChecker *dagChecker,
3640       const char *config, bool debugOptions)
3641 {
3642   processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
3643                                 dagChecker, config, debugOptions,
3644                                 "definitions");
3645 }
3646
3647 //----------------------------------------------------------------------------
3648 void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
3649                                             const char *config)
3650 {
3651   std::set<std::string> uniqueOptions;
3652   cmListFileBacktrace lfbt;
3653
3654   cmGeneratorExpressionDAGChecker dagChecker(lfbt,
3655                                               this->GetName(),
3656                                               "COMPILE_DEFINITIONS", 0, 0);
3657
3658   std::vector<std::string> debugProperties;
3659   const char *debugProp =
3660               this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
3661   if (debugProp)
3662     {
3663     cmSystemTools::ExpandListArgument(debugProp, debugProperties);
3664     }
3665
3666   bool debugDefines = !this->DebugCompileDefinitionsDone
3667                           && std::find(debugProperties.begin(),
3668                                 debugProperties.end(),
3669                                 "COMPILE_DEFINITIONS")
3670                         != debugProperties.end();
3671
3672   if (this->Makefile->IsGeneratingBuildSystem())
3673     {
3674     this->DebugCompileDefinitionsDone = true;
3675     }
3676
3677   processCompileDefinitions(this,
3678                             this->Internal->CompileDefinitionsEntries,
3679                             list,
3680                             uniqueOptions,
3681                             &dagChecker,
3682                             config,
3683                             debugDefines);
3684
3685   std::string configString = config ? config : "";
3686   if (!this->Internal->CacheLinkInterfaceCompileDefinitionsDone[configString])
3687     {
3688     for (std::vector<cmValueWithOrigin>::const_iterator
3689         it = this->Internal->LinkInterfacePropertyEntries.begin(),
3690         end = this->Internal->LinkInterfacePropertyEntries.end();
3691         it != end; ++it)
3692       {
3693       {
3694       cmGeneratorExpression ge(lfbt);
3695       cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
3696                                                         ge.Parse(it->Value);
3697       std::string targetResult = cge->Evaluate(this->Makefile, config,
3698                                         false, this, 0, 0);
3699       if (!this->Makefile->FindTargetToUse(targetResult.c_str()))
3700         {
3701         continue;
3702         }
3703       }
3704       std::string defsGenex = "$<TARGET_PROPERTY:" +
3705                               it->Value + ",INTERFACE_COMPILE_DEFINITIONS>";
3706       if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
3707         {
3708         // Because it->Value is a generator expression, ensure that it
3709         // evaluates to the non-empty string before being used in the
3710         // TARGET_PROPERTY expression.
3711         defsGenex = "$<$<BOOL:" + it->Value + ">:" + defsGenex + ">";
3712         }
3713       cmGeneratorExpression ge(it->Backtrace);
3714       cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
3715                                                                 defsGenex);
3716
3717       this->Internal
3718         ->CachedLinkInterfaceCompileDefinitionsEntries[configString].push_back(
3719                         new cmTargetInternals::TargetPropertyEntry(cge,
3720                                                               it->Value));
3721       }
3722     if (config)
3723       {
3724       std::string configPropName = "COMPILE_DEFINITIONS_"
3725                                           + cmSystemTools::UpperCase(config);
3726       const char *configProp = this->GetProperty(configPropName.c_str());
3727       std::string defsString = (configProp ? configProp : "");
3728
3729       cmGeneratorExpression ge(lfbt);
3730       cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
3731                                                         ge.Parse(defsString);
3732       this->Internal
3733         ->CachedLinkInterfaceCompileDefinitionsEntries[configString].push_back(
3734                         new cmTargetInternals::TargetPropertyEntry(cge));
3735       }
3736
3737     }
3738
3739   processCompileDefinitions(this,
3740     this->Internal->CachedLinkInterfaceCompileDefinitionsEntries[configString],
3741                             list,
3742                             uniqueOptions,
3743                             &dagChecker,
3744                             config,
3745                             debugDefines);
3746
3747   if (!this->Makefile->IsGeneratingBuildSystem())
3748     {
3749     deleteAndClear(this->Internal
3750                               ->CachedLinkInterfaceCompileDefinitionsEntries);
3751     }
3752   else
3753     {
3754     this->Internal->CacheLinkInterfaceCompileDefinitionsDone[configString]
3755                                                                       = true;
3756     }
3757 }
3758
3759 //----------------------------------------------------------------------------
3760 void cmTarget::MaybeInvalidatePropertyCache(const char* prop)
3761 {
3762   // Wipe out maps caching information affected by this property.
3763   if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
3764     {
3765     this->Internal->ImportInfoMap.clear();
3766     }
3767   if(!this->IsImported() && strncmp(prop, "LINK_INTERFACE_", 15) == 0)
3768     {
3769     this->ClearLinkMaps();
3770     }
3771 }
3772
3773 //----------------------------------------------------------------------------
3774 static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
3775   const char* prop, const char* value, cmMakefile* context, bool imported
3776   )
3777 {
3778   // Look for link-type keywords in the value.
3779   static cmsys::RegularExpression
3780     keys("(^|;)(debug|optimized|general)(;|$)");
3781   if(!keys.find(value))
3782     {
3783     return;
3784     }
3785
3786   // Support imported and non-imported versions of the property.
3787   const char* base = (imported?
3788                       "IMPORTED_LINK_INTERFACE_LIBRARIES" :
3789                       "LINK_INTERFACE_LIBRARIES");
3790
3791   // Report an error.
3792   cmOStringStream e;
3793   e << "Property " << prop << " may not contain link-type keyword \""
3794     << keys.match(2) << "\".  "
3795     << "The " << base << " property has a per-configuration "
3796     << "version called " << base << "_<CONFIG> which may be "
3797     << "used to specify per-configuration rules.";
3798   if(!imported)
3799     {
3800     e << "  "
3801       << "Alternatively, an IMPORTED library may be created, configured "
3802       << "with a per-configuration location, and then named in the "
3803       << "property value.  "
3804       << "See the add_library command's IMPORTED mode for details."
3805       << "\n"
3806       << "If you have a list of libraries that already contains the "
3807       << "keyword, use the target_link_libraries command with its "
3808       << "LINK_INTERFACE_LIBRARIES mode to set the property.  "
3809       << "The command automatically recognizes link-type keywords and sets "
3810       << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
3811       << "properties accordingly.";
3812     }
3813   context->IssueMessage(cmake::FATAL_ERROR, e.str());
3814 }
3815
3816 //----------------------------------------------------------------------------
3817 static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
3818                                                   cmMakefile* context)
3819 {
3820   // Look for link-type keywords in the value.
3821   static cmsys::RegularExpression
3822     keys("(^|;)(debug|optimized|general)(;|$)");
3823   if(!keys.find(value))
3824     {
3825     return;
3826     }
3827
3828   // Report an error.
3829   cmOStringStream e;
3830
3831   e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
3832     "keyword \"" << keys.match(2) << "\".  The INTERFACE_LINK_LIBRARIES "
3833     "property may contain configuration-sensitive generator-expressions "
3834     "which may be used to specify per-configuration rules.";
3835
3836   context->IssueMessage(cmake::FATAL_ERROR, e.str());
3837 }
3838
3839 //----------------------------------------------------------------------------
3840 void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
3841 {
3842   // Certain properties need checking.
3843   if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
3844     {
3845     if(const char* value = this->GetProperty(prop))
3846       {
3847       cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
3848       }
3849     }
3850   if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
3851     {
3852     if(const char* value = this->GetProperty(prop))
3853       {
3854       cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
3855       }
3856     }
3857   if(strncmp(prop, "INTERFACE_LINK_LIBRARIES", 24) == 0)
3858     {
3859     if(const char* value = this->GetProperty(prop))
3860       {
3861       cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
3862       }
3863     }
3864 }
3865
3866 //----------------------------------------------------------------------------
3867 void cmTarget::MarkAsImported()
3868 {
3869   this->IsImportedTarget = true;
3870 }
3871
3872 //----------------------------------------------------------------------------
3873 bool cmTarget::HaveWellDefinedOutputFiles()
3874 {
3875   return
3876     this->GetType() == cmTarget::STATIC_LIBRARY ||
3877     this->GetType() == cmTarget::SHARED_LIBRARY ||
3878     this->GetType() == cmTarget::MODULE_LIBRARY ||
3879     this->GetType() == cmTarget::EXECUTABLE;
3880 }
3881
3882 //----------------------------------------------------------------------------
3883 cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
3884 {
3885   // There is no output information for imported targets.
3886   if(this->IsImported())
3887     {
3888     return 0;
3889     }
3890
3891   // Only libraries and executables have well-defined output files.
3892   if(!this->HaveWellDefinedOutputFiles())
3893     {
3894     std::string msg = "cmTarget::GetOutputInfo called for ";
3895     msg += this->GetName();
3896     msg += " which has type ";
3897     msg += cmTarget::GetTargetTypeName(this->GetType());
3898     this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
3899     abort();
3900     return 0;
3901     }
3902
3903   // Lookup/compute/cache the output information for this configuration.
3904   std::string config_upper;
3905   if(config && *config)
3906     {
3907     config_upper = cmSystemTools::UpperCase(config);
3908     }
3909   typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
3910   OutputInfoMapType::const_iterator i =
3911     this->Internal->OutputInfoMap.find(config_upper);
3912   if(i == this->Internal->OutputInfoMap.end())
3913     {
3914     OutputInfo info;
3915     this->ComputeOutputDir(config, false, info.OutDir);
3916     this->ComputeOutputDir(config, true, info.ImpDir);
3917     if(!this->ComputePDBOutputDir(config, info.PdbDir))
3918       {
3919       info.PdbDir = info.OutDir;
3920       }
3921     OutputInfoMapType::value_type entry(config_upper, info);
3922     i = this->Internal->OutputInfoMap.insert(entry).first;
3923     }
3924   return &i->second;
3925 }
3926
3927 //----------------------------------------------------------------------------
3928 std::string cmTarget::GetDirectory(const char* config, bool implib)
3929 {
3930   if (this->IsImported())
3931     {
3932     // Return the directory from which the target is imported.
3933     return
3934       cmSystemTools::GetFilenamePath(
3935       this->ImportedGetFullPath(config, implib));
3936     }
3937   else if(OutputInfo const* info = this->GetOutputInfo(config))
3938     {
3939     // Return the directory in which the target will be built.
3940     return implib? info->ImpDir : info->OutDir;
3941     }
3942   return "";
3943 }
3944
3945 //----------------------------------------------------------------------------
3946 std::string cmTarget::GetPDBDirectory(const char* config)
3947 {
3948   if(OutputInfo const* info = this->GetOutputInfo(config))
3949     {
3950     // Return the directory in which the target will be built.
3951     return info->PdbDir;
3952     }
3953   return "";
3954 }
3955
3956 //----------------------------------------------------------------------------
3957 const char* cmTarget::GetLocation(const char* config)
3958 {
3959   if (this->IsImported())
3960     {
3961     return this->ImportedGetLocation(config);
3962     }
3963   else
3964     {
3965     return this->NormalGetLocation(config);
3966     }
3967 }
3968
3969 //----------------------------------------------------------------------------
3970 const char* cmTarget::ImportedGetLocation(const char* config)
3971 {
3972   this->Location = this->ImportedGetFullPath(config, false);
3973   return this->Location.c_str();
3974 }
3975
3976 //----------------------------------------------------------------------------
3977 const char* cmTarget::NormalGetLocation(const char* config)
3978 {
3979   // Handle the configuration-specific case first.
3980   if(config)
3981     {
3982     this->Location = this->GetFullPath(config, false);
3983     return this->Location.c_str();
3984     }
3985
3986   // Now handle the deprecated build-time configuration location.
3987   this->Location = this->GetDirectory();
3988   const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
3989   if(cfgid && strcmp(cfgid, ".") != 0)
3990     {
3991     this->Location += "/";
3992     this->Location += cfgid;
3993     }
3994
3995   if(this->IsAppBundleOnApple())
3996     {
3997     std::string macdir = this->BuildMacContentDirectory("", config, false);
3998     if(!macdir.empty())
3999       {
4000       this->Location += "/";
4001       this->Location += macdir;
4002       }
4003     }
4004   this->Location += "/";
4005   this->Location += this->GetFullName(config, false);
4006   return this->Location.c_str();
4007 }
4008
4009 //----------------------------------------------------------------------------
4010 void cmTarget::GetTargetVersion(int& major, int& minor)
4011 {
4012   int patch;
4013   this->GetTargetVersion(false, major, minor, patch);
4014 }
4015
4016 //----------------------------------------------------------------------------
4017 void cmTarget::GetTargetVersion(bool soversion,
4018                                 int& major, int& minor, int& patch)
4019 {
4020   // Set the default values.
4021   major = 0;
4022   minor = 0;
4023   patch = 0;
4024
4025   // Look for a VERSION or SOVERSION property.
4026   const char* prop = soversion? "SOVERSION" : "VERSION";
4027   if(const char* version = this->GetProperty(prop))
4028     {
4029     // Try to parse the version number and store the results that were
4030     // successfully parsed.
4031     int parsed_major;
4032     int parsed_minor;
4033     int parsed_patch;
4034     switch(sscanf(version, "%d.%d.%d",
4035                   &parsed_major, &parsed_minor, &parsed_patch))
4036       {
4037       case 3: patch = parsed_patch; // no break!
4038       case 2: minor = parsed_minor; // no break!
4039       case 1: major = parsed_major; // no break!
4040       default: break;
4041       }
4042     }
4043 }
4044
4045 //----------------------------------------------------------------------------
4046 const char* cmTarget::GetFeature(const char* feature, const char* config)
4047 {
4048   if(config && *config)
4049     {
4050     std::string featureConfig = feature;
4051     featureConfig += "_";
4052     featureConfig += cmSystemTools::UpperCase(config);
4053     if(const char* value = this->GetProperty(featureConfig.c_str()))
4054       {
4055       return value;
4056       }
4057     }
4058   if(const char* value = this->GetProperty(feature))
4059     {
4060     return value;
4061     }
4062   return this->Makefile->GetFeature(feature, config);
4063 }
4064
4065 //----------------------------------------------------------------------------
4066 const char *cmTarget::GetProperty(const char* prop)
4067 {
4068   return this->GetProperty(prop, cmProperty::TARGET);
4069 }
4070
4071 //----------------------------------------------------------------------------
4072 const char *cmTarget::GetProperty(const char* prop,
4073                                   cmProperty::ScopeType scope)
4074 {
4075   if(!prop)
4076     {
4077     return 0;
4078     }
4079
4080   if (strcmp(prop, "NAME") == 0)
4081     {
4082     return this->GetName();
4083     }
4084
4085   // Watch for special "computed" properties that are dependent on
4086   // other properties or variables.  Always recompute them.
4087   if(this->GetType() == cmTarget::EXECUTABLE ||
4088      this->GetType() == cmTarget::STATIC_LIBRARY ||
4089      this->GetType() == cmTarget::SHARED_LIBRARY ||
4090      this->GetType() == cmTarget::MODULE_LIBRARY ||
4091      this->GetType() == cmTarget::UNKNOWN_LIBRARY)
4092     {
4093     if(strcmp(prop,"LOCATION") == 0)
4094       {
4095       // Set the LOCATION property of the target.
4096       //
4097       // For an imported target this is the location of an arbitrary
4098       // available configuration.
4099       //
4100       // For a non-imported target this is deprecated because it
4101       // cannot take into account the per-configuration name of the
4102       // target because the configuration type may not be known at
4103       // CMake time.
4104       this->SetProperty("LOCATION", this->GetLocation(0));
4105       }
4106
4107     // Support "LOCATION_<CONFIG>".
4108     if(strncmp(prop, "LOCATION_", 9) == 0)
4109       {
4110       std::string configName = prop+9;
4111       this->SetProperty(prop, this->GetLocation(configName.c_str()));
4112       }
4113     else
4114       {
4115       // Support "<CONFIG>_LOCATION" for compatiblity.
4116       int len = static_cast<int>(strlen(prop));
4117       if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
4118         {
4119         std::string configName(prop, len-9);
4120         if(configName != "IMPORTED")
4121           {
4122           this->SetProperty(prop, this->GetLocation(configName.c_str()));
4123           }
4124         }
4125       }
4126     }
4127   if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
4128     {
4129     static std::string output;
4130     output = "";
4131     std::string sep;
4132     typedef cmTargetInternals::TargetPropertyEntry
4133                                 TargetPropertyEntry;
4134     for (std::vector<TargetPropertyEntry*>::const_iterator
4135         it = this->Internal->IncludeDirectoriesEntries.begin(),
4136         end = this->Internal->IncludeDirectoriesEntries.end();
4137         it != end; ++it)
4138       {
4139       output += sep;
4140       output += (*it)->ge->GetInput();
4141       sep = ";";
4142       }
4143     return output.c_str();
4144     }
4145   if(strcmp(prop,"COMPILE_OPTIONS") == 0)
4146     {
4147     static std::string output;
4148     output = "";
4149     std::string sep;
4150     typedef cmTargetInternals::TargetPropertyEntry
4151                                 TargetPropertyEntry;
4152     for (std::vector<TargetPropertyEntry*>::const_iterator
4153         it = this->Internal->CompileOptionsEntries.begin(),
4154         end = this->Internal->CompileOptionsEntries.end();
4155         it != end; ++it)
4156       {
4157       output += sep;
4158       output += (*it)->ge->GetInput();
4159       sep = ";";
4160       }
4161     return output.c_str();
4162     }
4163   if(strcmp(prop,"COMPILE_DEFINITIONS") == 0)
4164     {
4165     static std::string output;
4166     output = "";
4167     std::string sep;
4168     typedef cmTargetInternals::TargetPropertyEntry
4169                                 TargetPropertyEntry;
4170     for (std::vector<TargetPropertyEntry*>::const_iterator
4171         it = this->Internal->CompileDefinitionsEntries.begin(),
4172         end = this->Internal->CompileDefinitionsEntries.end();
4173         it != end; ++it)
4174       {
4175       output += sep;
4176       output += (*it)->ge->GetInput();
4177       sep = ";";
4178       }
4179     return output.c_str();
4180     }
4181
4182   if (strcmp(prop,"IMPORTED") == 0)
4183     {
4184     return this->IsImported()?"TRUE":"FALSE";
4185     }
4186
4187   if(!strcmp(prop,"SOURCES"))
4188     {
4189     cmOStringStream ss;
4190     const char* sep = "";
4191     for(std::vector<cmSourceFile*>::const_iterator
4192           i = this->SourceFiles.begin();
4193         i != this->SourceFiles.end(); ++i)
4194       {
4195       // Separate from the previous list entries.
4196       ss << sep;
4197       sep = ";";
4198
4199       // Construct what is known about this source file location.
4200       cmSourceFileLocation const& location = (*i)->GetLocation();
4201       std::string sname = location.GetDirectory();
4202       if(!sname.empty())
4203         {
4204         sname += "/";
4205         }
4206       sname += location.GetName();
4207
4208       // Append this list entry.
4209       ss << sname;
4210       }
4211     this->SetProperty("SOURCES", ss.str().c_str());
4212     }
4213
4214   // the type property returns what type the target is
4215   if (!strcmp(prop,"TYPE"))
4216     {
4217     return cmTarget::GetTargetTypeName(this->GetType());
4218     }
4219   bool chain = false;
4220   const char *retVal =
4221     this->Properties.GetPropertyValue(prop, scope, chain);
4222   if (chain)
4223     {
4224     return this->Makefile->GetProperty(prop,scope);
4225     }
4226   return retVal;
4227 }
4228
4229 //----------------------------------------------------------------------------
4230 bool cmTarget::GetPropertyAsBool(const char* prop)
4231 {
4232   return cmSystemTools::IsOn(this->GetProperty(prop));
4233 }
4234
4235 //----------------------------------------------------------------------------
4236 class cmTargetCollectLinkLanguages
4237 {
4238 public:
4239   cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
4240                                std::set<cmStdString>& languages,
4241                                cmTarget* head):
4242     Config(config), Languages(languages), HeadTarget(head)
4243   { this->Visited.insert(target); }
4244
4245   void Visit(cmTarget* target)
4246     {
4247     if(!target || !this->Visited.insert(target).second)
4248       {
4249       return;
4250       }
4251
4252     cmTarget::LinkInterface const* iface =
4253       target->GetLinkInterface(this->Config, this->HeadTarget);
4254     if(!iface) { return; }
4255
4256     for(std::vector<std::string>::const_iterator
4257           li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
4258       {
4259       this->Languages.insert(*li);
4260       }
4261
4262     cmMakefile* mf = target->GetMakefile();
4263     for(std::vector<std::string>::const_iterator
4264           li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
4265       {
4266       this->Visit(mf->FindTargetToUse(li->c_str()));
4267       }
4268     }
4269 private:
4270   const char* Config;
4271   std::set<cmStdString>& Languages;
4272   cmTarget* HeadTarget;
4273   std::set<cmTarget*> Visited;
4274 };
4275
4276 //----------------------------------------------------------------------------
4277 const char* cmTarget::GetLinkerLanguage(const char* config, cmTarget *head)
4278 {
4279   cmTarget *headTarget = head ? head : this;
4280   const char* lang = this->GetLinkClosure(config, headTarget)
4281                                                     ->LinkerLanguage.c_str();
4282   return *lang? lang : 0;
4283 }
4284
4285 //----------------------------------------------------------------------------
4286 cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config,
4287                                                       cmTarget *head)
4288 {
4289   TargetConfigPair key(head, cmSystemTools::UpperCase(config ? config : ""));
4290   cmTargetInternals::LinkClosureMapType::iterator
4291     i = this->Internal->LinkClosureMap.find(key);
4292   if(i == this->Internal->LinkClosureMap.end())
4293     {
4294     LinkClosure lc;
4295     this->ComputeLinkClosure(config, lc, head);
4296     cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
4297     i = this->Internal->LinkClosureMap.insert(entry).first;
4298     }
4299   return &i->second;
4300 }
4301
4302 //----------------------------------------------------------------------------
4303 class cmTargetSelectLinker
4304 {
4305   int Preference;
4306   cmTarget* Target;
4307   cmMakefile* Makefile;
4308   cmGlobalGenerator* GG;
4309   std::set<cmStdString> Preferred;
4310 public:
4311   cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
4312     {
4313     this->Makefile = this->Target->GetMakefile();
4314     this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
4315     }
4316   void Consider(const char* lang)
4317     {
4318     int preference = this->GG->GetLinkerPreference(lang);
4319     if(preference > this->Preference)
4320       {
4321       this->Preference = preference;
4322       this->Preferred.clear();
4323       }
4324     if(preference == this->Preference)
4325       {
4326       this->Preferred.insert(lang);
4327       }
4328     }
4329   std::string Choose()
4330     {
4331     if(this->Preferred.empty())
4332       {
4333       return "";
4334       }
4335     else if(this->Preferred.size() > 1)
4336       {
4337       cmOStringStream e;
4338       e << "Target " << this->Target->GetName()
4339         << " contains multiple languages with the highest linker preference"
4340         << " (" << this->Preference << "):\n";
4341       for(std::set<cmStdString>::const_iterator
4342             li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
4343         {
4344         e << "  " << *li << "\n";
4345         }
4346       e << "Set the LINKER_LANGUAGE property for this target.";
4347       cmake* cm = this->Makefile->GetCMakeInstance();
4348       cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
4349                        this->Target->GetBacktrace());
4350       }
4351     return *this->Preferred.begin();
4352     }
4353 };
4354
4355 //----------------------------------------------------------------------------
4356 void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc,
4357                                   cmTarget *head)
4358 {
4359   // Get languages built in this target.
4360   std::set<cmStdString> languages;
4361   LinkImplementation const* impl = this->GetLinkImplementation(config, head);
4362   for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
4363       li != impl->Languages.end(); ++li)
4364     {
4365     languages.insert(*li);
4366     }
4367
4368   // Add interface languages from linked targets.
4369   cmTargetCollectLinkLanguages cll(this, config, languages, head);
4370   for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
4371       li != impl->Libraries.end(); ++li)
4372     {
4373     cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
4374     }
4375
4376   // Store the transitive closure of languages.
4377   for(std::set<cmStdString>::const_iterator li = languages.begin();
4378       li != languages.end(); ++li)
4379     {
4380     lc.Languages.push_back(*li);
4381     }
4382
4383   // Choose the language whose linker should be used.
4384   if(this->GetProperty("HAS_CXX"))
4385     {
4386     lc.LinkerLanguage = "CXX";
4387     }
4388   else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
4389     {
4390     lc.LinkerLanguage = linkerLang;
4391     }
4392   else
4393     {
4394     // Find the language with the highest preference value.
4395     cmTargetSelectLinker tsl(this);
4396
4397     // First select from the languages compiled directly in this target.
4398     for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
4399         li != impl->Languages.end(); ++li)
4400       {
4401       tsl.Consider(li->c_str());
4402       }
4403
4404     // Now consider languages that propagate from linked targets.
4405     for(std::set<cmStdString>::const_iterator sit = languages.begin();
4406         sit != languages.end(); ++sit)
4407       {
4408       std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
4409       if(this->Makefile->IsOn(propagates.c_str()))
4410         {
4411         tsl.Consider(sit->c_str());
4412         }
4413       }
4414
4415     lc.LinkerLanguage = tsl.Choose();
4416     }
4417 }
4418
4419 //----------------------------------------------------------------------------
4420 const char* cmTarget::GetSuffixVariableInternal(bool implib)
4421 {
4422   switch(this->GetType())
4423     {
4424     case cmTarget::STATIC_LIBRARY:
4425       return "CMAKE_STATIC_LIBRARY_SUFFIX";
4426     case cmTarget::SHARED_LIBRARY:
4427       return (implib
4428               ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
4429               : "CMAKE_SHARED_LIBRARY_SUFFIX");
4430     case cmTarget::MODULE_LIBRARY:
4431       return (implib
4432               ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
4433               : "CMAKE_SHARED_MODULE_SUFFIX");
4434     case cmTarget::EXECUTABLE:
4435       return (implib
4436               ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
4437               : "CMAKE_EXECUTABLE_SUFFIX");
4438     default:
4439       break;
4440     }
4441   return "";
4442 }
4443
4444
4445 //----------------------------------------------------------------------------
4446 const char* cmTarget::GetPrefixVariableInternal(bool implib)
4447 {
4448   switch(this->GetType())
4449     {
4450     case cmTarget::STATIC_LIBRARY:
4451       return "CMAKE_STATIC_LIBRARY_PREFIX";
4452     case cmTarget::SHARED_LIBRARY:
4453       return (implib
4454               ? "CMAKE_IMPORT_LIBRARY_PREFIX"
4455               : "CMAKE_SHARED_LIBRARY_PREFIX");
4456     case cmTarget::MODULE_LIBRARY:
4457       return (implib
4458               ? "CMAKE_IMPORT_LIBRARY_PREFIX"
4459               : "CMAKE_SHARED_MODULE_PREFIX");
4460     case cmTarget::EXECUTABLE:
4461       return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
4462     default:
4463       break;
4464     }
4465   return "";
4466 }
4467
4468 //----------------------------------------------------------------------------
4469 std::string cmTarget::GetPDBName(const char* config)
4470 {
4471   std::string prefix;
4472   std::string base;
4473   std::string suffix;
4474   this->GetFullNameInternal(config, false, prefix, base, suffix);
4475
4476   std::vector<std::string> props;
4477   std::string configUpper =
4478     cmSystemTools::UpperCase(config? config : "");
4479   if(!configUpper.empty())
4480     {
4481     // PDB_NAME_<CONFIG>
4482     props.push_back("PDB_NAME_" + configUpper);
4483     }
4484
4485   // PDB_NAME
4486   props.push_back("PDB_NAME");
4487
4488   for(std::vector<std::string>::const_iterator i = props.begin();
4489       i != props.end(); ++i)
4490     {
4491     if(const char* outName = this->GetProperty(i->c_str()))
4492       {
4493       base = outName;
4494       break;
4495       }
4496     }
4497   return prefix+base+".pdb";
4498 }
4499
4500 //----------------------------------------------------------------------------
4501 bool cmTarget::HasSOName(const char* config)
4502 {
4503   // soname is supported only for shared libraries and modules,
4504   // and then only when the platform supports an soname flag.
4505   return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
4506            this->GetType() == cmTarget::MODULE_LIBRARY) &&
4507           !this->GetPropertyAsBool("NO_SONAME") &&
4508           this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config,
4509                                                                 this)));
4510 }
4511
4512 //----------------------------------------------------------------------------
4513 std::string cmTarget::GetSOName(const char* config)
4514 {
4515   if(this->IsImported())
4516     {
4517     // Lookup the imported soname.
4518     if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
4519       {
4520       if(info->NoSOName)
4521         {
4522         // The imported library has no builtin soname so the name
4523         // searched at runtime will be just the filename.
4524         return cmSystemTools::GetFilenameName(info->Location);
4525         }
4526       else
4527         {
4528         // Use the soname given if any.
4529         if(info->SOName.find("@rpath/") == 0)
4530           {
4531           return info->SOName.substr(6);
4532           }
4533         return info->SOName;
4534         }
4535       }
4536     else
4537       {
4538       return "";
4539       }
4540     }
4541   else
4542     {
4543     // Compute the soname that will be built.
4544     std::string name;
4545     std::string soName;
4546     std::string realName;
4547     std::string impName;
4548     std::string pdbName;
4549     this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
4550     return soName;
4551     }
4552 }
4553
4554 //----------------------------------------------------------------------------
4555 bool cmTarget::HasMacOSXRpath(const char* config)
4556 {
4557   bool install_name_is_rpath = false;
4558   bool macosx_rpath = this->GetPropertyAsBool("MACOSX_RPATH");
4559
4560   if(!this->IsImportedTarget)
4561     {
4562     const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
4563     bool use_install_name =
4564       this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
4565     if(install_name && use_install_name &&
4566        std::string(install_name) == "@rpath")
4567       {
4568       install_name_is_rpath = true;
4569       }
4570     else if(install_name && use_install_name)
4571       {
4572       return false;
4573       }
4574     }
4575   else
4576     {
4577     // Lookup the imported soname.
4578     if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
4579       {
4580       if(!info->NoSOName && !info->SOName.empty())
4581         {
4582         if(info->SOName.find("@rpath/") == 0)
4583           {
4584           install_name_is_rpath = true;
4585           }
4586         }
4587       else
4588         {
4589         std::string install_name;
4590         cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
4591         if(install_name.find("@rpath") != std::string::npos)
4592           {
4593           install_name_is_rpath = true;
4594           }
4595         }
4596       }
4597     }
4598
4599   if(!install_name_is_rpath && !macosx_rpath)
4600     {
4601     return false;
4602     }
4603
4604   if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
4605     {
4606     cmOStringStream w;
4607     w << "Attempting to use";
4608     if(macosx_rpath)
4609       {
4610       w << " MACOSX_RPATH";
4611       }
4612     else
4613       {
4614       w << " @rpath";
4615       }
4616     w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
4617     w << "  This could be because you are using a Mac OS X version";
4618     w << " less than 10.5 or because CMake's platform configuration is";
4619     w << " corrupt.";
4620     cmake* cm = this->Makefile->GetCMakeInstance();
4621     cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
4622     }
4623
4624   return true;
4625 }
4626
4627 //----------------------------------------------------------------------------
4628 bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
4629 {
4630   if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
4631     {
4632     if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
4633       {
4634       return info->NoSOName;
4635       }
4636     }
4637   return false;
4638 }
4639
4640 //----------------------------------------------------------------------------
4641 std::string cmTarget::NormalGetRealName(const char* config)
4642 {
4643   // This should not be called for imported targets.
4644   // TODO: Split cmTarget into a class hierarchy to get compile-time
4645   // enforcement of the limited imported target API.
4646   if(this->IsImported())
4647     {
4648     std::string msg =  "NormalGetRealName called on imported target: ";
4649     msg += this->GetName();
4650     this->GetMakefile()->
4651       IssueMessage(cmake::INTERNAL_ERROR,
4652                    msg.c_str());
4653     }
4654
4655   if(this->GetType() == cmTarget::EXECUTABLE)
4656     {
4657     // Compute the real name that will be built.
4658     std::string name;
4659     std::string realName;
4660     std::string impName;
4661     std::string pdbName;
4662     this->GetExecutableNames(name, realName, impName, pdbName, config);
4663     return realName;
4664     }
4665   else
4666     {
4667     // Compute the real name that will be built.
4668     std::string name;
4669     std::string soName;
4670     std::string realName;
4671     std::string impName;
4672     std::string pdbName;
4673     this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
4674     return realName;
4675     }
4676 }
4677
4678 //----------------------------------------------------------------------------
4679 std::string cmTarget::GetFullName(const char* config, bool implib)
4680 {
4681   if(this->IsImported())
4682     {
4683     return this->GetFullNameImported(config, implib);
4684     }
4685   else
4686     {
4687     return this->GetFullNameInternal(config, implib);
4688     }
4689 }
4690
4691 //----------------------------------------------------------------------------
4692 std::string cmTarget::GetFullNameImported(const char* config, bool implib)
4693 {
4694   return cmSystemTools::GetFilenameName(
4695     this->ImportedGetFullPath(config, implib));
4696 }
4697
4698 //----------------------------------------------------------------------------
4699 void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
4700                                      std::string& suffix, const char* config,
4701                                      bool implib)
4702 {
4703   this->GetFullNameInternal(config, implib, prefix, base, suffix);
4704 }
4705
4706 //----------------------------------------------------------------------------
4707 std::string cmTarget::GetFullPath(const char* config, bool implib,
4708                                   bool realname)
4709 {
4710   if(this->IsImported())
4711     {
4712     return this->ImportedGetFullPath(config, implib);
4713     }
4714   else
4715     {
4716     return this->NormalGetFullPath(config, implib, realname);
4717     }
4718 }
4719
4720 //----------------------------------------------------------------------------
4721 std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
4722                                         bool realname)
4723 {
4724   std::string fpath = this->GetDirectory(config, implib);
4725   fpath += "/";
4726   if(this->IsAppBundleOnApple())
4727     {
4728     fpath = this->BuildMacContentDirectory(fpath, config, false);
4729     fpath += "/";
4730     }
4731
4732   // Add the full name of the target.
4733   if(implib)
4734     {
4735     fpath += this->GetFullName(config, true);
4736     }
4737   else if(realname)
4738     {
4739     fpath += this->NormalGetRealName(config);
4740     }
4741   else
4742     {
4743     fpath += this->GetFullName(config, false);
4744     }
4745   return fpath;
4746 }
4747
4748 //----------------------------------------------------------------------------
4749 std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
4750 {
4751   std::string result;
4752   if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
4753     {
4754     result = implib? info->ImportLibrary : info->Location;
4755     }
4756   if(result.empty())
4757     {
4758     result = this->GetName();
4759     result += "-NOTFOUND";
4760     }
4761   return result;
4762 }
4763
4764 //----------------------------------------------------------------------------
4765 std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
4766 {
4767   std::string prefix;
4768   std::string base;
4769   std::string suffix;
4770   this->GetFullNameInternal(config, implib, prefix, base, suffix);
4771   return prefix+base+suffix;
4772 }
4773
4774 //----------------------------------------------------------------------------
4775 void cmTarget::GetFullNameInternal(const char* config,
4776                                    bool implib,
4777                                    std::string& outPrefix,
4778                                    std::string& outBase,
4779                                    std::string& outSuffix)
4780 {
4781   // Use just the target name for non-main target types.
4782   if(this->GetType() != cmTarget::STATIC_LIBRARY &&
4783      this->GetType() != cmTarget::SHARED_LIBRARY &&
4784      this->GetType() != cmTarget::MODULE_LIBRARY &&
4785      this->GetType() != cmTarget::EXECUTABLE)
4786     {
4787     outPrefix = "";
4788     outBase = this->GetName();
4789     outSuffix = "";
4790     return;
4791     }
4792
4793   // Return an empty name for the import library if this platform
4794   // does not support import libraries.
4795   if(implib &&
4796      !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
4797     {
4798     outPrefix = "";
4799     outBase = "";
4800     outSuffix = "";
4801     return;
4802     }
4803
4804   // The implib option is only allowed for shared libraries, module
4805   // libraries, and executables.
4806   if(this->GetType() != cmTarget::SHARED_LIBRARY &&
4807      this->GetType() != cmTarget::MODULE_LIBRARY &&
4808      this->GetType() != cmTarget::EXECUTABLE)
4809     {
4810     implib = false;
4811     }
4812
4813   // Compute the full name for main target types.
4814   const char* targetPrefix = (implib
4815                               ? this->GetProperty("IMPORT_PREFIX")
4816                               : this->GetProperty("PREFIX"));
4817   const char* targetSuffix = (implib
4818                               ? this->GetProperty("IMPORT_SUFFIX")
4819                               : this->GetProperty("SUFFIX"));
4820   const char* configPostfix = 0;
4821   if(config && *config)
4822     {
4823     std::string configProp = cmSystemTools::UpperCase(config);
4824     configProp += "_POSTFIX";
4825     configPostfix = this->GetProperty(configProp.c_str());
4826     // Mac application bundles and frameworks have no postfix.
4827     if(configPostfix &&
4828        (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
4829       {
4830       configPostfix = 0;
4831       }
4832     }
4833   const char* prefixVar = this->GetPrefixVariableInternal(implib);
4834   const char* suffixVar = this->GetSuffixVariableInternal(implib);
4835
4836   // Check for language-specific default prefix and suffix.
4837   if(const char* ll = this->GetLinkerLanguage(config, this))
4838     {
4839     if(!targetSuffix && suffixVar && *suffixVar)
4840       {
4841       std::string langSuff = suffixVar + std::string("_") + ll;
4842       targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
4843       }
4844     if(!targetPrefix && prefixVar && *prefixVar)
4845       {
4846       std::string langPrefix = prefixVar + std::string("_") + ll;
4847       targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
4848       }
4849     }
4850
4851   // if there is no prefix on the target use the cmake definition
4852   if(!targetPrefix && prefixVar)
4853     {
4854     targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
4855     }
4856   // if there is no suffix on the target use the cmake definition
4857   if(!targetSuffix && suffixVar)
4858     {
4859     targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
4860     }
4861
4862   // frameworks have directory prefix but no suffix
4863   std::string fw_prefix;
4864   if(this->IsFrameworkOnApple())
4865     {
4866     fw_prefix = this->GetOutputName(config, false);
4867     fw_prefix += ".framework/";
4868     targetPrefix = fw_prefix.c_str();
4869     targetSuffix = 0;
4870     }
4871
4872   if(this->IsCFBundleOnApple())
4873     {
4874     fw_prefix = this->GetOutputName(config, false);
4875     fw_prefix += ".";
4876     const char *ext = this->GetProperty("BUNDLE_EXTENSION");
4877     if (!ext)
4878       {
4879       ext = "bundle";
4880       }
4881     fw_prefix += ext;
4882     fw_prefix += "/Contents/MacOS/";
4883     targetPrefix = fw_prefix.c_str();
4884     targetSuffix = 0;
4885     }
4886
4887   // Begin the final name with the prefix.
4888   outPrefix = targetPrefix?targetPrefix:"";
4889
4890   // Append the target name or property-specified name.
4891   outBase += this->GetOutputName(config, implib);
4892
4893   // Append the per-configuration postfix.
4894   outBase += configPostfix?configPostfix:"";
4895
4896   // Name shared libraries with their version number on some platforms.
4897   if(const char* soversion = this->GetProperty("SOVERSION"))
4898     {
4899     if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
4900        this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
4901       {
4902       outBase += "-";
4903       outBase += soversion;
4904       }
4905     }
4906
4907   // Append the suffix.
4908   outSuffix = targetSuffix?targetSuffix:"";
4909 }
4910
4911 //----------------------------------------------------------------------------
4912 void cmTarget::GetLibraryNames(std::string& name,
4913                                std::string& soName,
4914                                std::string& realName,
4915                                std::string& impName,
4916                                std::string& pdbName,
4917                                const char* config)
4918 {
4919   // This should not be called for imported targets.
4920   // TODO: Split cmTarget into a class hierarchy to get compile-time
4921   // enforcement of the limited imported target API.
4922   if(this->IsImported())
4923     {
4924     std::string msg =  "GetLibraryNames called on imported target: ";
4925     msg += this->GetName();
4926     this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
4927                                  msg.c_str());
4928     return;
4929     }
4930
4931   // Check for library version properties.
4932   const char* version = this->GetProperty("VERSION");
4933   const char* soversion = this->GetProperty("SOVERSION");
4934   if(!this->HasSOName(config) ||
4935      this->IsFrameworkOnApple())
4936     {
4937     // Versioning is supported only for shared libraries and modules,
4938     // and then only when the platform supports an soname flag.
4939     version = 0;
4940     soversion = 0;
4941     }
4942   if(version && !soversion)
4943     {
4944     // The soversion must be set if the library version is set.  Use
4945     // the library version as the soversion.
4946     soversion = version;
4947     }
4948   if(!version && soversion)
4949     {
4950     // Use the soversion as the library version.
4951     version = soversion;
4952     }
4953
4954   // Get the components of the library name.
4955   std::string prefix;
4956   std::string base;
4957   std::string suffix;
4958   this->GetFullNameInternal(config, false, prefix, base, suffix);
4959
4960   // The library name.
4961   name = prefix+base+suffix;
4962
4963   if(this->IsFrameworkOnApple())
4964     {
4965     realName = prefix;
4966     realName += "Versions/";
4967     realName += this->GetFrameworkVersion();
4968     realName += "/";
4969     realName += base;
4970     soName = realName;
4971     }
4972   else
4973     {
4974     // The library's soname.
4975     this->ComputeVersionedName(soName, prefix, base, suffix,
4976                                name, soversion);
4977     // The library's real name on disk.
4978     this->ComputeVersionedName(realName, prefix, base, suffix,
4979                                name, version);
4980     }
4981
4982   // The import library name.
4983   if(this->GetType() == cmTarget::SHARED_LIBRARY ||
4984      this->GetType() == cmTarget::MODULE_LIBRARY)
4985     {
4986     impName = this->GetFullNameInternal(config, true);
4987     }
4988   else
4989     {
4990     impName = "";
4991     }
4992
4993   // The program database file name.
4994   pdbName = this->GetPDBName(config);
4995 }
4996
4997 //----------------------------------------------------------------------------
4998 void cmTarget::ComputeVersionedName(std::string& vName,
4999                                     std::string const& prefix,
5000                                     std::string const& base,
5001                                     std::string const& suffix,
5002                                     std::string const& name,
5003                                     const char* version)
5004 {
5005   vName = this->IsApple? (prefix+base) : name;
5006   if(version)
5007     {
5008     vName += ".";
5009     vName += version;
5010     }
5011   vName += this->IsApple? suffix : std::string();
5012 }
5013
5014 //----------------------------------------------------------------------------
5015 void cmTarget::GetExecutableNames(std::string& name,
5016                                   std::string& realName,
5017                                   std::string& impName,
5018                                   std::string& pdbName,
5019                                   const char* config)
5020 {
5021   // This should not be called for imported targets.
5022   // TODO: Split cmTarget into a class hierarchy to get compile-time
5023   // enforcement of the limited imported target API.
5024   if(this->IsImported())
5025     {
5026     std::string msg =
5027       "GetExecutableNames called on imported target: ";
5028     msg += this->GetName();
5029     this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
5030     }
5031
5032   // This versioning is supported only for executables and then only
5033   // when the platform supports symbolic links.
5034 #if defined(_WIN32) && !defined(__CYGWIN__)
5035   const char* version = 0;
5036 #else
5037   // Check for executable version properties.
5038   const char* version = this->GetProperty("VERSION");
5039   if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
5040     {
5041     version = 0;
5042     }
5043 #endif
5044
5045   // Get the components of the executable name.
5046   std::string prefix;
5047   std::string base;
5048   std::string suffix;
5049   this->GetFullNameInternal(config, false, prefix, base, suffix);
5050
5051   // The executable name.
5052   name = prefix+base+suffix;
5053
5054   // The executable's real name on disk.
5055 #if defined(__CYGWIN__)
5056   realName = prefix+base;
5057 #else
5058   realName = name;
5059 #endif
5060   if(version)
5061     {
5062     realName += "-";
5063     realName += version;
5064     }
5065 #if defined(__CYGWIN__)
5066   realName += suffix;
5067 #endif
5068
5069   // The import library name.
5070   impName = this->GetFullNameInternal(config, true);
5071
5072   // The program database file name.
5073   pdbName = this->GetPDBName(config);
5074 }
5075
5076 //----------------------------------------------------------------------------
5077 bool cmTarget::HasImplibGNUtoMS()
5078 {
5079   return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
5080 }
5081
5082 //----------------------------------------------------------------------------
5083 bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
5084                                 std::string& out, const char* newExt)
5085 {
5086   if(this->HasImplibGNUtoMS() &&
5087      gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
5088     {
5089     out = gnuName.substr(0, gnuName.size()-6);
5090     out += newExt? newExt : ".lib";
5091     return true;
5092     }
5093   return false;
5094 }
5095
5096 //----------------------------------------------------------------------------
5097 void cmTarget::GenerateTargetManifest(const char* config)
5098 {
5099   cmMakefile* mf = this->Makefile;
5100   cmLocalGenerator* lg = mf->GetLocalGenerator();
5101   cmGlobalGenerator* gg = lg->GetGlobalGenerator();
5102
5103   // Get the names.
5104   std::string name;
5105   std::string soName;
5106   std::string realName;
5107   std::string impName;
5108   std::string pdbName;
5109   if(this->GetType() == cmTarget::EXECUTABLE)
5110     {
5111     this->GetExecutableNames(name, realName, impName, pdbName, config);
5112     }
5113   else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
5114           this->GetType() == cmTarget::SHARED_LIBRARY ||
5115           this->GetType() == cmTarget::MODULE_LIBRARY)
5116     {
5117     this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
5118     }
5119   else
5120     {
5121     return;
5122     }
5123
5124   // Get the directory.
5125   std::string dir = this->GetDirectory(config, false);
5126
5127   // Add each name.
5128   std::string f;
5129   if(!name.empty())
5130     {
5131     f = dir;
5132     f += "/";
5133     f += name;
5134     gg->AddToManifest(config? config:"", f);
5135     }
5136   if(!soName.empty())
5137     {
5138     f = dir;
5139     f += "/";
5140     f += soName;
5141     gg->AddToManifest(config? config:"", f);
5142     }
5143   if(!realName.empty())
5144     {
5145     f = dir;
5146     f += "/";
5147     f += realName;
5148     gg->AddToManifest(config? config:"", f);
5149     }
5150   if(!pdbName.empty())
5151     {
5152     f = this->GetPDBDirectory(config);
5153     f += "/";
5154     f += pdbName;
5155     gg->AddToManifest(config? config:"", f);
5156     }
5157   if(!impName.empty())
5158     {
5159     f = this->GetDirectory(config, true);
5160     f += "/";
5161     f += impName;
5162     gg->AddToManifest(config? config:"", f);
5163     }
5164 }
5165
5166 //----------------------------------------------------------------------------
5167 void cmTarget::SetPropertyDefault(const char* property,
5168                                   const char* default_value)
5169 {
5170   // Compute the name of the variable holding the default value.
5171   std::string var = "CMAKE_";
5172   var += property;
5173
5174   if(const char* value = this->Makefile->GetDefinition(var.c_str()))
5175     {
5176     this->SetProperty(property, value);
5177     }
5178   else if(default_value)
5179     {
5180     this->SetProperty(property, default_value);
5181     }
5182 }
5183
5184 //----------------------------------------------------------------------------
5185 bool cmTarget::HaveBuildTreeRPATH(const char *config)
5186 {
5187   if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
5188     {
5189     return false;
5190     }
5191   std::vector<std::string> libs;
5192   this->GetDirectLinkLibraries(config, libs, this);
5193   return !libs.empty();
5194 }
5195
5196 //----------------------------------------------------------------------------
5197 bool cmTarget::HaveInstallTreeRPATH()
5198 {
5199   const char* install_rpath = this->GetProperty("INSTALL_RPATH");
5200   return (install_rpath && *install_rpath) &&
5201           !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
5202 }
5203
5204 //----------------------------------------------------------------------------
5205 bool cmTarget::NeedRelinkBeforeInstall(const char* config)
5206 {
5207   // Only executables and shared libraries can have an rpath and may
5208   // need relinking.
5209   if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
5210      this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
5211      this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
5212     {
5213     return false;
5214     }
5215
5216   // If there is no install location this target will not be installed
5217   // and therefore does not need relinking.
5218   if(!this->GetHaveInstallRule())
5219     {
5220     return false;
5221     }
5222
5223   // If skipping all rpaths completely then no relinking is needed.
5224   if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
5225     {
5226     return false;
5227     }
5228
5229   // If building with the install-tree rpath no relinking is needed.
5230   if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
5231     {
5232     return false;
5233     }
5234
5235   // If chrpath is going to be used no relinking is needed.
5236   if(this->IsChrpathUsed(config))
5237     {
5238     return false;
5239     }
5240
5241   // Check for rpath support on this platform.
5242   if(const char* ll = this->GetLinkerLanguage(config, this))
5243     {
5244     std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
5245     flagVar += ll;
5246     flagVar += "_FLAG";
5247     if(!this->Makefile->IsSet(flagVar.c_str()))
5248       {
5249       // There is no rpath support on this platform so nothing needs
5250       // relinking.
5251       return false;
5252       }
5253     }
5254   else
5255     {
5256     // No linker language is known.  This error will be reported by
5257     // other code.
5258     return false;
5259     }
5260
5261   // If either a build or install tree rpath is set then the rpath
5262   // will likely change between the build tree and install tree and
5263   // this target must be relinked.
5264   return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
5265 }
5266
5267 //----------------------------------------------------------------------------
5268 std::string cmTarget::GetInstallNameDirForBuildTree(const char* config)
5269 {
5270   // If building directly for installation then the build tree install_name
5271   // is the same as the install tree.
5272   if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
5273     {
5274     return GetInstallNameDirForInstallTree();
5275     }
5276
5277   // Use the build tree directory for the target.
5278   if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
5279      !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
5280      !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
5281     {
5282     std::string dir;
5283     if(this->GetPropertyAsBool("MACOSX_RPATH"))
5284       {
5285       dir = "@rpath";
5286       }
5287     else
5288       {
5289       dir = this->GetDirectory(config);
5290       }
5291     dir += "/";
5292     return dir;
5293     }
5294   else
5295     {
5296     return "";
5297     }
5298 }
5299
5300 //----------------------------------------------------------------------------
5301 std::string cmTarget::GetInstallNameDirForInstallTree()
5302 {
5303   if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
5304     {
5305     std::string dir;
5306     const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
5307
5308     if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
5309        !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
5310       {
5311       if(install_name_dir && *install_name_dir)
5312         {
5313         dir = install_name_dir;
5314         dir += "/";
5315         }
5316       }
5317     if(!install_name_dir && this->GetPropertyAsBool("MACOSX_RPATH"))
5318       {
5319       dir = "@rpath/";
5320       }
5321     return dir;
5322     }
5323   else
5324     {
5325     return "";
5326     }
5327 }
5328
5329 //----------------------------------------------------------------------------
5330 const char* cmTarget::GetOutputTargetType(bool implib)
5331 {
5332   switch(this->GetType())
5333     {
5334     case cmTarget::SHARED_LIBRARY:
5335       if(this->DLLPlatform)
5336         {
5337         if(implib)
5338           {
5339           // A DLL import library is treated as an archive target.
5340           return "ARCHIVE";
5341           }
5342         else
5343           {
5344           // A DLL shared library is treated as a runtime target.
5345           return "RUNTIME";
5346           }
5347         }
5348       else
5349         {
5350         // For non-DLL platforms shared libraries are treated as
5351         // library targets.
5352         return "LIBRARY";
5353         }
5354     case cmTarget::STATIC_LIBRARY:
5355       // Static libraries are always treated as archive targets.
5356       return "ARCHIVE";
5357     case cmTarget::MODULE_LIBRARY:
5358       if(implib)
5359         {
5360         // Module libraries are always treated as library targets.
5361         return "ARCHIVE";
5362         }
5363       else
5364         {
5365         // Module import libraries are treated as archive targets.
5366         return "LIBRARY";
5367         }
5368     case cmTarget::EXECUTABLE:
5369       if(implib)
5370         {
5371         // Executable import libraries are treated as archive targets.
5372         return "ARCHIVE";
5373         }
5374       else
5375         {
5376         // Executables are always treated as runtime targets.
5377         return "RUNTIME";
5378         }
5379     default:
5380       break;
5381     }
5382   return "";
5383 }
5384
5385 //----------------------------------------------------------------------------
5386 bool cmTarget::ComputeOutputDir(const char* config,
5387                                 bool implib, std::string& out)
5388 {
5389   bool usesDefaultOutputDir = false;
5390
5391   // Look for a target property defining the target output directory
5392   // based on the target type.
5393   std::string targetTypeName = this->GetOutputTargetType(implib);
5394   const char* propertyName = 0;
5395   std::string propertyNameStr = targetTypeName;
5396   if(!propertyNameStr.empty())
5397     {
5398     propertyNameStr += "_OUTPUT_DIRECTORY";
5399     propertyName = propertyNameStr.c_str();
5400     }
5401
5402   // Check for a per-configuration output directory target property.
5403   std::string configUpper = cmSystemTools::UpperCase(config? config : "");
5404   const char* configProp = 0;
5405   std::string configPropStr = targetTypeName;
5406   if(!configPropStr.empty())
5407     {
5408     configPropStr += "_OUTPUT_DIRECTORY_";
5409     configPropStr += configUpper;
5410     configProp = configPropStr.c_str();
5411     }
5412
5413   // Select an output directory.
5414   if(const char* config_outdir = this->GetProperty(configProp))
5415     {
5416     // Use the user-specified per-configuration output directory.
5417     out = config_outdir;
5418
5419     // Skip per-configuration subdirectory.
5420     config = 0;
5421     }
5422   else if(const char* outdir = this->GetProperty(propertyName))
5423     {
5424     // Use the user-specified output directory.
5425     out = outdir;
5426     }
5427   else if(this->GetType() == cmTarget::EXECUTABLE)
5428     {
5429     // Lookup the output path for executables.
5430     out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
5431     }
5432   else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
5433           this->GetType() == cmTarget::SHARED_LIBRARY ||
5434           this->GetType() == cmTarget::MODULE_LIBRARY)
5435     {
5436     // Lookup the output path for libraries.
5437     out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
5438     }
5439   if(out.empty())
5440     {
5441     // Default to the current output directory.
5442     usesDefaultOutputDir = true;
5443     out = ".";
5444     }
5445
5446   // Convert the output path to a full path in case it is
5447   // specified as a relative path.  Treat a relative path as
5448   // relative to the current output directory for this makefile.
5449   out = (cmSystemTools::CollapseFullPath
5450          (out.c_str(), this->Makefile->GetStartOutputDirectory()));
5451
5452   // The generator may add the configuration's subdirectory.
5453   if(config && *config)
5454     {
5455     const char *platforms = this->Makefile->GetDefinition(
5456       "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
5457     std::string suffix =
5458       usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
5459     this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
5460       AppendDirectoryForConfig("/", config, suffix.c_str(), out);
5461     }
5462
5463   return usesDefaultOutputDir;
5464 }
5465
5466 //----------------------------------------------------------------------------
5467 bool cmTarget::ComputePDBOutputDir(const char* config, std::string& out)
5468 {
5469   // Look for a target property defining the target output directory
5470   // based on the target type.
5471   std::string targetTypeName = "PDB";
5472   const char* propertyName = 0;
5473   std::string propertyNameStr = targetTypeName;
5474   if(!propertyNameStr.empty())
5475     {
5476     propertyNameStr += "_OUTPUT_DIRECTORY";
5477     propertyName = propertyNameStr.c_str();
5478     }
5479
5480   // Check for a per-configuration output directory target property.
5481   std::string configUpper = cmSystemTools::UpperCase(config? config : "");
5482   const char* configProp = 0;
5483   std::string configPropStr = targetTypeName;
5484   if(!configPropStr.empty())
5485     {
5486     configPropStr += "_OUTPUT_DIRECTORY_";
5487     configPropStr += configUpper;
5488     configProp = configPropStr.c_str();
5489     }
5490
5491   // Select an output directory.
5492   if(const char* config_outdir = this->GetProperty(configProp))
5493     {
5494     // Use the user-specified per-configuration output directory.
5495     out = config_outdir;
5496
5497     // Skip per-configuration subdirectory.
5498     config = 0;
5499     }
5500   else if(const char* outdir = this->GetProperty(propertyName))
5501     {
5502     // Use the user-specified output directory.
5503     out = outdir;
5504     }
5505   if(out.empty())
5506     {
5507     return false;
5508     }
5509
5510   // Convert the output path to a full path in case it is
5511   // specified as a relative path.  Treat a relative path as
5512   // relative to the current output directory for this makefile.
5513   out = (cmSystemTools::CollapseFullPath
5514          (out.c_str(), this->Makefile->GetStartOutputDirectory()));
5515
5516   // The generator may add the configuration's subdirectory.
5517   if(config && *config)
5518     {
5519     this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
5520       AppendDirectoryForConfig("/", config, "", out);
5521     }
5522   return true;
5523 }
5524
5525 //----------------------------------------------------------------------------
5526 bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib)
5527 {
5528   std::string dir;
5529   return this->ComputeOutputDir(config, implib, dir);
5530 }
5531
5532 //----------------------------------------------------------------------------
5533 std::string cmTarget::GetOutputName(const char* config, bool implib)
5534 {
5535   std::vector<std::string> props;
5536   std::string type = this->GetOutputTargetType(implib);
5537   std::string configUpper = cmSystemTools::UpperCase(config? config : "");
5538   if(!type.empty() && !configUpper.empty())
5539     {
5540     // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
5541     props.push_back(type + "_OUTPUT_NAME_" + configUpper);
5542     }
5543   if(!type.empty())
5544     {
5545     // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
5546     props.push_back(type + "_OUTPUT_NAME");
5547     }
5548   if(!configUpper.empty())
5549     {
5550     // OUTPUT_NAME_<CONFIG>
5551     props.push_back("OUTPUT_NAME_" + configUpper);
5552     // <CONFIG>_OUTPUT_NAME
5553     props.push_back(configUpper + "_OUTPUT_NAME");
5554     }
5555   // OUTPUT_NAME
5556   props.push_back("OUTPUT_NAME");
5557
5558   for(std::vector<std::string>::const_iterator i = props.begin();
5559       i != props.end(); ++i)
5560     {
5561     if(const char* outName = this->GetProperty(i->c_str()))
5562       {
5563       return outName;
5564       }
5565     }
5566   return this->GetName();
5567 }
5568
5569 //----------------------------------------------------------------------------
5570 std::string cmTarget::GetFrameworkVersion()
5571 {
5572   if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
5573     {
5574     return fversion;
5575     }
5576   else if(const char* tversion = this->GetProperty("VERSION"))
5577     {
5578     return tversion;
5579     }
5580   else
5581     {
5582     return "A";
5583     }
5584 }
5585
5586 //----------------------------------------------------------------------------
5587 const char* cmTarget::GetExportMacro()
5588 {
5589   // Define the symbol for targets that export symbols.
5590   if(this->GetType() == cmTarget::SHARED_LIBRARY ||
5591      this->GetType() == cmTarget::MODULE_LIBRARY ||
5592      this->IsExecutableWithExports())
5593     {
5594     if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
5595       {
5596       this->ExportMacro = custom_export_name;
5597       }
5598     else
5599       {
5600       std::string in = this->GetName();
5601       in += "_EXPORTS";
5602       this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
5603       }
5604     return this->ExportMacro.c_str();
5605     }
5606   else
5607     {
5608     return 0;
5609     }
5610 }
5611
5612 //----------------------------------------------------------------------------
5613 bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p)
5614 {
5615   return this->LinkImplicitNullProperties.find(p)
5616       != this->LinkImplicitNullProperties.end();
5617 }
5618
5619 //----------------------------------------------------------------------------
5620 template<typename PropertyType>
5621 PropertyType getTypedProperty(cmTarget *tgt, const char *prop,
5622                               PropertyType *);
5623
5624 //----------------------------------------------------------------------------
5625 template<>
5626 bool getTypedProperty<bool>(cmTarget *tgt, const char *prop, bool *)
5627 {
5628   return tgt->GetPropertyAsBool(prop);
5629 }
5630
5631 //----------------------------------------------------------------------------
5632 template<>
5633 const char *getTypedProperty<const char *>(cmTarget *tgt, const char *prop,
5634                                           const char **)
5635 {
5636   return tgt->GetProperty(prop);
5637 }
5638
5639 //----------------------------------------------------------------------------
5640 template<typename PropertyType>
5641 bool consistentProperty(PropertyType lhs, PropertyType rhs);
5642
5643 //----------------------------------------------------------------------------
5644 template<>
5645 bool consistentProperty(bool lhs, bool rhs)
5646 {
5647   return lhs == rhs;
5648 }
5649
5650 //----------------------------------------------------------------------------
5651 template<>
5652 bool consistentProperty(const char *lhs, const char *rhs)
5653 {
5654   if (!lhs && !rhs)
5655     return true;
5656   if (!lhs || !rhs)
5657     return false;
5658   return strcmp(lhs, rhs) == 0;
5659 }
5660
5661 //----------------------------------------------------------------------------
5662 template<typename PropertyType>
5663 PropertyType checkInterfacePropertyCompatibility(cmTarget *tgt,
5664                                           const std::string &p,
5665                                           const char *config,
5666                                           const char *defaultValue,
5667                                           PropertyType *)
5668 {
5669   PropertyType propContent = getTypedProperty<PropertyType>(tgt, p.c_str(),
5670                                                             0);
5671   const bool explicitlySet = tgt->GetProperties()
5672                                   .find(p.c_str())
5673                                   != tgt->GetProperties().end();
5674   const bool impliedByUse =
5675           tgt->IsNullImpliedByLinkLibraries(p);
5676   assert((impliedByUse ^ explicitlySet)
5677       || (!impliedByUse && !explicitlySet));
5678
5679   cmComputeLinkInformation *info = tgt->GetLinkInformation(config);
5680   if(!info)
5681     {
5682     return propContent;
5683     }
5684   const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
5685   bool propInitialized = explicitlySet;
5686
5687   for(cmComputeLinkInformation::ItemVector::const_iterator li =
5688       deps.begin();
5689       li != deps.end(); ++li)
5690     {
5691     // An error should be reported if one dependency
5692     // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
5693     // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
5694     // target itself has a POSITION_INDEPENDENT_CODE which disagrees
5695     // with a dependency.
5696
5697     if (!li->Target)
5698       {
5699       continue;
5700       }
5701
5702     const bool ifaceIsSet = li->Target->GetProperties()
5703                             .find("INTERFACE_" + p)
5704                             != li->Target->GetProperties().end();
5705     PropertyType ifacePropContent =
5706                     getTypedProperty<PropertyType>(li->Target,
5707                               ("INTERFACE_" + p).c_str(), 0);
5708     if (explicitlySet)
5709       {
5710       if (ifaceIsSet)
5711         {
5712         if (!consistentProperty(propContent, ifacePropContent))
5713           {
5714           cmOStringStream e;
5715           e << "Property " << p << " on target \""
5716             << tgt->GetName() << "\" does\nnot match the "
5717             "INTERFACE_" << p << " property requirement\nof "
5718             "dependency \"" << li->Target->GetName() << "\".\n";
5719           cmSystemTools::Error(e.str().c_str());
5720           break;
5721           }
5722         else
5723           {
5724           // Agree
5725           continue;
5726           }
5727         }
5728       else
5729         {
5730         // Explicitly set on target and not set in iface. Can't disagree.
5731         continue;
5732         }
5733       }
5734     else if (impliedByUse)
5735       {
5736       if (ifaceIsSet)
5737         {
5738         if (!consistentProperty(propContent, ifacePropContent))
5739           {
5740           cmOStringStream e;
5741           e << "Property " << p << " on target \""
5742             << tgt->GetName() << "\" is\nimplied to be " << defaultValue
5743             << " because it was used to determine the link libraries\n"
5744                "already. The INTERFACE_" << p << " property on\ndependency \""
5745             << li->Target->GetName() << "\" is in conflict.\n";
5746           cmSystemTools::Error(e.str().c_str());
5747           break;
5748           }
5749         else
5750           {
5751           // Agree
5752           continue;
5753           }
5754         }
5755       else
5756         {
5757         // Implicitly set on target and not set in iface. Can't disagree.
5758         continue;
5759         }
5760       }
5761     else
5762       {
5763       if (ifaceIsSet)
5764         {
5765         if (propInitialized)
5766           {
5767           if (!consistentProperty(propContent, ifacePropContent))
5768             {
5769             cmOStringStream e;
5770             e << "The INTERFACE_" << p << " property of \""
5771               << li->Target->GetName() << "\" does\nnot agree with the value "
5772                 "of " << p << " already determined\nfor \""
5773               << tgt->GetName() << "\".\n";
5774             cmSystemTools::Error(e.str().c_str());
5775             break;
5776             }
5777           else
5778             {
5779             // Agree.
5780             continue;
5781             }
5782           }
5783         else
5784           {
5785           propContent = ifacePropContent;
5786           propInitialized = true;
5787           }
5788         }
5789       else
5790         {
5791         // Not set. Nothing to agree on.
5792         continue;
5793         }
5794       }
5795     }
5796   return propContent;
5797 }
5798
5799 //----------------------------------------------------------------------------
5800 bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
5801                                                      const char *config)
5802 {
5803   return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
5804                                                    0);
5805 }
5806
5807 //----------------------------------------------------------------------------
5808 const char * cmTarget::GetLinkInterfaceDependentStringProperty(
5809                                                       const std::string &p,
5810                                                       const char *config)
5811 {
5812   return checkInterfacePropertyCompatibility<const char *>(this,
5813                                                            p,
5814                                                            config,
5815                                                            "empty", 0);
5816 }
5817
5818 //----------------------------------------------------------------------------
5819 bool isLinkDependentProperty(cmTarget *tgt, const std::string &p,
5820                              const char *interfaceProperty,
5821                              const char *config)
5822 {
5823   cmComputeLinkInformation *info = tgt->GetLinkInformation(config);
5824   if(!info)
5825     {
5826     return false;
5827     }
5828
5829   const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
5830
5831   for(cmComputeLinkInformation::ItemVector::const_iterator li =
5832       deps.begin();
5833       li != deps.end(); ++li)
5834     {
5835     if (!li->Target)
5836       {
5837       continue;
5838       }
5839     const char *prop = li->Target->GetProperty(interfaceProperty);
5840     if (!prop)
5841       {
5842       continue;
5843       }
5844
5845     std::vector<std::string> props;
5846     cmSystemTools::ExpandListArgument(prop, props);
5847
5848     for(std::vector<std::string>::iterator pi = props.begin();
5849         pi != props.end(); ++pi)
5850       {
5851       if (*pi == p)
5852         {
5853         return true;
5854         }
5855       }
5856     }
5857
5858   return false;
5859 }
5860
5861 //----------------------------------------------------------------------------
5862 bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
5863                                            const char *config)
5864 {
5865   if (this->TargetTypeValue == OBJECT_LIBRARY)
5866     {
5867     return false;
5868     }
5869   return (p == "POSITION_INDEPENDENT_CODE") ||
5870     isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_BOOL",
5871                                  config);
5872 }
5873
5874 //----------------------------------------------------------------------------
5875 bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
5876                                     const char *config)
5877 {
5878   if (this->TargetTypeValue == OBJECT_LIBRARY)
5879     {
5880     return false;
5881     }
5882   return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_STRING",
5883                                  config);
5884 }
5885
5886 //----------------------------------------------------------------------------
5887 void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
5888 {
5889   for(std::vector<cmSourceFile*>::const_iterator
5890         i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
5891     {
5892     if(const char* lang = (*i)->GetLanguage())
5893       {
5894       languages.insert(lang);
5895       }
5896     }
5897 }
5898
5899 //----------------------------------------------------------------------------
5900 bool cmTarget::IsChrpathUsed(const char* config)
5901 {
5902   // Only certain target types have an rpath.
5903   if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
5904        this->GetType() == cmTarget::MODULE_LIBRARY ||
5905        this->GetType() == cmTarget::EXECUTABLE))
5906     {
5907     return false;
5908     }
5909
5910   // If the target will not be installed we do not need to change its
5911   // rpath.
5912   if(!this->GetHaveInstallRule())
5913     {
5914     return false;
5915     }
5916
5917   // Skip chrpath if skipping rpath altogether.
5918   if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
5919     {
5920     return false;
5921     }
5922
5923   // Skip chrpath if it does not need to be changed at install time.
5924   if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
5925     {
5926     return false;
5927     }
5928
5929   // Allow the user to disable builtin chrpath explicitly.
5930   if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
5931     {
5932     return false;
5933     }
5934
5935   if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
5936     {
5937     return true;
5938     }
5939
5940 #if defined(CMAKE_USE_ELF_PARSER)
5941   // Enable if the rpath flag uses a separator and the target uses ELF
5942   // binaries.
5943   if(const char* ll = this->GetLinkerLanguage(config, this))
5944     {
5945     std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
5946     sepVar += ll;
5947     sepVar += "_FLAG_SEP";
5948     const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
5949     if(sep && *sep)
5950       {
5951       // TODO: Add ELF check to ABI detection and get rid of
5952       // CMAKE_EXECUTABLE_FORMAT.
5953       if(const char* fmt =
5954          this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
5955         {
5956         return strcmp(fmt, "ELF") == 0;
5957         }
5958       }
5959     }
5960 #endif
5961   static_cast<void>(config);
5962   return false;
5963 }
5964
5965 //----------------------------------------------------------------------------
5966 cmTarget::ImportInfo const*
5967 cmTarget::GetImportInfo(const char* config, cmTarget *headTarget)
5968 {
5969   // There is no imported information for non-imported targets.
5970   if(!this->IsImported())
5971     {
5972     return 0;
5973     }
5974
5975   // Lookup/compute/cache the import information for this
5976   // configuration.
5977   std::string config_upper;
5978   if(config && *config)
5979     {
5980     config_upper = cmSystemTools::UpperCase(config);
5981     }
5982   else
5983     {
5984     config_upper = "NOCONFIG";
5985     }
5986   TargetConfigPair key(headTarget, config_upper);
5987   typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
5988
5989   ImportInfoMapType::const_iterator i =
5990     this->Internal->ImportInfoMap.find(key);
5991   if(i == this->Internal->ImportInfoMap.end())
5992     {
5993     ImportInfo info;
5994     this->ComputeImportInfo(config_upper, info, headTarget);
5995     ImportInfoMapType::value_type entry(key, info);
5996     i = this->Internal->ImportInfoMap.insert(entry).first;
5997     }
5998
5999   // If the location is empty then the target is not available for
6000   // this configuration.
6001   if(i->second.Location.empty() && i->second.ImportLibrary.empty())
6002     {
6003     return 0;
6004     }
6005
6006   // Return the import information.
6007   return &i->second;
6008 }
6009
6010 bool cmTarget::GetMappedConfig(std::string const& desired_config,
6011                                const char** loc,
6012                                const char** imp,
6013                                std::string& suffix)
6014 {
6015   // Track the configuration-specific property suffix.
6016   suffix = "_";
6017   suffix += desired_config;
6018
6019   std::vector<std::string> mappedConfigs;
6020   {
6021   std::string mapProp = "MAP_IMPORTED_CONFIG_";
6022   mapProp += desired_config;
6023   if(const char* mapValue = this->GetProperty(mapProp.c_str()))
6024     {
6025     cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
6026     }
6027   }
6028
6029   // If we needed to find one of the mapped configurations but did not
6030   // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
6031   // library or an executable with exports.
6032   bool allowImp = this->HasImportLibrary();
6033
6034   // If a mapping was found, check its configurations.
6035   for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
6036       !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
6037     {
6038     // Look for this configuration.
6039     std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
6040     std::string locProp = "IMPORTED_LOCATION_";
6041     locProp += mcUpper;
6042     *loc = this->GetProperty(locProp.c_str());
6043     if(allowImp)
6044       {
6045       std::string impProp = "IMPORTED_IMPLIB_";
6046       impProp += mcUpper;
6047       *imp = this->GetProperty(impProp.c_str());
6048       }
6049
6050     // If it was found, use it for all properties below.
6051     if(*loc || *imp)
6052       {
6053       suffix = "_";
6054       suffix += mcUpper;
6055       }
6056     }
6057
6058   // If we needed to find one of the mapped configurations but did not
6059   // then the target is not found.  The project does not want any
6060   // other configuration.
6061   if(!mappedConfigs.empty() && !*loc && !*imp)
6062     {
6063     return false;
6064     }
6065
6066   // If we have not yet found it then there are no mapped
6067   // configurations.  Look for an exact-match.
6068   if(!*loc && !*imp)
6069     {
6070     std::string locProp = "IMPORTED_LOCATION";
6071     locProp += suffix;
6072     *loc = this->GetProperty(locProp.c_str());
6073     if(allowImp)
6074       {
6075       std::string impProp = "IMPORTED_IMPLIB";
6076       impProp += suffix;
6077       *imp = this->GetProperty(impProp.c_str());
6078       }
6079     }
6080
6081   // If we have not yet found it then there are no mapped
6082   // configurations and no exact match.
6083   if(!*loc && !*imp)
6084     {
6085     // The suffix computed above is not useful.
6086     suffix = "";
6087
6088     // Look for a configuration-less location.  This may be set by
6089     // manually-written code.
6090     *loc = this->GetProperty("IMPORTED_LOCATION");
6091     if(allowImp)
6092       {
6093       *imp = this->GetProperty("IMPORTED_IMPLIB");
6094       }
6095     }
6096
6097   // If we have not yet found it then the project is willing to try
6098   // any available configuration.
6099   if(!*loc && !*imp)
6100     {
6101     std::vector<std::string> availableConfigs;
6102     if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
6103       {
6104       cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
6105       }
6106     for(std::vector<std::string>::const_iterator
6107           aci = availableConfigs.begin();
6108         !*loc && !*imp && aci != availableConfigs.end(); ++aci)
6109       {
6110       suffix = "_";
6111       suffix += cmSystemTools::UpperCase(*aci);
6112       std::string locProp = "IMPORTED_LOCATION";
6113       locProp += suffix;
6114       *loc = this->GetProperty(locProp.c_str());
6115       if(allowImp)
6116         {
6117         std::string impProp = "IMPORTED_IMPLIB";
6118         impProp += suffix;
6119         *imp = this->GetProperty(impProp.c_str());
6120         }
6121       }
6122     }
6123   // If we have not yet found it then the target is not available.
6124   if(!*loc && !*imp)
6125     {
6126     return false;
6127     }
6128
6129   return true;
6130 }
6131
6132 //----------------------------------------------------------------------------
6133 void cmTarget::ComputeImportInfo(std::string const& desired_config,
6134                                  ImportInfo& info,
6135                                  cmTarget *headTarget)
6136 {
6137   // This method finds information about an imported target from its
6138   // properties.  The "IMPORTED_" namespace is reserved for properties
6139   // defined by the project exporting the target.
6140
6141   // Initialize members.
6142   info.NoSOName = false;
6143
6144   const char* loc = 0;
6145   const char* imp = 0;
6146   std::string suffix;
6147   if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
6148     {
6149     return;
6150     }
6151
6152   // A provided configuration has been chosen.  Load the
6153   // configuration's properties.
6154
6155   // Get the location.
6156   if(loc)
6157     {
6158     info.Location = loc;
6159     }
6160   else
6161     {
6162     std::string impProp = "IMPORTED_LOCATION";
6163     impProp += suffix;
6164     if(const char* config_location = this->GetProperty(impProp.c_str()))
6165       {
6166       info.Location = config_location;
6167       }
6168     else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
6169       {
6170       info.Location = location;
6171       }
6172     }
6173
6174   // Get the soname.
6175   if(this->GetType() == cmTarget::SHARED_LIBRARY)
6176     {
6177     std::string soProp = "IMPORTED_SONAME";
6178     soProp += suffix;
6179     if(const char* config_soname = this->GetProperty(soProp.c_str()))
6180       {
6181       info.SOName = config_soname;
6182       }
6183     else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
6184       {
6185       info.SOName = soname;
6186       }
6187     }
6188
6189   // Get the "no-soname" mark.
6190   if(this->GetType() == cmTarget::SHARED_LIBRARY)
6191     {
6192     std::string soProp = "IMPORTED_NO_SONAME";
6193     soProp += suffix;
6194     if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
6195       {
6196       info.NoSOName = cmSystemTools::IsOn(config_no_soname);
6197       }
6198     else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
6199       {
6200       info.NoSOName = cmSystemTools::IsOn(no_soname);
6201       }
6202     }
6203
6204   // Get the import library.
6205   if(imp)
6206     {
6207     info.ImportLibrary = imp;
6208     }
6209   else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
6210           this->IsExecutableWithExports())
6211     {
6212     std::string impProp = "IMPORTED_IMPLIB";
6213     impProp += suffix;
6214     if(const char* config_implib = this->GetProperty(impProp.c_str()))
6215       {
6216       info.ImportLibrary = config_implib;
6217       }
6218     else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
6219       {
6220       info.ImportLibrary = implib;
6221       }
6222     }
6223
6224   // Get the link interface.
6225   {
6226   std::string linkProp = "INTERFACE_LINK_LIBRARIES";
6227   const char *propertyLibs = this->GetProperty(linkProp.c_str());
6228
6229   if (!propertyLibs)
6230     {
6231     linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
6232     linkProp += suffix;
6233     propertyLibs = this->GetProperty(linkProp.c_str());
6234     }
6235
6236   if(!propertyLibs)
6237     {
6238     linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
6239     propertyLibs = this->GetProperty(linkProp.c_str());
6240     }
6241   if(propertyLibs)
6242     {
6243     cmListFileBacktrace lfbt;
6244     cmGeneratorExpression ge(lfbt);
6245
6246     cmGeneratorExpressionDAGChecker dagChecker(lfbt,
6247                                         this->GetName(),
6248                                         linkProp, 0, 0);
6249     cmSystemTools::ExpandListArgument(ge.Parse(propertyLibs)
6250                                        ->Evaluate(this->Makefile,
6251                                                   desired_config.c_str(),
6252                                                   false,
6253                                                   headTarget,
6254                                                   this,
6255                                                   &dagChecker),
6256                                     info.LinkInterface.Libraries);
6257     }
6258   }
6259
6260   // Get the link dependencies.
6261   {
6262   std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
6263   linkProp += suffix;
6264   if(const char* config_libs = this->GetProperty(linkProp.c_str()))
6265     {
6266     cmSystemTools::ExpandListArgument(config_libs,
6267                                       info.LinkInterface.SharedDeps);
6268     }
6269   else if(const char* libs =
6270           this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
6271     {
6272     cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
6273     }
6274   }
6275
6276   // Get the link languages.
6277   if(this->LinkLanguagePropagatesToDependents())
6278     {
6279     std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
6280     linkProp += suffix;
6281     if(const char* config_libs = this->GetProperty(linkProp.c_str()))
6282       {
6283       cmSystemTools::ExpandListArgument(config_libs,
6284                                         info.LinkInterface.Languages);
6285       }
6286     else if(const char* libs =
6287             this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
6288       {
6289       cmSystemTools::ExpandListArgument(libs,
6290                                         info.LinkInterface.Languages);
6291       }
6292     }
6293
6294   // Get the cyclic repetition count.
6295   if(this->GetType() == cmTarget::STATIC_LIBRARY)
6296     {
6297     std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
6298     linkProp += suffix;
6299     if(const char* config_reps = this->GetProperty(linkProp.c_str()))
6300       {
6301       sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
6302       }
6303     else if(const char* reps =
6304             this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
6305       {
6306       sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
6307       }
6308     }
6309 }
6310
6311 //----------------------------------------------------------------------------
6312 cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config,
6313                                                       cmTarget *head)
6314 {
6315   // Imported targets have their own link interface.
6316   if(this->IsImported())
6317     {
6318     if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head))
6319       {
6320       return &info->LinkInterface;
6321       }
6322     return 0;
6323     }
6324
6325   // Link interfaces are not supported for executables that do not
6326   // export symbols.
6327   if(this->GetType() == cmTarget::EXECUTABLE &&
6328      !this->IsExecutableWithExports())
6329     {
6330     return 0;
6331     }
6332
6333   // Lookup any existing link interface for this configuration.
6334   TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
6335
6336   cmTargetInternals::LinkInterfaceMapType::iterator
6337     i = this->Internal->LinkInterfaceMap.find(key);
6338   if(i == this->Internal->LinkInterfaceMap.end())
6339     {
6340     // Compute the link interface for this configuration.
6341     cmTargetInternals::OptionalLinkInterface iface;
6342     iface.Exists = this->ComputeLinkInterface(config, iface, head);
6343
6344     // Store the information for this configuration.
6345     cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
6346     i = this->Internal->LinkInterfaceMap.insert(entry).first;
6347     }
6348
6349   return i->second.Exists? &i->second : 0;
6350 }
6351
6352 //----------------------------------------------------------------------------
6353 void cmTarget::GetTransitivePropertyLinkLibraries(
6354                                       const char* config,
6355                                       cmTarget *headTarget,
6356                                       std::vector<std::string> &libs)
6357 {
6358   cmTarget::LinkInterface const* iface = this->GetLinkInterface(config,
6359                                                                 headTarget);
6360   if (!iface)
6361     {
6362     return;
6363     }
6364   if(this->GetType() != STATIC_LIBRARY
6365       || this->GetPolicyStatusCMP0022() == cmPolicies::WARN
6366       || this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
6367     {
6368     libs = iface->Libraries;
6369     return;
6370     }
6371
6372   const char* linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
6373   const char* interfaceLibs = this->GetProperty(linkIfaceProp);
6374
6375   if (!interfaceLibs)
6376     {
6377     return;
6378     }
6379
6380   // The interface libraries have been explicitly set.
6381   cmListFileBacktrace lfbt;
6382   cmGeneratorExpression ge(lfbt);
6383   cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
6384                                               linkIfaceProp, 0, 0);
6385   dagChecker.SetTransitivePropertiesOnly();
6386   cmSystemTools::ExpandListArgument(ge.Parse(interfaceLibs)->Evaluate(
6387                                       this->Makefile,
6388                                       config,
6389                                       false,
6390                                       headTarget,
6391                                       this, &dagChecker), libs);
6392 }
6393
6394 //----------------------------------------------------------------------------
6395 bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface,
6396                                     cmTarget *headTarget)
6397 {
6398   // Construct the property name suffix for this configuration.
6399   std::string suffix = "_";
6400   if(config && *config)
6401     {
6402     suffix += cmSystemTools::UpperCase(config);
6403     }
6404   else
6405     {
6406     suffix += "NOCONFIG";
6407     }
6408
6409   // An explicit list of interface libraries may be set for shared
6410   // libraries and executables that export symbols.
6411   const char* explicitLibraries = 0;
6412   std::string linkIfaceProp;
6413   if(this->PolicyStatusCMP0022 != cmPolicies::OLD &&
6414      this->PolicyStatusCMP0022 != cmPolicies::WARN)
6415     {
6416     // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
6417     linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
6418     explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
6419     }
6420   else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
6421           this->IsExecutableWithExports())
6422     {
6423     // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
6424     // shared lib or executable.
6425
6426     // Lookup the per-configuration property.
6427     linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
6428     linkIfaceProp += suffix;
6429     explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
6430
6431     // If not set, try the generic property.
6432     if(!explicitLibraries)
6433       {
6434       linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
6435       explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
6436       }
6437     }
6438
6439   if(explicitLibraries && this->PolicyStatusCMP0022 == cmPolicies::WARN &&
6440      !this->Internal->PolicyWarnedCMP0022)
6441     {
6442     // Compare the explicitly set old link interface properties to the
6443     // preferred new link interface property one and warn if different.
6444     const char* newExplicitLibraries =
6445       this->GetProperty("INTERFACE_LINK_LIBRARIES");
6446     if (newExplicitLibraries
6447         && strcmp(newExplicitLibraries, explicitLibraries) != 0)
6448       {
6449       cmOStringStream w;
6450       w <<
6451         (this->Makefile->GetPolicies()
6452          ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
6453         "Target \"" << this->GetName() << "\" has an "
6454         "INTERFACE_LINK_LIBRARIES property which differs from its " <<
6455         linkIfaceProp << " properties."
6456         "\n"
6457         "INTERFACE_LINK_LIBRARIES:\n"
6458         "  " << newExplicitLibraries << "\n" <<
6459         linkIfaceProp << ":\n"
6460         "  " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
6461       this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
6462       this->Internal->PolicyWarnedCMP0022 = true;
6463       }
6464     }
6465
6466   // There is no implicit link interface for executables or modules
6467   // so if none was explicitly set then there is no link interface.
6468   // Note that CMake versions 2.2 and below allowed linking to modules.
6469   bool canLinkModules = this->Makefile->NeedBackwardsCompatibility(2,2);
6470   if(!explicitLibraries &&
6471      (this->GetType() == cmTarget::EXECUTABLE ||
6472       (this->GetType() == cmTarget::MODULE_LIBRARY && !canLinkModules)))
6473     {
6474     return false;
6475     }
6476
6477   if(explicitLibraries)
6478     {
6479     // The interface libraries have been explicitly set.
6480     cmListFileBacktrace lfbt;
6481     cmGeneratorExpression ge(lfbt);
6482     cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
6483                                                linkIfaceProp, 0, 0);
6484     cmSystemTools::ExpandListArgument(ge.Parse(explicitLibraries)->Evaluate(
6485                                         this->Makefile,
6486                                         config,
6487                                         false,
6488                                         headTarget,
6489                                         this, &dagChecker), iface.Libraries);
6490
6491     if(this->GetType() == cmTarget::SHARED_LIBRARY
6492         || this->GetType() == cmTarget::STATIC_LIBRARY)
6493       {
6494       // Shared libraries may have runtime implementation dependencies
6495       // on other shared libraries that are not in the interface.
6496       std::set<cmStdString> emitted;
6497       for(std::vector<std::string>::const_iterator
6498             li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
6499         {
6500         emitted.insert(*li);
6501         }
6502       LinkImplementation const* impl = this->GetLinkImplementation(config,
6503                                                                 headTarget);
6504       for(std::vector<std::string>::const_iterator
6505             li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
6506         {
6507         if(emitted.insert(*li).second)
6508           {
6509           if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
6510             {
6511             // This is a runtime dependency on another shared library.
6512             if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
6513               {
6514               iface.SharedDeps.push_back(*li);
6515               }
6516             }
6517           else
6518             {
6519             // TODO: Recognize shared library file names.  Perhaps this
6520             // should be moved to cmComputeLinkInformation, but that creates
6521             // a chicken-and-egg problem since this list is needed for its
6522             // construction.
6523             }
6524           }
6525         }
6526       if(this->LinkLanguagePropagatesToDependents())
6527         {
6528         // Targets using this archive need its language runtime libraries.
6529         iface.Languages = impl->Languages;
6530         }
6531       }
6532     }
6533   else if (this->PolicyStatusCMP0022 == cmPolicies::WARN
6534         || this->PolicyStatusCMP0022 == cmPolicies::OLD)
6535     // If CMP0022 is NEW then the plain tll signature sets the
6536     // INTERFACE_LINK_LIBRARIES, so if we get here then the project
6537     // cleared the property explicitly and we should not fall back
6538     // to the link implementation.
6539     {
6540     // The link implementation is the default link interface.
6541     LinkImplementation const* impl = this->GetLinkImplementation(config,
6542                                                               headTarget);
6543     iface.ImplementationIsInterface = true;
6544     iface.Libraries = impl->Libraries;
6545     iface.WrongConfigLibraries = impl->WrongConfigLibraries;
6546     if(this->LinkLanguagePropagatesToDependents())
6547       {
6548       // Targets using this archive need its language runtime libraries.
6549       iface.Languages = impl->Languages;
6550       }
6551
6552     if(this->PolicyStatusCMP0022 == cmPolicies::WARN &&
6553        !this->Internal->PolicyWarnedCMP0022)
6554       {
6555       // Compare the link implementation fallback link interface to the
6556       // preferred new link interface property and warn if different.
6557       cmListFileBacktrace lfbt;
6558       cmGeneratorExpression ge(lfbt);
6559       cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
6560                                       "INTERFACE_LINK_LIBRARIES", 0, 0);
6561       std::vector<std::string> ifaceLibs;
6562       const char* newExplicitLibraries =
6563         this->GetProperty("INTERFACE_LINK_LIBRARIES");
6564       cmSystemTools::ExpandListArgument(
6565         ge.Parse(newExplicitLibraries)->Evaluate(this->Makefile,
6566                                                  config,
6567                                                  false,
6568                                                  headTarget,
6569                                                  this, &dagChecker),
6570         ifaceLibs);
6571       if (ifaceLibs != impl->Libraries)
6572         {
6573         std::string oldLibraries;
6574         std::string newLibraries;
6575         const char *sep = "";
6576         for(std::vector<std::string>::const_iterator it
6577               = impl->Libraries.begin(); it != impl->Libraries.end(); ++it)
6578           {
6579           oldLibraries += sep;
6580           oldLibraries += *it;
6581           sep = ";";
6582           }
6583         sep = "";
6584         for(std::vector<std::string>::const_iterator it
6585               = ifaceLibs.begin(); it != ifaceLibs.end(); ++it)
6586           {
6587           newLibraries += sep;
6588           newLibraries += *it;
6589           sep = ";";
6590           }
6591         if(oldLibraries.empty())
6592           { oldLibraries = "(empty)"; }
6593         if(newLibraries.empty())
6594           { newLibraries = "(empty)"; }
6595
6596         cmOStringStream w;
6597         w <<
6598           (this->Makefile->GetPolicies()
6599            ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
6600           "Target \"" << this->GetName() << "\" has an "
6601           "INTERFACE_LINK_LIBRARIES property.  "
6602           "This should be preferred as the source of the link interface "
6603           "for this library but because CMP0022 is not set CMake is "
6604           "ignoring the property and using the link implementation "
6605           "as the link interface instead."
6606           "\n"
6607           "INTERFACE_LINK_LIBRARIES:\n"
6608           "  " << newLibraries << "\n"
6609           "Link implementation:\n"
6610           "  " << oldLibraries << "\n";
6611         this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
6612         this->Internal->PolicyWarnedCMP0022 = true;
6613         }
6614       }
6615     }
6616
6617   if(this->GetType() == cmTarget::STATIC_LIBRARY)
6618     {
6619     // How many repetitions are needed if this library has cyclic
6620     // dependencies?
6621     std::string propName = "LINK_INTERFACE_MULTIPLICITY";
6622     propName += suffix;
6623     if(const char* config_reps = this->GetProperty(propName.c_str()))
6624       {
6625       sscanf(config_reps, "%u", &iface.Multiplicity);
6626       }
6627     else if(const char* reps =
6628             this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
6629       {
6630       sscanf(reps, "%u", &iface.Multiplicity);
6631       }
6632     }
6633
6634   return true;
6635 }
6636
6637 //----------------------------------------------------------------------------
6638 cmTarget::LinkImplementation const*
6639 cmTarget::GetLinkImplementation(const char* config, cmTarget *head)
6640 {
6641   // There is no link implementation for imported targets.
6642   if(this->IsImported())
6643     {
6644     return 0;
6645     }
6646
6647   // Lookup any existing link implementation for this configuration.
6648   TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
6649
6650   cmTargetInternals::LinkImplMapType::iterator
6651     i = this->Internal->LinkImplMap.find(key);
6652   if(i == this->Internal->LinkImplMap.end())
6653     {
6654     // Compute the link implementation for this configuration.
6655     LinkImplementation impl;
6656     this->ComputeLinkImplementation(config, impl, head);
6657
6658     // Store the information for this configuration.
6659     cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
6660     i = this->Internal->LinkImplMap.insert(entry).first;
6661     }
6662
6663   return &i->second;
6664 }
6665
6666 //----------------------------------------------------------------------------
6667 void cmTarget::ComputeLinkImplementation(const char* config,
6668                                          LinkImplementation& impl,
6669                                          cmTarget *head)
6670 {
6671   // Compute which library configuration to link.
6672   cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
6673
6674   // Collect libraries directly linked in this configuration.
6675   std::vector<std::string> llibs;
6676   this->GetDirectLinkLibraries(config, llibs, head);
6677   for(std::vector<std::string>::const_iterator li = llibs.begin();
6678       li != llibs.end(); ++li)
6679     {
6680     // Skip entries that resolve to the target itself or are empty.
6681     std::string item = this->CheckCMP0004(*li);
6682     if(item == this->GetName() || item.empty())
6683       {
6684       continue;
6685       }
6686     // The entry is meant for this configuration.
6687     impl.Libraries.push_back(item);
6688     }
6689
6690   LinkLibraryVectorType const& oldllibs = this->GetOriginalLinkLibraries();
6691   for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
6692       li != oldllibs.end(); ++li)
6693     {
6694     if(li->second != cmTarget::GENERAL && li->second != linkType)
6695       {
6696       std::string item = this->CheckCMP0004(li->first);
6697       if(item == this->GetName() || item.empty())
6698         {
6699         continue;
6700         }
6701       // Support OLD behavior for CMP0003.
6702       impl.WrongConfigLibraries.push_back(item);
6703       }
6704     }
6705
6706   // This target needs runtime libraries for its source languages.
6707   std::set<cmStdString> languages;
6708   // Get languages used in our source files.
6709   this->GetLanguages(languages);
6710   // Get languages used in object library sources.
6711   for(std::vector<std::string>::iterator i = this->ObjectLibraries.begin();
6712       i != this->ObjectLibraries.end(); ++i)
6713     {
6714     if(cmTarget* objLib = this->Makefile->FindTargetToUse(i->c_str()))
6715       {
6716       if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
6717         {
6718         objLib->GetLanguages(languages);
6719         }
6720       }
6721     }
6722   // Copy the set of langauges to the link implementation.
6723   for(std::set<cmStdString>::iterator li = languages.begin();
6724       li != languages.end(); ++li)
6725     {
6726     impl.Languages.push_back(*li);
6727     }
6728 }
6729
6730 //----------------------------------------------------------------------------
6731 std::string cmTarget::CheckCMP0004(std::string const& item)
6732 {
6733   // Strip whitespace off the library names because we used to do this
6734   // in case variables were expanded at generate time.  We no longer
6735   // do the expansion but users link to libraries like " ${VAR} ".
6736   std::string lib = item;
6737   std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
6738   if(pos != lib.npos)
6739     {
6740     lib = lib.substr(pos, lib.npos);
6741     }
6742   pos = lib.find_last_not_of(" \t\r\n");
6743   if(pos != lib.npos)
6744     {
6745     lib = lib.substr(0, pos+1);
6746     }
6747   if(lib != item)
6748     {
6749     cmake* cm = this->Makefile->GetCMakeInstance();
6750     switch(this->PolicyStatusCMP0004)
6751       {
6752       case cmPolicies::WARN:
6753         {
6754         cmOStringStream w;
6755         w << (this->Makefile->GetPolicies()
6756               ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
6757           << "Target \"" << this->GetName() << "\" links to item \""
6758           << item << "\" which has leading or trailing whitespace.";
6759         cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
6760                          this->GetBacktrace());
6761         }
6762       case cmPolicies::OLD:
6763         break;
6764       case cmPolicies::NEW:
6765         {
6766         cmOStringStream e;
6767         e << "Target \"" << this->GetName() << "\" links to item \""
6768           << item << "\" which has leading or trailing whitespace.  "
6769           << "This is now an error according to policy CMP0004.";
6770         cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
6771         }
6772         break;
6773       case cmPolicies::REQUIRED_IF_USED:
6774       case cmPolicies::REQUIRED_ALWAYS:
6775         {
6776         cmOStringStream e;
6777         e << (this->Makefile->GetPolicies()
6778               ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
6779           << "Target \"" << this->GetName() << "\" links to item \""
6780           << item << "\" which has leading or trailing whitespace.";
6781         cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
6782         }
6783         break;
6784       }
6785     }
6786   return lib;
6787 }
6788
6789 template<typename PropertyType>
6790 PropertyType getLinkInterfaceDependentProperty(cmTarget *tgt,
6791                                                const std::string prop,
6792                                                const char *config,
6793                                                PropertyType *);
6794
6795 template<>
6796 bool getLinkInterfaceDependentProperty(cmTarget *tgt,
6797                                          const std::string prop,
6798                                          const char *config, bool *)
6799 {
6800   return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
6801 }
6802
6803 template<>
6804 const char * getLinkInterfaceDependentProperty(cmTarget *tgt,
6805                                                  const std::string prop,
6806                                                  const char *config,
6807                                                  const char **)
6808 {
6809   return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
6810 }
6811
6812 //----------------------------------------------------------------------------
6813 template<typename PropertyType>
6814 void checkPropertyConsistency(cmTarget *depender, cmTarget *dependee,
6815                               const char *propName,
6816                               std::set<cmStdString> &emitted,
6817                               const char *config,
6818                               PropertyType *)
6819 {
6820   const char *prop = dependee->GetProperty(propName);
6821   if (!prop)
6822     {
6823     return;
6824     }
6825
6826   std::vector<std::string> props;
6827   cmSystemTools::ExpandListArgument(prop, props);
6828
6829   for(std::vector<std::string>::iterator pi = props.begin();
6830       pi != props.end(); ++pi)
6831     {
6832     if (depender->GetMakefile()->GetCMakeInstance()
6833                       ->GetIsPropertyDefined(pi->c_str(),
6834                                               cmProperty::TARGET))
6835       {
6836       cmOStringStream e;
6837       e << "Target \"" << dependee->GetName() << "\" has property \""
6838         << *pi << "\" listed in its " << propName << " property.  "
6839           "This is not allowed.  Only user-defined properties may appear "
6840           "listed in the " << propName << " property.";
6841       depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
6842       return;
6843       }
6844     if(emitted.insert(*pi).second)
6845       {
6846       getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
6847                                                       0);
6848       if (cmSystemTools::GetErrorOccuredFlag())
6849         {
6850         return;
6851         }
6852       }
6853     }
6854 }
6855
6856 //----------------------------------------------------------------------------
6857 void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
6858                                           const char* config)
6859 {
6860   const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
6861
6862   std::set<cmStdString> emittedBools;
6863   std::set<cmStdString> emittedStrings;
6864
6865   for(cmComputeLinkInformation::ItemVector::const_iterator li =
6866       deps.begin();
6867       li != deps.end(); ++li)
6868     {
6869     if (!li->Target)
6870       {
6871       continue;
6872       }
6873
6874     checkPropertyConsistency<bool>(this, li->Target,
6875                                    "COMPATIBLE_INTERFACE_BOOL",
6876                                    emittedBools, config, 0);
6877     if (cmSystemTools::GetErrorOccuredFlag())
6878       {
6879       return;
6880       }
6881     checkPropertyConsistency<const char *>(this, li->Target,
6882                                            "COMPATIBLE_INTERFACE_STRING",
6883                                            emittedStrings, config, 0);
6884     if (cmSystemTools::GetErrorOccuredFlag())
6885       {
6886       return;
6887       }
6888     }
6889
6890   for(std::set<cmStdString>::const_iterator li = emittedBools.begin();
6891       li != emittedBools.end(); ++li)
6892     {
6893     const std::set<cmStdString>::const_iterator si = emittedStrings.find(*li);
6894     if (si != emittedStrings.end())
6895       {
6896       cmOStringStream e;
6897       e << "Property \"" << *li << "\" appears in both the "
6898       "COMPATIBLE_INTERFACE_BOOL and the COMPATIBLE_INTERFACE_STRING "
6899       "property in the dependencies of target \"" << this->GetName() <<
6900       "\".  This is not allowed. A property may only require compatibility "
6901       "in a boolean interpretation or a string interpretation, but not both.";
6902       this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
6903       break;
6904       }
6905     }
6906 }
6907
6908 //----------------------------------------------------------------------------
6909 cmComputeLinkInformation*
6910 cmTarget::GetLinkInformation(const char* config, cmTarget *head)
6911 {
6912   cmTarget *headTarget = head ? head : this;
6913   // Lookup any existing information for this configuration.
6914   TargetConfigPair key(headTarget,
6915                                   cmSystemTools::UpperCase(config?config:""));
6916   cmTargetLinkInformationMap::iterator
6917     i = this->LinkInformation.find(key);
6918   if(i == this->LinkInformation.end())
6919     {
6920     // Compute information for this configuration.
6921     cmComputeLinkInformation* info =
6922       new cmComputeLinkInformation(this, config, headTarget);
6923     if(!info || !info->Compute())
6924       {
6925       delete info;
6926       info = 0;
6927       }
6928
6929     // Store the information for this configuration.
6930     cmTargetLinkInformationMap::value_type entry(key, info);
6931     i = this->LinkInformation.insert(entry).first;
6932
6933     if (info)
6934       {
6935       this->CheckPropertyCompatibility(info, config);
6936       }
6937     }
6938   return i->second;
6939 }
6940
6941 //----------------------------------------------------------------------------
6942 std::string cmTarget::GetFrameworkDirectory(const char* config,
6943                                             bool rootDir)
6944 {
6945   std::string fpath;
6946   fpath += this->GetOutputName(config, false);
6947   fpath += ".framework";
6948   if(!rootDir)
6949     {
6950     fpath += "/Versions/";
6951     fpath += this->GetFrameworkVersion();
6952     }
6953   return fpath;
6954 }
6955
6956 //----------------------------------------------------------------------------
6957 std::string cmTarget::GetCFBundleDirectory(const char* config,
6958                                            bool contentOnly)
6959 {
6960   std::string fpath;
6961   fpath += this->GetOutputName(config, false);
6962   fpath += ".";
6963   const char *ext = this->GetProperty("BUNDLE_EXTENSION");
6964   if (!ext)
6965     {
6966     ext = "bundle";
6967     }
6968   fpath += ext;
6969   fpath += "/Contents";
6970   if(!contentOnly)
6971     fpath += "/MacOS";
6972   return fpath;
6973 }
6974
6975 //----------------------------------------------------------------------------
6976 std::string cmTarget::GetAppBundleDirectory(const char* config,
6977                                             bool contentOnly)
6978 {
6979   std::string fpath = this->GetFullName(config, false);
6980   fpath += ".app/Contents";
6981   if(!contentOnly)
6982     fpath += "/MacOS";
6983   return fpath;
6984 }
6985
6986 //----------------------------------------------------------------------------
6987 std::string cmTarget::BuildMacContentDirectory(const std::string& base,
6988                                                const char* config,
6989                                                bool contentOnly)
6990 {
6991   std::string fpath = base;
6992   if(this->IsAppBundleOnApple())
6993     {
6994     fpath += this->GetAppBundleDirectory(config, contentOnly);
6995     }
6996   if(this->IsFrameworkOnApple())
6997     {
6998     fpath += this->GetFrameworkDirectory(config, contentOnly);
6999     }
7000   if(this->IsCFBundleOnApple())
7001     {
7002     fpath += this->GetCFBundleDirectory(config, contentOnly);
7003     }
7004   return fpath;
7005 }
7006
7007 //----------------------------------------------------------------------------
7008 std::string cmTarget::GetMacContentDirectory(const char* config,
7009                                              bool implib)
7010 {
7011   // Start with the output directory for the target.
7012   std::string fpath = this->GetDirectory(config, implib);
7013   fpath += "/";
7014   bool contentOnly = true;
7015   if(this->IsFrameworkOnApple())
7016     {
7017     // additional files with a framework go into the version specific
7018     // directory
7019     contentOnly = false;
7020     }
7021   fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
7022   return fpath;
7023 }
7024
7025 //----------------------------------------------------------------------------
7026 cmTargetLinkInformationMap
7027 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
7028 {
7029   // Ideally cmTarget instances should never be copied.  However until
7030   // we can make a sweep to remove that, this copy constructor avoids
7031   // allowing the resources (LinkInformation) from getting copied.  In
7032   // the worst case this will lead to extra cmComputeLinkInformation
7033   // instances.  We also enforce in debug mode that the map be emptied
7034   // when copied.
7035   static_cast<void>(r);
7036   assert(r.empty());
7037 }
7038
7039 //----------------------------------------------------------------------------
7040 cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
7041 {
7042   for(derived::iterator i = this->begin(); i != this->end(); ++i)
7043     {
7044     delete i->second;
7045     }
7046 }
7047
7048 //----------------------------------------------------------------------------
7049 cmTargetInternalPointer::cmTargetInternalPointer()
7050 {
7051   this->Pointer = new cmTargetInternals;
7052 }
7053
7054 //----------------------------------------------------------------------------
7055 cmTargetInternalPointer
7056 ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
7057 {
7058   // Ideally cmTarget instances should never be copied.  However until
7059   // we can make a sweep to remove that, this copy constructor avoids
7060   // allowing the resources (Internals) to be copied.
7061   this->Pointer = new cmTargetInternals(*r.Pointer);
7062 }
7063
7064 //----------------------------------------------------------------------------
7065 cmTargetInternalPointer::~cmTargetInternalPointer()
7066 {
7067   deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
7068   deleteAndClear(this->Pointer->CompileOptionsEntries);
7069   deleteAndClear(this->Pointer->CompileDefinitionsEntries);
7070   delete this->Pointer;
7071 }
7072
7073 //----------------------------------------------------------------------------
7074 cmTargetInternalPointer&
7075 cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
7076 {
7077   if(this == &r) { return *this; } // avoid warning on HP about self check
7078   // Ideally cmTarget instances should never be copied.  However until
7079   // we can make a sweep to remove that, this copy constructor avoids
7080   // allowing the resources (Internals) to be copied.
7081   cmTargetInternals* oldPointer = this->Pointer;
7082   this->Pointer = new cmTargetInternals(*r.Pointer);
7083   delete oldPointer;
7084   return *this;
7085 }