Imported Upstream version 2.8.9
[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 "cmDocumentLocationUndefined.h"
21 #include "cmListFileCache.h"
22 #include "cmGeneratorExpression.h"
23 #include <cmsys/RegularExpression.hxx>
24 #include <map>
25 #include <set>
26 #include <queue>
27 #include <stdlib.h> // required for atof
28 #include <assert.h>
29
30 const char* cmTarget::GetTargetTypeName(TargetType targetType)
31 {
32   switch( targetType )
33     {
34       case cmTarget::STATIC_LIBRARY:
35         return "STATIC_LIBRARY";
36       case cmTarget::MODULE_LIBRARY:
37         return "MODULE_LIBRARY";
38       case cmTarget::SHARED_LIBRARY:
39         return "SHARED_LIBRARY";
40       case cmTarget::OBJECT_LIBRARY:
41         return "OBJECT_LIBRARY";
42       case cmTarget::EXECUTABLE:
43         return "EXECUTABLE";
44       case cmTarget::UTILITY:
45         return "UTILITY";
46       case cmTarget::GLOBAL_TARGET:
47         return "GLOBAL_TARGET";
48       case cmTarget::UNKNOWN_LIBRARY:
49         return "UNKNOWN_LIBRARY";
50     }
51   assert(0 && "Unexpected target type");
52   return 0;
53 }
54
55 //----------------------------------------------------------------------------
56 struct cmTarget::OutputInfo
57 {
58   std::string OutDir;
59   std::string ImpDir;
60 };
61
62 //----------------------------------------------------------------------------
63 struct cmTarget::ImportInfo
64 {
65   bool NoSOName;
66   std::string Location;
67   std::string SOName;
68   std::string ImportLibrary;
69   cmTarget::LinkInterface LinkInterface;
70 };
71
72 //----------------------------------------------------------------------------
73 class cmTargetInternals
74 {
75 public:
76   cmTargetInternals()
77     {
78     this->SourceFileFlagsConstructed = false;
79     }
80   cmTargetInternals(cmTargetInternals const& r)
81     {
82     this->SourceFileFlagsConstructed = false;
83     // Only some of these entries are part of the object state.
84     // Others not copied here are result caches.
85     this->SourceEntries = r.SourceEntries;
86     }
87   typedef cmTarget::SourceFileFlags SourceFileFlags;
88   std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
89   bool SourceFileFlagsConstructed;
90
91   // The backtrace when the target was created.
92   cmListFileBacktrace Backtrace;
93
94   // Cache link interface computation from each configuration.
95   struct OptionalLinkInterface: public cmTarget::LinkInterface
96   {
97     OptionalLinkInterface(): Exists(false) {}
98     bool Exists;
99   };
100   typedef std::map<cmStdString, OptionalLinkInterface> LinkInterfaceMapType;
101   LinkInterfaceMapType LinkInterfaceMap;
102
103   typedef std::map<cmStdString, cmTarget::OutputInfo> OutputInfoMapType;
104   OutputInfoMapType OutputInfoMap;
105
106   typedef std::map<cmStdString, cmTarget::ImportInfo> ImportInfoMapType;
107   ImportInfoMapType ImportInfoMap;
108
109   // Cache link implementation computation from each configuration.
110   typedef std::map<cmStdString, cmTarget::LinkImplementation> LinkImplMapType;
111   LinkImplMapType LinkImplMap;
112
113   typedef std::map<cmStdString, cmTarget::LinkClosure> LinkClosureMapType;
114   LinkClosureMapType LinkClosureMap;
115
116   struct SourceEntry { std::vector<cmSourceFile*> Depends; };
117   typedef std::map<cmSourceFile*, SourceEntry> SourceEntriesType;
118   SourceEntriesType SourceEntries;
119 };
120
121 //----------------------------------------------------------------------------
122 cmTarget::cmTarget()
123 {
124   this->Makefile = 0;
125   this->PolicyStatusCMP0003 = cmPolicies::WARN;
126   this->PolicyStatusCMP0004 = cmPolicies::WARN;
127   this->PolicyStatusCMP0008 = cmPolicies::WARN;
128   this->LinkLibrariesAnalyzed = false;
129   this->HaveInstallRule = false;
130   this->DLLPlatform = false;
131   this->IsApple = false;
132   this->IsImportedTarget = false;
133 }
134
135 //----------------------------------------------------------------------------
136 void cmTarget::DefineProperties(cmake *cm)
137 {
138   cm->DefineProperty
139     ("AUTOMOC", cmProperty::TARGET,
140      "Should the target be processed with automoc (for Qt projects).",
141      "AUTOMOC is a boolean specifying whether CMake will handle "
142      "the Qt moc preprocessor automatically, i.e. without having to use "
143      "the QT4_WRAP_CPP() macro. Currently Qt4 is supported. "
144      "When this property is set to TRUE, CMake will scan the source files "
145      "at build time and invoke moc accordingly. "
146      "If an #include statement like #include \"moc_foo.cpp\" is found, "
147      "the Q_OBJECT class declaration is expected in the header, and moc is "
148      "run on the header file. "
149      "If an #include statement like #include \"foo.moc\" is found, "
150      "then a Q_OBJECT is expected in the current source file and moc "
151      "is run on the file itself. "
152      "Additionally, all header files are parsed for Q_OBJECT macros, "
153      "and if found, moc is also executed on those files. The resulting "
154      "moc files, which are not included as shown above in any of the source "
155      "files are included in a generated <targetname>_automoc.cpp file, "
156      "which is compiled as part of the target."
157      "This property is initialized by the value of the variable "
158      "CMAKE_AUTOMOC if it is set when a target is created.\n"
159      "Additional command line options for moc can be set via the "
160      "AUTOMOC_MOC_OPTIONS property.\n"
161      "By setting the CMAKE_AUTOMOC_RELAXED_MODE variable to TRUE the rules "
162      "for searching the files which will be processed by moc can be relaxed. "
163      "See the documentation for this variable for more details.");
164
165   cm->DefineProperty
166     ("AUTOMOC_MOC_OPTIONS", cmProperty::TARGET,
167     "Additional options for moc when using automoc (see the AUTOMOC property)",
168      "This property is only used if the AUTOMOC property is set to TRUE for "
169      "this target. In this case, it holds additional command line options "
170      "which will be used when moc is executed during the build, i.e. it is "
171      "equivalent to the optional OPTIONS argument of the qt4_wrap_cpp() "
172      "macro.\n"
173      "By default it is empty.");
174
175   cm->DefineProperty
176     ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
177      "Should build tree targets have install tree rpaths.",
178      "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
179      "the target in the build tree with the INSTALL_RPATH.  This takes "
180      "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
181      "before installation.  "
182      "This property is initialized by the value of the variable "
183      "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
184
185   cm->DefineProperty
186     ("COMPILE_FLAGS", cmProperty::TARGET,
187      "Additional flags to use when compiling this target's sources.",
188      "The COMPILE_FLAGS property sets additional compiler flags used "
189      "to build sources within the target.  Use COMPILE_DEFINITIONS "
190      "to pass additional preprocessor definitions.");
191
192   cm->DefineProperty
193     ("COMPILE_DEFINITIONS", cmProperty::TARGET,
194      "Preprocessor definitions for compiling a target's sources.",
195      "The COMPILE_DEFINITIONS property may be set to a "
196      "semicolon-separated list of preprocessor "
197      "definitions using the syntax VAR or VAR=value.  Function-style "
198      "definitions are not supported.  CMake will automatically escape "
199      "the value correctly for the native build system (note that CMake "
200      "language syntax may require escapes to specify some values).  "
201      "This property may be set on a per-configuration basis using the name "
202      "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
203      "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
204      "CMake will automatically drop some definitions that "
205      "are not supported by the native build tool.  "
206      "The VS6 IDE does not support definition values with spaces "
207      "(but NMake does).\n"
208      CM_DOCUMENT_COMPILE_DEFINITIONS_DISCLAIMER);
209
210   cm->DefineProperty
211     ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
212      "Per-configuration preprocessor definitions on a target.",
213      "This is the configuration-specific version of COMPILE_DEFINITIONS.");
214
215   cm->DefineProperty
216     ("DEFINE_SYMBOL", cmProperty::TARGET,
217      "Define a symbol when compiling this target's sources.",
218      "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
219      "compiling sources in a shared library. "
220      "If not set here then it is set to target_EXPORTS by default "
221      "(with some substitutions if the target is not a valid C "
222      "identifier). This is useful for headers to know whether they are "
223      "being included from inside their library our outside to properly "
224      "setup dllexport/dllimport decorations. ");
225
226   cm->DefineProperty
227     ("DEBUG_POSTFIX", cmProperty::TARGET,
228      "See target property <CONFIG>_POSTFIX.",
229      "This property is a special case of the more-general <CONFIG>_POSTFIX "
230      "property for the DEBUG configuration.");
231
232   cm->DefineProperty
233     ("<CONFIG>_POSTFIX", cmProperty::TARGET,
234      "Postfix to append to the target file name for configuration <CONFIG>.",
235      "When building with configuration <CONFIG> the value of this property "
236      "is appended to the target file name built on disk.  "
237      "For non-executable targets, this property is initialized by the value "
238      "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
239      "created.  "
240      "This property is ignored on the Mac for Frameworks and App Bundles.");
241
242   cm->DefineProperty
243     ("EchoString", cmProperty::TARGET,
244      "A message to be displayed when the target is built.",
245      "A message to display on some generators (such as makefiles) when "
246      "the target is built.");
247
248   cm->DefineProperty
249     ("BUNDLE", cmProperty::TARGET,
250      "This target is a CFBundle on the Mac.",
251      "If a module library target has this property set to true it will "
252      "be built as a CFBundle when built on the mac. It will have the "
253      "directory structure required for a CFBundle and will be suitable "
254      "to be used for creating Browser Plugins or other application "
255      "resources.");
256
257   cm->DefineProperty
258     ("BUNDLE_EXTENSION", cmProperty::TARGET,
259      "The file extension used to name a BUNDLE target on the Mac.",
260      "The default value is \"bundle\" - you can also use \"plugin\" or "
261      "whatever file extension is required by the host app for your "
262      "bundle.");
263
264   cm->DefineProperty
265     ("FRAMEWORK", cmProperty::TARGET,
266      "This target is a framework on the Mac.",
267      "If a shared library target has this property set to true it will "
268      "be built as a framework when built on the mac. It will have the "
269      "directory structure required for a framework and will be suitable "
270      "to be used with the -framework option");
271
272   cm->DefineProperty
273     ("HAS_CXX", cmProperty::TARGET,
274      "Link the target using the C++ linker tool (obsolete).",
275      "This is equivalent to setting the LINKER_LANGUAGE property to CXX.  "
276      "See that property's documentation for details.");
277
278   cm->DefineProperty
279     ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
280      "Specify #include line transforms for dependencies in a target.",
281      "This property specifies rules to transform macro-like #include lines "
282      "during implicit dependency scanning of C and C++ source files.  "
283      "The list of rules must be semicolon-separated with each entry of "
284      "the form \"A_MACRO(%)=value-with-%\" (the % must be literal).  "
285      "During dependency scanning occurrences of A_MACRO(...) on #include "
286      "lines will be replaced by the value given with the macro argument "
287      "substituted for '%'.  For example, the entry\n"
288      "  MYDIR(%)=<mydir/%>\n"
289      "will convert lines of the form\n"
290      "  #include MYDIR(myheader.h)\n"
291      "to\n"
292      "  #include <mydir/myheader.h>\n"
293      "allowing the dependency to be followed.\n"
294      "This property applies to sources in the target on which it is set.");
295
296   cm->DefineProperty
297     ("IMPORT_PREFIX", cmProperty::TARGET,
298      "What comes before the import library name.",
299      "Similar to the target property PREFIX, but used for import libraries "
300      "(typically corresponding to a DLL) instead of regular libraries. "
301      "A target property that can be set to override the prefix "
302      "(such as \"lib\") on an import library name.");
303
304   cm->DefineProperty
305     ("IMPORT_SUFFIX", cmProperty::TARGET,
306      "What comes after the import library name.",
307      "Similar to the target property SUFFIX, but used for import libraries "
308      "(typically corresponding to a DLL) instead of regular libraries. "
309      "A target property that can be set to override the suffix "
310      "(such as \".lib\") on an import library name.");
311
312   cm->DefineProperty
313     ("IMPORTED", cmProperty::TARGET,
314      "Read-only indication of whether a target is IMPORTED.",
315      "The boolean value of this property is true for targets created with "
316      "the IMPORTED option to add_executable or add_library.  "
317      "It is false for targets built within the project.");
318
319   cm->DefineProperty
320     ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
321      "Configurations provided for an IMPORTED target.",
322      "Set this to the list of configuration names available for an "
323      "IMPORTED target.  "
324      "The names correspond to configurations defined in the project from "
325      "which the target is imported.  "
326      "If the importing project uses a different set of configurations "
327      "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
328      "property.  "
329      "Ignored for non-imported targets.");
330
331   cm->DefineProperty
332     ("IMPORTED_IMPLIB", cmProperty::TARGET,
333      "Full path to the import library for an IMPORTED target.",
334      "Set this to the location of the \".lib\" part of a windows DLL.  "
335      "Ignored for non-imported targets.");
336
337   cm->DefineProperty
338     ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
339      "<CONFIG>-specific version of IMPORTED_IMPLIB property.",
340      "Configuration names correspond to those provided by the project "
341      "from which the target is imported.");
342
343   cm->DefineProperty
344     ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
345      "Dependent shared libraries of an imported shared library.",
346      "Shared libraries may be linked to other shared libraries as part "
347      "of their implementation.  On some platforms the linker searches "
348      "for the dependent libraries of shared libraries they are including "
349      "in the link.  "
350      "Set this property to the list of dependent shared libraries of an "
351      "imported library.  "
352      "The list "
353      "should be disjoint from the list of interface libraries in the "
354      "IMPORTED_LINK_INTERFACE_LIBRARIES property.  On platforms requiring "
355      "dependent shared libraries to be found at link time CMake uses this "
356      "list to add appropriate files or paths to the link command line.  "
357      "Ignored for non-imported targets.");
358
359   cm->DefineProperty
360     ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
361      "<CONFIG>-specific version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
362      "Configuration names correspond to those provided by the project "
363      "from which the target is imported.  "
364      "If set, this property completely overrides the generic property "
365      "for the named configuration.");
366
367   cm->DefineProperty
368     ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
369      "Transitive link interface of an IMPORTED target.",
370      "Set this to the list of libraries whose interface is included when "
371      "an IMPORTED library target is linked to another target.  "
372      "The libraries will be included on the link line for the target.  "
373      "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
374      "to all imported target types, including STATIC libraries.  "
375      "This property is ignored for non-imported targets.");
376
377   cm->DefineProperty
378     ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
379      "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
380      "Configuration names correspond to those provided by the project "
381      "from which the target is imported.  "
382      "If set, this property completely overrides the generic property "
383      "for the named configuration.");
384
385   cm->DefineProperty
386     ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET,
387      "Languages compiled into an IMPORTED static library.",
388      "Set this to the list of languages of source files compiled to "
389      "produce a STATIC IMPORTED library (such as \"C\" or \"CXX\").  "
390      "CMake accounts for these languages when computing how to link a "
391      "target to the imported library.  "
392      "For example, when a C executable links to an imported C++ static "
393      "library CMake chooses the C++ linker to satisfy language runtime "
394      "dependencies of the static library.  "
395      "\n"
396      "This property is ignored for targets that are not STATIC libraries.  "
397      "This property is ignored for non-imported targets.");
398
399   cm->DefineProperty
400     ("IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>", cmProperty::TARGET,
401      "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LANGUAGES.",
402      "Configuration names correspond to those provided by the project "
403      "from which the target is imported.  "
404      "If set, this property completely overrides the generic property "
405      "for the named configuration.");
406
407   cm->DefineProperty
408     ("IMPORTED_LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
409      "Repetition count for cycles of IMPORTED static libraries.",
410      "This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.");
411   cm->DefineProperty
412     ("IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
413      "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_MULTIPLICITY.",
414      "If set, this property completely overrides the generic property "
415      "for the named configuration.");
416
417   cm->DefineProperty
418     ("IMPORTED_LOCATION", cmProperty::TARGET,
419      "Full path to the main file on disk for an IMPORTED target.",
420      "Set this to the location of an IMPORTED target file on disk.  "
421      "For executables this is the location of the executable file.  "
422      "For bundles on OS X this is the location of the executable file "
423      "inside Contents/MacOS under the application bundle folder.  "
424      "For static libraries and modules this is the location of the "
425      "library or module.  "
426      "For shared libraries on non-DLL platforms this is the location of "
427      "the shared library.  "
428      "For frameworks on OS X this is the location of the library file "
429      "symlink just inside the framework folder.  "
430      "For DLLs this is the location of the \".dll\" part of the library.  "
431      "For UNKNOWN libraries this is the location of the file to be linked.  "
432      "Ignored for non-imported targets."
433      "\n"
434      "Projects may skip IMPORTED_LOCATION if the configuration-specific "
435      "property IMPORTED_LOCATION_<CONFIG> is set.  "
436      "To get the location of an imported target read one of the "
437      "LOCATION or LOCATION_<CONFIG> properties.");
438
439   cm->DefineProperty
440     ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
441      "<CONFIG>-specific version of IMPORTED_LOCATION property.",
442      "Configuration names correspond to those provided by the project "
443      "from which the target is imported.");
444
445   cm->DefineProperty
446     ("IMPORTED_SONAME", cmProperty::TARGET,
447      "The \"soname\" of an IMPORTED target of shared library type.",
448      "Set this to the \"soname\" embedded in an imported shared library.  "
449      "This is meaningful only on platforms supporting the feature.  "
450      "Ignored for non-imported targets.");
451
452   cm->DefineProperty
453     ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
454      "<CONFIG>-specific version of IMPORTED_SONAME property.",
455      "Configuration names correspond to those provided by the project "
456      "from which the target is imported.");
457
458   cm->DefineProperty
459     ("IMPORTED_NO_SONAME", cmProperty::TARGET,
460      "Specifies that an IMPORTED shared library target has no \"soname\".  ",
461      "Set this property to true for an imported shared library file that "
462      "has no \"soname\" field.  "
463      "CMake may adjust generated link commands for some platforms to prevent "
464      "the linker from using the path to the library in place of its missing "
465      "soname.  "
466      "Ignored for non-imported targets.");
467
468   cm->DefineProperty
469     ("IMPORTED_NO_SONAME_<CONFIG>", cmProperty::TARGET,
470      "<CONFIG>-specific version of IMPORTED_NO_SONAME property.",
471      "Configuration names correspond to those provided by the project "
472      "from which the target is imported.");
473
474   cm->DefineProperty
475     ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
476      "Exclude the target from the all target.",
477      "A property on a target that indicates if the target is excluded "
478      "from the default build target. If it is not, then with a Makefile "
479      "for example typing make will cause this target to be built. "
480      "The same concept applies to the default build of other generators. "
481      "Installing a target with EXCLUDE_FROM_ALL set to true has "
482      "undefined behavior.");
483
484   cm->DefineProperty
485     ("INCLUDE_DIRECTORIES", cmProperty::TARGET,
486      "List of preprocessor include file search directories.",
487      "This property specifies the list of directories given "
488      "so far to the include_directories command. "
489      "This property exists on directories and targets. "
490      "In addition to accepting values from the include_directories "
491      "command, values may be set directly on any directory or any "
492      "target using the set_property command. "
493      "A target gets its initial value for this property from the value "
494      "of the directory property. "
495      "A directory gets its initial value from its parent directory if "
496      "it has one. "
497      "Both directory and target property values are adjusted by calls "
498      "to the include_directories command."
499      "\n"
500      "The target property values are used by the generators to set "
501      "the include paths for the compiler. "
502      "See also the include_directories command.");
503
504   cm->DefineProperty
505     ("INSTALL_NAME_DIR", cmProperty::TARGET,
506      "Mac OSX directory name for installed targets.",
507      "INSTALL_NAME_DIR is a string specifying the "
508      "directory portion of the \"install_name\" field of shared libraries "
509      "on Mac OSX to use in the installed targets. ");
510
511   cm->DefineProperty
512     ("INSTALL_RPATH", cmProperty::TARGET,
513      "The rpath to use for installed targets.",
514      "A semicolon-separated list specifying the rpath "
515      "to use in installed targets (for platforms that support it).  "
516      "This property is initialized by the value of the variable "
517      "CMAKE_INSTALL_RPATH if it is set when a target is created.");
518
519   cm->DefineProperty
520     ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
521      "Add paths to linker search and installed rpath.",
522      "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
523      "append directories in the linker search path and outside the "
524      "project to the INSTALL_RPATH.  "
525      "This property is initialized by the value of the variable "
526      "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
527      "created.");
528
529   cm->DefineProperty
530     ("INTERPROCEDURAL_OPTIMIZATION", cmProperty::TARGET,
531      "Enable interprocedural optimization for a target.",
532      "If set to true, enables interprocedural optimizations "
533      "if they are known to be supported by the compiler.");
534
535   cm->DefineProperty
536     ("INTERPROCEDURAL_OPTIMIZATION_<CONFIG>", cmProperty::TARGET,
537      "Per-configuration interprocedural optimization for a target.",
538      "This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION.  "
539      "If set, this property overrides the generic property "
540      "for the named configuration.");
541
542   cm->DefineProperty
543     ("LABELS", cmProperty::TARGET,
544      "Specify a list of text labels associated with a target.",
545      "Target label semantics are currently unspecified.");
546
547   cm->DefineProperty
548     ("LINK_FLAGS", cmProperty::TARGET,
549      "Additional flags to use when linking this target.",
550      "The LINK_FLAGS property can be used to add extra flags to the "
551      "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
552      "configuration <CONFIG>, "
553      "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
554
555   cm->DefineProperty
556     ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
557      "Per-configuration linker flags for a target.",
558      "This is the configuration-specific version of LINK_FLAGS.");
559
560 #define CM_LINK_SEARCH_SUMMARY \
561   "Some linkers support switches such as -Bstatic and -Bdynamic " \
562   "to determine whether to use static or shared libraries for -lXXX " \
563   "options.  CMake uses these options to set the link type for " \
564   "libraries whose full paths are not known or (in some cases) are in " \
565   "implicit link directories for the platform.  "
566
567   cm->DefineProperty
568     ("LINK_SEARCH_START_STATIC", cmProperty::TARGET,
569      "Assume the linker looks for static libraries by default.",
570      CM_LINK_SEARCH_SUMMARY
571      "By default the linker search type is assumed to be -Bdynamic at "
572      "the beginning of the library list.  This property switches the "
573      "assumption to -Bstatic.  It is intended for use when linking an "
574      "executable statically (e.g. with the GNU -static option).  "
575      "See also LINK_SEARCH_END_STATIC.");
576
577   cm->DefineProperty
578     ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
579      "End a link line such that static system libraries are used.",
580      CM_LINK_SEARCH_SUMMARY
581      "By default CMake adds an option at the end of the library list (if "
582      "necessary) to set the linker search type back to its starting type.  "
583      "This property switches the final linker search type to -Bstatic "
584      "regardless of how it started.  "
585      "See also LINK_SEARCH_START_STATIC.");
586
587   cm->DefineProperty
588     ("LINKER_LANGUAGE", cmProperty::TARGET,
589      "Specifies language whose compiler will invoke the linker.",
590      "For executables, shared libraries, and modules, this sets the "
591      "language whose compiler is used to link the target "
592      "(such as \"C\" or \"CXX\").  "
593      "A typical value for an executable is the language of the source "
594      "file providing the program entry point (main).  "
595      "If not set, the language with the highest linker preference "
596      "value is the default.  "
597      "See documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables.");
598
599   cm->DefineProperty
600     ("LOCATION", cmProperty::TARGET,
601      "Read-only location of a target on disk.",
602      "For an imported target, this read-only property returns the value of "
603      "the LOCATION_<CONFIG> property for an unspecified configuration "
604      "<CONFIG> provided by the target.\n"
605      "For a non-imported target, this property is provided for compatibility "
606      "with CMake 2.4 and below.  "
607      "It was meant to get the location of an executable target's output file "
608      "for use in add_custom_command.  "
609      "The path may contain a build-system-specific portion that "
610      "is replaced at build time with the configuration getting built "
611      "(such as \"$(ConfigurationName)\" in VS). "
612      "In CMake 2.6 and above add_custom_command automatically recognizes a "
613      "target name in its COMMAND and DEPENDS options and computes the "
614      "target location.  "
615      "In CMake 2.8.4 and above add_custom_command recognizes generator "
616      "expressions to refer to target locations anywhere in the command.  "
617      "Therefore this property is not needed for creating custom commands."
618      CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
619
620   cm->DefineProperty
621     ("LOCATION_<CONFIG>", cmProperty::TARGET,
622      "Read-only property providing a target location on disk.",
623      "A read-only property that indicates where a target's main file is "
624      "located on disk for the configuration <CONFIG>.  "
625      "The property is defined only for library and executable targets.  "
626      "An imported target may provide a set of configurations different "
627      "from that of the importing project.  "
628      "By default CMake looks for an exact-match but otherwise uses an "
629      "arbitrary available configuration.  "
630      "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
631      "configurations explicitly."
632      CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
633
634   cm->DefineProperty
635     ("LINK_DEPENDS", cmProperty::TARGET,
636      "Additional files on which a target binary depends for linking.",
637      "Specifies a semicolon-separated list of full-paths to files on which "
638      "the link rule for this target depends.  "
639      "The target binary will be linked if any of the named files is newer "
640      "than it."
641      "\n"
642      "This property is ignored by non-Makefile generators.  "
643      "It is intended to specify dependencies on \"linker scripts\" for "
644      "custom Makefile link rules.");
645
646   cm->DefineProperty
647     ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
648      "List public interface libraries for a shared library or executable.",
649      "By default linking to a shared library target transitively "
650      "links to targets with which the library itself was linked.  "
651      "For an executable with exports (see the ENABLE_EXPORTS property) "
652      "no default transitive link dependencies are used.  "
653      "This property replaces the default transitive link dependencies with "
654      "an explicit list.  "
655      "When the target is linked into another target the libraries "
656      "listed (and recursively their link interface libraries) will be "
657      "provided to the other target also.  "
658      "If the list is empty then no transitive link dependencies will be "
659      "incorporated when this target is linked into another target even if "
660      "the default set is non-empty.  "
661      "This property is initialized by the value of the variable "
662      "CMAKE_LINK_INTERFACE_LIBRARIES if it is set when a target is "
663      "created.  "
664      "This property is ignored for STATIC libraries.");
665
666   cm->DefineProperty
667     ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
668      "Per-configuration list of public interface libraries for a target.",
669      "This is the configuration-specific version of "
670      "LINK_INTERFACE_LIBRARIES.  "
671      "If set, this property completely overrides the generic property "
672      "for the named configuration.");
673
674   cm->DefineProperty
675     ("LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
676      "Repetition count for STATIC libraries with cyclic dependencies.",
677      "When linking to a STATIC library target with cyclic dependencies the "
678      "linker may need to scan more than once through the archives in the "
679      "strongly connected component of the dependency graph.  "
680      "CMake by default constructs the link line so that the linker will "
681      "scan through the component at least twice.  "
682      "This property specifies the minimum number of scans if it is larger "
683      "than the default.  "
684      "CMake uses the largest value specified by any target in a component.");
685   cm->DefineProperty
686     ("LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
687      "Per-configuration repetition count for cycles of STATIC libraries.",
688      "This is the configuration-specific version of "
689      "LINK_INTERFACE_MULTIPLICITY.  "
690      "If set, this property completely overrides the generic property "
691      "for the named configuration.");
692
693   cm->DefineProperty
694     ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
695      "Map from project configuration to IMPORTED target's configuration.",
696      "Set this to the list of configurations of an imported target that "
697      "may be used for the current project's <CONFIG> configuration.  "
698      "Targets imported from another project may not provide the same set "
699      "of configuration names available in the current project.  "
700      "Setting this property tells CMake what imported configurations are "
701      "suitable for use when building the <CONFIG> configuration.  "
702      "The first configuration in the list found to be provided by the "
703      "imported target is selected.  If this property is set and no matching "
704      "configurations are available, then the imported target is considered "
705      "to be not found.  This property is ignored for non-imported targets.",
706      false /* TODO: make this chained */ );
707
708   cm->DefineProperty
709     ("OSX_ARCHITECTURES", cmProperty::TARGET,
710      "Target specific architectures for OS X.",
711      "The OSX_ARCHITECTURES property sets the target binary architecture "
712      "for targets on OS X.  "
713      "This property is initialized by the value of the variable "
714      "CMAKE_OSX_ARCHITECTURES if it is set when a target is created.  "
715      "Use OSX_ARCHITECTURES_<CONFIG> to set the binary architectures on a "
716      "per-configuration basis.  "
717      "<CONFIG> is an upper-case name (ex: \"OSX_ARCHITECTURES_DEBUG\").");
718
719   cm->DefineProperty
720     ("OSX_ARCHITECTURES_<CONFIG>", cmProperty::TARGET,
721      "Per-configuration OS X binary architectures for a target.",
722      "This property is the configuration-specific version of "
723      "OSX_ARCHITECTURES.");
724
725   cm->DefineProperty
726     ("OUTPUT_NAME", cmProperty::TARGET,
727      "Output name for target files.",
728      "This sets the base name for output files created for an executable or "
729      "library target.  "
730      "If not set, the logical target name is used by default.");
731
732   cm->DefineProperty
733     ("OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
734      "Per-configuration target file base name.",
735      "This is the configuration-specific version of OUTPUT_NAME.");
736
737   cm->DefineProperty
738     ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET,
739      "Old per-configuration target file base name.",
740      "This is a configuration-specific version of OUTPUT_NAME.  "
741      "Use OUTPUT_NAME_<CONFIG> instead.");
742
743   cm->DefineProperty
744     ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
745      "Deprecated install support.",
746      "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
747      "old way to specify CMake scripts to run before and after "
748      "installing a target.  They are used only when the old "
749      "INSTALL_TARGETS command is used to install the target.  Use the "
750      "INSTALL command instead.");
751
752   cm->DefineProperty
753     ("PREFIX", cmProperty::TARGET,
754      "What comes before the library name.",
755      "A target property that can be set to override the prefix "
756      "(such as \"lib\") on a library name.");
757
758   cm->DefineProperty
759     ("POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
760      "Whether to create a position-independent target",
761      "The POSITION_INDEPENDENT_CODE property determines whether position "
762      "independent executables or shared libraries will be created.  "
763      "This property is true by default for SHARED and MODULE library "
764      "targets and false otherwise.");
765
766   cm->DefineProperty
767     ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
768      "Deprecated install support.",
769      "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
770      "old way to specify CMake scripts to run before and after "
771      "installing a target.  They are used only when the old "
772      "INSTALL_TARGETS command is used to install the target.  Use the "
773      "INSTALL command instead.");
774
775   cm->DefineProperty
776     ("PRIVATE_HEADER", cmProperty::TARGET,
777      "Specify private header files in a FRAMEWORK shared library target.",
778      "Shared library targets marked with the FRAMEWORK property generate "
779      "frameworks on OS X and normal shared libraries on other platforms.  "
780      "This property may be set to a list of header files to be placed "
781      "in the PrivateHeaders directory inside the framework folder.  "
782      "On non-Apple platforms these headers may be installed using the "
783      "PRIVATE_HEADER option to the install(TARGETS) command.");
784
785   cm->DefineProperty
786     ("PUBLIC_HEADER", cmProperty::TARGET,
787      "Specify public header files in a FRAMEWORK shared library target.",
788      "Shared library targets marked with the FRAMEWORK property generate "
789      "frameworks on OS X and normal shared libraries on other platforms.  "
790      "This property may be set to a list of header files to be placed "
791      "in the Headers directory inside the framework folder.  "
792      "On non-Apple platforms these headers may be installed using the "
793      "PUBLIC_HEADER option to the install(TARGETS) command.");
794
795   cm->DefineProperty
796     ("RESOURCE", cmProperty::TARGET,
797      "Specify resource files in a FRAMEWORK shared library target.",
798      "Shared library targets marked with the FRAMEWORK property generate "
799      "frameworks on OS X and normal shared libraries on other platforms.  "
800      "This property may be set to a list of files to be placed "
801      "in the Resources directory inside the framework folder.  "
802      "On non-Apple platforms these files may be installed using the "
803      "RESOURCE option to the install(TARGETS) command.");
804
805   cm->DefineProperty
806     ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
807      "Specify a launcher for compile rules.",
808      "See the global property of the same name for details.  "
809      "This overrides the global and directory property for a target.",
810      true);
811   cm->DefineProperty
812     ("RULE_LAUNCH_LINK", cmProperty::TARGET,
813      "Specify a launcher for link rules.",
814      "See the global property of the same name for details.  "
815      "This overrides the global and directory property for a target.",
816      true);
817   cm->DefineProperty
818     ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
819      "Specify a launcher for custom rules.",
820      "See the global property of the same name for details.  "
821      "This overrides the global and directory property for a target.",
822      true);
823
824   cm->DefineProperty
825     ("SKIP_BUILD_RPATH", cmProperty::TARGET,
826      "Should rpaths be used for the build tree.",
827      "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
828      "generation of an rpath allowing the target to run from the "
829      "build tree.  "
830      "This property is initialized by the value of the variable "
831      "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
832
833   cm->DefineProperty
834     ("NO_SONAME", cmProperty::TARGET,
835      "Whether to set \"soname\" when linking a shared library or module.",
836      "Enable this boolean property if a generated shared library or module "
837      "should not have \"soname\" set. Default is to set \"soname\" on all "
838      "shared libraries and modules as long as the platform supports it. "
839      "Generally, use this property only for leaf private libraries or "
840      "plugins. If you use it on normal shared libraries which other targets "
841      "link against, on some platforms a linker will insert a full path to "
842      "the library (as specified at link time) into the dynamic section of "
843      "the dependent binary. Therefore, once installed, dynamic loader may "
844      "eventually fail to locate the library for the binary.");
845
846   cm->DefineProperty
847     ("SOVERSION", cmProperty::TARGET,
848      "What version number is this target.",
849      "For shared libraries VERSION and SOVERSION can be used to specify "
850      "the build version and api version respectively. When building or "
851      "installing appropriate symlinks are created if the platform "
852      "supports symlinks and the linker supports so-names. "
853      "If only one of both is specified the missing is assumed to have "
854      "the same version number. "
855      "SOVERSION is ignored if NO_SONAME property is set. "
856      "For shared libraries and executables on Windows the VERSION "
857      "attribute is parsed to extract a \"major.minor\" version number. "
858      "These numbers are used as the image version of the binary. ");
859
860   cm->DefineProperty
861     ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
862      "Extra flags to use when linking static libraries.",
863      "Extra flags to use when linking a static library.");
864
865   cm->DefineProperty
866     ("STATIC_LIBRARY_FLAGS_<CONFIG>", cmProperty::TARGET,
867      "Per-configuration flags for creating a static library.",
868      "This is the configuration-specific version of STATIC_LIBRARY_FLAGS.");
869
870   cm->DefineProperty
871     ("SUFFIX", cmProperty::TARGET,
872      "What comes after the target name.",
873      "A target property that can be set to override the suffix "
874      "(such as \".so\" or \".exe\") on the name of a library, module or "
875      "executable.");
876
877   cm->DefineProperty
878     ("TYPE", cmProperty::TARGET,
879      "The type of the target.",
880      "This read-only property can be used to test the type of the given "
881      "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
882      "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
883
884   cm->DefineProperty
885     ("VERSION", cmProperty::TARGET,
886      "What version number is this target.",
887      "For shared libraries VERSION and SOVERSION can be used to specify "
888      "the build version and api version respectively. When building or "
889      "installing appropriate symlinks are created if the platform "
890      "supports symlinks and the linker supports so-names. "
891      "If only one of both is specified the missing is assumed to have "
892      "the same version number. "
893      "For executables VERSION can be used to specify the build version. "
894      "When building or installing appropriate symlinks are created if "
895      "the platform supports symlinks. "
896      "For shared libraries and executables on Windows the VERSION "
897      "attribute is parsed to extract a \"major.minor\" version number. "
898      "These numbers are used as the image version of the binary. ");
899
900
901   cm->DefineProperty
902     ("WIN32_EXECUTABLE", cmProperty::TARGET,
903      "Build an executable with a WinMain entry point on windows.",
904      "When this property is set to true the executable when linked "
905      "on Windows will be created with a WinMain() entry point instead "
906      "of of just main()."
907      "This makes it a GUI executable instead of a console application.  "
908      "See the CMAKE_MFC_FLAG variable documentation to configure use "
909      "of MFC for WinMain executables.  "
910      "This property is initialized by the value of the variable "
911      "CMAKE_WIN32_EXECUTABLE if it is set when a target is created.");
912
913   cm->DefineProperty
914     ("MACOSX_BUNDLE", cmProperty::TARGET,
915      "Build an executable as an application bundle on Mac OS X.",
916      "When this property is set to true the executable when built "
917      "on Mac OS X will be created as an application bundle.  "
918      "This makes it a GUI executable that can be launched from "
919      "the Finder.  "
920      "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
921      "about creation of the Info.plist file for the application bundle.  "
922      "This property is initialized by the value of the variable "
923      "CMAKE_MACOSX_BUNDLE if it is set when a target is created.");
924
925   cm->DefineProperty
926     ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
927      "Specify a custom Info.plist template for a Mac OS X App Bundle.",
928      "An executable target with MACOSX_BUNDLE enabled will be built as an "
929      "application bundle on Mac OS X.  "
930      "By default its Info.plist file is created by configuring a template "
931      "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH.  "
932      "This property specifies an alternative template file name which "
933      "may be a full path.\n"
934      "The following target properties may be set to specify content to "
935      "be configured into the file:\n"
936      "  MACOSX_BUNDLE_INFO_STRING\n"
937      "  MACOSX_BUNDLE_ICON_FILE\n"
938      "  MACOSX_BUNDLE_GUI_IDENTIFIER\n"
939      "  MACOSX_BUNDLE_LONG_VERSION_STRING\n"
940      "  MACOSX_BUNDLE_BUNDLE_NAME\n"
941      "  MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
942      "  MACOSX_BUNDLE_BUNDLE_VERSION\n"
943      "  MACOSX_BUNDLE_COPYRIGHT\n"
944      "CMake variables of the same name may be set to affect all targets "
945      "in a directory that do not have each specific property set.  "
946      "If a custom Info.plist is specified by this property it may of course "
947      "hard-code all the settings instead of using the target properties.");
948
949   cm->DefineProperty
950     ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
951      "Specify a custom Info.plist template for a Mac OS X Framework.",
952      "An library target with FRAMEWORK enabled will be built as a "
953      "framework on Mac OS X.  "
954      "By default its Info.plist file is created by configuring a template "
955      "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH.  "
956      "This property specifies an alternative template file name which "
957      "may be a full path.\n"
958      "The following target properties may be set to specify content to "
959      "be configured into the file:\n"
960      "  MACOSX_FRAMEWORK_ICON_FILE\n"
961      "  MACOSX_FRAMEWORK_IDENTIFIER\n"
962      "  MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
963      "  MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
964      "CMake variables of the same name may be set to affect all targets "
965      "in a directory that do not have each specific property set.  "
966      "If a custom Info.plist is specified by this property it may of course "
967      "hard-code all the settings instead of using the target properties.");
968
969   cm->DefineProperty
970     ("ENABLE_EXPORTS", cmProperty::TARGET,
971      "Specify whether an executable exports symbols for loadable modules.",
972      "Normally an executable does not export any symbols because it is "
973      "the final program.  It is possible for an executable to export "
974      "symbols to be used by loadable modules.  When this property is "
975      "set to true CMake will allow other targets to \"link\" to the "
976      "executable with the TARGET_LINK_LIBRARIES command.  "
977      "On all platforms a target-level dependency on the executable is "
978      "created for targets that link to it.  "
979      "For DLL platforms an import library will be created for the "
980      "exported symbols and then used for linking.  "
981      "All Windows-based systems including Cygwin are DLL platforms.  "
982      "For non-DLL platforms that require all symbols to be resolved at "
983      "link time, such as Mac OS X, the module will \"link\" to the "
984      "executable using a flag like \"-bundle_loader\".  "
985      "For other non-DLL platforms the link rule is simply ignored since "
986      "the dynamic loader will automatically bind symbols when the "
987      "module is loaded.  "
988       );
989
990   cm->DefineProperty
991     ("Fortran_FORMAT", cmProperty::TARGET,
992      "Set to FIXED or FREE to indicate the Fortran source layout.",
993      "This property tells CMake whether the Fortran source files "
994      "in a target use fixed-format or free-format.  "
995      "CMake will pass the corresponding format flag to the compiler.  "
996      "Use the source-specific Fortran_FORMAT property to change the "
997      "format of a specific source file.  "
998      "If the variable CMAKE_Fortran_FORMAT is set when a target "
999      "is created its value is used to initialize this property.");
1000
1001   cm->DefineProperty
1002     ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
1003      "Specify output directory for Fortran modules provided by the target.",
1004      "If the target contains Fortran source files that provide modules "
1005      "and the compiler supports a module output directory this specifies "
1006      "the directory in which the modules will be placed.  "
1007      "When this property is not set the modules will be placed in the "
1008      "build directory corresponding to the target's source directory.  "
1009      "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
1010      "is created its value is used to initialize this property."
1011      "\n"
1012      "Note that some compilers will automatically search the module output "
1013      "directory for modules USEd during compilation but others will not.  "
1014      "If your sources USE modules their location must be specified by "
1015      "INCLUDE_DIRECTORIES regardless of this property.");
1016
1017   cm->DefineProperty
1018     ("GNUtoMS", cmProperty::TARGET,
1019      "Convert GNU import library (.dll.a) to MS format (.lib).",
1020      "When linking a shared library or executable that exports symbols "
1021      "using GNU tools on Windows (MinGW/MSYS) with Visual Studio installed "
1022      "convert the import library (.dll.a) from GNU to MS format (.lib).  "
1023      "Both import libraries will be installed by install(TARGETS) and "
1024      "exported by install(EXPORT) and export() to be linked by applications "
1025      "with either GNU- or MS-compatible tools."
1026      "\n"
1027      "If the variable CMAKE_GNUtoMS is set when a target "
1028      "is created its value is used to initialize this property.  "
1029      "The variable must be set prior to the first command that enables "
1030      "a language such as project() or enable_language().  "
1031      "CMake provides the variable as an option to the user automatically "
1032      "when configuring on Windows with GNU tools.");
1033
1034   cm->DefineProperty
1035     ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
1036      "Set Xcode target attributes directly.",
1037      "Tell the Xcode generator to set '<an-attribute>' to a given value "
1038      "in the generated Xcode project.  Ignored on other generators.");
1039
1040   cm->DefineProperty
1041     ("GENERATOR_FILE_NAME", cmProperty::TARGET,
1042      "Generator's file for this target.",
1043      "An internal property used by some generators to record the name of "
1044      "project or dsp file associated with this target.");
1045
1046   cm->DefineProperty
1047     ("SOURCES", cmProperty::TARGET,
1048      "Source names specified for a target.",
1049      "Read-only list of sources specified for a target.  "
1050      "The names returned are suitable for passing to the "
1051      "set_source_files_properties command.");
1052
1053   cm->DefineProperty
1054     ("FOLDER", cmProperty::TARGET,
1055      "Set the folder name. Use to organize targets in an IDE.",
1056      "Targets with no FOLDER property will appear as top level "
1057      "entities in IDEs like Visual Studio. Targets with the same "
1058      "FOLDER property value will appear next to each other in a "
1059      "folder of that name. To nest folders, use FOLDER values such "
1060      "as 'GUI/Dialogs' with '/' characters separating folder levels.");
1061
1062   cm->DefineProperty
1063     ("PROJECT_LABEL", cmProperty::TARGET,
1064      "Change the name of a target in an IDE.",
1065      "Can be used to change the name of the target in an IDE "
1066      "like Visual Studio. ");
1067   cm->DefineProperty
1068     ("VS_KEYWORD", cmProperty::TARGET,
1069      "Visual Studio project keyword.",
1070      "Can be set to change the visual studio keyword, for example "
1071      "QT integration works better if this is set to Qt4VSv1.0. ");
1072   cm->DefineProperty
1073     ("VS_SCC_PROVIDER", cmProperty::TARGET,
1074      "Visual Studio Source Code Control Provider.",
1075      "Can be set to change the visual studio source code control "
1076      "provider property.");
1077   cm->DefineProperty
1078     ("VS_SCC_LOCALPATH", cmProperty::TARGET,
1079      "Visual Studio Source Code Control Local Path.",
1080      "Can be set to change the visual studio source code control "
1081      "local path property.");
1082   cm->DefineProperty
1083     ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
1084      "Visual Studio Source Code Control Project.",
1085      "Can be set to change the visual studio source code control "
1086      "project name property.");
1087   cm->DefineProperty
1088     ("VS_SCC_AUXPATH", cmProperty::TARGET,
1089      "Visual Studio Source Code Control Aux Path.",
1090      "Can be set to change the visual studio source code control "
1091      "auxpath property.");
1092   cm->DefineProperty
1093     ("VS_GLOBAL_PROJECT_TYPES", cmProperty::TARGET,
1094      "Visual Studio project type(s).",
1095      "Can be set to one or more UUIDs recognized by Visual Studio "
1096      "to indicate the type of project. This value is copied "
1097      "verbatim into the generated project file. Example for a "
1098      "managed C++ unit testing project:\n"
1099      " {3AC096D0-A1C2-E12C-1390-A8335801FDAB};"
1100      "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\n"
1101      "UUIDs are semicolon-delimited.");
1102   cm->DefineProperty
1103     ("VS_GLOBAL_KEYWORD", cmProperty::TARGET,
1104      "Visual Studio project keyword.",
1105      "Sets the \"keyword\" attribute for a generated Visual Studio "
1106      "project. Defaults to \"Win32Proj\". You may wish to override "
1107      "this value with \"ManagedCProj\", for example, in a Visual "
1108      "Studio managed C++ unit test project.");
1109   cm->DefineProperty
1110     ("VS_DOTNET_REFERENCES", cmProperty::TARGET,
1111      "Visual Studio managed project .NET references",
1112      "Adds one or more semicolon-delimited .NET references to a "
1113      "generated Visual Studio project. For example, \"System;"
1114      "System.Windows.Forms\".");
1115   cm->DefineProperty
1116     ("VS_WINRT_EXTENSIONS", cmProperty::TARGET,
1117      "Visual Studio project C++/CX language extensions for Windows Runtime",
1118      "Can be set to enable C++/CX language extensions.");
1119   cm->DefineProperty
1120     ("VS_WINRT_REFERENCES", cmProperty::TARGET,
1121      "Visual Studio project Windows Runtime Metadata references",
1122      "Adds one or more semicolon-delimited WinRT references to a "
1123      "generated Visual Studio project. For example, \"Windows;"
1124      "Windows.UI.Core\".");
1125   cm->DefineProperty
1126     ("VS_GLOBAL_<variable>", cmProperty::TARGET,
1127      "Visual Studio project-specific global variable.",
1128      "Tell the Visual Studio generator to set the global variable "
1129      "'<variable>' to a given value in the generated Visual Studio "
1130      "project. Ignored on other generators. Qt integration works "
1131      "better if VS_GLOBAL_QtVersion is set to the version "
1132      "FindQt4.cmake found. For example, \"4.7.3\"");
1133
1134 #define CM_TARGET_FILE_TYPES_DOC                                            \
1135      "There are three kinds of target files that may be built: "            \
1136      "archive, library, and runtime.  "                                     \
1137      "Executables are always treated as runtime targets. "                  \
1138      "Static libraries are always treated as archive targets. "             \
1139      "Module libraries are always treated as library targets. "             \
1140      "For non-DLL platforms shared libraries are treated as library "       \
1141      "targets. "                                                            \
1142      "For DLL platforms the DLL part of a shared library is treated as "    \
1143      "a runtime target and the corresponding import library is treated as " \
1144      "an archive target. "                                                  \
1145      "All Windows-based systems including Cygwin are DLL platforms."
1146
1147 #define CM_TARGET_OUTDIR_DOC(TYPE, type)                                    \
1148      "This property specifies the directory into which " #type " target "   \
1149      "files should be built. "                                              \
1150      "Multi-configuration generators (VS, Xcode) append "                   \
1151      "a per-configuration subdirectory to the specified directory.  "       \
1152      CM_TARGET_FILE_TYPES_DOC "  "                                          \
1153      "This property is initialized by the value of the variable "           \
1154      "CMAKE_" #TYPE "_OUTPUT_DIRECTORY if it is set when a target is created."
1155
1156 #define CM_TARGET_OUTDIR_CONFIG_DOC(TYPE)                                   \
1157      "This is a per-configuration version of " #TYPE "_OUTPUT_DIRECTORY, "  \
1158      "but multi-configuration generators (VS, Xcode) do NOT append "        \
1159      "a per-configuration subdirectory to the specified directory.  "       \
1160      "This property is initialized by the value of the variable "           \
1161      "CMAKE_" #TYPE "_OUTPUT_DIRECTORY_<CONFIG> "                           \
1162      "if it is set when a target is created."
1163
1164   cm->DefineProperty
1165     ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
1166      "Output directory in which to build ARCHIVE target files.",
1167      CM_TARGET_OUTDIR_DOC(ARCHIVE, archive));
1168   cm->DefineProperty
1169     ("ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1170      "Per-configuration output directory for ARCHIVE target files.",
1171      CM_TARGET_OUTDIR_CONFIG_DOC(ARCHIVE));
1172   cm->DefineProperty
1173     ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
1174      "Output directory in which to build LIBRARY target files.",
1175      CM_TARGET_OUTDIR_DOC(LIBRARY, library));
1176   cm->DefineProperty
1177     ("LIBRARY_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1178      "Per-configuration output directory for LIBRARY target files.",
1179      CM_TARGET_OUTDIR_CONFIG_DOC(LIBRARY));
1180   cm->DefineProperty
1181     ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
1182      "Output directory in which to build RUNTIME target files.",
1183      CM_TARGET_OUTDIR_DOC(RUNTIME, runtime));
1184   cm->DefineProperty
1185     ("RUNTIME_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1186      "Per-configuration output directory for RUNTIME target files.",
1187      CM_TARGET_OUTDIR_CONFIG_DOC(RUNTIME));
1188
1189   cm->DefineProperty
1190     ("ARCHIVE_OUTPUT_NAME", cmProperty::TARGET,
1191      "Output name for ARCHIVE target files.",
1192      "This property specifies the base name for archive target files. "
1193      "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties.  "
1194      CM_TARGET_FILE_TYPES_DOC);
1195   cm->DefineProperty
1196     ("ARCHIVE_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1197      "Per-configuration output name for ARCHIVE target files.",
1198      "This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.");
1199   cm->DefineProperty
1200     ("LIBRARY_OUTPUT_NAME", cmProperty::TARGET,
1201      "Output name for LIBRARY target files.",
1202      "This property specifies the base name for library target files. "
1203      "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties.  "
1204      CM_TARGET_FILE_TYPES_DOC);
1205   cm->DefineProperty
1206     ("LIBRARY_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1207      "Per-configuration output name for LIBRARY target files.",
1208      "This is the configuration-specific version of LIBRARY_OUTPUT_NAME.");
1209   cm->DefineProperty
1210     ("RUNTIME_OUTPUT_NAME", cmProperty::TARGET,
1211      "Output name for RUNTIME target files.",
1212      "This property specifies the base name for runtime target files.  "
1213      "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties.  "
1214      CM_TARGET_FILE_TYPES_DOC);
1215   cm->DefineProperty
1216     ("RUNTIME_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1217      "Per-configuration output name for RUNTIME target files.",
1218      "This is the configuration-specific version of RUNTIME_OUTPUT_NAME.");
1219 }
1220
1221 void cmTarget::SetType(TargetType type, const char* name)
1222 {
1223   this->Name = name;
1224   // only add dependency information for library targets
1225   this->TargetTypeValue = type;
1226   if(this->TargetTypeValue >= STATIC_LIBRARY
1227      && this->TargetTypeValue <= MODULE_LIBRARY)
1228     {
1229     this->RecordDependencies = true;
1230     }
1231   else
1232     {
1233     this->RecordDependencies = false;
1234     }
1235 }
1236
1237 //----------------------------------------------------------------------------
1238 void cmTarget::SetMakefile(cmMakefile* mf)
1239 {
1240   // Set our makefile.
1241   this->Makefile = mf;
1242
1243   // set the cmake instance of the properties
1244   this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
1245
1246   // Check whether this is a DLL platform.
1247   this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
1248                        this->Makefile->IsOn("CYGWIN") ||
1249                        this->Makefile->IsOn("MINGW"));
1250
1251   // Check whether we are targeting an Apple platform.
1252   this->IsApple = this->Makefile->IsOn("APPLE");
1253
1254   // Setup default property values.
1255   this->SetPropertyDefault("INSTALL_NAME_DIR", "");
1256   this->SetPropertyDefault("INSTALL_RPATH", "");
1257   this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
1258   this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
1259   this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
1260   this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
1261   this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
1262   this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
1263   this->SetPropertyDefault("Fortran_FORMAT", 0);
1264   this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
1265   this->SetPropertyDefault("GNUtoMS", 0);
1266   this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
1267   this->SetPropertyDefault("AUTOMOC", 0);
1268   this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
1269   this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
1270   this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
1271   this->SetPropertyDefault("MACOSX_BUNDLE", 0);
1272
1273   // Collect the set of configuration types.
1274   std::vector<std::string> configNames;
1275   mf->GetConfigurations(configNames);
1276
1277   // Setup per-configuration property default values.
1278   const char* configProps[] = {
1279     "ARCHIVE_OUTPUT_DIRECTORY_",
1280     "LIBRARY_OUTPUT_DIRECTORY_",
1281     "RUNTIME_OUTPUT_DIRECTORY_",
1282     0};
1283   for(std::vector<std::string>::iterator ci = configNames.begin();
1284       ci != configNames.end(); ++ci)
1285     {
1286     std::string configUpper = cmSystemTools::UpperCase(*ci);
1287     for(const char** p = configProps; *p; ++p)
1288       {
1289       std::string property = *p;
1290       property += configUpper;
1291       this->SetPropertyDefault(property.c_str(), 0);
1292       }
1293
1294     // Initialize per-configuration name postfix property from the
1295     // variable only for non-executable targets.  This preserves
1296     // compatibility with previous CMake versions in which executables
1297     // did not support this variable.  Projects may still specify the
1298     // property directly.  TODO: Make this depend on backwards
1299     // compatibility setting.
1300     if(this->TargetTypeValue != cmTarget::EXECUTABLE)
1301       {
1302       std::string property = cmSystemTools::UpperCase(*ci);
1303       property += "_POSTFIX";
1304       this->SetPropertyDefault(property.c_str(), 0);
1305       }
1306     }
1307
1308   // Save the backtrace of target construction.
1309   this->Makefile->GetBacktrace(this->Internal->Backtrace);
1310
1311   // Initialize the INCLUDE_DIRECTORIES property based on the current value
1312   // of the same directory property:
1313   this->SetProperty("INCLUDE_DIRECTORIES",
1314                     this->Makefile->GetProperty("INCLUDE_DIRECTORIES"));
1315
1316   if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
1317       || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
1318     {
1319     this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
1320     }
1321   this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
1322
1323   // Record current policies for later use.
1324   this->PolicyStatusCMP0003 =
1325     this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
1326   this->PolicyStatusCMP0004 =
1327     this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
1328   this->PolicyStatusCMP0008 =
1329     this->Makefile->GetPolicyStatus(cmPolicies::CMP0008);
1330 }
1331
1332 //----------------------------------------------------------------------------
1333 void cmTarget::FinishConfigure()
1334 {
1335   // Erase any cached link information that might have been comptued
1336   // on-demand during the configuration.  This ensures that build
1337   // system generation uses up-to-date information even if other cache
1338   // invalidation code in this source file is buggy.
1339   this->ClearLinkMaps();
1340
1341   // Do old-style link dependency analysis.
1342   this->AnalyzeLibDependencies(*this->Makefile);
1343 }
1344
1345 //----------------------------------------------------------------------------
1346 void cmTarget::ClearLinkMaps()
1347 {
1348   this->Internal->LinkImplMap.clear();
1349   this->Internal->LinkInterfaceMap.clear();
1350   this->Internal->LinkClosureMap.clear();
1351 }
1352
1353 //----------------------------------------------------------------------------
1354 cmListFileBacktrace const& cmTarget::GetBacktrace() const
1355 {
1356   return this->Internal->Backtrace;
1357 }
1358
1359 //----------------------------------------------------------------------------
1360 std::string cmTarget::GetSupportDirectory() const
1361 {
1362   std::string dir = this->Makefile->GetCurrentOutputDirectory();
1363   dir += cmake::GetCMakeFilesDirectory();
1364   dir += "/";
1365   dir += this->Name;
1366 #if defined(__VMS)
1367   dir += "_dir";
1368 #else
1369   dir += ".dir";
1370 #endif
1371   return dir;
1372 }
1373
1374 //----------------------------------------------------------------------------
1375 bool cmTarget::IsExecutableWithExports()
1376 {
1377   return (this->GetType() == cmTarget::EXECUTABLE &&
1378           this->GetPropertyAsBool("ENABLE_EXPORTS"));
1379 }
1380
1381 //----------------------------------------------------------------------------
1382 bool cmTarget::IsLinkable()
1383 {
1384   return (this->GetType() == cmTarget::STATIC_LIBRARY ||
1385           this->GetType() == cmTarget::SHARED_LIBRARY ||
1386           this->GetType() == cmTarget::MODULE_LIBRARY ||
1387           this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
1388           this->IsExecutableWithExports());
1389 }
1390
1391 //----------------------------------------------------------------------------
1392 bool cmTarget::HasImportLibrary()
1393 {
1394   return (this->DLLPlatform &&
1395           (this->GetType() == cmTarget::SHARED_LIBRARY ||
1396            this->IsExecutableWithExports()));
1397 }
1398
1399 //----------------------------------------------------------------------------
1400 bool cmTarget::IsFrameworkOnApple()
1401 {
1402   return (this->GetType() == cmTarget::SHARED_LIBRARY &&
1403           this->Makefile->IsOn("APPLE") &&
1404           this->GetPropertyAsBool("FRAMEWORK"));
1405 }
1406
1407 //----------------------------------------------------------------------------
1408 bool cmTarget::IsAppBundleOnApple()
1409 {
1410   return (this->GetType() == cmTarget::EXECUTABLE &&
1411           this->Makefile->IsOn("APPLE") &&
1412           this->GetPropertyAsBool("MACOSX_BUNDLE"));
1413 }
1414
1415 //----------------------------------------------------------------------------
1416 bool cmTarget::IsCFBundleOnApple()
1417 {
1418   return (this->GetType() == cmTarget::MODULE_LIBRARY &&
1419           this->Makefile->IsOn("APPLE") &&
1420           this->GetPropertyAsBool("BUNDLE"));
1421 }
1422
1423 //----------------------------------------------------------------------------
1424 class cmTargetTraceDependencies
1425 {
1426 public:
1427   cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
1428                             const char* vsProjectFile);
1429   void Trace();
1430 private:
1431   cmTarget* Target;
1432   cmTargetInternals* Internal;
1433   cmMakefile* Makefile;
1434   cmGlobalGenerator* GlobalGenerator;
1435   typedef cmTargetInternals::SourceEntry SourceEntry;
1436   SourceEntry* CurrentEntry;
1437   std::queue<cmSourceFile*> SourceQueue;
1438   std::set<cmSourceFile*> SourcesQueued;
1439   typedef std::map<cmStdString, cmSourceFile*> NameMapType;
1440   NameMapType NameMap;
1441
1442   void QueueSource(cmSourceFile* sf);
1443   void FollowName(std::string const& name);
1444   void FollowNames(std::vector<std::string> const& names);
1445   bool IsUtility(std::string const& dep);
1446   void CheckCustomCommand(cmCustomCommand const& cc);
1447   void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
1448 };
1449
1450 //----------------------------------------------------------------------------
1451 cmTargetTraceDependencies
1452 ::cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
1453                             const char* vsProjectFile):
1454   Target(target), Internal(internal)
1455 {
1456   // Convenience.
1457   this->Makefile = this->Target->GetMakefile();
1458   this->GlobalGenerator =
1459     this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
1460   this->CurrentEntry = 0;
1461
1462   // Queue all the source files already specified for the target.
1463   std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
1464   for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
1465       si != sources.end(); ++si)
1466     {
1467     this->QueueSource(*si);
1468     }
1469
1470   // Queue the VS project file to check dependencies on the rule to
1471   // generate it.
1472   if(vsProjectFile)
1473     {
1474     this->FollowName(vsProjectFile);
1475     }
1476
1477   // Queue pre-build, pre-link, and post-build rule dependencies.
1478   this->CheckCustomCommands(this->Target->GetPreBuildCommands());
1479   this->CheckCustomCommands(this->Target->GetPreLinkCommands());
1480   this->CheckCustomCommands(this->Target->GetPostBuildCommands());
1481 }
1482
1483 //----------------------------------------------------------------------------
1484 void cmTargetTraceDependencies::Trace()
1485 {
1486   // Process one dependency at a time until the queue is empty.
1487   while(!this->SourceQueue.empty())
1488     {
1489     // Get the next source from the queue.
1490     cmSourceFile* sf = this->SourceQueue.front();
1491     this->SourceQueue.pop();
1492     this->CurrentEntry = &this->Internal->SourceEntries[sf];
1493
1494     // Queue dependencies added explicitly by the user.
1495     if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
1496       {
1497       std::vector<std::string> objDeps;
1498       cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
1499       this->FollowNames(objDeps);
1500       }
1501
1502     // Queue the source needed to generate this file, if any.
1503     this->FollowName(sf->GetFullPath());
1504
1505     // Queue dependencies added programatically by commands.
1506     this->FollowNames(sf->GetDepends());
1507
1508     // Queue custom command dependencies.
1509     if(cmCustomCommand const* cc = sf->GetCustomCommand())
1510       {
1511       this->CheckCustomCommand(*cc);
1512       }
1513     }
1514   this->CurrentEntry = 0;
1515 }
1516
1517 //----------------------------------------------------------------------------
1518 void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
1519 {
1520   if(this->SourcesQueued.insert(sf).second)
1521     {
1522     this->SourceQueue.push(sf);
1523
1524     // Make sure this file is in the target.
1525     this->Target->AddSourceFile(sf);
1526     }
1527 }
1528
1529 //----------------------------------------------------------------------------
1530 void cmTargetTraceDependencies::FollowName(std::string const& name)
1531 {
1532   NameMapType::iterator i = this->NameMap.find(name);
1533   if(i == this->NameMap.end())
1534     {
1535     // Check if we know how to generate this file.
1536     cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
1537     NameMapType::value_type entry(name, sf);
1538     i = this->NameMap.insert(entry).first;
1539     }
1540   if(cmSourceFile* sf = i->second)
1541     {
1542     // Record the dependency we just followed.
1543     if(this->CurrentEntry)
1544       {
1545       this->CurrentEntry->Depends.push_back(sf);
1546       }
1547
1548     this->QueueSource(sf);
1549     }
1550 }
1551
1552 //----------------------------------------------------------------------------
1553 void
1554 cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
1555 {
1556   for(std::vector<std::string>::const_iterator i = names.begin();
1557       i != names.end(); ++i)
1558     {
1559     this->FollowName(*i);
1560     }
1561 }
1562
1563 //----------------------------------------------------------------------------
1564 bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
1565 {
1566   // Dependencies on targets (utilities) are supposed to be named by
1567   // just the target name.  However for compatibility we support
1568   // naming the output file generated by the target (assuming there is
1569   // no output-name property which old code would not have set).  In
1570   // that case the target name will be the file basename of the
1571   // dependency.
1572   std::string util = cmSystemTools::GetFilenameName(dep);
1573   if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
1574     {
1575     util = cmSystemTools::GetFilenameWithoutLastExtension(util);
1576     }
1577
1578   // Check for a target with this name.
1579   if(cmTarget* t = this->Makefile->FindTargetToUse(util.c_str()))
1580     {
1581     // If we find the target and the dep was given as a full path,
1582     // then make sure it was not a full path to something else, and
1583     // the fact that the name matched a target was just a coincidence.
1584     if(cmSystemTools::FileIsFullPath(dep.c_str()))
1585       {
1586       if(t->GetType() >= cmTarget::EXECUTABLE &&
1587          t->GetType() <= cmTarget::MODULE_LIBRARY)
1588         {
1589         // This is really only for compatibility so we do not need to
1590         // worry about configuration names and output names.
1591         std::string tLocation = t->GetLocation(0);
1592         tLocation = cmSystemTools::GetFilenamePath(tLocation);
1593         std::string depLocation = cmSystemTools::GetFilenamePath(dep);
1594         depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
1595         tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
1596         if(depLocation == tLocation)
1597           {
1598           this->Target->AddUtility(util.c_str());
1599           return true;
1600           }
1601         }
1602       }
1603     else
1604       {
1605       // The original name of the dependency was not a full path.  It
1606       // must name a target, so add the target-level dependency.
1607       this->Target->AddUtility(util.c_str());
1608       return true;
1609       }
1610     }
1611
1612   // The dependency does not name a target built in this project.
1613   return false;
1614 }
1615
1616 //----------------------------------------------------------------------------
1617 void
1618 cmTargetTraceDependencies
1619 ::CheckCustomCommand(cmCustomCommand const& cc)
1620 {
1621   // Transform command names that reference targets built in this
1622   // project to corresponding target-level dependencies.
1623   cmGeneratorExpression ge(this->Makefile, 0, cc.GetBacktrace(), true);
1624   for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
1625       cit != cc.GetCommandLines().end(); ++cit)
1626     {
1627     std::string const& command = *cit->begin();
1628     // Check for a target with this name.
1629     if(cmTarget* t = this->Makefile->FindTargetToUse(command.c_str()))
1630       {
1631       if(t->GetType() == cmTarget::EXECUTABLE)
1632         {
1633         // The command refers to an executable target built in
1634         // this project.  Add the target-level dependency to make
1635         // sure the executable is up to date before this custom
1636         // command possibly runs.
1637         this->Target->AddUtility(command.c_str());
1638         }
1639       }
1640
1641     // Check for target references in generator expressions.
1642     for(cmCustomCommandLine::const_iterator cli = cit->begin();
1643         cli != cit->end(); ++cli)
1644       {
1645       ge.Process(*cli);
1646       }
1647     }
1648
1649   // Add target-level dependencies referenced by generator expressions.
1650   std::set<cmTarget*> targets = ge.GetTargets();
1651   for(std::set<cmTarget*>::iterator ti = targets.begin();
1652       ti != targets.end(); ++ti)
1653     {
1654     this->Target->AddUtility((*ti)->GetName());
1655     }
1656
1657   // Queue the custom command dependencies.
1658   std::vector<std::string> const& depends = cc.GetDepends();
1659   for(std::vector<std::string>::const_iterator di = depends.begin();
1660       di != depends.end(); ++di)
1661     {
1662     std::string const& dep = *di;
1663     if(!this->IsUtility(dep))
1664       {
1665       // The dependency does not name a target and may be a file we
1666       // know how to generate.  Queue it.
1667       this->FollowName(dep);
1668       }
1669     }
1670 }
1671
1672 //----------------------------------------------------------------------------
1673 void
1674 cmTargetTraceDependencies
1675 ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
1676 {
1677   for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
1678       cli != commands.end(); ++cli)
1679     {
1680     this->CheckCustomCommand(*cli);
1681     }
1682 }
1683
1684 //----------------------------------------------------------------------------
1685 void cmTarget::TraceDependencies(const char* vsProjectFile)
1686 {
1687   // CMake-generated targets have no dependencies to trace.  Normally tracing
1688   // would find nothing anyway, but when building CMake itself the "install"
1689   // target command ends up referencing the "cmake" target but we do not
1690   // really want the dependency because "install" depend on "all" anyway.
1691   if(this->GetType() == cmTarget::GLOBAL_TARGET)
1692     {
1693     return;
1694     }
1695
1696   // Use a helper object to trace the dependencies.
1697   cmTargetTraceDependencies tracer(this, this->Internal.Get(), vsProjectFile);
1698   tracer.Trace();
1699 }
1700
1701 //----------------------------------------------------------------------------
1702 bool cmTarget::FindSourceFiles()
1703 {
1704   for(std::vector<cmSourceFile*>::const_iterator
1705         si = this->SourceFiles.begin();
1706       si != this->SourceFiles.end(); ++si)
1707     {
1708     std::string e;
1709     if((*si)->GetFullPath(&e).empty())
1710       {
1711       if(!e.empty())
1712         {
1713         cmake* cm = this->Makefile->GetCMakeInstance();
1714         cm->IssueMessage(cmake::FATAL_ERROR, e,
1715                          this->GetBacktrace());
1716         }
1717       return false;
1718       }
1719     }
1720   return true;
1721 }
1722
1723 //----------------------------------------------------------------------------
1724 std::vector<cmSourceFile*> const& cmTarget::GetSourceFiles()
1725 {
1726   return this->SourceFiles;
1727 }
1728
1729 //----------------------------------------------------------------------------
1730 void cmTarget::AddSourceFile(cmSourceFile* sf)
1731 {
1732   typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
1733   SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
1734   if(i == this->Internal->SourceEntries.end())
1735     {
1736     typedef cmTargetInternals::SourceEntry SourceEntry;
1737     SourceEntriesType::value_type entry(sf, SourceEntry());
1738     i = this->Internal->SourceEntries.insert(entry).first;
1739     this->SourceFiles.push_back(sf);
1740     }
1741 }
1742
1743 //----------------------------------------------------------------------------
1744 std::vector<cmSourceFile*> const*
1745 cmTarget::GetSourceDepends(cmSourceFile* sf)
1746 {
1747   typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
1748   SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
1749   if(i != this->Internal->SourceEntries.end())
1750     {
1751     return &i->second.Depends;
1752     }
1753   return 0;
1754 }
1755
1756 //----------------------------------------------------------------------------
1757 void cmTarget::AddSources(std::vector<std::string> const& srcs)
1758 {
1759   for(std::vector<std::string>::const_iterator i = srcs.begin();
1760       i != srcs.end(); ++i)
1761     {
1762     const char* src = i->c_str();
1763     if(src[0] == '$' && src[1] == '<')
1764       {
1765       this->ProcessSourceExpression(*i);
1766       }
1767     else
1768       {
1769       this->AddSource(src);
1770       }
1771     }
1772 }
1773
1774 //----------------------------------------------------------------------------
1775 cmSourceFile* cmTarget::AddSource(const char* s)
1776 {
1777   std::string src = s;
1778
1779   // For backwards compatibility replace varibles in source names.
1780   // This should eventually be removed.
1781   this->Makefile->ExpandVariablesInString(src);
1782
1783   cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
1784   this->AddSourceFile(sf);
1785   return sf;
1786 }
1787
1788 //----------------------------------------------------------------------------
1789 void cmTarget::ProcessSourceExpression(std::string const& expr)
1790 {
1791   if(strncmp(expr.c_str(), "$<TARGET_OBJECTS:", 17) == 0 &&
1792      expr[expr.size()-1] == '>')
1793     {
1794     std::string objLibName = expr.substr(17, expr.size()-18);
1795     this->ObjectLibraries.push_back(objLibName);
1796     }
1797   else
1798     {
1799     cmOStringStream e;
1800     e << "Unrecognized generator expression:\n"
1801       << "  " << expr;
1802     this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
1803     }
1804 }
1805
1806 //----------------------------------------------------------------------------
1807 struct cmTarget::SourceFileFlags
1808 cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
1809 {
1810   struct SourceFileFlags flags;
1811   this->ConstructSourceFileFlags();
1812   std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
1813     this->Internal->SourceFlagsMap.find(sf);
1814   if(si != this->Internal->SourceFlagsMap.end())
1815     {
1816     flags = si->second;
1817     }
1818   return flags;
1819 }
1820
1821 //----------------------------------------------------------------------------
1822 void cmTarget::ConstructSourceFileFlags()
1823 {
1824   if(this->Internal->SourceFileFlagsConstructed)
1825     {
1826     return;
1827     }
1828   this->Internal->SourceFileFlagsConstructed = true;
1829
1830   // Process public headers to mark the source files.
1831   if(const char* files = this->GetProperty("PUBLIC_HEADER"))
1832     {
1833     std::vector<std::string> relFiles;
1834     cmSystemTools::ExpandListArgument(files, relFiles);
1835     for(std::vector<std::string>::iterator it = relFiles.begin();
1836         it != relFiles.end(); ++it)
1837       {
1838       if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1839         {
1840         SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1841         flags.MacFolder = "Headers";
1842         flags.Type = cmTarget::SourceFileTypePublicHeader;
1843         }
1844       }
1845     }
1846
1847   // Process private headers after public headers so that they take
1848   // precedence if a file is listed in both.
1849   if(const char* files = this->GetProperty("PRIVATE_HEADER"))
1850     {
1851     std::vector<std::string> relFiles;
1852     cmSystemTools::ExpandListArgument(files, relFiles);
1853     for(std::vector<std::string>::iterator it = relFiles.begin();
1854         it != relFiles.end(); ++it)
1855       {
1856       if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1857         {
1858         SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1859         flags.MacFolder = "PrivateHeaders";
1860         flags.Type = cmTarget::SourceFileTypePrivateHeader;
1861         }
1862       }
1863     }
1864
1865   // Mark sources listed as resources.
1866   if(const char* files = this->GetProperty("RESOURCE"))
1867     {
1868     std::vector<std::string> relFiles;
1869     cmSystemTools::ExpandListArgument(files, relFiles);
1870     for(std::vector<std::string>::iterator it = relFiles.begin();
1871         it != relFiles.end(); ++it)
1872       {
1873       if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1874         {
1875         SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1876         flags.MacFolder = "Resources";
1877         flags.Type = cmTarget::SourceFileTypeResource;
1878         }
1879       }
1880     }
1881
1882   // Handle the MACOSX_PACKAGE_LOCATION property on source files that
1883   // were not listed in one of the other lists.
1884   std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
1885   for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
1886       si != sources.end(); ++si)
1887     {
1888     cmSourceFile* sf = *si;
1889     if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
1890       {
1891       SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1892       if(flags.Type == cmTarget::SourceFileTypeNormal)
1893         {
1894         flags.MacFolder = location;
1895         if(strcmp(location, "Resources") == 0)
1896           {
1897           flags.Type = cmTarget::SourceFileTypeResource;
1898           }
1899         else
1900           {
1901           flags.Type = cmTarget::SourceFileTypeMacContent;
1902           }
1903         }
1904       }
1905     }
1906 }
1907
1908 //----------------------------------------------------------------------------
1909 void cmTarget::MergeLinkLibraries( cmMakefile& mf,
1910                                    const char *selfname,
1911                                    const LinkLibraryVectorType& libs )
1912 {
1913   // Only add on libraries we haven't added on before.
1914   // Assumption: the global link libraries could only grow, never shrink
1915   LinkLibraryVectorType::const_iterator i = libs.begin();
1916   i += this->PrevLinkedLibraries.size();
1917   for( ; i != libs.end(); ++i )
1918     {
1919     // We call this so that the dependencies get written to the cache
1920     this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
1921     }
1922   this->PrevLinkedLibraries = libs;
1923 }
1924
1925 //----------------------------------------------------------------------------
1926 void cmTarget::AddLinkDirectory(const char* d)
1927 {
1928   // Make sure we don't add unnecessary search directories.
1929   if(this->LinkDirectoriesEmmitted.insert(d).second)
1930     {
1931     this->LinkDirectories.push_back(d);
1932     }
1933 }
1934
1935 //----------------------------------------------------------------------------
1936 const std::vector<std::string>& cmTarget::GetLinkDirectories()
1937 {
1938   return this->LinkDirectories;
1939 }
1940
1941 //----------------------------------------------------------------------------
1942 cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
1943 {
1944   // No configuration is always optimized.
1945   if(!(config && *config))
1946     {
1947     return cmTarget::OPTIMIZED;
1948     }
1949
1950   // Get the list of configurations considered to be DEBUG.
1951   std::vector<std::string> const& debugConfigs =
1952     this->Makefile->GetCMakeInstance()->GetDebugConfigs();
1953
1954   // Check if any entry in the list matches this configuration.
1955   std::string configUpper = cmSystemTools::UpperCase(config);
1956   for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
1957       i != debugConfigs.end(); ++i)
1958     {
1959     if(*i == configUpper)
1960       {
1961       return cmTarget::DEBUG;
1962       }
1963     }
1964
1965   // The current configuration is not a debug configuration.
1966   return cmTarget::OPTIMIZED;
1967 }
1968
1969 //----------------------------------------------------------------------------
1970 void cmTarget::ClearDependencyInformation( cmMakefile& mf,
1971                                            const char* target )
1972 {
1973   // Clear the dependencies. The cache variable must exist iff we are
1974   // recording dependency information for this target.
1975   std::string depname = target;
1976   depname += "_LIB_DEPENDS";
1977   if (this->RecordDependencies)
1978     {
1979     mf.AddCacheDefinition(depname.c_str(), "",
1980                           "Dependencies for target", cmCacheManager::STATIC);
1981     }
1982   else
1983     {
1984     if (mf.GetDefinition( depname.c_str() ))
1985       {
1986       std::string message = "Target ";
1987       message += target;
1988       message += " has dependency information when it shouldn't.\n";
1989       message += "Your cache is probably stale. Please remove the entry\n  ";
1990       message += depname;
1991       message += "\nfrom the cache.";
1992       cmSystemTools::Error( message.c_str() );
1993       }
1994     }
1995 }
1996
1997 //----------------------------------------------------------------------------
1998 bool cmTarget::NameResolvesToFramework(const std::string& libname)
1999 {
2000   return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
2001     NameResolvesToFramework(libname);
2002 }
2003
2004 //----------------------------------------------------------------------------
2005 bool cmTarget::AddFramework(const std::string& libname, LinkLibraryType llt)
2006 {
2007   (void)llt; // TODO: What is this?
2008   if(this->NameResolvesToFramework(libname.c_str()))
2009     {
2010     std::string frameworkDir = libname;
2011     frameworkDir += "/../";
2012     frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
2013     std::vector<std::string>::iterator i =
2014       std::find(this->Frameworks.begin(),
2015                 this->Frameworks.end(), frameworkDir);
2016     if(i == this->Frameworks.end())
2017       {
2018       this->Frameworks.push_back(frameworkDir);
2019       }
2020     return true;
2021     }
2022   return false;
2023 }
2024
2025 //----------------------------------------------------------------------------
2026 void cmTarget::AddLinkLibrary(cmMakefile& mf,
2027                               const char *target, const char* lib,
2028                               LinkLibraryType llt)
2029 {
2030   // Never add a self dependency, even if the user asks for it.
2031   if(strcmp( target, lib ) == 0)
2032     {
2033     return;
2034     }
2035   this->AddFramework(lib, llt);
2036   cmTarget::LibraryID tmp;
2037   tmp.first = lib;
2038   tmp.second = llt;
2039   this->LinkLibraries.push_back( tmp );
2040   this->OriginalLinkLibraries.push_back(tmp);
2041   this->ClearLinkMaps();
2042
2043   // Add the explicit dependency information for this target. This is
2044   // simply a set of libraries separated by ";". There should always
2045   // be a trailing ";". These library names are not canonical, in that
2046   // they may be "-framework x", "-ly", "/path/libz.a", etc.
2047   // We shouldn't remove duplicates here because external libraries
2048   // may be purposefully duplicated to handle recursive dependencies,
2049   // and we removing one instance will break the link line. Duplicates
2050   // will be appropriately eliminated at emit time.
2051   if(this->RecordDependencies)
2052     {
2053     std::string targetEntry = target;
2054     targetEntry += "_LIB_DEPENDS";
2055     std::string dependencies;
2056     const char* old_val = mf.GetDefinition( targetEntry.c_str() );
2057     if( old_val )
2058       {
2059       dependencies += old_val;
2060       }
2061     switch (llt)
2062       {
2063       case cmTarget::GENERAL:
2064         dependencies += "general";
2065         break;
2066       case cmTarget::DEBUG:
2067         dependencies += "debug";
2068         break;
2069       case cmTarget::OPTIMIZED:
2070         dependencies += "optimized";
2071         break;
2072       }
2073     dependencies += ";";
2074     dependencies += lib;
2075     dependencies += ";";
2076     mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
2077                            "Dependencies for the target",
2078                            cmCacheManager::STATIC );
2079     }
2080
2081 }
2082
2083 //----------------------------------------------------------------------------
2084 void
2085 cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
2086 {
2087   // There are two key parts of the dependency analysis: (1)
2088   // determining the libraries in the link line, and (2) constructing
2089   // the dependency graph for those libraries.
2090   //
2091   // The latter is done using the cache entries that record the
2092   // dependencies of each library.
2093   //
2094   // The former is a more thorny issue, since it is not clear how to
2095   // determine if two libraries listed on the link line refer to the a
2096   // single library or not. For example, consider the link "libraries"
2097   //    /usr/lib/libtiff.so -ltiff
2098   // Is this one library or two? The solution implemented here is the
2099   // simplest (and probably the only practical) one: two libraries are
2100   // the same if their "link strings" are identical. Thus, the two
2101   // libraries above are considered distinct. This also means that for
2102   // dependency analysis to be effective, the CMake user must specify
2103   // libraries build by his project without using any linker flags or
2104   // file extensions. That is,
2105   //    LINK_LIBRARIES( One Two )
2106   // instead of
2107   //    LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
2108   // The former is probably what most users would do, but it never
2109   // hurts to document the assumptions. :-) Therefore, in the analysis
2110   // code, the "canonical name" of a library is simply its name as
2111   // given to a LINK_LIBRARIES command.
2112   //
2113   // Also, we will leave the original link line intact; we will just add any
2114   // dependencies that were missing.
2115   //
2116   // There is a problem with recursive external libraries
2117   // (i.e. libraries with no dependency information that are
2118   // recursively dependent). We must make sure that the we emit one of
2119   // the libraries twice to satisfy the recursion, but we shouldn't
2120   // emit it more times than necessary. In particular, we must make
2121   // sure that handling this improbable case doesn't cost us when
2122   // dealing with the common case of non-recursive libraries. The
2123   // solution is to assume that the recursion is satisfied at one node
2124   // of the dependency tree. To illustrate, assume libA and libB are
2125   // extrenal and mutually dependent. Suppose libX depends on
2126   // libA, and libY on libA and libX. Then
2127   //   TARGET_LINK_LIBRARIES( Y X A B A )
2128   //   TARGET_LINK_LIBRARIES( X A B A )
2129   //   TARGET_LINK_LIBRARIES( Exec Y )
2130   // would result in "-lY -lX -lA -lB -lA". This is the correct way to
2131   // specify the dependencies, since the mutual dependency of A and B
2132   // is resolved *every time libA is specified*.
2133   //
2134   // Something like
2135   //   TARGET_LINK_LIBRARIES( Y X A B A )
2136   //   TARGET_LINK_LIBRARIES( X A B )
2137   //   TARGET_LINK_LIBRARIES( Exec Y )
2138   // would result in "-lY -lX -lA -lB", and the mutual dependency
2139   // information is lost. This is because in some case (Y), the mutual
2140   // dependency of A and B is listed, while in another other case (X),
2141   // it is not. Depending on which line actually emits A, the mutual
2142   // dependency may or may not be on the final link line.  We can't
2143   // handle this pathalogical case cleanly without emitting extra
2144   // libraries for the normal cases. Besides, the dependency
2145   // information for X is wrong anyway: if we build an executable
2146   // depending on X alone, we would not have the mutual dependency on
2147   // A and B resolved.
2148   //
2149   // IMPROVEMENTS:
2150   // -- The current algorithm will not always pick the "optimal" link line
2151   //    when recursive dependencies are present. It will instead break the
2152   //    cycles at an aribtrary point. The majority of projects won't have
2153   //    cyclic dependencies, so this is probably not a big deal. Note that
2154   //    the link line is always correct, just not necessary optimal.
2155
2156  {
2157  // Expand variables in link library names.  This is for backwards
2158  // compatibility with very early CMake versions and should
2159  // eventually be removed.  This code was moved here from the end of
2160  // old source list processing code which was called just before this
2161  // method.
2162  for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
2163      p != this->LinkLibraries.end(); ++p)
2164    {
2165    this->Makefile->ExpandVariablesInString(p->first, true, true);
2166    }
2167  }
2168
2169  typedef std::vector< std::string > LinkLine;
2170
2171  // The dependency map.
2172  DependencyMap dep_map;
2173
2174  // 1. Build the dependency graph
2175  //
2176  for(LinkLibraryVectorType::reverse_iterator lib
2177        = this->LinkLibraries.rbegin();
2178      lib != this->LinkLibraries.rend(); ++lib)
2179    {
2180    this->GatherDependencies( mf, *lib, dep_map);
2181    }
2182
2183  // 2. Remove any dependencies that are already satisfied in the original
2184  // link line.
2185  //
2186  for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
2187      lib != this->LinkLibraries.end(); ++lib)
2188    {
2189    for( LinkLibraryVectorType::iterator lib2 = lib;
2190         lib2 != this->LinkLibraries.end(); ++lib2)
2191      {
2192      this->DeleteDependency( dep_map, *lib, *lib2);
2193      }
2194    }
2195
2196
2197  // 3. Create the new link line by simply emitting any dependencies that are
2198  // missing.  Start from the back and keep adding.
2199  //
2200  std::set<DependencyMap::key_type> done, visited;
2201  std::vector<DependencyMap::key_type> newLinkLibraries;
2202  for(LinkLibraryVectorType::reverse_iterator lib =
2203        this->LinkLibraries.rbegin();
2204      lib != this->LinkLibraries.rend(); ++lib)
2205    {
2206    // skip zero size library entries, this may happen
2207    // if a variable expands to nothing.
2208    if (lib->first.size() != 0)
2209      {
2210      this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
2211      }
2212    }
2213
2214  // 4. Add the new libraries to the link line.
2215  //
2216  for( std::vector<DependencyMap::key_type>::reverse_iterator k =
2217         newLinkLibraries.rbegin();
2218       k != newLinkLibraries.rend(); ++k )
2219    {
2220    // get the llt from the dep_map
2221    this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
2222    }
2223  this->LinkLibrariesAnalyzed = true;
2224 }
2225
2226 //----------------------------------------------------------------------------
2227 void cmTarget::InsertDependency( DependencyMap& depMap,
2228                                  const LibraryID& lib,
2229                                  const LibraryID& dep)
2230 {
2231   depMap[lib].push_back(dep);
2232 }
2233
2234 //----------------------------------------------------------------------------
2235 void cmTarget::DeleteDependency( DependencyMap& depMap,
2236                                  const LibraryID& lib,
2237                                  const LibraryID& dep)
2238 {
2239   // Make sure there is an entry in the map for lib. If so, delete all
2240   // dependencies to dep. There may be repeated entries because of
2241   // external libraries that are specified multiple times.
2242   DependencyMap::iterator map_itr = depMap.find( lib );
2243   if( map_itr != depMap.end() )
2244     {
2245     DependencyList& depList = map_itr->second;
2246     DependencyList::iterator itr;
2247     while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
2248            depList.end() )
2249       {
2250       depList.erase( itr );
2251       }
2252     }
2253 }
2254
2255 //----------------------------------------------------------------------------
2256 void cmTarget::Emit(const LibraryID lib,
2257                     const DependencyMap& dep_map,
2258                     std::set<LibraryID>& emitted,
2259                     std::set<LibraryID>& visited,
2260                     DependencyList& link_line )
2261 {
2262   // It's already been emitted
2263   if( emitted.find(lib) != emitted.end() )
2264     {
2265     return;
2266     }
2267
2268   // Emit the dependencies only if this library node hasn't been
2269   // visited before. If it has, then we have a cycle. The recursion
2270   // that got us here should take care of everything.
2271
2272   if( visited.insert(lib).second )
2273     {
2274     if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
2275       {
2276       const DependencyList& dep_on = dep_map.find( lib )->second;
2277       DependencyList::const_reverse_iterator i;
2278
2279       // To cater for recursive external libraries, we must emit
2280       // duplicates on this link line *unless* they were emitted by
2281       // some other node, in which case we assume that the recursion
2282       // was resolved then. We making the simplifying assumption that
2283       // any duplicates on a single link line are on purpose, and must
2284       // be preserved.
2285
2286       // This variable will keep track of the libraries that were
2287       // emitted directory from the current node, and not from a
2288       // recursive call. This way, if we come across a library that
2289       // has already been emitted, we repeat it iff it has been
2290       // emitted here.
2291       std::set<DependencyMap::key_type> emitted_here;
2292       for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
2293         {
2294         if( emitted_here.find(*i) != emitted_here.end() )
2295           {
2296           // a repeat. Must emit.
2297           emitted.insert(*i);
2298           link_line.push_back( *i );
2299           }
2300         else
2301           {
2302           // Emit only if no-one else has
2303           if( emitted.find(*i) == emitted.end() )
2304             {
2305             // emit dependencies
2306             Emit( *i, dep_map, emitted, visited, link_line );
2307             // emit self
2308             emitted.insert(*i);
2309             emitted_here.insert(*i);
2310             link_line.push_back( *i );
2311             }
2312           }
2313         }
2314       }
2315     }
2316 }
2317
2318 //----------------------------------------------------------------------------
2319 void cmTarget::GatherDependencies( const cmMakefile& mf,
2320                                    const LibraryID& lib,
2321                                    DependencyMap& dep_map)
2322 {
2323   // If the library is already in the dependency map, then it has
2324   // already been fully processed.
2325   if( dep_map.find(lib) != dep_map.end() )
2326     {
2327     return;
2328     }
2329
2330   const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
2331   if( deps && strcmp(deps,"") != 0 )
2332     {
2333     // Make sure this library is in the map, even if it has an empty
2334     // set of dependencies. This distinguishes the case of explicitly
2335     // no dependencies with that of unspecified dependencies.
2336     dep_map[lib];
2337
2338     // Parse the dependency information, which is a set of
2339     // type, library pairs separated by ";". There is always a trailing ";".
2340     cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
2341     std::string depline = deps;
2342     std::string::size_type start = 0;
2343     std::string::size_type end;
2344     end = depline.find( ";", start );
2345     while( end != std::string::npos )
2346       {
2347       std::string l = depline.substr( start, end-start );
2348       if( l.size() != 0 )
2349         {
2350         if (l == "debug")
2351           {
2352           llt = cmTarget::DEBUG;
2353           }
2354         else if (l == "optimized")
2355           {
2356           llt = cmTarget::OPTIMIZED;
2357           }
2358         else if (l == "general")
2359           {
2360           llt = cmTarget::GENERAL;
2361           }
2362         else
2363           {
2364           LibraryID lib2(l,llt);
2365           this->InsertDependency( dep_map, lib, lib2);
2366           this->GatherDependencies( mf, lib2, dep_map);
2367           llt = cmTarget::GENERAL;
2368           }
2369         }
2370       start = end+1; // skip the ;
2371       end = depline.find( ";", start );
2372       }
2373     // cannot depend on itself
2374     this->DeleteDependency( dep_map, lib, lib);
2375     }
2376 }
2377
2378 //----------------------------------------------------------------------------
2379 void cmTarget::SetProperty(const char* prop, const char* value)
2380 {
2381   if (!prop)
2382     {
2383     return;
2384     }
2385
2386   this->Properties.SetProperty(prop, value, cmProperty::TARGET);
2387   this->MaybeInvalidatePropertyCache(prop);
2388 }
2389
2390 //----------------------------------------------------------------------------
2391 void cmTarget::AppendProperty(const char* prop, const char* value,
2392                               bool asString)
2393 {
2394   if (!prop)
2395     {
2396     return;
2397     }
2398   this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
2399   this->MaybeInvalidatePropertyCache(prop);
2400 }
2401
2402 //----------------------------------------------------------------------------
2403 void cmTarget::MaybeInvalidatePropertyCache(const char* prop)
2404 {
2405   // Wipe wipe out maps caching information affected by this property.
2406   if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
2407     {
2408     this->Internal->ImportInfoMap.clear();
2409     }
2410   if(!this->IsImported() && strncmp(prop, "LINK_INTERFACE_", 15) == 0)
2411     {
2412     this->ClearLinkMaps();
2413     }
2414 }
2415
2416 //----------------------------------------------------------------------------
2417 static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
2418   const char* prop, const char* value, cmMakefile* context, bool imported
2419   )
2420 {
2421   // Look for link-type keywords in the value.
2422   static cmsys::RegularExpression
2423     keys("(^|;)(debug|optimized|general)(;|$)");
2424   if(!keys.find(value))
2425     {
2426     return;
2427     }
2428
2429   // Support imported and non-imported versions of the property.
2430   const char* base = (imported?
2431                       "IMPORTED_LINK_INTERFACE_LIBRARIES" :
2432                       "LINK_INTERFACE_LIBRARIES");
2433
2434   // Report an error.
2435   cmOStringStream e;
2436   e << "Property " << prop << " may not contain link-type keyword \""
2437     << keys.match(2) << "\".  "
2438     << "The " << base << " property has a per-configuration "
2439     << "version called " << base << "_<CONFIG> which may be "
2440     << "used to specify per-configuration rules.";
2441   if(!imported)
2442     {
2443     e << "  "
2444       << "Alternatively, an IMPORTED library may be created, configured "
2445       << "with a per-configuration location, and then named in the "
2446       << "property value.  "
2447       << "See the add_library command's IMPORTED mode for details."
2448       << "\n"
2449       << "If you have a list of libraries that already contains the "
2450       << "keyword, use the target_link_libraries command with its "
2451       << "LINK_INTERFACE_LIBRARIES mode to set the property.  "
2452       << "The command automatically recognizes link-type keywords and sets "
2453       << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
2454       << "properties accordingly.";
2455     }
2456   context->IssueMessage(cmake::FATAL_ERROR, e.str());
2457 }
2458
2459 //----------------------------------------------------------------------------
2460 void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
2461 {
2462   // Certain properties need checking.
2463   if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
2464     {
2465     if(const char* value = this->GetProperty(prop))
2466       {
2467       cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
2468       }
2469     }
2470   if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
2471     {
2472     if(const char* value = this->GetProperty(prop))
2473       {
2474       cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
2475       }
2476     }
2477 }
2478
2479 //----------------------------------------------------------------------------
2480 void cmTarget::MarkAsImported()
2481 {
2482   this->IsImportedTarget = true;
2483 }
2484
2485 //----------------------------------------------------------------------------
2486 bool cmTarget::HaveWellDefinedOutputFiles()
2487 {
2488   return
2489     this->GetType() == cmTarget::STATIC_LIBRARY ||
2490     this->GetType() == cmTarget::SHARED_LIBRARY ||
2491     this->GetType() == cmTarget::MODULE_LIBRARY ||
2492     this->GetType() == cmTarget::EXECUTABLE;
2493 }
2494
2495 //----------------------------------------------------------------------------
2496 cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
2497 {
2498   // There is no output information for imported targets.
2499   if(this->IsImported())
2500     {
2501     return 0;
2502     }
2503
2504   // Only libraries and executables have well-defined output files.
2505   if(!this->HaveWellDefinedOutputFiles())
2506     {
2507     std::string msg = "cmTarget::GetOutputInfo called for ";
2508     msg += this->GetName();
2509     msg += " which has type ";
2510     msg += cmTarget::GetTargetTypeName(this->GetType());
2511     this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
2512     abort();
2513     return 0;
2514     }
2515
2516   // Lookup/compute/cache the output information for this configuration.
2517   std::string config_upper;
2518   if(config && *config)
2519     {
2520     config_upper = cmSystemTools::UpperCase(config);
2521     }
2522   typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
2523   OutputInfoMapType::const_iterator i =
2524     this->Internal->OutputInfoMap.find(config_upper);
2525   if(i == this->Internal->OutputInfoMap.end())
2526     {
2527     OutputInfo info;
2528     this->ComputeOutputDir(config, false, info.OutDir);
2529     this->ComputeOutputDir(config, true, info.ImpDir);
2530     OutputInfoMapType::value_type entry(config_upper, info);
2531     i = this->Internal->OutputInfoMap.insert(entry).first;
2532     }
2533   return &i->second;
2534 }
2535
2536 //----------------------------------------------------------------------------
2537 std::string cmTarget::GetDirectory(const char* config, bool implib)
2538 {
2539   if (this->IsImported())
2540     {
2541     // Return the directory from which the target is imported.
2542     return
2543       cmSystemTools::GetFilenamePath(
2544       this->ImportedGetFullPath(config, implib));
2545     }
2546   else if(OutputInfo const* info = this->GetOutputInfo(config))
2547     {
2548     // Return the directory in which the target will be built.
2549     return implib? info->ImpDir : info->OutDir;
2550     }
2551   return "";
2552 }
2553
2554 //----------------------------------------------------------------------------
2555 const char* cmTarget::GetLocation(const char* config)
2556 {
2557   if (this->IsImported())
2558     {
2559     return this->ImportedGetLocation(config);
2560     }
2561   else
2562     {
2563     return this->NormalGetLocation(config);
2564     }
2565 }
2566
2567 //----------------------------------------------------------------------------
2568 const char* cmTarget::ImportedGetLocation(const char* config)
2569 {
2570   this->Location = this->ImportedGetFullPath(config, false);
2571   return this->Location.c_str();
2572 }
2573
2574 //----------------------------------------------------------------------------
2575 const char* cmTarget::NormalGetLocation(const char* config)
2576 {
2577   // Handle the configuration-specific case first.
2578   if(config)
2579     {
2580     this->Location = this->GetFullPath(config, false);
2581     return this->Location.c_str();
2582     }
2583
2584   // Now handle the deprecated build-time configuration location.
2585   this->Location = this->GetDirectory();
2586   if(!this->Location.empty())
2587     {
2588     this->Location += "/";
2589     }
2590   const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
2591   if(cfgid && strcmp(cfgid, ".") != 0)
2592     {
2593     this->Location += cfgid;
2594     this->Location += "/";
2595     }
2596   this->Location = this->BuildMacContentDirectory(this->Location, config);
2597   this->Location += this->GetFullName(config, false);
2598   return this->Location.c_str();
2599 }
2600
2601 //----------------------------------------------------------------------------
2602 void cmTarget::GetTargetVersion(int& major, int& minor)
2603 {
2604   int patch;
2605   this->GetTargetVersion(false, major, minor, patch);
2606 }
2607
2608 //----------------------------------------------------------------------------
2609 void cmTarget::GetTargetVersion(bool soversion,
2610                                 int& major, int& minor, int& patch)
2611 {
2612   // Set the default values.
2613   major = 0;
2614   minor = 0;
2615   patch = 0;
2616
2617   // Look for a VERSION or SOVERSION property.
2618   const char* prop = soversion? "SOVERSION" : "VERSION";
2619   if(const char* version = this->GetProperty(prop))
2620     {
2621     // Try to parse the version number and store the results that were
2622     // successfully parsed.
2623     int parsed_major;
2624     int parsed_minor;
2625     int parsed_patch;
2626     switch(sscanf(version, "%d.%d.%d",
2627                   &parsed_major, &parsed_minor, &parsed_patch))
2628       {
2629       case 3: patch = parsed_patch; // no break!
2630       case 2: minor = parsed_minor; // no break!
2631       case 1: major = parsed_major; // no break!
2632       default: break;
2633       }
2634     }
2635 }
2636
2637 //----------------------------------------------------------------------------
2638 const char* cmTarget::GetFeature(const char* feature, const char* config)
2639 {
2640   if(config && *config)
2641     {
2642     std::string featureConfig = feature;
2643     featureConfig += "_";
2644     featureConfig += cmSystemTools::UpperCase(config);
2645     if(const char* value = this->GetProperty(featureConfig.c_str()))
2646       {
2647       return value;
2648       }
2649     }
2650   if(const char* value = this->GetProperty(feature))
2651     {
2652     return value;
2653     }
2654   return this->Makefile->GetFeature(feature, config);
2655 }
2656
2657 //----------------------------------------------------------------------------
2658 const char *cmTarget::GetProperty(const char* prop)
2659 {
2660   return this->GetProperty(prop, cmProperty::TARGET);
2661 }
2662
2663 //----------------------------------------------------------------------------
2664 const char *cmTarget::GetProperty(const char* prop,
2665                                   cmProperty::ScopeType scope)
2666 {
2667   if(!prop)
2668     {
2669     return 0;
2670     }
2671
2672   // Watch for special "computed" properties that are dependent on
2673   // other properties or variables.  Always recompute them.
2674   if(this->GetType() == cmTarget::EXECUTABLE ||
2675      this->GetType() == cmTarget::STATIC_LIBRARY ||
2676      this->GetType() == cmTarget::SHARED_LIBRARY ||
2677      this->GetType() == cmTarget::MODULE_LIBRARY ||
2678      this->GetType() == cmTarget::UNKNOWN_LIBRARY)
2679     {
2680     if(strcmp(prop,"LOCATION") == 0)
2681       {
2682       // Set the LOCATION property of the target.
2683       //
2684       // For an imported target this is the location of an arbitrary
2685       // available configuration.
2686       //
2687       // For a non-imported target this is deprecated because it
2688       // cannot take into account the per-configuration name of the
2689       // target because the configuration type may not be known at
2690       // CMake time.
2691       this->SetProperty("LOCATION", this->GetLocation(0));
2692       }
2693
2694     // Support "LOCATION_<CONFIG>".
2695     if(strncmp(prop, "LOCATION_", 9) == 0)
2696       {
2697       std::string configName = prop+9;
2698       this->SetProperty(prop, this->GetLocation(configName.c_str()));
2699       }
2700     else
2701       {
2702       // Support "<CONFIG>_LOCATION" for compatiblity.
2703       int len = static_cast<int>(strlen(prop));
2704       if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
2705         {
2706         std::string configName(prop, len-9);
2707         if(configName != "IMPORTED")
2708           {
2709           this->SetProperty(prop, this->GetLocation(configName.c_str()));
2710           }
2711         }
2712       }
2713     }
2714
2715   if (strcmp(prop,"IMPORTED") == 0)
2716     {
2717     return this->IsImported()?"TRUE":"FALSE";
2718     }
2719
2720   if(!strcmp(prop,"SOURCES"))
2721     {
2722     cmOStringStream ss;
2723     const char* sep = "";
2724     for(std::vector<cmSourceFile*>::const_iterator
2725           i = this->SourceFiles.begin();
2726         i != this->SourceFiles.end(); ++i)
2727       {
2728       // Separate from the previous list entries.
2729       ss << sep;
2730       sep = ";";
2731
2732       // Construct what is known about this source file location.
2733       cmSourceFileLocation const& location = (*i)->GetLocation();
2734       std::string sname = location.GetDirectory();
2735       if(!sname.empty())
2736         {
2737         sname += "/";
2738         }
2739       sname += location.GetName();
2740
2741       // Append this list entry.
2742       ss << sname;
2743       }
2744     this->SetProperty("SOURCES", ss.str().c_str());
2745     }
2746
2747   // the type property returns what type the target is
2748   if (!strcmp(prop,"TYPE"))
2749     {
2750     return cmTarget::GetTargetTypeName(this->GetType());
2751     }
2752   bool chain = false;
2753   const char *retVal =
2754     this->Properties.GetPropertyValue(prop, scope, chain);
2755   if (chain)
2756     {
2757     return this->Makefile->GetProperty(prop,scope);
2758     }
2759   return retVal;
2760 }
2761
2762 //----------------------------------------------------------------------------
2763 bool cmTarget::GetPropertyAsBool(const char* prop)
2764 {
2765   return cmSystemTools::IsOn(this->GetProperty(prop));
2766 }
2767
2768 //----------------------------------------------------------------------------
2769 class cmTargetCollectLinkLanguages
2770 {
2771 public:
2772   cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
2773                                std::set<cmStdString>& languages):
2774     Config(config), Languages(languages) { this->Visited.insert(target); }
2775   void Visit(cmTarget* target)
2776     {
2777     if(!target || !this->Visited.insert(target).second)
2778       {
2779       return;
2780       }
2781
2782     cmTarget::LinkInterface const* iface =
2783       target->GetLinkInterface(this->Config);
2784     if(!iface) { return; }
2785
2786     for(std::vector<std::string>::const_iterator
2787           li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
2788       {
2789       this->Languages.insert(*li);
2790       }
2791
2792     cmMakefile* mf = target->GetMakefile();
2793     for(std::vector<std::string>::const_iterator
2794           li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
2795       {
2796       this->Visit(mf->FindTargetToUse(li->c_str()));
2797       }
2798     }
2799 private:
2800   const char* Config;
2801   std::set<cmStdString>& Languages;
2802   std::set<cmTarget*> Visited;
2803 };
2804
2805 //----------------------------------------------------------------------------
2806 const char* cmTarget::GetLinkerLanguage(const char* config)
2807 {
2808   const char* lang = this->GetLinkClosure(config)->LinkerLanguage.c_str();
2809   return *lang? lang : 0;
2810 }
2811
2812 //----------------------------------------------------------------------------
2813 cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config)
2814 {
2815   std::string key = cmSystemTools::UpperCase(config? config : "");
2816   cmTargetInternals::LinkClosureMapType::iterator
2817     i = this->Internal->LinkClosureMap.find(key);
2818   if(i == this->Internal->LinkClosureMap.end())
2819     {
2820     LinkClosure lc;
2821     this->ComputeLinkClosure(config, lc);
2822     cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
2823     i = this->Internal->LinkClosureMap.insert(entry).first;
2824     }
2825   return &i->second;
2826 }
2827
2828 //----------------------------------------------------------------------------
2829 class cmTargetSelectLinker
2830 {
2831   int Preference;
2832   cmTarget* Target;
2833   cmMakefile* Makefile;
2834   cmGlobalGenerator* GG;
2835   std::set<cmStdString> Preferred;
2836 public:
2837   cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
2838     {
2839     this->Makefile = this->Target->GetMakefile();
2840     this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
2841     }
2842   void Consider(const char* lang)
2843     {
2844     int preference = this->GG->GetLinkerPreference(lang);
2845     if(preference > this->Preference)
2846       {
2847       this->Preference = preference;
2848       this->Preferred.clear();
2849       }
2850     if(preference == this->Preference)
2851       {
2852       this->Preferred.insert(lang);
2853       }
2854     }
2855   std::string Choose()
2856     {
2857     if(this->Preferred.empty())
2858       {
2859       return "";
2860       }
2861     else if(this->Preferred.size() > 1)
2862       {
2863       cmOStringStream e;
2864       e << "Target " << this->Target->GetName()
2865         << " contains multiple languages with the highest linker preference"
2866         << " (" << this->Preference << "):\n";
2867       for(std::set<cmStdString>::const_iterator
2868             li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
2869         {
2870         e << "  " << *li << "\n";
2871         }
2872       e << "Set the LINKER_LANGUAGE property for this target.";
2873       cmake* cm = this->Makefile->GetCMakeInstance();
2874       cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
2875                        this->Target->GetBacktrace());
2876       }
2877     return *this->Preferred.begin();
2878     }
2879 };
2880
2881 //----------------------------------------------------------------------------
2882 void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc)
2883 {
2884   // Get languages built in this target.
2885   std::set<cmStdString> languages;
2886   LinkImplementation const* impl = this->GetLinkImplementation(config);
2887   for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
2888       li != impl->Languages.end(); ++li)
2889     {
2890     languages.insert(*li);
2891     }
2892
2893   // Add interface languages from linked targets.
2894   cmTargetCollectLinkLanguages cll(this, config, languages);
2895   for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
2896       li != impl->Libraries.end(); ++li)
2897     {
2898     cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
2899     }
2900
2901   // Store the transitive closure of languages.
2902   for(std::set<cmStdString>::const_iterator li = languages.begin();
2903       li != languages.end(); ++li)
2904     {
2905     lc.Languages.push_back(*li);
2906     }
2907
2908   // Choose the language whose linker should be used.
2909   if(this->GetProperty("HAS_CXX"))
2910     {
2911     lc.LinkerLanguage = "CXX";
2912     }
2913   else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
2914     {
2915     lc.LinkerLanguage = linkerLang;
2916     }
2917   else
2918     {
2919     // Find the language with the highest preference value.
2920     cmTargetSelectLinker tsl(this);
2921
2922     // First select from the languages compiled directly in this target.
2923     for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
2924         li != impl->Languages.end(); ++li)
2925       {
2926       tsl.Consider(li->c_str());
2927       }
2928
2929     // Now consider languages that propagate from linked targets.
2930     for(std::set<cmStdString>::const_iterator sit = languages.begin();
2931         sit != languages.end(); ++sit)
2932       {
2933       std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
2934       if(this->Makefile->IsOn(propagates.c_str()))
2935         {
2936         tsl.Consider(sit->c_str());
2937         }
2938       }
2939
2940     lc.LinkerLanguage = tsl.Choose();
2941     }
2942 }
2943
2944 //----------------------------------------------------------------------------
2945 const char* cmTarget::GetCreateRuleVariable()
2946 {
2947   switch(this->GetType())
2948     {
2949     case cmTarget::STATIC_LIBRARY:
2950       return "_CREATE_STATIC_LIBRARY";
2951     case cmTarget::SHARED_LIBRARY:
2952       return "_CREATE_SHARED_LIBRARY";
2953     case cmTarget::MODULE_LIBRARY:
2954       return "_CREATE_SHARED_MODULE";
2955     case cmTarget::EXECUTABLE:
2956       return "_LINK_EXECUTABLE";
2957     default:
2958       break;
2959     }
2960   return "";
2961 }
2962
2963 //----------------------------------------------------------------------------
2964 const char* cmTarget::GetSuffixVariableInternal(bool implib)
2965 {
2966   switch(this->GetType())
2967     {
2968     case cmTarget::STATIC_LIBRARY:
2969       return "CMAKE_STATIC_LIBRARY_SUFFIX";
2970     case cmTarget::SHARED_LIBRARY:
2971       return (implib
2972               ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2973               : "CMAKE_SHARED_LIBRARY_SUFFIX");
2974     case cmTarget::MODULE_LIBRARY:
2975       return (implib
2976               ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2977               : "CMAKE_SHARED_MODULE_SUFFIX");
2978     case cmTarget::EXECUTABLE:
2979       return (implib
2980               ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2981               : "CMAKE_EXECUTABLE_SUFFIX");
2982     default:
2983       break;
2984     }
2985   return "";
2986 }
2987
2988
2989 //----------------------------------------------------------------------------
2990 const char* cmTarget::GetPrefixVariableInternal(bool implib)
2991 {
2992   switch(this->GetType())
2993     {
2994     case cmTarget::STATIC_LIBRARY:
2995       return "CMAKE_STATIC_LIBRARY_PREFIX";
2996     case cmTarget::SHARED_LIBRARY:
2997       return (implib
2998               ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2999               : "CMAKE_SHARED_LIBRARY_PREFIX");
3000     case cmTarget::MODULE_LIBRARY:
3001       return (implib
3002               ? "CMAKE_IMPORT_LIBRARY_PREFIX"
3003               : "CMAKE_SHARED_MODULE_PREFIX");
3004     case cmTarget::EXECUTABLE:
3005       return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
3006     default:
3007       break;
3008     }
3009   return "";
3010 }
3011
3012 //----------------------------------------------------------------------------
3013 std::string cmTarget::GetPDBName(const char* config)
3014 {
3015   std::string prefix;
3016   std::string base;
3017   std::string suffix;
3018   this->GetFullNameInternal(config, false, prefix, base, suffix);
3019   return prefix+base+".pdb";
3020 }
3021
3022 //----------------------------------------------------------------------------
3023 bool cmTarget::HasSOName(const char* config)
3024 {
3025   // soname is supported only for shared libraries and modules,
3026   // and then only when the platform supports an soname flag.
3027   return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
3028            this->GetType() == cmTarget::MODULE_LIBRARY) &&
3029           !this->GetPropertyAsBool("NO_SONAME") &&
3030           this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
3031 }
3032
3033 //----------------------------------------------------------------------------
3034 std::string cmTarget::GetSOName(const char* config)
3035 {
3036   if(this->IsImported())
3037     {
3038     // Lookup the imported soname.
3039     if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
3040       {
3041       if(info->NoSOName)
3042         {
3043         // The imported library has no builtin soname so the name
3044         // searched at runtime will be just the filename.
3045         return cmSystemTools::GetFilenameName(info->Location);
3046         }
3047       else
3048         {
3049         // Use the soname given if any.
3050         return info->SOName;
3051         }
3052       }
3053     else
3054       {
3055       return "";
3056       }
3057     }
3058   else
3059     {
3060     // Compute the soname that will be built.
3061     std::string name;
3062     std::string soName;
3063     std::string realName;
3064     std::string impName;
3065     std::string pdbName;
3066     this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
3067     return soName;
3068     }
3069 }
3070
3071 //----------------------------------------------------------------------------
3072 bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
3073 {
3074   if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
3075     {
3076     if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
3077       {
3078       return info->NoSOName;
3079       }
3080     }
3081   return false;
3082 }
3083
3084 //----------------------------------------------------------------------------
3085 std::string cmTarget::NormalGetRealName(const char* config)
3086 {
3087   // This should not be called for imported targets.
3088   // TODO: Split cmTarget into a class hierarchy to get compile-time
3089   // enforcement of the limited imported target API.
3090   if(this->IsImported())
3091     {
3092     std::string msg =  "NormalGetRealName called on imported target: ";
3093     msg += this->GetName();
3094     this->GetMakefile()->
3095       IssueMessage(cmake::INTERNAL_ERROR,
3096                    msg.c_str());
3097     }
3098
3099   if(this->GetType() == cmTarget::EXECUTABLE)
3100     {
3101     // Compute the real name that will be built.
3102     std::string name;
3103     std::string realName;
3104     std::string impName;
3105     std::string pdbName;
3106     this->GetExecutableNames(name, realName, impName, pdbName, config);
3107     return realName;
3108     }
3109   else
3110     {
3111     // Compute the real name that will be built.
3112     std::string name;
3113     std::string soName;
3114     std::string realName;
3115     std::string impName;
3116     std::string pdbName;
3117     this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
3118     return realName;
3119     }
3120 }
3121
3122 //----------------------------------------------------------------------------
3123 std::string cmTarget::GetFullName(const char* config, bool implib)
3124 {
3125   if(this->IsImported())
3126     {
3127     return this->GetFullNameImported(config, implib);
3128     }
3129   else
3130     {
3131     return this->GetFullNameInternal(config, implib);
3132     }
3133 }
3134
3135 //----------------------------------------------------------------------------
3136 std::string cmTarget::GetFullNameImported(const char* config, bool implib)
3137 {
3138   return cmSystemTools::GetFilenameName(
3139     this->ImportedGetFullPath(config, implib));
3140 }
3141
3142 //----------------------------------------------------------------------------
3143 void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
3144                                      std::string& suffix, const char* config,
3145                                      bool implib)
3146 {
3147   this->GetFullNameInternal(config, implib, prefix, base, suffix);
3148 }
3149
3150 //----------------------------------------------------------------------------
3151 std::string cmTarget::GetFullPath(const char* config, bool implib,
3152                                   bool realname)
3153 {
3154   if(this->IsImported())
3155     {
3156     return this->ImportedGetFullPath(config, implib);
3157     }
3158   else
3159     {
3160     return this->NormalGetFullPath(config, implib, realname);
3161     }
3162 }
3163
3164 //----------------------------------------------------------------------------
3165 std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
3166                                         bool realname)
3167 {
3168   std::string fpath = this->GetMacContentDirectory(config, implib);
3169
3170   // Add the full name of the target.
3171   if(implib)
3172     {
3173     fpath += this->GetFullName(config, true);
3174     }
3175   else if(realname)
3176     {
3177     fpath += this->NormalGetRealName(config);
3178     }
3179   else
3180     {
3181     fpath += this->GetFullName(config, false);
3182     }
3183   return fpath;
3184 }
3185
3186 //----------------------------------------------------------------------------
3187 std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
3188 {
3189   std::string result;
3190   if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
3191     {
3192     result = implib? info->ImportLibrary : info->Location;
3193     }
3194   if(result.empty())
3195     {
3196     result = this->GetName();
3197     result += "-NOTFOUND";
3198     }
3199   return result;
3200 }
3201
3202 //----------------------------------------------------------------------------
3203 std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
3204 {
3205   std::string prefix;
3206   std::string base;
3207   std::string suffix;
3208   this->GetFullNameInternal(config, implib, prefix, base, suffix);
3209   return prefix+base+suffix;
3210 }
3211
3212 //----------------------------------------------------------------------------
3213 void cmTarget::GetFullNameInternal(const char* config,
3214                                    bool implib,
3215                                    std::string& outPrefix,
3216                                    std::string& outBase,
3217                                    std::string& outSuffix)
3218 {
3219   // Use just the target name for non-main target types.
3220   if(this->GetType() != cmTarget::STATIC_LIBRARY &&
3221      this->GetType() != cmTarget::SHARED_LIBRARY &&
3222      this->GetType() != cmTarget::MODULE_LIBRARY &&
3223      this->GetType() != cmTarget::EXECUTABLE)
3224     {
3225     outPrefix = "";
3226     outBase = this->GetName();
3227     outSuffix = "";
3228     return;
3229     }
3230
3231   // Return an empty name for the import library if this platform
3232   // does not support import libraries.
3233   if(implib &&
3234      !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
3235     {
3236     outPrefix = "";
3237     outBase = "";
3238     outSuffix = "";
3239     return;
3240     }
3241
3242   // The implib option is only allowed for shared libraries, module
3243   // libraries, and executables.
3244   if(this->GetType() != cmTarget::SHARED_LIBRARY &&
3245      this->GetType() != cmTarget::MODULE_LIBRARY &&
3246      this->GetType() != cmTarget::EXECUTABLE)
3247     {
3248     implib = false;
3249     }
3250
3251   // Compute the full name for main target types.
3252   const char* targetPrefix = (implib
3253                               ? this->GetProperty("IMPORT_PREFIX")
3254                               : this->GetProperty("PREFIX"));
3255   const char* targetSuffix = (implib
3256                               ? this->GetProperty("IMPORT_SUFFIX")
3257                               : this->GetProperty("SUFFIX"));
3258   const char* configPostfix = 0;
3259   if(config && *config)
3260     {
3261     std::string configProp = cmSystemTools::UpperCase(config);
3262     configProp += "_POSTFIX";
3263     configPostfix = this->GetProperty(configProp.c_str());
3264     // Mac application bundles and frameworks have no postfix.
3265     if(configPostfix &&
3266        (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
3267       {
3268       configPostfix = 0;
3269       }
3270     }
3271   const char* prefixVar = this->GetPrefixVariableInternal(implib);
3272   const char* suffixVar = this->GetSuffixVariableInternal(implib);
3273
3274   // Check for language-specific default prefix and suffix.
3275   if(const char* ll = this->GetLinkerLanguage(config))
3276     {
3277     if(!targetSuffix && suffixVar && *suffixVar)
3278       {
3279       std::string langSuff = suffixVar + std::string("_") + ll;
3280       targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
3281       }
3282     if(!targetPrefix && prefixVar && *prefixVar)
3283       {
3284       std::string langPrefix = prefixVar + std::string("_") + ll;
3285       targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
3286       }
3287     }
3288
3289   // if there is no prefix on the target use the cmake definition
3290   if(!targetPrefix && prefixVar)
3291     {
3292     targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
3293     }
3294   // if there is no suffix on the target use the cmake definition
3295   if(!targetSuffix && suffixVar)
3296     {
3297     targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
3298     }
3299
3300   // frameworks do not have a prefix or a suffix
3301   if(this->IsFrameworkOnApple())
3302     {
3303     targetPrefix = 0;
3304     targetSuffix = 0;
3305     }
3306
3307   // Begin the final name with the prefix.
3308   outPrefix = targetPrefix?targetPrefix:"";
3309
3310   // Append the target name or property-specified name.
3311   outBase += this->GetOutputName(config, implib);
3312
3313   // Append the per-configuration postfix.
3314   outBase += configPostfix?configPostfix:"";
3315
3316   // Name shared libraries with their version number on some platforms.
3317   if(const char* soversion = this->GetProperty("SOVERSION"))
3318     {
3319     if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
3320        this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
3321       {
3322       outBase += "-";
3323       outBase += soversion;
3324       }
3325     }
3326
3327   // Append the suffix.
3328   outSuffix = targetSuffix?targetSuffix:"";
3329 }
3330
3331 //----------------------------------------------------------------------------
3332 void cmTarget::GetLibraryNames(std::string& name,
3333                                std::string& soName,
3334                                std::string& realName,
3335                                std::string& impName,
3336                                std::string& pdbName,
3337                                const char* config)
3338 {
3339   // This should not be called for imported targets.
3340   // TODO: Split cmTarget into a class hierarchy to get compile-time
3341   // enforcement of the limited imported target API.
3342   if(this->IsImported())
3343     {
3344     std::string msg =  "GetLibraryNames called on imported target: ";
3345     msg += this->GetName();
3346     this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
3347                                  msg.c_str());
3348     return;
3349     }
3350
3351   // Check for library version properties.
3352   const char* version = this->GetProperty("VERSION");
3353   const char* soversion = this->GetProperty("SOVERSION");
3354   if(!this->HasSOName(config) ||
3355      this->IsFrameworkOnApple())
3356     {
3357     // Versioning is supported only for shared libraries and modules,
3358     // and then only when the platform supports an soname flag.
3359     version = 0;
3360     soversion = 0;
3361     }
3362   if(version && !soversion)
3363     {
3364     // The soversion must be set if the library version is set.  Use
3365     // the library version as the soversion.
3366     soversion = version;
3367     }
3368   if(!version && soversion)
3369     {
3370     // Use the soversion as the library version.
3371     version = soversion;
3372     }
3373
3374   // Get the components of the library name.
3375   std::string prefix;
3376   std::string base;
3377   std::string suffix;
3378   this->GetFullNameInternal(config, false, prefix, base, suffix);
3379
3380   // The library name.
3381   name = prefix+base+suffix;
3382
3383   // The library's soname.
3384   this->ComputeVersionedName(soName, prefix, base, suffix,
3385                              name, soversion);
3386
3387   // The library's real name on disk.
3388   this->ComputeVersionedName(realName, prefix, base, suffix,
3389                              name, version);
3390
3391   // The import library name.
3392   if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3393      this->GetType() == cmTarget::MODULE_LIBRARY)
3394     {
3395     impName = this->GetFullNameInternal(config, true);
3396     }
3397   else
3398     {
3399     impName = "";
3400     }
3401
3402   // The program database file name.
3403   pdbName = prefix+base+".pdb";
3404 }
3405
3406 //----------------------------------------------------------------------------
3407 void cmTarget::ComputeVersionedName(std::string& vName,
3408                                     std::string const& prefix,
3409                                     std::string const& base,
3410                                     std::string const& suffix,
3411                                     std::string const& name,
3412                                     const char* version)
3413 {
3414   vName = this->IsApple? (prefix+base) : name;
3415   if(version)
3416     {
3417     vName += ".";
3418     vName += version;
3419     }
3420   vName += this->IsApple? suffix : std::string();
3421 }
3422
3423 //----------------------------------------------------------------------------
3424 void cmTarget::GetExecutableNames(std::string& name,
3425                                   std::string& realName,
3426                                   std::string& impName,
3427                                   std::string& pdbName,
3428                                   const char* config)
3429 {
3430   // This should not be called for imported targets.
3431   // TODO: Split cmTarget into a class hierarchy to get compile-time
3432   // enforcement of the limited imported target API.
3433   if(this->IsImported())
3434     {
3435     std::string msg =
3436       "GetExecutableNames called on imported target: ";
3437     msg += this->GetName();
3438     this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
3439     }
3440
3441   // This versioning is supported only for executables and then only
3442   // when the platform supports symbolic links.
3443 #if defined(_WIN32) && !defined(__CYGWIN__)
3444   const char* version = 0;
3445 #else
3446   // Check for executable version properties.
3447   const char* version = this->GetProperty("VERSION");
3448   if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
3449     {
3450     version = 0;
3451     }
3452 #endif
3453
3454   // Get the components of the executable name.
3455   std::string prefix;
3456   std::string base;
3457   std::string suffix;
3458   this->GetFullNameInternal(config, false, prefix, base, suffix);
3459
3460   // The executable name.
3461   name = prefix+base+suffix;
3462
3463   // The executable's real name on disk.
3464 #if defined(__CYGWIN__)
3465   realName = prefix+base;
3466 #else
3467   realName = name;
3468 #endif
3469   if(version)
3470     {
3471     realName += "-";
3472     realName += version;
3473     }
3474 #if defined(__CYGWIN__)
3475   realName += suffix;
3476 #endif
3477
3478   // The import library name.
3479   impName = this->GetFullNameInternal(config, true);
3480
3481   // The program database file name.
3482   pdbName = prefix+base+".pdb";
3483 }
3484
3485 //----------------------------------------------------------------------------
3486 bool cmTarget::HasImplibGNUtoMS()
3487 {
3488   return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
3489 }
3490
3491 //----------------------------------------------------------------------------
3492 bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
3493                                 std::string& out, const char* newExt)
3494 {
3495   if(this->HasImplibGNUtoMS() &&
3496      gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
3497     {
3498     out = gnuName.substr(0, gnuName.size()-6);
3499     out += newExt? newExt : ".lib";
3500     return true;
3501     }
3502   return false;
3503 }
3504
3505 //----------------------------------------------------------------------------
3506 void cmTarget::GenerateTargetManifest(const char* config)
3507 {
3508   cmMakefile* mf = this->Makefile;
3509   cmLocalGenerator* lg = mf->GetLocalGenerator();
3510   cmGlobalGenerator* gg = lg->GetGlobalGenerator();
3511
3512   // Get the names.
3513   std::string name;
3514   std::string soName;
3515   std::string realName;
3516   std::string impName;
3517   std::string pdbName;
3518   if(this->GetType() == cmTarget::EXECUTABLE)
3519     {
3520     this->GetExecutableNames(name, realName, impName, pdbName, config);
3521     }
3522   else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
3523           this->GetType() == cmTarget::SHARED_LIBRARY ||
3524           this->GetType() == cmTarget::MODULE_LIBRARY)
3525     {
3526     this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
3527     }
3528   else
3529     {
3530     return;
3531     }
3532
3533   // Get the directory.
3534   std::string dir = this->GetDirectory(config, false);
3535
3536   // Add each name.
3537   std::string f;
3538   if(!name.empty())
3539     {
3540     f = dir;
3541     f += "/";
3542     f += name;
3543     gg->AddToManifest(config? config:"", f);
3544     }
3545   if(!soName.empty())
3546     {
3547     f = dir;
3548     f += "/";
3549     f += soName;
3550     gg->AddToManifest(config? config:"", f);
3551     }
3552   if(!realName.empty())
3553     {
3554     f = dir;
3555     f += "/";
3556     f += realName;
3557     gg->AddToManifest(config? config:"", f);
3558     }
3559   if(!pdbName.empty())
3560     {
3561     f = dir;
3562     f += "/";
3563     f += pdbName;
3564     gg->AddToManifest(config? config:"", f);
3565     }
3566   if(!impName.empty())
3567     {
3568     f = this->GetDirectory(config, true);
3569     f += "/";
3570     f += impName;
3571     gg->AddToManifest(config? config:"", f);
3572     }
3573 }
3574
3575 //----------------------------------------------------------------------------
3576 void cmTarget::SetPropertyDefault(const char* property,
3577                                   const char* default_value)
3578 {
3579   // Compute the name of the variable holding the default value.
3580   std::string var = "CMAKE_";
3581   var += property;
3582
3583   if(const char* value = this->Makefile->GetDefinition(var.c_str()))
3584     {
3585     this->SetProperty(property, value);
3586     }
3587   else if(default_value)
3588     {
3589     this->SetProperty(property, default_value);
3590     }
3591 }
3592
3593 //----------------------------------------------------------------------------
3594 bool cmTarget::HaveBuildTreeRPATH()
3595 {
3596   return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
3597           !this->LinkLibraries.empty());
3598 }
3599
3600 //----------------------------------------------------------------------------
3601 bool cmTarget::HaveInstallTreeRPATH()
3602 {
3603   const char* install_rpath = this->GetProperty("INSTALL_RPATH");
3604   return (install_rpath && *install_rpath) &&
3605           !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
3606 }
3607
3608 //----------------------------------------------------------------------------
3609 bool cmTarget::NeedRelinkBeforeInstall(const char* config)
3610 {
3611   // Only executables and shared libraries can have an rpath and may
3612   // need relinking.
3613   if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
3614      this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
3615      this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
3616     {
3617     return false;
3618     }
3619
3620   // If there is no install location this target will not be installed
3621   // and therefore does not need relinking.
3622   if(!this->GetHaveInstallRule())
3623     {
3624     return false;
3625     }
3626
3627   // If skipping all rpaths completely then no relinking is needed.
3628   if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
3629     {
3630     return false;
3631     }
3632
3633   // If building with the install-tree rpath no relinking is needed.
3634   if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3635     {
3636     return false;
3637     }
3638
3639   // If chrpath is going to be used no relinking is needed.
3640   if(this->IsChrpathUsed(config))
3641     {
3642     return false;
3643     }
3644
3645   // Check for rpath support on this platform.
3646   if(const char* ll = this->GetLinkerLanguage(config))
3647     {
3648     std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
3649     flagVar += ll;
3650     flagVar += "_FLAG";
3651     if(!this->Makefile->IsSet(flagVar.c_str()))
3652       {
3653       // There is no rpath support on this platform so nothing needs
3654       // relinking.
3655       return false;
3656       }
3657     }
3658   else
3659     {
3660     // No linker language is known.  This error will be reported by
3661     // other code.
3662     return false;
3663     }
3664
3665   // If either a build or install tree rpath is set then the rpath
3666   // will likely change between the build tree and install tree and
3667   // this target must be relinked.
3668   return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
3669 }
3670
3671 //----------------------------------------------------------------------------
3672 std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
3673                                                     bool for_xcode)
3674 {
3675   // If building directly for installation then the build tree install_name
3676   // is the same as the install tree.
3677   if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3678     {
3679     return GetInstallNameDirForInstallTree(config, for_xcode);
3680     }
3681
3682   // Use the build tree directory for the target.
3683   if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3684      !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
3685      !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
3686     {
3687     std::string dir = this->GetDirectory(config);
3688     dir += "/";
3689     if(this->IsFrameworkOnApple() && !for_xcode)
3690       {
3691       dir += this->GetFrameworkDirectory(config);
3692       }
3693     return dir;
3694     }
3695   else
3696     {
3697     return "";
3698     }
3699 }
3700
3701 //----------------------------------------------------------------------------
3702 std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
3703                                                       bool for_xcode)
3704 {
3705   if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
3706     {
3707     std::string dir;
3708
3709     if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
3710        !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
3711       {
3712       const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
3713       if(install_name_dir && *install_name_dir)
3714         {
3715         dir = install_name_dir;
3716         dir += "/";
3717         }
3718       }
3719
3720     if(this->IsFrameworkOnApple() && !for_xcode)
3721       {
3722       dir += this->GetFrameworkDirectory(config);
3723       }
3724
3725     return dir;
3726     }
3727   else
3728     {
3729     return "";
3730     }
3731 }
3732
3733 //----------------------------------------------------------------------------
3734 const char* cmTarget::GetOutputTargetType(bool implib)
3735 {
3736   switch(this->GetType())
3737     {
3738     case cmTarget::SHARED_LIBRARY:
3739       if(this->DLLPlatform)
3740         {
3741         if(implib)
3742           {
3743           // A DLL import library is treated as an archive target.
3744           return "ARCHIVE";
3745           }
3746         else
3747           {
3748           // A DLL shared library is treated as a runtime target.
3749           return "RUNTIME";
3750           }
3751         }
3752       else
3753         {
3754         // For non-DLL platforms shared libraries are treated as
3755         // library targets.
3756         return "LIBRARY";
3757         }
3758     case cmTarget::STATIC_LIBRARY:
3759       // Static libraries are always treated as archive targets.
3760       return "ARCHIVE";
3761     case cmTarget::MODULE_LIBRARY:
3762       if(implib)
3763         {
3764         // Module libraries are always treated as library targets.
3765         return "ARCHIVE";
3766         }
3767       else
3768         {
3769         // Module import libraries are treated as archive targets.
3770         return "LIBRARY";
3771         }
3772     case cmTarget::EXECUTABLE:
3773       if(implib)
3774         {
3775         // Executable import libraries are treated as archive targets.
3776         return "ARCHIVE";
3777         }
3778       else
3779         {
3780         // Executables are always treated as runtime targets.
3781         return "RUNTIME";
3782         }
3783     default:
3784       break;
3785     }
3786   return "";
3787 }
3788
3789 //----------------------------------------------------------------------------
3790 bool cmTarget::ComputeOutputDir(const char* config,
3791                                 bool implib, std::string& out)
3792 {
3793   bool usesDefaultOutputDir = false;
3794
3795   // Look for a target property defining the target output directory
3796   // based on the target type.
3797   std::string targetTypeName = this->GetOutputTargetType(implib);
3798   const char* propertyName = 0;
3799   std::string propertyNameStr = targetTypeName;
3800   if(!propertyNameStr.empty())
3801     {
3802     propertyNameStr += "_OUTPUT_DIRECTORY";
3803     propertyName = propertyNameStr.c_str();
3804     }
3805
3806   // Check for a per-configuration output directory target property.
3807   std::string configUpper = cmSystemTools::UpperCase(config? config : "");
3808   const char* configProp = 0;
3809   std::string configPropStr = targetTypeName;
3810   if(!configPropStr.empty())
3811     {
3812     configPropStr += "_OUTPUT_DIRECTORY_";
3813     configPropStr += configUpper;
3814     configProp = configPropStr.c_str();
3815     }
3816
3817   // Select an output directory.
3818   if(const char* config_outdir = this->GetProperty(configProp))
3819     {
3820     // Use the user-specified per-configuration output directory.
3821     out = config_outdir;
3822
3823     // Skip per-configuration subdirectory.
3824     config = 0;
3825     }
3826   else if(const char* outdir = this->GetProperty(propertyName))
3827     {
3828     // Use the user-specified output directory.
3829     out = outdir;
3830     }
3831   else if(this->GetType() == cmTarget::EXECUTABLE)
3832     {
3833     // Lookup the output path for executables.
3834     out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
3835     }
3836   else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
3837           this->GetType() == cmTarget::SHARED_LIBRARY ||
3838           this->GetType() == cmTarget::MODULE_LIBRARY)
3839     {
3840     // Lookup the output path for libraries.
3841     out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
3842     }
3843   if(out.empty())
3844     {
3845     // Default to the current output directory.
3846     usesDefaultOutputDir = true;
3847     out = ".";
3848     }
3849
3850   // Convert the output path to a full path in case it is
3851   // specified as a relative path.  Treat a relative path as
3852   // relative to the current output directory for this makefile.
3853   out = (cmSystemTools::CollapseFullPath
3854          (out.c_str(), this->Makefile->GetStartOutputDirectory()));
3855
3856   // The generator may add the configuration's subdirectory.
3857   if(config && *config)
3858     {
3859     const char *platforms = this->Makefile->GetDefinition(
3860       "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
3861     std::string suffix =
3862       usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
3863     this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
3864       AppendDirectoryForConfig("/", config, suffix.c_str(), out);
3865     }
3866
3867   return usesDefaultOutputDir;
3868 }
3869
3870 //----------------------------------------------------------------------------
3871 bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib)
3872 {
3873   std::string dir;
3874   return this->ComputeOutputDir(config, implib, dir);
3875 }
3876
3877 //----------------------------------------------------------------------------
3878 std::string cmTarget::GetOutputName(const char* config, bool implib)
3879 {
3880   std::vector<std::string> props;
3881   std::string type = this->GetOutputTargetType(implib);
3882   std::string configUpper = cmSystemTools::UpperCase(config? config : "");
3883   if(!type.empty() && !configUpper.empty())
3884     {
3885     // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
3886     props.push_back(type + "_OUTPUT_NAME_" + configUpper);
3887     }
3888   if(!type.empty())
3889     {
3890     // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
3891     props.push_back(type + "_OUTPUT_NAME");
3892     }
3893   if(!configUpper.empty())
3894     {
3895     // OUTPUT_NAME_<CONFIG>
3896     props.push_back("OUTPUT_NAME_" + configUpper);
3897     // <CONFIG>_OUTPUT_NAME
3898     props.push_back(configUpper + "_OUTPUT_NAME");
3899     }
3900   // OUTPUT_NAME
3901   props.push_back("OUTPUT_NAME");
3902
3903   for(std::vector<std::string>::const_iterator i = props.begin();
3904       i != props.end(); ++i)
3905     {
3906     if(const char* outName = this->GetProperty(i->c_str()))
3907       {
3908       return outName;
3909       }
3910     }
3911   return this->GetName();
3912 }
3913
3914 //----------------------------------------------------------------------------
3915 std::string cmTarget::GetFrameworkVersion()
3916 {
3917   if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
3918     {
3919     return fversion;
3920     }
3921   else if(const char* tversion = this->GetProperty("VERSION"))
3922     {
3923     return tversion;
3924     }
3925   else
3926     {
3927     return "A";
3928     }
3929 }
3930
3931 //----------------------------------------------------------------------------
3932 const char* cmTarget::GetExportMacro()
3933 {
3934   // Define the symbol for targets that export symbols.
3935   if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3936      this->GetType() == cmTarget::MODULE_LIBRARY ||
3937      this->IsExecutableWithExports())
3938     {
3939     if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
3940       {
3941       this->ExportMacro = custom_export_name;
3942       }
3943     else
3944       {
3945       std::string in = this->GetName();
3946       in += "_EXPORTS";
3947       this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
3948       }
3949     return this->ExportMacro.c_str();
3950     }
3951   else
3952     {
3953     return 0;
3954     }
3955 }
3956
3957 //----------------------------------------------------------------------------
3958 void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
3959 {
3960   for(std::vector<cmSourceFile*>::const_iterator
3961         i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
3962     {
3963     if(const char* lang = (*i)->GetLanguage())
3964       {
3965       languages.insert(lang);
3966       }
3967     }
3968 }
3969
3970 //----------------------------------------------------------------------------
3971 void cmTarget::GetAppleArchs(const char* config,
3972                              std::vector<std::string>& archVec)
3973 {
3974   const char* archs = 0;
3975   if(config && *config)
3976     {
3977     std::string defVarName = "OSX_ARCHITECTURES_";
3978     defVarName += cmSystemTools::UpperCase(config);
3979     archs = this->GetProperty(defVarName.c_str());
3980     }
3981   if(!archs)
3982     {
3983     archs = this->GetProperty("OSX_ARCHITECTURES");
3984     }
3985   if(archs)
3986     {
3987     cmSystemTools::ExpandListArgument(std::string(archs), archVec);
3988     }
3989 }
3990
3991 //----------------------------------------------------------------------------
3992 bool cmTarget::IsChrpathUsed(const char* config)
3993 {
3994 #if defined(CMAKE_USE_ELF_PARSER)
3995   // Only certain target types have an rpath.
3996   if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
3997        this->GetType() == cmTarget::MODULE_LIBRARY ||
3998        this->GetType() == cmTarget::EXECUTABLE))
3999     {
4000     return false;
4001     }
4002
4003   // If the target will not be installed we do not need to change its
4004   // rpath.
4005   if(!this->GetHaveInstallRule())
4006     {
4007     return false;
4008     }
4009
4010   // Skip chrpath if skipping rpath altogether.
4011   if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
4012     {
4013     return false;
4014     }
4015
4016   // Skip chrpath if it does not need to be changed at install time.
4017   if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
4018     {
4019     return false;
4020     }
4021
4022   // Allow the user to disable builtin chrpath explicitly.
4023   if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
4024     {
4025     return false;
4026     }
4027
4028   // Enable if the rpath flag uses a separator and the target uses ELF
4029   // binaries.
4030   if(const char* ll = this->GetLinkerLanguage(config))
4031     {
4032     std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
4033     sepVar += ll;
4034     sepVar += "_FLAG_SEP";
4035     const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
4036     if(sep && *sep)
4037       {
4038       // TODO: Add ELF check to ABI detection and get rid of
4039       // CMAKE_EXECUTABLE_FORMAT.
4040       if(const char* fmt =
4041          this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
4042         {
4043         return strcmp(fmt, "ELF") == 0;
4044         }
4045       }
4046     }
4047 #endif
4048   static_cast<void>(config);
4049   return false;
4050 }
4051
4052 //----------------------------------------------------------------------------
4053 cmTarget::ImportInfo const*
4054 cmTarget::GetImportInfo(const char* config)
4055 {
4056   // There is no imported information for non-imported targets.
4057   if(!this->IsImported())
4058     {
4059     return 0;
4060     }
4061
4062   // Lookup/compute/cache the import information for this
4063   // configuration.
4064   std::string config_upper;
4065   if(config && *config)
4066     {
4067     config_upper = cmSystemTools::UpperCase(config);
4068     }
4069   else
4070     {
4071     config_upper = "NOCONFIG";
4072     }
4073   typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
4074   ImportInfoMapType::const_iterator i =
4075     this->Internal->ImportInfoMap.find(config_upper);
4076   if(i == this->Internal->ImportInfoMap.end())
4077     {
4078     ImportInfo info;
4079     this->ComputeImportInfo(config_upper, info);
4080     ImportInfoMapType::value_type entry(config_upper, info);
4081     i = this->Internal->ImportInfoMap.insert(entry).first;
4082     }
4083
4084   // If the location is empty then the target is not available for
4085   // this configuration.
4086   if(i->second.Location.empty() && i->second.ImportLibrary.empty())
4087     {
4088     return 0;
4089     }
4090
4091   // Return the import information.
4092   return &i->second;
4093 }
4094
4095 //----------------------------------------------------------------------------
4096 void cmTarget::ComputeImportInfo(std::string const& desired_config,
4097                                  ImportInfo& info)
4098 {
4099   // This method finds information about an imported target from its
4100   // properties.  The "IMPORTED_" namespace is reserved for properties
4101   // defined by the project exporting the target.
4102
4103   // Initialize members.
4104   info.NoSOName = false;
4105
4106   // Track the configuration-specific property suffix.
4107   std::string suffix = "_";
4108   suffix += desired_config;
4109
4110   // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
4111   // library or an executable with exports.
4112   bool allowImp = this->HasImportLibrary();
4113
4114   // Look for a mapping from the current project's configuration to
4115   // the imported project's configuration.
4116   std::vector<std::string> mappedConfigs;
4117   {
4118   std::string mapProp = "MAP_IMPORTED_CONFIG_";
4119   mapProp += desired_config;
4120   if(const char* mapValue = this->GetProperty(mapProp.c_str()))
4121     {
4122     cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
4123     }
4124   }
4125
4126   // If a mapping was found, check its configurations.
4127   const char* loc = 0;
4128   const char* imp = 0;
4129   for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
4130       !loc && !imp && mci != mappedConfigs.end(); ++mci)
4131     {
4132     // Look for this configuration.
4133     std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
4134     std::string locProp = "IMPORTED_LOCATION_";
4135     locProp += mcUpper;
4136     loc = this->GetProperty(locProp.c_str());
4137     if(allowImp)
4138       {
4139       std::string impProp = "IMPORTED_IMPLIB_";
4140       impProp += mcUpper;
4141       imp = this->GetProperty(impProp.c_str());
4142       }
4143
4144     // If it was found, use it for all properties below.
4145     if(loc || imp)
4146       {
4147       suffix = "_";
4148       suffix += mcUpper;
4149       }
4150     }
4151
4152   // If we needed to find one of the mapped configurations but did not
4153   // then the target is not found.  The project does not want any
4154   // other configuration.
4155   if(!mappedConfigs.empty() && !loc && !imp)
4156     {
4157     return;
4158     }
4159
4160   // If we have not yet found it then there are no mapped
4161   // configurations.  Look for an exact-match.
4162   if(!loc && !imp)
4163     {
4164     std::string locProp = "IMPORTED_LOCATION";
4165     locProp += suffix;
4166     loc = this->GetProperty(locProp.c_str());
4167     if(allowImp)
4168       {
4169       std::string impProp = "IMPORTED_IMPLIB";
4170       impProp += suffix;
4171       imp = this->GetProperty(impProp.c_str());
4172       }
4173     }
4174
4175   // If we have not yet found it then there are no mapped
4176   // configurations and no exact match.
4177   if(!loc && !imp)
4178     {
4179     // The suffix computed above is not useful.
4180     suffix = "";
4181
4182     // Look for a configuration-less location.  This may be set by
4183     // manually-written code.
4184     loc = this->GetProperty("IMPORTED_LOCATION");
4185     if(allowImp)
4186       {
4187       imp = this->GetProperty("IMPORTED_IMPLIB");
4188       }
4189     }
4190
4191   // If we have not yet found it then the project is willing to try
4192   // any available configuration.
4193   if(!loc && !imp)
4194     {
4195     std::vector<std::string> availableConfigs;
4196     if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
4197       {
4198       cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
4199       }
4200     for(std::vector<std::string>::const_iterator
4201           aci = availableConfigs.begin();
4202         !loc && !imp && aci != availableConfigs.end(); ++aci)
4203       {
4204       suffix = "_";
4205       suffix += cmSystemTools::UpperCase(*aci);
4206       std::string locProp = "IMPORTED_LOCATION";
4207       locProp += suffix;
4208       loc = this->GetProperty(locProp.c_str());
4209       if(allowImp)
4210         {
4211         std::string impProp = "IMPORTED_IMPLIB";
4212         impProp += suffix;
4213         imp = this->GetProperty(impProp.c_str());
4214         }
4215       }
4216     }
4217
4218   // If we have not yet found it then the target is not available.
4219   if(!loc && !imp)
4220     {
4221     return;
4222     }
4223
4224   // A provided configuration has been chosen.  Load the
4225   // configuration's properties.
4226
4227   // Get the location.
4228   if(loc)
4229     {
4230     info.Location = loc;
4231     }
4232   else
4233     {
4234     std::string impProp = "IMPORTED_LOCATION";
4235     impProp += suffix;
4236     if(const char* config_location = this->GetProperty(impProp.c_str()))
4237       {
4238       info.Location = config_location;
4239       }
4240     else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
4241       {
4242       info.Location = location;
4243       }
4244     }
4245
4246   // Get the soname.
4247   if(this->GetType() == cmTarget::SHARED_LIBRARY)
4248     {
4249     std::string soProp = "IMPORTED_SONAME";
4250     soProp += suffix;
4251     if(const char* config_soname = this->GetProperty(soProp.c_str()))
4252       {
4253       info.SOName = config_soname;
4254       }
4255     else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
4256       {
4257       info.SOName = soname;
4258       }
4259     }
4260
4261   // Get the "no-soname" mark.
4262   if(this->GetType() == cmTarget::SHARED_LIBRARY)
4263     {
4264     std::string soProp = "IMPORTED_NO_SONAME";
4265     soProp += suffix;
4266     if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
4267       {
4268       info.NoSOName = cmSystemTools::IsOn(config_no_soname);
4269       }
4270     else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
4271       {
4272       info.NoSOName = cmSystemTools::IsOn(no_soname);
4273       }
4274     }
4275
4276   // Get the import library.
4277   if(imp)
4278     {
4279     info.ImportLibrary = imp;
4280     }
4281   else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
4282           this->IsExecutableWithExports())
4283     {
4284     std::string impProp = "IMPORTED_IMPLIB";
4285     impProp += suffix;
4286     if(const char* config_implib = this->GetProperty(impProp.c_str()))
4287       {
4288       info.ImportLibrary = config_implib;
4289       }
4290     else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
4291       {
4292       info.ImportLibrary = implib;
4293       }
4294     }
4295
4296   // Get the link interface.
4297   {
4298   std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
4299   linkProp += suffix;
4300   if(const char* config_libs = this->GetProperty(linkProp.c_str()))
4301     {
4302     cmSystemTools::ExpandListArgument(config_libs,
4303                                       info.LinkInterface.Libraries);
4304     }
4305   else if(const char* libs =
4306           this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
4307     {
4308     cmSystemTools::ExpandListArgument(libs,
4309                                       info.LinkInterface.Libraries);
4310     }
4311   }
4312
4313   // Get the link dependencies.
4314   {
4315   std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
4316   linkProp += suffix;
4317   if(const char* config_libs = this->GetProperty(linkProp.c_str()))
4318     {
4319     cmSystemTools::ExpandListArgument(config_libs,
4320                                       info.LinkInterface.SharedDeps);
4321     }
4322   else if(const char* libs =
4323           this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
4324     {
4325     cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
4326     }
4327   }
4328
4329   // Get the link languages.
4330   if(this->GetType() == cmTarget::STATIC_LIBRARY)
4331     {
4332     std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
4333     linkProp += suffix;
4334     if(const char* config_libs = this->GetProperty(linkProp.c_str()))
4335       {
4336       cmSystemTools::ExpandListArgument(config_libs,
4337                                         info.LinkInterface.Languages);
4338       }
4339     else if(const char* libs =
4340             this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
4341       {
4342       cmSystemTools::ExpandListArgument(libs,
4343                                         info.LinkInterface.Languages);
4344       }
4345     }
4346
4347   // Get the cyclic repetition count.
4348   if(this->GetType() == cmTarget::STATIC_LIBRARY)
4349     {
4350     std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
4351     linkProp += suffix;
4352     if(const char* config_reps = this->GetProperty(linkProp.c_str()))
4353       {
4354       sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
4355       }
4356     else if(const char* reps =
4357             this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
4358       {
4359       sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
4360       }
4361     }
4362 }
4363
4364 //----------------------------------------------------------------------------
4365 cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config)
4366 {
4367   // Imported targets have their own link interface.
4368   if(this->IsImported())
4369     {
4370     if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
4371       {
4372       return &info->LinkInterface;
4373       }
4374     return 0;
4375     }
4376
4377   // Link interfaces are not supported for executables that do not
4378   // export symbols.
4379   if(this->GetType() == cmTarget::EXECUTABLE &&
4380      !this->IsExecutableWithExports())
4381     {
4382     return 0;
4383     }
4384
4385   // Lookup any existing link interface for this configuration.
4386   std::string key = cmSystemTools::UpperCase(config? config : "");
4387   cmTargetInternals::LinkInterfaceMapType::iterator
4388     i = this->Internal->LinkInterfaceMap.find(key);
4389   if(i == this->Internal->LinkInterfaceMap.end())
4390     {
4391     // Compute the link interface for this configuration.
4392     cmTargetInternals::OptionalLinkInterface iface;
4393     iface.Exists = this->ComputeLinkInterface(config, iface);
4394
4395     // Store the information for this configuration.
4396     cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
4397     i = this->Internal->LinkInterfaceMap.insert(entry).first;
4398     }
4399
4400   return i->second.Exists? &i->second : 0;
4401 }
4402
4403 //----------------------------------------------------------------------------
4404 bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface)
4405 {
4406   // Construct the property name suffix for this configuration.
4407   std::string suffix = "_";
4408   if(config && *config)
4409     {
4410     suffix += cmSystemTools::UpperCase(config);
4411     }
4412   else
4413     {
4414     suffix += "NOCONFIG";
4415     }
4416
4417   // An explicit list of interface libraries may be set for shared
4418   // libraries and executables that export symbols.
4419   const char* explicitLibraries = 0;
4420   if(this->GetType() == cmTarget::SHARED_LIBRARY ||
4421      this->IsExecutableWithExports())
4422     {
4423     // Lookup the per-configuration property.
4424     std::string propName = "LINK_INTERFACE_LIBRARIES";
4425     propName += suffix;
4426     explicitLibraries = this->GetProperty(propName.c_str());
4427
4428     // If not set, try the generic property.
4429     if(!explicitLibraries)
4430       {
4431       explicitLibraries = this->GetProperty("LINK_INTERFACE_LIBRARIES");
4432       }
4433     }
4434
4435   // There is no implicit link interface for executables or modules
4436   // so if none was explicitly set then there is no link interface.
4437   // Note that CMake versions 2.2 and below allowed linking to modules.
4438   bool canLinkModules = this->Makefile->NeedBackwardsCompatibility(2,2);
4439   if(!explicitLibraries &&
4440      (this->GetType() == cmTarget::EXECUTABLE ||
4441       (this->GetType() == cmTarget::MODULE_LIBRARY && !canLinkModules)))
4442     {
4443     return false;
4444     }
4445
4446   if(explicitLibraries)
4447     {
4448     // The interface libraries have been explicitly set.
4449     cmSystemTools::ExpandListArgument(explicitLibraries, iface.Libraries);
4450
4451     if(this->GetType() == cmTarget::SHARED_LIBRARY)
4452       {
4453       // Shared libraries may have runtime implementation dependencies
4454       // on other shared libraries that are not in the interface.
4455       std::set<cmStdString> emitted;
4456       for(std::vector<std::string>::const_iterator
4457             li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
4458         {
4459         emitted.insert(*li);
4460         }
4461       LinkImplementation const* impl = this->GetLinkImplementation(config);
4462       for(std::vector<std::string>::const_iterator
4463             li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
4464         {
4465         if(emitted.insert(*li).second)
4466           {
4467           if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
4468             {
4469             // This is a runtime dependency on another shared library.
4470             if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
4471               {
4472               iface.SharedDeps.push_back(*li);
4473               }
4474             }
4475           else
4476             {
4477             // TODO: Recognize shared library file names.  Perhaps this
4478             // should be moved to cmComputeLinkInformation, but that creates
4479             // a chicken-and-egg problem since this list is needed for its
4480             // construction.
4481             }
4482           }
4483         }
4484       }
4485     }
4486   else
4487     {
4488     // The link implementation is the default link interface.
4489     LinkImplementation const* impl = this->GetLinkImplementation(config);
4490     iface.Libraries = impl->Libraries;
4491     iface.WrongConfigLibraries = impl->WrongConfigLibraries;
4492     if(this->GetType() == cmTarget::STATIC_LIBRARY)
4493       {
4494       // Targets using this archive need its language runtime libraries.
4495       iface.Languages = impl->Languages;
4496       }
4497     }
4498
4499   if(this->GetType() == cmTarget::STATIC_LIBRARY)
4500     {
4501     // How many repetitions are needed if this library has cyclic
4502     // dependencies?
4503     std::string propName = "LINK_INTERFACE_MULTIPLICITY";
4504     propName += suffix;
4505     if(const char* config_reps = this->GetProperty(propName.c_str()))
4506       {
4507       sscanf(config_reps, "%u", &iface.Multiplicity);
4508       }
4509     else if(const char* reps =
4510             this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
4511       {
4512       sscanf(reps, "%u", &iface.Multiplicity);
4513       }
4514     }
4515
4516   return true;
4517 }
4518
4519 //----------------------------------------------------------------------------
4520 cmTarget::LinkImplementation const*
4521 cmTarget::GetLinkImplementation(const char* config)
4522 {
4523   // There is no link implementation for imported targets.
4524   if(this->IsImported())
4525     {
4526     return 0;
4527     }
4528
4529   // Lookup any existing link implementation for this configuration.
4530   std::string key = cmSystemTools::UpperCase(config? config : "");
4531   cmTargetInternals::LinkImplMapType::iterator
4532     i = this->Internal->LinkImplMap.find(key);
4533   if(i == this->Internal->LinkImplMap.end())
4534     {
4535     // Compute the link implementation for this configuration.
4536     LinkImplementation impl;
4537     this->ComputeLinkImplementation(config, impl);
4538
4539     // Store the information for this configuration.
4540     cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
4541     i = this->Internal->LinkImplMap.insert(entry).first;
4542     }
4543
4544   return &i->second;
4545 }
4546
4547 //----------------------------------------------------------------------------
4548 void cmTarget::ComputeLinkImplementation(const char* config,
4549                                          LinkImplementation& impl)
4550 {
4551   // Compute which library configuration to link.
4552   cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
4553
4554   // Collect libraries directly linked in this configuration.
4555   LinkLibraryVectorType const& llibs = this->GetOriginalLinkLibraries();
4556   for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
4557       li != llibs.end(); ++li)
4558     {
4559     // Skip entries that resolve to the target itself or are empty.
4560     std::string item = this->CheckCMP0004(li->first);
4561     if(item == this->GetName() || item.empty())
4562       {
4563       continue;
4564       }
4565
4566     if(li->second == cmTarget::GENERAL || li->second == linkType)
4567       {
4568       // The entry is meant for this configuration.
4569       impl.Libraries.push_back(item);
4570       }
4571     else
4572       {
4573       // Support OLD behavior for CMP0003.
4574       impl.WrongConfigLibraries.push_back(item);
4575       }
4576     }
4577
4578   // This target needs runtime libraries for its source languages.
4579   std::set<cmStdString> languages;
4580   // Get languages used in our source files.
4581   this->GetLanguages(languages);
4582   // Get languages used in object library sources.
4583   for(std::vector<std::string>::iterator i = this->ObjectLibraries.begin();
4584       i != this->ObjectLibraries.end(); ++i)
4585     {
4586     if(cmTarget* objLib = this->Makefile->FindTargetToUse(i->c_str()))
4587       {
4588       if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
4589         {
4590         objLib->GetLanguages(languages);
4591         }
4592       }
4593     }
4594   // Copy the set of langauges to the link implementation.
4595   for(std::set<cmStdString>::iterator li = languages.begin();
4596       li != languages.end(); ++li)
4597     {
4598     impl.Languages.push_back(*li);
4599     }
4600 }
4601
4602 //----------------------------------------------------------------------------
4603 std::string cmTarget::CheckCMP0004(std::string const& item)
4604 {
4605   // Strip whitespace off the library names because we used to do this
4606   // in case variables were expanded at generate time.  We no longer
4607   // do the expansion but users link to libraries like " ${VAR} ".
4608   std::string lib = item;
4609   std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
4610   if(pos != lib.npos)
4611     {
4612     lib = lib.substr(pos, lib.npos);
4613     }
4614   pos = lib.find_last_not_of(" \t\r\n");
4615   if(pos != lib.npos)
4616     {
4617     lib = lib.substr(0, pos+1);
4618     }
4619   if(lib != item)
4620     {
4621     cmake* cm = this->Makefile->GetCMakeInstance();
4622     switch(this->PolicyStatusCMP0004)
4623       {
4624       case cmPolicies::WARN:
4625         {
4626         cmOStringStream w;
4627         w << (this->Makefile->GetPolicies()
4628               ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
4629           << "Target \"" << this->GetName() << "\" links to item \""
4630           << item << "\" which has leading or trailing whitespace.";
4631         cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
4632                          this->GetBacktrace());
4633         }
4634       case cmPolicies::OLD:
4635         break;
4636       case cmPolicies::NEW:
4637         {
4638         cmOStringStream e;
4639         e << "Target \"" << this->GetName() << "\" links to item \""
4640           << item << "\" which has leading or trailing whitespace.  "
4641           << "This is now an error according to policy CMP0004.";
4642         cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
4643         }
4644         break;
4645       case cmPolicies::REQUIRED_IF_USED:
4646       case cmPolicies::REQUIRED_ALWAYS:
4647         {
4648         cmOStringStream e;
4649         e << (this->Makefile->GetPolicies()
4650               ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
4651           << "Target \"" << this->GetName() << "\" links to item \""
4652           << item << "\" which has leading or trailing whitespace.";
4653         cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
4654         }
4655         break;
4656       }
4657     }
4658   return lib;
4659 }
4660
4661 //----------------------------------------------------------------------------
4662 cmComputeLinkInformation*
4663 cmTarget::GetLinkInformation(const char* config)
4664 {
4665   // Lookup any existing information for this configuration.
4666   std::map<cmStdString, cmComputeLinkInformation*>::iterator
4667     i = this->LinkInformation.find(config?config:"");
4668   if(i == this->LinkInformation.end())
4669     {
4670     // Compute information for this configuration.
4671     cmComputeLinkInformation* info =
4672       new cmComputeLinkInformation(this, config);
4673     if(!info || !info->Compute())
4674       {
4675       delete info;
4676       info = 0;
4677       }
4678
4679     // Store the information for this configuration.
4680     std::map<cmStdString, cmComputeLinkInformation*>::value_type
4681       entry(config?config:"", info);
4682     i = this->LinkInformation.insert(entry).first;
4683     }
4684   return i->second;
4685 }
4686
4687 //----------------------------------------------------------------------------
4688 std::vector<std::string> cmTarget::GetIncludeDirectories()
4689 {
4690   std::vector<std::string> includes;
4691   const char *prop = this->GetProperty("INCLUDE_DIRECTORIES");
4692   if(prop)
4693     {
4694     cmSystemTools::ExpandListArgument(prop, includes);
4695     }
4696
4697   std::set<std::string> uniqueIncludes;
4698   std::vector<std::string> orderedAndUniqueIncludes;
4699   for(std::vector<std::string>::const_iterator
4700       li = includes.begin(); li != includes.end(); ++li)
4701     {
4702     if(uniqueIncludes.insert(*li).second)
4703       {
4704       orderedAndUniqueIncludes.push_back(*li);
4705       }
4706     }
4707
4708   return orderedAndUniqueIncludes;
4709 }
4710
4711 //----------------------------------------------------------------------------
4712 std::string cmTarget::GetFrameworkDirectory(const char* config)
4713 {
4714   std::string fpath;
4715   fpath += this->GetFullName(config, false);
4716   fpath += ".framework/Versions/";
4717   fpath += this->GetFrameworkVersion();
4718   fpath += "/";
4719   return fpath;
4720 }
4721
4722 //----------------------------------------------------------------------------
4723 std::string cmTarget::BuildMacContentDirectory(const std::string& base,
4724                                                const char* config,
4725                                                bool includeMacOS)
4726 {
4727   std::string fpath = base;
4728   if(this->IsAppBundleOnApple())
4729     {
4730     fpath += this->GetFullName(config, false);
4731     fpath += ".app/Contents/";
4732     if(includeMacOS)
4733       fpath += "MacOS/";
4734     }
4735   if(this->IsFrameworkOnApple())
4736     {
4737     fpath += this->GetFrameworkDirectory(config);
4738     }
4739   if(this->IsCFBundleOnApple())
4740     {
4741     fpath += this->GetFullName(config, false);
4742     fpath += ".";
4743     const char *ext = this->GetProperty("BUNDLE_EXTENSION");
4744     if (!ext)
4745       {
4746       ext = "bundle";
4747       }
4748     fpath += ext;
4749     fpath += "/Contents/";
4750     if(includeMacOS)
4751       fpath += "MacOS/";
4752     }
4753   return fpath;
4754 }
4755
4756 //----------------------------------------------------------------------------
4757 std::string cmTarget::GetMacContentDirectory(const char* config,
4758                                              bool implib,
4759                                              bool includeMacOS)
4760 {
4761   // Start with the output directory for the target.
4762   std::string fpath = this->GetDirectory(config, implib);
4763   fpath += "/";
4764   fpath = this->BuildMacContentDirectory(fpath, config, includeMacOS);
4765   return fpath;
4766 }
4767
4768 //----------------------------------------------------------------------------
4769 cmTargetLinkInformationMap
4770 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
4771 {
4772   // Ideally cmTarget instances should never be copied.  However until
4773   // we can make a sweep to remove that, this copy constructor avoids
4774   // allowing the resources (LinkInformation) from getting copied.  In
4775   // the worst case this will lead to extra cmComputeLinkInformation
4776   // instances.  We also enforce in debug mode that the map be emptied
4777   // when copied.
4778   static_cast<void>(r);
4779   assert(r.empty());
4780 }
4781
4782 //----------------------------------------------------------------------------
4783 cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
4784 {
4785   for(derived::iterator i = this->begin(); i != this->end(); ++i)
4786     {
4787     delete i->second;
4788     }
4789 }
4790
4791 //----------------------------------------------------------------------------
4792 cmTargetInternalPointer::cmTargetInternalPointer()
4793 {
4794   this->Pointer = new cmTargetInternals;
4795 }
4796
4797 //----------------------------------------------------------------------------
4798 cmTargetInternalPointer
4799 ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
4800 {
4801   // Ideally cmTarget instances should never be copied.  However until
4802   // we can make a sweep to remove that, this copy constructor avoids
4803   // allowing the resources (Internals) to be copied.
4804   this->Pointer = new cmTargetInternals(*r.Pointer);
4805 }
4806
4807 //----------------------------------------------------------------------------
4808 cmTargetInternalPointer::~cmTargetInternalPointer()
4809 {
4810   delete this->Pointer;
4811 }
4812
4813 //----------------------------------------------------------------------------
4814 cmTargetInternalPointer&
4815 cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
4816 {
4817   if(this == &r) { return *this; } // avoid warning on HP about self check
4818   // Ideally cmTarget instances should never be copied.  However until
4819   // we can make a sweep to remove that, this copy constructor avoids
4820   // allowing the resources (Internals) to be copied.
4821   cmTargetInternals* oldPointer = this->Pointer;
4822   this->Pointer = new cmTargetInternals(*r.Pointer);
4823   delete oldPointer;
4824   return *this;
4825 }