fix issue 9346. add binary directory to window title to make it easier to deal with...
[cmake.git] / Source / cmTarget.cxx
blobf84380b3031588bff0ec51d9f2e8f1d5e1215bcb
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmTarget.cxx,v $
5 Language: C++
6 Date: $Date: 2009-09-07 14:11:42 $
7 Version: $Revision: 1.271 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmTarget.h"
18 #include "cmake.h"
19 #include "cmMakefile.h"
20 #include "cmSourceFile.h"
21 #include "cmLocalGenerator.h"
22 #include "cmGlobalGenerator.h"
23 #include "cmComputeLinkInformation.h"
24 #include "cmListFileCache.h"
25 #include <cmsys/RegularExpression.hxx>
26 #include <map>
27 #include <set>
28 #include <queue>
29 #include <stdlib.h> // required for atof
30 #include <assert.h>
31 const char* cmTarget::TargetTypeNames[] = {
32 "EXECUTABLE", "STATIC_LIBRARY",
33 "SHARED_LIBRARY", "MODULE_LIBRARY", "UTILITY", "GLOBAL_TARGET",
34 "INSTALL_FILES", "INSTALL_PROGRAMS", "INSTALL_DIRECTORY",
35 "UNKNOWN_LIBRARY"
38 //----------------------------------------------------------------------------
39 struct cmTarget::OutputInfo
41 std::string OutDir;
42 std::string ImpDir;
45 //----------------------------------------------------------------------------
46 struct cmTarget::ImportInfo
48 bool NoSOName;
49 std::string Location;
50 std::string SOName;
51 std::string ImportLibrary;
52 cmTarget::LinkInterface LinkInterface;
55 //----------------------------------------------------------------------------
56 class cmTargetInternals
58 public:
59 cmTargetInternals()
61 this->SourceFileFlagsConstructed = false;
63 typedef cmTarget::SourceFileFlags SourceFileFlags;
64 std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
65 bool SourceFileFlagsConstructed;
67 // The backtrace when the target was created.
68 cmListFileBacktrace Backtrace;
70 // Cache link interface computation from each configuration.
71 struct OptionalLinkInterface: public cmTarget::LinkInterface
73 OptionalLinkInterface(): Exists(false) {}
74 bool Exists;
76 typedef std::map<cmStdString, OptionalLinkInterface> LinkInterfaceMapType;
77 LinkInterfaceMapType LinkInterfaceMap;
79 typedef std::map<cmStdString, cmTarget::OutputInfo> OutputInfoMapType;
80 OutputInfoMapType OutputInfoMap;
82 typedef std::map<cmStdString, cmTarget::ImportInfo> ImportInfoMapType;
83 ImportInfoMapType ImportInfoMap;
85 // Cache link implementation computation from each configuration.
86 typedef std::map<cmStdString, cmTarget::LinkImplementation> LinkImplMapType;
87 LinkImplMapType LinkImplMap;
89 typedef std::map<cmStdString, cmTarget::LinkClosure> LinkClosureMapType;
90 LinkClosureMapType LinkClosureMap;
92 struct SourceEntry { std::vector<cmSourceFile*> Depends; };
93 typedef std::map<cmSourceFile*, SourceEntry> SourceEntriesType;
94 SourceEntriesType SourceEntries;
97 //----------------------------------------------------------------------------
98 cmTarget::cmTarget()
100 this->Makefile = 0;
101 this->PolicyStatusCMP0003 = cmPolicies::WARN;
102 this->PolicyStatusCMP0004 = cmPolicies::WARN;
103 this->PolicyStatusCMP0008 = cmPolicies::WARN;
104 this->LinkLibrariesAnalyzed = false;
105 this->HaveInstallRule = false;
106 this->DLLPlatform = false;
107 this->IsImportedTarget = false;
110 //----------------------------------------------------------------------------
111 void cmTarget::DefineProperties(cmake *cm)
113 cm->DefineProperty
114 ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
115 "Should build tree targets have install tree rpaths.",
116 "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
117 "the target in the build tree with the INSTALL_RPATH. This takes "
118 "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
119 "before installation. "
120 "This property is initialized by the value of the variable "
121 "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
123 cm->DefineProperty
124 ("COMPILE_FLAGS", cmProperty::TARGET,
125 "Additional flags to use when compiling this target's sources.",
126 "The COMPILE_FLAGS property sets additional compiler flags used "
127 "to build sources within the target. Use COMPILE_DEFINITIONS "
128 "to pass additional preprocessor definitions.");
130 cm->DefineProperty
131 ("COMPILE_DEFINITIONS", cmProperty::TARGET,
132 "Preprocessor definitions for compiling a target's sources.",
133 "The COMPILE_DEFINITIONS property may be set to a "
134 "semicolon-separated list of preprocessor "
135 "definitions using the syntax VAR or VAR=value. Function-style "
136 "definitions are not supported. CMake will automatically escape "
137 "the value correctly for the native build system (note that CMake "
138 "language syntax may require escapes to specify some values). "
139 "This property may be set on a per-configuration basis using the name "
140 "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
141 "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
142 "CMake will automatically drop some definitions that "
143 "are not supported by the native build tool. "
144 "The VS6 IDE does not support definition values with spaces "
145 "(but NMake does).\n"
146 "Dislaimer: Most native build tools have poor support for escaping "
147 "certain values. CMake has work-arounds for many cases but some "
148 "values may just not be possible to pass correctly. If a value "
149 "does not seem to be escaped correctly, do not attempt to "
150 "work-around the problem by adding escape sequences to the value. "
151 "Your work-around may break in a future version of CMake that "
152 "has improved escape support. Instead consider defining the macro "
153 "in a (configured) header file. Then report the limitation.");
155 cm->DefineProperty
156 ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
157 "Per-configuration preprocessor definitions on a target.",
158 "This is the configuration-specific version of COMPILE_DEFINITIONS.");
160 cm->DefineProperty
161 ("DEFINE_SYMBOL", cmProperty::TARGET,
162 "Define a symbol when compiling this target's sources.",
163 "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
164 "compiling sources in a shared library. "
165 "If not set here then it is set to target_EXPORTS by default "
166 "(with some substitutions if the target is not a valid C "
167 "identifier). This is useful for headers to know whether they are "
168 "being included from inside their library our outside to properly "
169 "setup dllexport/dllimport decorations. ");
171 cm->DefineProperty
172 ("DEBUG_POSTFIX", cmProperty::TARGET,
173 "See target property <CONFIG>_POSTFIX.",
174 "This property is a special case of the more-general <CONFIG>_POSTFIX "
175 "property for the DEBUG configuration.");
177 cm->DefineProperty
178 ("<CONFIG>_POSTFIX", cmProperty::TARGET,
179 "Postfix to append to the target file name for configuration <CONFIG>.",
180 "When building with configuration <CONFIG> the value of this property "
181 "is appended to the target file name built on disk. "
182 "For non-executable targets, this property is initialized by the value "
183 "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
184 "created. "
185 "This property is ignored on the Mac for Frameworks and App Bundles.");
187 cm->DefineProperty
188 ("EchoString", cmProperty::TARGET,
189 "A message to be displayed when the target is built.",
190 "A message to display on some generators (such as makefiles) when "
191 "the target is built.");
193 cm->DefineProperty
194 ("FRAMEWORK", cmProperty::TARGET,
195 "This target is a framework on the Mac.",
196 "If a shared library target has this property set to true it will "
197 "be built as a framework when built on the mac. It will have the "
198 "directory structure required for a framework and will be suitable "
199 "to be used with the -framework option");
201 cm->DefineProperty
202 ("HAS_CXX", cmProperty::TARGET,
203 "Link the target using the C++ linker tool (obselete).",
204 "This is equivalent to setting the LINKER_LANGUAGE property to CXX. "
205 "See that property's documentation for details.");
207 cm->DefineProperty
208 ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
209 "Specify #include line transforms for dependencies in a target.",
210 "This property specifies rules to transform macro-like #include lines "
211 "during implicit dependency scanning of C and C++ source files. "
212 "The list of rules must be semicolon-separated with each entry of "
213 "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
214 "During dependency scanning occurrences of A_MACRO(...) on #include "
215 "lines will be replaced by the value given with the macro argument "
216 "substituted for '%'. For example, the entry\n"
217 " MYDIR(%)=<mydir/%>\n"
218 "will convert lines of the form\n"
219 " #include MYDIR(myheader.h)\n"
220 "to\n"
221 " #include <mydir/myheader.h>\n"
222 "allowing the dependency to be followed.\n"
223 "This property applies to sources in the target on which it is set.");
225 cm->DefineProperty
226 ("IMPORT_PREFIX", cmProperty::TARGET,
227 "What comes before the import library name.",
228 "Similar to the target property PREFIX, but used for import libraries "
229 "(typically corresponding to a DLL) instead of regular libraries. "
230 "A target property that can be set to override the prefix "
231 "(such as \"lib\") on an import library name.");
233 cm->DefineProperty
234 ("IMPORT_SUFFIX", cmProperty::TARGET,
235 "What comes after the import library name.",
236 "Similar to the target property SUFFIX, but used for import libraries "
237 "(typically corresponding to a DLL) instead of regular libraries. "
238 "A target property that can be set to override the suffix "
239 "(such as \".lib\") on an import library name.");
241 cm->DefineProperty
242 ("IMPORTED", cmProperty::TARGET,
243 "Read-only indication of whether a target is IMPORTED.",
244 "The boolean value of this property is true for targets created with "
245 "the IMPORTED option to add_executable or add_library. "
246 "It is false for targets built within the project.");
248 cm->DefineProperty
249 ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
250 "Configurations provided for an IMPORTED target.",
251 "Lists configuration names available for an IMPORTED target. "
252 "The names correspond to configurations defined in the project from "
253 "which the target is imported. "
254 "If the importing project uses a different set of configurations "
255 "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
256 "property. "
257 "Ignored for non-imported targets.");
259 cm->DefineProperty
260 ("IMPORTED_IMPLIB", cmProperty::TARGET,
261 "Full path to the import library for an IMPORTED target.",
262 "Specifies the location of the \".lib\" part of a windows DLL. "
263 "Ignored for non-imported targets.");
265 cm->DefineProperty
266 ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
267 "Per-configuration version of IMPORTED_IMPLIB property.",
268 "This property is used when loading settings for the <CONFIG> "
269 "configuration of an imported target. "
270 "Configuration names correspond to those provided by the project "
271 "from which the target is imported.");
273 cm->DefineProperty
274 ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
275 "Dependent shared libraries of an imported shared library.",
276 "Shared libraries may be linked to other shared libraries as part "
277 "of their implementation. On some platforms the linker searches "
278 "for the dependent libraries of shared libraries they are including "
279 "in the link. This property lists "
280 "the dependent shared libraries of an imported library. The list "
281 "should be disjoint from the list of interface libraries in the "
282 "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring "
283 "dependent shared libraries to be found at link time CMake uses this "
284 "list to add appropriate files or paths to the link command line. "
285 "Ignored for non-imported targets.");
287 cm->DefineProperty
288 ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
289 "Per-configuration version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
290 "This property is used when loading settings for the <CONFIG> "
291 "configuration of an imported target. "
292 "Configuration names correspond to those provided by the project "
293 "from which the target is imported. "
294 "If set, this property completely overrides the generic property "
295 "for the named configuration.");
297 cm->DefineProperty
298 ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
299 "Transitive link interface of an IMPORTED target.",
300 "Lists libraries whose interface is included when an IMPORTED library "
301 "target is linked to another target. "
302 "The libraries will be included on the link line for the target. "
303 "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
304 "to all imported target types, including STATIC libraries. "
305 "This property is ignored for non-imported targets.");
307 cm->DefineProperty
308 ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
309 "Per-configuration version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
310 "This property is used when loading settings for the <CONFIG> "
311 "configuration of an imported target. "
312 "Configuration names correspond to those provided by the project "
313 "from which the target is imported. "
314 "If set, this property completely overrides the generic property "
315 "for the named configuration.");
317 cm->DefineProperty
318 ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET,
319 "Languages compiled into an IMPORTED static library.",
320 "Lists languages of soure files compiled to produce a STATIC IMPORTED "
321 "library (such as \"C\" or \"CXX\"). "
322 "CMake accounts for these languages when computing how to link a "
323 "target to the imported library. "
324 "For example, when a C executable links to an imported C++ static "
325 "library CMake chooses the C++ linker to satisfy language runtime "
326 "dependencies of the static library. "
327 "\n"
328 "This property is ignored for targets that are not STATIC libraries. "
329 "This property is ignored for non-imported targets.");
331 cm->DefineProperty
332 ("IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>", cmProperty::TARGET,
333 "Per-configuration version of IMPORTED_LINK_INTERFACE_LANGUAGES.",
334 "This property is used when loading settings for the <CONFIG> "
335 "configuration of an imported target. "
336 "Configuration names correspond to those provided by the project "
337 "from which the target is imported. "
338 "If set, this property completely overrides the generic property "
339 "for the named configuration.");
341 cm->DefineProperty
342 ("IMPORTED_LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
343 "Repetition count for cycles of IMPORTED static libraries.",
344 "This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.");
345 cm->DefineProperty
346 ("IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
347 "Per-configuration repetition count for cycles of IMPORTED archives.",
348 "This is the configuration-specific version of "
349 "IMPORTED_LINK_INTERFACE_MULTIPLICITY. "
350 "If set, this property completely overrides the generic property "
351 "for the named configuration.");
353 cm->DefineProperty
354 ("IMPORTED_LOCATION", cmProperty::TARGET,
355 "Full path to the main file on disk for an IMPORTED target.",
356 "Specifies the location of an IMPORTED target file on disk. "
357 "For executables this is the location of the executable file. "
358 "For bundles on OS X this is the location of the executable file "
359 "inside Contents/MacOS under the application bundle folder. "
360 "For static libraries and modules this is the location of the "
361 "library or module. "
362 "For shared libraries on non-DLL platforms this is the location of "
363 "the shared library. "
364 "For frameworks on OS X this is the location of the library file "
365 "symlink just inside the framework folder. "
366 "For DLLs this is the location of the \".dll\" part of the library. "
367 "For UNKNOWN libraries this is the location of the file to be linked. "
368 "Ignored for non-imported targets.");
370 cm->DefineProperty
371 ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
372 "Per-configuration version of IMPORTED_LOCATION property.",
373 "This property is used when loading settings for the <CONFIG> "
374 "configuration of an imported target. "
375 "Configuration names correspond to those provided by the project "
376 "from which the target is imported.");
378 cm->DefineProperty
379 ("IMPORTED_SONAME", cmProperty::TARGET,
380 "The \"soname\" of an IMPORTED target of shared library type.",
381 "Specifies the \"soname\" embedded in an imported shared library. "
382 "This is meaningful only on platforms supporting the feature. "
383 "Ignored for non-imported targets.");
385 cm->DefineProperty
386 ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
387 "Per-configuration version of IMPORTED_SONAME property.",
388 "This property is used when loading settings for the <CONFIG> "
389 "configuration of an imported target. "
390 "Configuration names correspond to those provided by the project "
391 "from which the target is imported.");
393 cm->DefineProperty
394 ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
395 "Exclude the target from the all target.",
396 "A property on a target that indicates if the target is excluded "
397 "from the default build target. If it is not, then with a Makefile "
398 "for example typing make will cause this target to be built. "
399 "The same concept applies to the default build of other generators. "
400 "Installing a target with EXCLUDE_FROM_ALL set to true has "
401 "undefined behavior.");
403 cm->DefineProperty
404 ("INSTALL_NAME_DIR", cmProperty::TARGET,
405 "Mac OSX directory name for installed targets.",
406 "INSTALL_NAME_DIR is a string specifying the "
407 "directory portion of the \"install_name\" field of shared libraries "
408 "on Mac OSX to use in the installed targets. ");
410 cm->DefineProperty
411 ("INSTALL_RPATH", cmProperty::TARGET,
412 "The rpath to use for installed targets.",
413 "A semicolon-separated list specifying the rpath "
414 "to use in installed targets (for platforms that support it). "
415 "This property is initialized by the value of the variable "
416 "CMAKE_INSTALL_RPATH if it is set when a target is created.");
418 cm->DefineProperty
419 ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
420 "Add paths to linker search and installed rpath.",
421 "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
422 "append directories in the linker search path and outside the "
423 "project to the INSTALL_RPATH. "
424 "This property is initialized by the value of the variable "
425 "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
426 "created.");
428 cm->DefineProperty
429 ("LABELS", cmProperty::TARGET,
430 "Specify a list of text labels associated with a target.",
431 "Target label semantics are currently unspecified.");
433 cm->DefineProperty
434 ("LINK_FLAGS", cmProperty::TARGET,
435 "Additional flags to use when linking this target.",
436 "The LINK_FLAGS property can be used to add extra flags to the "
437 "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
438 "configuration <CONFIG>, "
439 "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
441 cm->DefineProperty
442 ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
443 "Per-configuration linker flags for a target.",
444 "This is the configuration-specific version of LINK_FLAGS.");
446 cm->DefineProperty
447 ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
448 "End a link line such that static system libraries are used.",
449 "Some linkers support switches such as -Bstatic and -Bdynamic "
450 "to determine whether to use static or shared libraries for -lXXX "
451 "options. CMake uses these options to set the link type for "
452 "libraries whose full paths are not known or (in some cases) are in "
453 "implicit link directories for the platform. By default the "
454 "linker search type is left at -Bdynamic by the end of the library "
455 "list. This property switches the final linker search type to "
456 "-Bstatic.");
458 cm->DefineProperty
459 ("LINKER_LANGUAGE", cmProperty::TARGET,
460 "Specifies language whose compiler will invoke the linker.",
461 "For executables, shared libraries, and modules, this sets the "
462 "language whose compiler is used to link the target "
463 "(such as \"C\" or \"CXX\"). "
464 "A typical value for an executable is the language of the source "
465 "file providing the program entry point (main). "
466 "If not set, the language with the highest linker preference "
467 "value is the default. "
468 "See documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables.");
470 cm->DefineProperty
471 ("LOCATION", cmProperty::TARGET,
472 "Read-only location of a target on disk.",
473 "For an imported target, this read-only property returns the value of "
474 "the LOCATION_<CONFIG> property for an unspecified configuration "
475 "<CONFIG> provided by the target.\n"
476 "For a non-imported target, this property is provided for compatibility "
477 "with CMake 2.4 and below. "
478 "It was meant to get the location of an executable target's output file "
479 "for use in add_custom_command. "
480 "The path may contain a build-system-specific portion that "
481 "is replaced at build time with the configuration getting built "
482 "(such as \"$(ConfigurationName)\" in VS). "
483 "In CMake 2.6 and above add_custom_command automatically recognizes a "
484 "target name in its COMMAND and DEPENDS options and computes the "
485 "target location. "
486 "Therefore this property is not needed for creating custom commands.");
488 cm->DefineProperty
489 ("LOCATION_<CONFIG>", cmProperty::TARGET,
490 "Read-only property providing a target location on disk.",
491 "A read-only property that indicates where a target's main file is "
492 "located on disk for the configuration <CONFIG>. "
493 "The property is defined only for library and executable targets. "
494 "An imported target may provide a set of configurations different "
495 "from that of the importing project. "
496 "By default CMake looks for an exact-match but otherwise uses an "
497 "arbitrary available configuration. "
498 "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
499 "configurations explicitly.");
501 cm->DefineProperty
502 ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
503 "List public interface libraries for a shared library or executable.",
504 "By default linking to a shared library target transitively "
505 "links to targets with which the library itself was linked. "
506 "For an executable with exports (see the ENABLE_EXPORTS property) "
507 "no default transitive link dependencies are used. "
508 "This property replaces the default transitive link dependencies with "
509 "an explict list. "
510 "When the target is linked into another target the libraries "
511 "listed (and recursively their link interface libraries) will be "
512 "provided to the other target also. "
513 "If the list is empty then no transitive link dependencies will be "
514 "incorporated when this target is linked into another target even if "
515 "the default set is non-empty. "
516 "This property is ignored for STATIC libraries.");
518 cm->DefineProperty
519 ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
520 "Per-configuration list of public interface libraries for a target.",
521 "This is the configuration-specific version of "
522 "LINK_INTERFACE_LIBRARIES. "
523 "If set, this property completely overrides the generic property "
524 "for the named configuration.");
526 cm->DefineProperty
527 ("LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
528 "Repetition count for STATIC libraries with cyclic dependencies.",
529 "When linking to a STATIC library target with cyclic dependencies the "
530 "linker may need to scan more than once through the archives in the "
531 "strongly connected component of the dependency graph. "
532 "CMake by default constructs the link line so that the linker will "
533 "scan through the component at least twice. "
534 "This property specifies the minimum number of scans if it is larger "
535 "than the default. "
536 "CMake uses the largest value specified by any target in a component.");
537 cm->DefineProperty
538 ("LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
539 "Per-configuration repetition count for cycles of STATIC libraries.",
540 "This is the configuration-specific version of "
541 "LINK_INTERFACE_MULTIPLICITY. "
542 "If set, this property completely overrides the generic property "
543 "for the named configuration.");
545 cm->DefineProperty
546 ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
547 "Map from project configuration to IMPORTED target's configuration.",
548 "List configurations of an imported target that may be used for "
549 "the current project's <CONFIG> configuration. "
550 "Targets imported from another project may not provide the same set "
551 "of configuration names available in the current project. "
552 "Setting this property tells CMake what imported configurations are "
553 "suitable for use when building the <CONFIG> configuration. "
554 "The first configuration in the list found to be provided by the "
555 "imported target is selected. If no matching configurations are "
556 "available the imported target is considered to be not found. "
557 "This property is ignored for non-imported targets.",
558 false /* TODO: make this chained */ );
560 cm->DefineProperty
561 ("OUTPUT_NAME", cmProperty::TARGET,
562 "Output name for target files.",
563 "This sets the base name for output files created for an executable or "
564 "library target. "
565 "If not set, the logical target name is used by default.");
567 cm->DefineProperty
568 ("OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
569 "Per-configuration target file base name.",
570 "This is the configuration-specific version of OUTPUT_NAME.");
572 cm->DefineProperty
573 ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET,
574 "Old per-configuration target file base name.",
575 "This is a configuration-specific version of OUTPUT_NAME. "
576 "Use OUTPUT_NAME_<CONFIG> instead.");
578 cm->DefineProperty
579 ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
580 "Deprecated install support.",
581 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
582 "old way to specify CMake scripts to run before and after "
583 "installing a target. They are used only when the old "
584 "INSTALL_TARGETS command is used to install the target. Use the "
585 "INSTALL command instead.");
587 cm->DefineProperty
588 ("PREFIX", cmProperty::TARGET,
589 "What comes before the library name.",
590 "A target property that can be set to override the prefix "
591 "(such as \"lib\") on a library name.");
593 cm->DefineProperty
594 ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
595 "Deprecated install support.",
596 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
597 "old way to specify CMake scripts to run before and after "
598 "installing a target. They are used only when the old "
599 "INSTALL_TARGETS command is used to install the target. Use the "
600 "INSTALL command instead.");
602 cm->DefineProperty
603 ("PRIVATE_HEADER", cmProperty::TARGET,
604 "Specify private header files in a FRAMEWORK shared library target.",
605 "Shared library targets marked with the FRAMEWORK property generate "
606 "frameworks on OS X and normal shared libraries on other platforms. "
607 "This property may be set to a list of header files to be placed "
608 "in the PrivateHeaders directory inside the framework folder. "
609 "On non-Apple platforms these headers may be installed using the "
610 "PRIVATE_HEADER option to the install(TARGETS) command.");
612 cm->DefineProperty
613 ("PUBLIC_HEADER", cmProperty::TARGET,
614 "Specify public header files in a FRAMEWORK shared library target.",
615 "Shared library targets marked with the FRAMEWORK property generate "
616 "frameworks on OS X and normal shared libraries on other platforms. "
617 "This property may be set to a list of header files to be placed "
618 "in the Headers directory inside the framework folder. "
619 "On non-Apple platforms these headers may be installed using the "
620 "PUBLIC_HEADER option to the install(TARGETS) command.");
622 cm->DefineProperty
623 ("RESOURCE", cmProperty::TARGET,
624 "Specify resource files in a FRAMEWORK shared library target.",
625 "Shared library targets marked with the FRAMEWORK property generate "
626 "frameworks on OS X and normal shared libraries on other platforms. "
627 "This property may be set to a list of files to be placed "
628 "in the Resources directory inside the framework folder. "
629 "On non-Apple platforms these files may be installed using the "
630 "RESOURCE option to the install(TARGETS) command.");
632 cm->DefineProperty
633 ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
634 "Specify a launcher for compile rules.",
635 "See the global property of the same name for details. "
636 "This overrides the global and directory property for a target.",
637 true);
638 cm->DefineProperty
639 ("RULE_LAUNCH_LINK", cmProperty::TARGET,
640 "Specify a launcher for link rules.",
641 "See the global property of the same name for details. "
642 "This overrides the global and directory property for a target.",
643 true);
644 cm->DefineProperty
645 ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
646 "Specify a launcher for custom rules.",
647 "See the global property of the same name for details. "
648 "This overrides the global and directory property for a target.",
649 true);
651 cm->DefineProperty
652 ("SKIP_BUILD_RPATH", cmProperty::TARGET,
653 "Should rpaths be used for the build tree.",
654 "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
655 "generation of an rpath allowing the target to run from the "
656 "build tree. "
657 "This property is initialized by the value of the variable "
658 "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
660 cm->DefineProperty
661 ("SOVERSION", cmProperty::TARGET,
662 "What version number is this target.",
663 "For shared libraries VERSION and SOVERSION can be used to specify "
664 "the build version and api version respectively. When building or "
665 "installing appropriate symlinks are created if the platform "
666 "supports symlinks and the linker supports so-names. "
667 "If only one of both is specified the missing is assumed to have "
668 "the same version number. "
669 "For shared libraries and executables on Windows the VERSION "
670 "attribute is parsed to extract a \"major.minor\" version number. "
671 "These numbers are used as the image version of the binary. ");
673 cm->DefineProperty
674 ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
675 "Extra flags to use when linking static libraries.",
676 "Extra flags to use when linking a static library.");
678 cm->DefineProperty
679 ("SUFFIX", cmProperty::TARGET,
680 "What comes after the library name.",
681 "A target property that can be set to override the suffix "
682 "(such as \".so\") on a library name.");
684 cm->DefineProperty
685 ("TYPE", cmProperty::TARGET,
686 "The type of the target.",
687 "This read-only property can be used to test the type of the given "
688 "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
689 "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
691 cm->DefineProperty
692 ("VERSION", cmProperty::TARGET,
693 "What version number is this target.",
694 "For shared libraries VERSION and SOVERSION can be used to specify "
695 "the build version and api version respectively. When building or "
696 "installing appropriate symlinks are created if the platform "
697 "supports symlinks and the linker supports so-names. "
698 "If only one of both is specified the missing is assumed to have "
699 "the same version number. "
700 "For executables VERSION can be used to specify the build version. "
701 "When building or installing appropriate symlinks are created if "
702 "the platform supports symlinks. "
703 "For shared libraries and executables on Windows the VERSION "
704 "attribute is parsed to extract a \"major.minor\" version number. "
705 "These numbers are used as the image version of the binary. ");
708 cm->DefineProperty
709 ("WIN32_EXECUTABLE", cmProperty::TARGET,
710 "Build an executable with a WinMain entry point on windows.",
711 "When this property is set to true the executable when linked "
712 "on Windows will be created with a WinMain() entry point instead "
713 "of of just main()."
714 "This makes it a GUI executable instead of a console application. "
715 "See the CMAKE_MFC_FLAG variable documentation to configure use "
716 "of MFC for WinMain executables.");
718 cm->DefineProperty
719 ("MACOSX_BUNDLE", cmProperty::TARGET,
720 "Build an executable as an application bundle on Mac OS X.",
721 "When this property is set to true the executable when built "
722 "on Mac OS X will be created as an application bundle. "
723 "This makes it a GUI executable that can be launched from "
724 "the Finder. "
725 "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
726 "about creation of the Info.plist file for the application bundle.");
728 cm->DefineProperty
729 ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
730 "Specify a custom Info.plist template for a Mac OS X App Bundle.",
731 "An executable target with MACOSX_BUNDLE enabled will be built as an "
732 "application bundle on Mac OS X. "
733 "By default its Info.plist file is created by configuring a template "
734 "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
735 "This property specifies an alternative template file name which "
736 "may be a full path.\n"
737 "The following target properties may be set to specify content to "
738 "be configured into the file:\n"
739 " MACOSX_BUNDLE_INFO_STRING\n"
740 " MACOSX_BUNDLE_ICON_FILE\n"
741 " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
742 " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
743 " MACOSX_BUNDLE_BUNDLE_NAME\n"
744 " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
745 " MACOSX_BUNDLE_BUNDLE_VERSION\n"
746 " MACOSX_BUNDLE_COPYRIGHT\n"
747 "CMake variables of the same name may be set to affect all targets "
748 "in a directory that do not have each specific property set. "
749 "If a custom Info.plist is specified by this property it may of course "
750 "hard-code all the settings instead of using the target properties.");
752 cm->DefineProperty
753 ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
754 "Specify a custom Info.plist template for a Mac OS X Framework.",
755 "An library target with FRAMEWORK enabled will be built as a "
756 "framework on Mac OS X. "
757 "By default its Info.plist file is created by configuring a template "
758 "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
759 "This property specifies an alternative template file name which "
760 "may be a full path.\n"
761 "The following target properties may be set to specify content to "
762 "be configured into the file:\n"
763 " MACOSX_FRAMEWORK_ICON_FILE\n"
764 " MACOSX_FRAMEWORK_IDENTIFIER\n"
765 " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
766 " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
767 "CMake variables of the same name may be set to affect all targets "
768 "in a directory that do not have each specific property set. "
769 "If a custom Info.plist is specified by this property it may of course "
770 "hard-code all the settings instead of using the target properties.");
772 cm->DefineProperty
773 ("ENABLE_EXPORTS", cmProperty::TARGET,
774 "Specify whether an executable exports symbols for loadable modules.",
775 "Normally an executable does not export any symbols because it is "
776 "the final program. It is possible for an executable to export "
777 "symbols to be used by loadable modules. When this property is "
778 "set to true CMake will allow other targets to \"link\" to the "
779 "executable with the TARGET_LINK_LIBRARIES command. "
780 "On all platforms a target-level dependency on the executable is "
781 "created for targets that link to it. "
782 "For non-DLL platforms the link rule is simply ignored since "
783 "the dynamic loader will automatically bind symbols when the "
784 "module is loaded. "
785 "For DLL platforms an import library will be created for the "
786 "exported symbols and then used for linking. "
787 "All Windows-based systems including Cygwin are DLL platforms.");
789 cm->DefineProperty
790 ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
791 "Specify output directory for Fortran modules provided by the target.",
792 "If the target contains Fortran source files that provide modules "
793 "and the compiler supports a module output directory this specifies "
794 "the directory in which the modules will be placed. "
795 "When this property is not set the modules will be placed in the "
796 "build directory corresponding to the target's source directory. "
797 "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
798 "is created its value is used to initialize this property.");
800 cm->DefineProperty
801 ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
802 "Set Xcode target attributes directly.",
803 "Tell the Xcode generator to set '<an-attribute>' to a given value "
804 "in the generated Xcode project. Ignored on other generators.");
806 cm->DefineProperty
807 ("GENERATOR_FILE_NAME", cmProperty::TARGET,
808 "Generator's file for this target.",
809 "An internal property used by some generators to record the name of "
810 "project or dsp file associated with this target.");
812 cm->DefineProperty
813 ("SOURCES", cmProperty::TARGET,
814 "Source names specified for a target.",
815 "Read-only list of sources specified for a target. "
816 "The names returned are suitable for passing to the "
817 "set_source_files_properties command.");
819 cm->DefineProperty
820 ("PROJECT_LABEL", cmProperty::TARGET,
821 "Change the name of a target in an IDE.",
822 "Can be used to change the name of the target in an IDE "
823 "like visual stuido. ");
824 cm->DefineProperty
825 ("VS_KEYWORD", cmProperty::TARGET,
826 "Visual Studio project keyword.",
827 "Can be set to change the visual studio keyword, for example "
828 "QT integration works better if this is set to Qt4VSv1.0. ");
829 cm->DefineProperty
830 ("VS_SCC_PROVIDER", cmProperty::TARGET,
831 "Visual Studio Source Code Control Provider.",
832 "Can be set to change the visual studio source code control "
833 "provider property.");
834 cm->DefineProperty
835 ("VS_SCC_LOCALPATH", cmProperty::TARGET,
836 "Visual Studio Source Code Control Provider.",
837 "Can be set to change the visual studio source code control "
838 "local path property.");
839 cm->DefineProperty
840 ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
841 "Visual Studio Source Code Control Project.",
842 "Can be set to change the visual studio source code control "
843 "project name property.");
845 #if 0
846 cm->DefineProperty
847 ("OBJECT_FILES", cmProperty::TARGET,
848 "Used to get the resulting list of object files that make up a "
849 "target.",
850 "This can be used to put object files from one library "
851 "into another library. It is a read only property. It "
852 "converts the source list for the target into a list of full "
853 "paths to object names that will be produced by the target.");
854 #endif
856 #define CM_TARGET_FILE_TYPES_DOC \
857 "There are three kinds of target files that may be built: " \
858 "archive, library, and runtime. " \
859 "Executables are always treated as runtime targets. " \
860 "Static libraries are always treated as archive targets. " \
861 "Module libraries are always treated as library targets. " \
862 "For non-DLL platforms shared libraries are treated as library " \
863 "targets. " \
864 "For DLL platforms the DLL part of a shared library is treated as " \
865 "a runtime target and the corresponding import library is treated as " \
866 "an archive target. " \
867 "All Windows-based systems including Cygwin are DLL platforms."
869 cm->DefineProperty
870 ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
871 "Output directory in which to build ARCHIVE target files.",
872 "This property specifies the directory into which archive target files "
873 "should be built. "
874 CM_TARGET_FILE_TYPES_DOC " "
875 "This property is initialized by the value of the variable "
876 "CMAKE_ARCHIVE_OUTPUT_DIRECTORY if it is set when a target is created.");
877 cm->DefineProperty
878 ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
879 "Output directory in which to build LIBRARY target files.",
880 "This property specifies the directory into which library target files "
881 "should be built. "
882 CM_TARGET_FILE_TYPES_DOC " "
883 "This property is initialized by the value of the variable "
884 "CMAKE_LIBRARY_OUTPUT_DIRECTORY if it is set when a target is created.");
885 cm->DefineProperty
886 ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
887 "Output directory in which to build RUNTIME target files.",
888 "This property specifies the directory into which runtime target files "
889 "should be built. "
890 CM_TARGET_FILE_TYPES_DOC " "
891 "This property is initialized by the value of the variable "
892 "CMAKE_RUNTIME_OUTPUT_DIRECTORY if it is set when a target is created.");
894 cm->DefineProperty
895 ("ARCHIVE_OUTPUT_NAME", cmProperty::TARGET,
896 "Output name for ARCHIVE target files.",
897 "This property specifies the base name for archive target files. "
898 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
899 CM_TARGET_FILE_TYPES_DOC);
900 cm->DefineProperty
901 ("ARCHIVE_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
902 "Per-configuration output name for ARCHIVE target files.",
903 "This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.");
904 cm->DefineProperty
905 ("LIBRARY_OUTPUT_NAME", cmProperty::TARGET,
906 "Output name for LIBRARY target files.",
907 "This property specifies the base name for library target files. "
908 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
909 CM_TARGET_FILE_TYPES_DOC);
910 cm->DefineProperty
911 ("LIBRARY_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
912 "Per-configuration output name for LIBRARY target files.",
913 "This is the configuration-specific version of LIBRARY_OUTPUT_NAME.");
914 cm->DefineProperty
915 ("RUNTIME_OUTPUT_NAME", cmProperty::TARGET,
916 "Output name for RUNTIME target files.",
917 "This property specifies the base name for runtime target files. "
918 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
919 CM_TARGET_FILE_TYPES_DOC);
920 cm->DefineProperty
921 ("RUNTIME_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
922 "Per-configuration output name for RUNTIME target files.",
923 "This is the configuration-specific version of RUNTIME_OUTPUT_NAME.");
926 void cmTarget::SetType(TargetType type, const char* name)
928 this->Name = name;
929 if(type == cmTarget::INSTALL_FILES ||
930 type == cmTarget::INSTALL_PROGRAMS ||
931 type == cmTarget::INSTALL_DIRECTORY)
933 this->Makefile->
934 IssueMessage(cmake::INTERNAL_ERROR,
935 "SetType called on cmTarget for INSTALL_FILES, "
936 "INSTALL_PROGRAMS, or INSTALL_DIRECTORY ");
937 return;
939 // only add dependency information for library targets
940 this->TargetTypeValue = type;
941 if(this->TargetTypeValue >= STATIC_LIBRARY
942 && this->TargetTypeValue <= MODULE_LIBRARY)
944 this->RecordDependencies = true;
946 else
948 this->RecordDependencies = false;
952 //----------------------------------------------------------------------------
953 void cmTarget::SetMakefile(cmMakefile* mf)
955 // Set our makefile.
956 this->Makefile = mf;
958 // set the cmake instance of the properties
959 this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
961 // Check whether this is a DLL platform.
962 this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
963 this->Makefile->IsOn("CYGWIN") ||
964 this->Makefile->IsOn("MINGW"));
966 // Setup default property values.
967 this->SetPropertyDefault("INSTALL_NAME_DIR", "");
968 this->SetPropertyDefault("INSTALL_RPATH", "");
969 this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
970 this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
971 this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
972 this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
973 this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
974 this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
975 this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
977 // Collect the set of configuration types.
978 std::vector<std::string> configNames;
979 if(const char* configurationTypes =
980 mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
982 cmSystemTools::ExpandListArgument(configurationTypes, configNames);
984 else if(const char* buildType = mf->GetDefinition("CMAKE_BUILD_TYPE"))
986 if(*buildType)
988 configNames.push_back(buildType);
992 // Setup per-configuration property default values.
993 for(std::vector<std::string>::iterator ci = configNames.begin();
994 ci != configNames.end(); ++ci)
996 // Initialize per-configuration name postfix property from the
997 // variable only for non-executable targets. This preserves
998 // compatibility with previous CMake versions in which executables
999 // did not support this variable. Projects may still specify the
1000 // property directly. TODO: Make this depend on backwards
1001 // compatibility setting.
1002 if(this->TargetTypeValue != cmTarget::EXECUTABLE)
1004 std::string property = cmSystemTools::UpperCase(*ci);
1005 property += "_POSTFIX";
1006 this->SetPropertyDefault(property.c_str(), 0);
1010 // Save the backtrace of target construction.
1011 this->Makefile->GetBacktrace(this->Internal->Backtrace);
1013 // Record current policies for later use.
1014 this->PolicyStatusCMP0003 =
1015 this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
1016 this->PolicyStatusCMP0004 =
1017 this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
1018 this->PolicyStatusCMP0008 =
1019 this->Makefile->GetPolicyStatus(cmPolicies::CMP0008);
1022 //----------------------------------------------------------------------------
1023 cmListFileBacktrace const& cmTarget::GetBacktrace() const
1025 return this->Internal->Backtrace;
1028 //----------------------------------------------------------------------------
1029 std::string cmTarget::GetSupportDirectory() const
1031 std::string dir = this->Makefile->GetCurrentOutputDirectory();
1032 dir += cmake::GetCMakeFilesDirectory();
1033 dir += "/";
1034 dir += this->Name;
1035 #if defined(__VMS)
1036 dir += "_dir";
1037 #else
1038 dir += ".dir";
1039 #endif
1040 return dir;
1043 //----------------------------------------------------------------------------
1044 bool cmTarget::IsExecutableWithExports()
1046 return (this->GetType() == cmTarget::EXECUTABLE &&
1047 this->GetPropertyAsBool("ENABLE_EXPORTS"));
1050 //----------------------------------------------------------------------------
1051 bool cmTarget::IsLinkable()
1053 return (this->GetType() == cmTarget::STATIC_LIBRARY ||
1054 this->GetType() == cmTarget::SHARED_LIBRARY ||
1055 this->GetType() == cmTarget::MODULE_LIBRARY ||
1056 this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
1057 this->IsExecutableWithExports());
1060 //----------------------------------------------------------------------------
1061 bool cmTarget::HasImportLibrary()
1063 return (this->DLLPlatform &&
1064 (this->GetType() == cmTarget::SHARED_LIBRARY ||
1065 this->IsExecutableWithExports()));
1068 //----------------------------------------------------------------------------
1069 bool cmTarget::IsFrameworkOnApple()
1071 return (this->GetType() == cmTarget::SHARED_LIBRARY &&
1072 this->Makefile->IsOn("APPLE") &&
1073 this->GetPropertyAsBool("FRAMEWORK"));
1076 //----------------------------------------------------------------------------
1077 bool cmTarget::IsAppBundleOnApple()
1079 return (this->GetType() == cmTarget::EXECUTABLE &&
1080 this->Makefile->IsOn("APPLE") &&
1081 this->GetPropertyAsBool("MACOSX_BUNDLE"));
1084 //----------------------------------------------------------------------------
1085 class cmTargetTraceDependencies
1087 public:
1088 cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
1089 const char* vsProjectFile);
1090 void Trace();
1091 private:
1092 cmTarget* Target;
1093 cmTargetInternals* Internal;
1094 cmMakefile* Makefile;
1095 cmGlobalGenerator* GlobalGenerator;
1096 typedef cmTargetInternals::SourceEntry SourceEntry;
1097 SourceEntry* CurrentEntry;
1098 std::queue<cmSourceFile*> SourceQueue;
1099 std::set<cmSourceFile*> SourcesQueued;
1100 typedef std::map<cmStdString, cmSourceFile*> NameMapType;
1101 NameMapType NameMap;
1103 void QueueSource(cmSourceFile* sf);
1104 void FollowName(std::string const& name);
1105 void FollowNames(std::vector<std::string> const& names);
1106 bool IsUtility(std::string const& dep);
1107 void CheckCustomCommand(cmCustomCommand const& cc);
1108 void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
1111 //----------------------------------------------------------------------------
1112 cmTargetTraceDependencies
1113 ::cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
1114 const char* vsProjectFile):
1115 Target(target), Internal(internal)
1117 // Convenience.
1118 this->Makefile = this->Target->GetMakefile();
1119 this->GlobalGenerator =
1120 this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
1121 this->CurrentEntry = 0;
1123 // Queue all the source files already specified for the target.
1124 std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
1125 for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
1126 si != sources.end(); ++si)
1128 this->QueueSource(*si);
1131 // Queue the VS project file to check dependencies on the rule to
1132 // generate it.
1133 if(vsProjectFile)
1135 this->FollowName(vsProjectFile);
1138 // Queue pre-build, pre-link, and post-build rule dependencies.
1139 this->CheckCustomCommands(this->Target->GetPreBuildCommands());
1140 this->CheckCustomCommands(this->Target->GetPreLinkCommands());
1141 this->CheckCustomCommands(this->Target->GetPostBuildCommands());
1144 //----------------------------------------------------------------------------
1145 void cmTargetTraceDependencies::Trace()
1147 // Process one dependency at a time until the queue is empty.
1148 while(!this->SourceQueue.empty())
1150 // Get the next source from the queue.
1151 cmSourceFile* sf = this->SourceQueue.front();
1152 this->SourceQueue.pop();
1153 this->CurrentEntry = &this->Internal->SourceEntries[sf];
1155 // Queue dependencies added explicitly by the user.
1156 if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
1158 std::vector<std::string> objDeps;
1159 cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
1160 this->FollowNames(objDeps);
1163 // Queue the source needed to generate this file, if any.
1164 this->FollowName(sf->GetFullPath());
1166 // Queue dependencies added programatically by commands.
1167 this->FollowNames(sf->GetDepends());
1169 // Queue custom command dependencies.
1170 if(cmCustomCommand const* cc = sf->GetCustomCommand())
1172 this->CheckCustomCommand(*cc);
1175 this->CurrentEntry = 0;
1178 //----------------------------------------------------------------------------
1179 void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
1181 if(this->SourcesQueued.insert(sf).second)
1183 this->SourceQueue.push(sf);
1185 // Make sure this file is in the target.
1186 this->Target->AddSourceFile(sf);
1190 //----------------------------------------------------------------------------
1191 void cmTargetTraceDependencies::FollowName(std::string const& name)
1193 NameMapType::iterator i = this->NameMap.find(name);
1194 if(i == this->NameMap.end())
1196 // Check if we know how to generate this file.
1197 cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
1198 NameMapType::value_type entry(name, sf);
1199 i = this->NameMap.insert(entry).first;
1201 if(cmSourceFile* sf = i->second)
1203 // Record the dependency we just followed.
1204 if(this->CurrentEntry)
1206 this->CurrentEntry->Depends.push_back(sf);
1209 this->QueueSource(sf);
1213 //----------------------------------------------------------------------------
1214 void
1215 cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
1217 for(std::vector<std::string>::const_iterator i = names.begin();
1218 i != names.end(); ++i)
1220 this->FollowName(*i);
1224 //----------------------------------------------------------------------------
1225 bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
1227 // Dependencies on targets (utilities) are supposed to be named by
1228 // just the target name. However for compatibility we support
1229 // naming the output file generated by the target (assuming there is
1230 // no output-name property which old code would not have set). In
1231 // that case the target name will be the file basename of the
1232 // dependency.
1233 std::string util = cmSystemTools::GetFilenameName(dep);
1234 if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
1236 util = cmSystemTools::GetFilenameWithoutLastExtension(util);
1239 // Check for a non-imported target with this name.
1240 if(cmTarget* t = this->GlobalGenerator->FindTarget(0, util.c_str()))
1242 // If we find the target and the dep was given as a full path,
1243 // then make sure it was not a full path to something else, and
1244 // the fact that the name matched a target was just a coincidence.
1245 if(cmSystemTools::FileIsFullPath(dep.c_str()))
1247 // This is really only for compatibility so we do not need to
1248 // worry about configuration names and output names.
1249 std::string tLocation = t->GetLocation(0);
1250 tLocation = cmSystemTools::GetFilenamePath(tLocation);
1251 std::string depLocation = cmSystemTools::GetFilenamePath(dep);
1252 depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
1253 tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
1254 if(depLocation == tLocation)
1256 this->Target->AddUtility(util.c_str());
1257 return true;
1260 else
1262 // The original name of the dependency was not a full path. It
1263 // must name a target, so add the target-level dependency.
1264 this->Target->AddUtility(util.c_str());
1265 return true;
1269 // The dependency does not name a target built in this project.
1270 return false;
1273 //----------------------------------------------------------------------------
1274 void
1275 cmTargetTraceDependencies
1276 ::CheckCustomCommand(cmCustomCommand const& cc)
1278 // Transform command names that reference targets built in this
1279 // project to corresponding target-level dependencies.
1280 for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
1281 cit != cc.GetCommandLines().end(); ++cit)
1283 std::string const& command = *cit->begin();
1284 // Look for a non-imported target with this name.
1285 if(cmTarget* t = this->GlobalGenerator->FindTarget(0, command.c_str()))
1287 if(t->GetType() == cmTarget::EXECUTABLE)
1289 // The command refers to an executable target built in
1290 // this project. Add the target-level dependency to make
1291 // sure the executable is up to date before this custom
1292 // command possibly runs.
1293 this->Target->AddUtility(command.c_str());
1298 // Queue the custom command dependencies.
1299 std::vector<std::string> const& depends = cc.GetDepends();
1300 for(std::vector<std::string>::const_iterator di = depends.begin();
1301 di != depends.end(); ++di)
1303 std::string const& dep = *di;
1304 if(!this->IsUtility(dep))
1306 // The dependency does not name a target and may be a file we
1307 // know how to generate. Queue it.
1308 this->FollowName(dep);
1313 //----------------------------------------------------------------------------
1314 void
1315 cmTargetTraceDependencies
1316 ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
1318 for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
1319 cli != commands.end(); ++cli)
1321 this->CheckCustomCommand(*cli);
1325 //----------------------------------------------------------------------------
1326 void cmTarget::TraceDependencies(const char* vsProjectFile)
1328 // Use a helper object to trace the dependencies.
1329 cmTargetTraceDependencies tracer(this, this->Internal.Get(), vsProjectFile);
1330 tracer.Trace();
1333 //----------------------------------------------------------------------------
1334 bool cmTarget::FindSourceFiles()
1336 for(std::vector<cmSourceFile*>::const_iterator
1337 si = this->SourceFiles.begin();
1338 si != this->SourceFiles.end(); ++si)
1340 if((*si)->GetFullPath().empty())
1342 return false;
1345 return true;
1348 //----------------------------------------------------------------------------
1349 std::vector<cmSourceFile*> const& cmTarget::GetSourceFiles()
1351 return this->SourceFiles;
1354 //----------------------------------------------------------------------------
1355 void cmTarget::AddSourceFile(cmSourceFile* sf)
1357 typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
1358 SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
1359 if(i == this->Internal->SourceEntries.end())
1361 typedef cmTargetInternals::SourceEntry SourceEntry;
1362 SourceEntriesType::value_type entry(sf, SourceEntry());
1363 i = this->Internal->SourceEntries.insert(entry).first;
1364 this->SourceFiles.push_back(sf);
1368 //----------------------------------------------------------------------------
1369 std::vector<cmSourceFile*> const*
1370 cmTarget::GetSourceDepends(cmSourceFile* sf)
1372 typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
1373 SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
1374 if(i != this->Internal->SourceEntries.end())
1376 return &i->second.Depends;
1378 return 0;
1381 //----------------------------------------------------------------------------
1382 void cmTarget::AddSources(std::vector<std::string> const& srcs)
1384 for(std::vector<std::string>::const_iterator i = srcs.begin();
1385 i != srcs.end(); ++i)
1387 this->AddSource(i->c_str());
1391 //----------------------------------------------------------------------------
1392 cmSourceFile* cmTarget::AddSource(const char* s)
1394 std::string src = s;
1396 // For backwards compatibility replace varibles in source names.
1397 // This should eventually be removed.
1398 this->Makefile->ExpandVariablesInString(src);
1400 cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
1401 this->AddSourceFile(sf);
1402 return sf;
1405 //----------------------------------------------------------------------------
1406 struct cmTarget::SourceFileFlags
1407 cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
1409 struct SourceFileFlags flags;
1410 this->ConstructSourceFileFlags();
1411 std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
1412 this->Internal->SourceFlagsMap.find(sf);
1413 if(si != this->Internal->SourceFlagsMap.end())
1415 flags = si->second;
1417 return flags;
1420 //----------------------------------------------------------------------------
1421 void cmTarget::ConstructSourceFileFlags()
1423 if(this->Internal->SourceFileFlagsConstructed)
1425 return;
1427 this->Internal->SourceFileFlagsConstructed = true;
1429 // Process public headers to mark the source files.
1430 if(const char* files = this->GetProperty("PUBLIC_HEADER"))
1432 std::vector<std::string> relFiles;
1433 cmSystemTools::ExpandListArgument(files, relFiles);
1434 for(std::vector<std::string>::iterator it = relFiles.begin();
1435 it != relFiles.end(); ++it)
1437 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1439 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1440 flags.MacFolder = "Headers";
1441 flags.Type = cmTarget::SourceFileTypePublicHeader;
1446 // Process private headers after public headers so that they take
1447 // precedence if a file is listed in both.
1448 if(const char* files = this->GetProperty("PRIVATE_HEADER"))
1450 std::vector<std::string> relFiles;
1451 cmSystemTools::ExpandListArgument(files, relFiles);
1452 for(std::vector<std::string>::iterator it = relFiles.begin();
1453 it != relFiles.end(); ++it)
1455 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1457 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1458 flags.MacFolder = "PrivateHeaders";
1459 flags.Type = cmTarget::SourceFileTypePrivateHeader;
1464 // Mark sources listed as resources.
1465 if(const char* files = this->GetProperty("RESOURCE"))
1467 std::vector<std::string> relFiles;
1468 cmSystemTools::ExpandListArgument(files, relFiles);
1469 for(std::vector<std::string>::iterator it = relFiles.begin();
1470 it != relFiles.end(); ++it)
1472 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1474 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1475 flags.MacFolder = "Resources";
1476 flags.Type = cmTarget::SourceFileTypeResource;
1481 // Handle the MACOSX_PACKAGE_LOCATION property on source files that
1482 // were not listed in one of the other lists.
1483 std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
1484 for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
1485 si != sources.end(); ++si)
1487 cmSourceFile* sf = *si;
1488 if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
1490 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1491 if(flags.Type == cmTarget::SourceFileTypeNormal)
1493 flags.MacFolder = location;
1494 if(strcmp(location, "Resources") == 0)
1496 flags.Type = cmTarget::SourceFileTypeResource;
1498 else
1500 flags.Type = cmTarget::SourceFileTypeMacContent;
1507 //----------------------------------------------------------------------------
1508 void cmTarget::MergeLinkLibraries( cmMakefile& mf,
1509 const char *selfname,
1510 const LinkLibraryVectorType& libs )
1512 // Only add on libraries we haven't added on before.
1513 // Assumption: the global link libraries could only grow, never shrink
1514 LinkLibraryVectorType::const_iterator i = libs.begin();
1515 i += this->PrevLinkedLibraries.size();
1516 for( ; i != libs.end(); ++i )
1518 // We call this so that the dependencies get written to the cache
1519 this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
1521 this->PrevLinkedLibraries = libs;
1524 //----------------------------------------------------------------------------
1525 void cmTarget::AddLinkDirectory(const char* d)
1527 // Make sure we don't add unnecessary search directories.
1528 if(this->LinkDirectoriesEmmitted.insert(d).second)
1530 this->LinkDirectories.push_back(d);
1534 //----------------------------------------------------------------------------
1535 const std::vector<std::string>& cmTarget::GetLinkDirectories()
1537 return this->LinkDirectories;
1540 //----------------------------------------------------------------------------
1541 cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
1543 // No configuration is always optimized.
1544 if(!(config && *config))
1546 return cmTarget::OPTIMIZED;
1549 // Get the list of configurations considered to be DEBUG.
1550 std::vector<std::string> const& debugConfigs =
1551 this->Makefile->GetCMakeInstance()->GetDebugConfigs();
1553 // Check if any entry in the list matches this configuration.
1554 std::string configUpper = cmSystemTools::UpperCase(config);
1555 for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
1556 i != debugConfigs.end(); ++i)
1558 if(*i == configUpper)
1560 return cmTarget::DEBUG;
1564 // The current configuration is not a debug configuration.
1565 return cmTarget::OPTIMIZED;
1568 //----------------------------------------------------------------------------
1569 void cmTarget::ClearDependencyInformation( cmMakefile& mf,
1570 const char* target )
1572 // Clear the dependencies. The cache variable must exist iff we are
1573 // recording dependency information for this target.
1574 std::string depname = target;
1575 depname += "_LIB_DEPENDS";
1576 if (this->RecordDependencies)
1578 mf.AddCacheDefinition(depname.c_str(), "",
1579 "Dependencies for target", cmCacheManager::STATIC);
1581 else
1583 if (mf.GetDefinition( depname.c_str() ))
1585 std::string message = "Target ";
1586 message += target;
1587 message += " has dependency information when it shouldn't.\n";
1588 message += "Your cache is probably stale. Please remove the entry\n ";
1589 message += depname;
1590 message += "\nfrom the cache.";
1591 cmSystemTools::Error( message.c_str() );
1596 //----------------------------------------------------------------------------
1597 void cmTarget::AddLinkLibrary(const std::string& lib,
1598 LinkLibraryType llt)
1600 this->AddFramework(lib.c_str(), llt);
1601 cmTarget::LibraryID tmp;
1602 tmp.first = lib;
1603 tmp.second = llt;
1604 this->LinkLibraries.push_back(tmp);
1605 this->OriginalLinkLibraries.push_back(tmp);
1608 //----------------------------------------------------------------------------
1609 bool cmTarget::NameResolvesToFramework(const std::string& libname)
1611 return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
1612 NameResolvesToFramework(libname);
1615 //----------------------------------------------------------------------------
1616 bool cmTarget::AddFramework(const std::string& libname, LinkLibraryType llt)
1618 (void)llt; // TODO: What is this?
1619 if(this->NameResolvesToFramework(libname.c_str()))
1621 std::string frameworkDir = libname;
1622 frameworkDir += "/../";
1623 frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
1624 std::vector<std::string>::iterator i =
1625 std::find(this->Frameworks.begin(),
1626 this->Frameworks.end(), frameworkDir);
1627 if(i == this->Frameworks.end())
1629 this->Frameworks.push_back(frameworkDir);
1631 return true;
1633 return false;
1636 //----------------------------------------------------------------------------
1637 void cmTarget::AddLinkLibrary(cmMakefile& mf,
1638 const char *target, const char* lib,
1639 LinkLibraryType llt)
1641 // Never add a self dependency, even if the user asks for it.
1642 if(strcmp( target, lib ) == 0)
1644 return;
1646 this->AddFramework(lib, llt);
1647 cmTarget::LibraryID tmp;
1648 tmp.first = lib;
1649 tmp.second = llt;
1650 this->LinkLibraries.push_back( tmp );
1651 this->OriginalLinkLibraries.push_back(tmp);
1653 // Add the explicit dependency information for this target. This is
1654 // simply a set of libraries separated by ";". There should always
1655 // be a trailing ";". These library names are not canonical, in that
1656 // they may be "-framework x", "-ly", "/path/libz.a", etc.
1657 // We shouldn't remove duplicates here because external libraries
1658 // may be purposefully duplicated to handle recursive dependencies,
1659 // and we removing one instance will break the link line. Duplicates
1660 // will be appropriately eliminated at emit time.
1661 if(this->RecordDependencies)
1663 std::string targetEntry = target;
1664 targetEntry += "_LIB_DEPENDS";
1665 std::string dependencies;
1666 const char* old_val = mf.GetDefinition( targetEntry.c_str() );
1667 if( old_val )
1669 dependencies += old_val;
1671 switch (llt)
1673 case cmTarget::GENERAL:
1674 dependencies += "general";
1675 break;
1676 case cmTarget::DEBUG:
1677 dependencies += "debug";
1678 break;
1679 case cmTarget::OPTIMIZED:
1680 dependencies += "optimized";
1681 break;
1683 dependencies += ";";
1684 dependencies += lib;
1685 dependencies += ";";
1686 mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
1687 "Dependencies for the target",
1688 cmCacheManager::STATIC );
1693 //----------------------------------------------------------------------------
1694 void
1695 cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
1697 // There are two key parts of the dependency analysis: (1)
1698 // determining the libraries in the link line, and (2) constructing
1699 // the dependency graph for those libraries.
1701 // The latter is done using the cache entries that record the
1702 // dependencies of each library.
1704 // The former is a more thorny issue, since it is not clear how to
1705 // determine if two libraries listed on the link line refer to the a
1706 // single library or not. For example, consider the link "libraries"
1707 // /usr/lib/libtiff.so -ltiff
1708 // Is this one library or two? The solution implemented here is the
1709 // simplest (and probably the only practical) one: two libraries are
1710 // the same if their "link strings" are identical. Thus, the two
1711 // libraries above are considered distinct. This also means that for
1712 // dependency analysis to be effective, the CMake user must specify
1713 // libraries build by his project without using any linker flags or
1714 // file extensions. That is,
1715 // LINK_LIBRARIES( One Two )
1716 // instead of
1717 // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
1718 // The former is probably what most users would do, but it never
1719 // hurts to document the assumptions. :-) Therefore, in the analysis
1720 // code, the "canonical name" of a library is simply its name as
1721 // given to a LINK_LIBRARIES command.
1723 // Also, we will leave the original link line intact; we will just add any
1724 // dependencies that were missing.
1726 // There is a problem with recursive external libraries
1727 // (i.e. libraries with no dependency information that are
1728 // recursively dependent). We must make sure that the we emit one of
1729 // the libraries twice to satisfy the recursion, but we shouldn't
1730 // emit it more times than necessary. In particular, we must make
1731 // sure that handling this improbable case doesn't cost us when
1732 // dealing with the common case of non-recursive libraries. The
1733 // solution is to assume that the recursion is satisfied at one node
1734 // of the dependency tree. To illustrate, assume libA and libB are
1735 // extrenal and mutually dependent. Suppose libX depends on
1736 // libA, and libY on libA and libX. Then
1737 // TARGET_LINK_LIBRARIES( Y X A B A )
1738 // TARGET_LINK_LIBRARIES( X A B A )
1739 // TARGET_LINK_LIBRARIES( Exec Y )
1740 // would result in "-lY -lX -lA -lB -lA". This is the correct way to
1741 // specify the dependencies, since the mutual dependency of A and B
1742 // is resolved *every time libA is specified*.
1744 // Something like
1745 // TARGET_LINK_LIBRARIES( Y X A B A )
1746 // TARGET_LINK_LIBRARIES( X A B )
1747 // TARGET_LINK_LIBRARIES( Exec Y )
1748 // would result in "-lY -lX -lA -lB", and the mutual dependency
1749 // information is lost. This is because in some case (Y), the mutual
1750 // dependency of A and B is listed, while in another other case (X),
1751 // it is not. Depending on which line actually emits A, the mutual
1752 // dependency may or may not be on the final link line. We can't
1753 // handle this pathalogical case cleanly without emitting extra
1754 // libraries for the normal cases. Besides, the dependency
1755 // information for X is wrong anyway: if we build an executable
1756 // depending on X alone, we would not have the mutual dependency on
1757 // A and B resolved.
1759 // IMPROVEMENTS:
1760 // -- The current algorithm will not always pick the "optimal" link line
1761 // when recursive dependencies are present. It will instead break the
1762 // cycles at an aribtrary point. The majority of projects won't have
1763 // cyclic dependencies, so this is probably not a big deal. Note that
1764 // the link line is always correct, just not necessary optimal.
1767 // Expand variables in link library names. This is for backwards
1768 // compatibility with very early CMake versions and should
1769 // eventually be removed. This code was moved here from the end of
1770 // old source list processing code which was called just before this
1771 // method.
1772 for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
1773 p != this->LinkLibraries.end(); ++p)
1775 this->Makefile->ExpandVariablesInString(p->first, true, true);
1779 typedef std::vector< std::string > LinkLine;
1781 // The dependency map.
1782 DependencyMap dep_map;
1784 // 1. Build the dependency graph
1786 for(LinkLibraryVectorType::reverse_iterator lib
1787 = this->LinkLibraries.rbegin();
1788 lib != this->LinkLibraries.rend(); ++lib)
1790 this->GatherDependencies( mf, *lib, dep_map);
1793 // 2. Remove any dependencies that are already satisfied in the original
1794 // link line.
1796 for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
1797 lib != this->LinkLibraries.end(); ++lib)
1799 for( LinkLibraryVectorType::iterator lib2 = lib;
1800 lib2 != this->LinkLibraries.end(); ++lib2)
1802 this->DeleteDependency( dep_map, *lib, *lib2);
1807 // 3. Create the new link line by simply emitting any dependencies that are
1808 // missing. Start from the back and keep adding.
1810 std::set<DependencyMap::key_type> done, visited;
1811 std::vector<DependencyMap::key_type> newLinkLibraries;
1812 for(LinkLibraryVectorType::reverse_iterator lib =
1813 this->LinkLibraries.rbegin();
1814 lib != this->LinkLibraries.rend(); ++lib)
1816 // skip zero size library entries, this may happen
1817 // if a variable expands to nothing.
1818 if (lib->first.size() != 0)
1820 this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
1824 // 4. Add the new libraries to the link line.
1826 for( std::vector<DependencyMap::key_type>::reverse_iterator k =
1827 newLinkLibraries.rbegin();
1828 k != newLinkLibraries.rend(); ++k )
1830 // get the llt from the dep_map
1831 this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
1833 this->LinkLibrariesAnalyzed = true;
1836 //----------------------------------------------------------------------------
1837 void cmTarget::InsertDependency( DependencyMap& depMap,
1838 const LibraryID& lib,
1839 const LibraryID& dep)
1841 depMap[lib].push_back(dep);
1844 //----------------------------------------------------------------------------
1845 void cmTarget::DeleteDependency( DependencyMap& depMap,
1846 const LibraryID& lib,
1847 const LibraryID& dep)
1849 // Make sure there is an entry in the map for lib. If so, delete all
1850 // dependencies to dep. There may be repeated entries because of
1851 // external libraries that are specified multiple times.
1852 DependencyMap::iterator map_itr = depMap.find( lib );
1853 if( map_itr != depMap.end() )
1855 DependencyList& depList = map_itr->second;
1856 DependencyList::iterator itr;
1857 while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
1858 depList.end() )
1860 depList.erase( itr );
1865 //----------------------------------------------------------------------------
1866 void cmTarget::Emit(const LibraryID lib,
1867 const DependencyMap& dep_map,
1868 std::set<LibraryID>& emitted,
1869 std::set<LibraryID>& visited,
1870 DependencyList& link_line )
1872 // It's already been emitted
1873 if( emitted.find(lib) != emitted.end() )
1875 return;
1878 // Emit the dependencies only if this library node hasn't been
1879 // visited before. If it has, then we have a cycle. The recursion
1880 // that got us here should take care of everything.
1882 if( visited.insert(lib).second )
1884 if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
1886 const DependencyList& dep_on = dep_map.find( lib )->second;
1887 DependencyList::const_reverse_iterator i;
1889 // To cater for recursive external libraries, we must emit
1890 // duplicates on this link line *unless* they were emitted by
1891 // some other node, in which case we assume that the recursion
1892 // was resolved then. We making the simplifying assumption that
1893 // any duplicates on a single link line are on purpose, and must
1894 // be preserved.
1896 // This variable will keep track of the libraries that were
1897 // emitted directory from the current node, and not from a
1898 // recursive call. This way, if we come across a library that
1899 // has already been emitted, we repeat it iff it has been
1900 // emitted here.
1901 std::set<DependencyMap::key_type> emitted_here;
1902 for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
1904 if( emitted_here.find(*i) != emitted_here.end() )
1906 // a repeat. Must emit.
1907 emitted.insert(*i);
1908 link_line.push_back( *i );
1910 else
1912 // Emit only if no-one else has
1913 if( emitted.find(*i) == emitted.end() )
1915 // emit dependencies
1916 Emit( *i, dep_map, emitted, visited, link_line );
1917 // emit self
1918 emitted.insert(*i);
1919 emitted_here.insert(*i);
1920 link_line.push_back( *i );
1928 //----------------------------------------------------------------------------
1929 void cmTarget::GatherDependencies( const cmMakefile& mf,
1930 const LibraryID& lib,
1931 DependencyMap& dep_map)
1933 // If the library is already in the dependency map, then it has
1934 // already been fully processed.
1935 if( dep_map.find(lib) != dep_map.end() )
1937 return;
1940 const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
1941 if( deps && strcmp(deps,"") != 0 )
1943 // Make sure this library is in the map, even if it has an empty
1944 // set of dependencies. This distinguishes the case of explicitly
1945 // no dependencies with that of unspecified dependencies.
1946 dep_map[lib];
1948 // Parse the dependency information, which is a set of
1949 // type, library pairs separated by ";". There is always a trailing ";".
1950 cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
1951 std::string depline = deps;
1952 std::string::size_type start = 0;
1953 std::string::size_type end;
1954 end = depline.find( ";", start );
1955 while( end != std::string::npos )
1957 std::string l = depline.substr( start, end-start );
1958 if( l.size() != 0 )
1960 if (l == "debug")
1962 llt = cmTarget::DEBUG;
1964 else if (l == "optimized")
1966 llt = cmTarget::OPTIMIZED;
1968 else if (l == "general")
1970 llt = cmTarget::GENERAL;
1972 else
1974 LibraryID lib2(l,llt);
1975 this->InsertDependency( dep_map, lib, lib2);
1976 this->GatherDependencies( mf, lib2, dep_map);
1977 llt = cmTarget::GENERAL;
1980 start = end+1; // skip the ;
1981 end = depline.find( ";", start );
1983 // cannot depend on itself
1984 this->DeleteDependency( dep_map, lib, lib);
1988 //----------------------------------------------------------------------------
1989 void cmTarget::SetProperty(const char* prop, const char* value)
1991 if (!prop)
1993 return;
1996 this->Properties.SetProperty(prop, value, cmProperty::TARGET);
1998 // If imported information is being set, wipe out cached
1999 // information.
2000 if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
2002 this->Internal->ImportInfoMap.clear();
2006 //----------------------------------------------------------------------------
2007 void cmTarget::AppendProperty(const char* prop, const char* value)
2009 if (!prop)
2011 return;
2013 this->Properties.AppendProperty(prop, value, cmProperty::TARGET);
2015 // If imported information is being set, wipe out cached
2016 // information.
2017 if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
2019 this->Internal->ImportInfoMap.clear();
2023 //----------------------------------------------------------------------------
2024 static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
2025 const char* prop, const char* value, cmMakefile* context, bool imported
2028 // Look for link-type keywords in the value.
2029 static cmsys::RegularExpression
2030 keys("(^|;)(debug|optimized|general)(;|$)");
2031 if(!keys.find(value))
2033 return;
2036 // Support imported and non-imported versions of the property.
2037 const char* base = (imported?
2038 "IMPORTED_LINK_INTERFACE_LIBRARIES" :
2039 "LINK_INTERFACE_LIBRARIES");
2041 // Report an error.
2042 cmOStringStream e;
2043 e << "Property " << prop << " may not contain link-type keyword \""
2044 << keys.match(2) << "\". "
2045 << "The " << base << " property has a per-configuration "
2046 << "version called " << base << "_<CONFIG> which may be "
2047 << "used to specify per-configuration rules.";
2048 if(!imported)
2050 e << " "
2051 << "Alternatively, an IMPORTED library may be created, configured "
2052 << "with a per-configuration location, and then named in the "
2053 << "property value. "
2054 << "See the add_library command's IMPORTED mode for details."
2055 << "\n"
2056 << "If you have a list of libraries that already contains the "
2057 << "keyword, use the target_link_libraries command with its "
2058 << "LINK_INTERFACE_LIBRARIES mode to set the property. "
2059 << "The command automatically recognizes link-type keywords and sets "
2060 << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
2061 << "properties accordingly.";
2063 context->IssueMessage(cmake::FATAL_ERROR, e.str());
2066 //----------------------------------------------------------------------------
2067 void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
2069 // Certain properties need checking.
2070 if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
2072 if(const char* value = this->GetProperty(prop))
2074 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
2077 if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
2079 if(const char* value = this->GetProperty(prop))
2081 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
2086 //----------------------------------------------------------------------------
2087 void cmTarget::MarkAsImported()
2089 this->IsImportedTarget = true;
2092 //----------------------------------------------------------------------------
2093 cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
2095 // There is no output information for imported targets.
2096 if(this->IsImported())
2098 return 0;
2101 // Only libraries and executables have well-defined output files.
2102 if(this->GetType() != cmTarget::STATIC_LIBRARY &&
2103 this->GetType() != cmTarget::SHARED_LIBRARY &&
2104 this->GetType() != cmTarget::MODULE_LIBRARY &&
2105 this->GetType() != cmTarget::EXECUTABLE)
2107 std::string msg = "cmTarget::GetOutputInfo called for ";
2108 msg += this->GetName();
2109 msg += " which has type ";
2110 msg += cmTarget::TargetTypeNames[this->GetType()];
2111 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
2112 abort();
2113 return 0;
2116 // Lookup/compute/cache the output information for this configuration.
2117 std::string config_upper;
2118 if(config && *config)
2120 config_upper = cmSystemTools::UpperCase(config);
2122 typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
2123 OutputInfoMapType::const_iterator i =
2124 this->Internal->OutputInfoMap.find(config_upper);
2125 if(i == this->Internal->OutputInfoMap.end())
2127 OutputInfo info;
2128 this->ComputeOutputDir(config, false, info.OutDir);
2129 this->ComputeOutputDir(config, true, info.ImpDir);
2130 OutputInfoMapType::value_type entry(config_upper, info);
2131 i = this->Internal->OutputInfoMap.insert(entry).first;
2133 return &i->second;
2136 //----------------------------------------------------------------------------
2137 std::string cmTarget::GetDirectory(const char* config, bool implib)
2139 if (this->IsImported())
2141 // Return the directory from which the target is imported.
2142 return
2143 cmSystemTools::GetFilenamePath(
2144 this->ImportedGetFullPath(config, implib));
2146 else if(OutputInfo const* info = this->GetOutputInfo(config))
2148 // Return the directory in which the target will be built.
2149 return implib? info->ImpDir : info->OutDir;
2151 return "";
2154 //----------------------------------------------------------------------------
2155 const char* cmTarget::GetLocation(const char* config)
2157 if (this->IsImported())
2159 return this->ImportedGetLocation(config);
2161 else
2163 return this->NormalGetLocation(config);
2167 //----------------------------------------------------------------------------
2168 const char* cmTarget::ImportedGetLocation(const char* config)
2170 this->Location = this->ImportedGetFullPath(config, false);
2171 return this->Location.c_str();
2174 //----------------------------------------------------------------------------
2175 const char* cmTarget::NormalGetLocation(const char* config)
2177 // Handle the configuration-specific case first.
2178 if(config)
2180 this->Location = this->GetFullPath(config, false);
2181 return this->Location.c_str();
2184 // Now handle the deprecated build-time configuration location.
2185 this->Location = this->GetDirectory();
2186 if(!this->Location.empty())
2188 this->Location += "/";
2190 const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
2191 if(cfgid && strcmp(cfgid, ".") != 0)
2193 this->Location += cfgid;
2194 this->Location += "/";
2196 if(this->IsAppBundleOnApple())
2198 this->Location += this->GetFullName(config, false);
2199 this->Location += ".app/Contents/MacOS/";
2201 if(this->IsFrameworkOnApple())
2203 this->Location += this->GetFullName(config, false);
2204 this->Location += ".framework/Versions/";
2205 this->Location += this->GetFrameworkVersion();
2206 this->Location += "/";
2208 this->Location += this->GetFullName(config, false);
2209 return this->Location.c_str();
2212 //----------------------------------------------------------------------------
2213 void cmTarget::GetTargetVersion(int& major, int& minor)
2215 int patch;
2216 this->GetTargetVersion(false, major, minor, patch);
2219 //----------------------------------------------------------------------------
2220 void cmTarget::GetTargetVersion(bool soversion,
2221 int& major, int& minor, int& patch)
2223 // Set the default values.
2224 major = 0;
2225 minor = 0;
2226 patch = 0;
2228 // Look for a VERSION or SOVERSION property.
2229 const char* prop = soversion? "SOVERSION" : "VERSION";
2230 if(const char* version = this->GetProperty(prop))
2232 // Try to parse the version number and store the results that were
2233 // successfully parsed.
2234 int parsed_major;
2235 int parsed_minor;
2236 int parsed_patch;
2237 switch(sscanf(version, "%d.%d.%d",
2238 &parsed_major, &parsed_minor, &parsed_patch))
2240 case 3: patch = parsed_patch; // no break!
2241 case 2: minor = parsed_minor; // no break!
2242 case 1: major = parsed_major; // no break!
2243 default: break;
2248 //----------------------------------------------------------------------------
2249 const char *cmTarget::GetProperty(const char* prop)
2251 return this->GetProperty(prop, cmProperty::TARGET);
2254 //----------------------------------------------------------------------------
2255 void cmTarget::ComputeObjectFiles()
2257 if (this->IsImported())
2259 return;
2261 #if 0
2262 std::vector<std::string> dirs;
2263 this->Makefile->GetLocalGenerator()->
2264 GetTargetObjectFileDirectories(this,
2265 dirs);
2266 std::string objectFiles;
2267 std::string objExtensionLookup1 = "CMAKE_";
2268 std::string objExtensionLookup2 = "_OUTPUT_EXTENSION";
2270 for(std::vector<std::string>::iterator d = dirs.begin();
2271 d != dirs.end(); ++d)
2273 for(std::vector<cmSourceFile*>::iterator s = this->SourceFiles.begin();
2274 s != this->SourceFiles.end(); ++s)
2276 cmSourceFile* sf = *s;
2277 if(const char* lang = sf->GetLanguage())
2279 std::string lookupObj = objExtensionLookup1 + lang;
2280 lookupObj += objExtensionLookup2;
2281 const char* obj = this->Makefile->GetDefinition(lookupObj.c_str());
2282 if(obj)
2284 if(objectFiles.size())
2286 objectFiles += ";";
2288 std::string objFile = *d;
2289 objFile += "/";
2290 objFile += this->Makefile->GetLocalGenerator()->
2291 GetSourceObjectName(*sf);
2292 objFile += obj;
2293 objectFiles += objFile;
2298 this->SetProperty("OBJECT_FILES", objectFiles.c_str());
2299 #endif
2302 //----------------------------------------------------------------------------
2303 const char *cmTarget::GetProperty(const char* prop,
2304 cmProperty::ScopeType scope)
2306 if(!prop)
2308 return 0;
2311 // Watch for special "computed" properties that are dependent on
2312 // other properties or variables. Always recompute them.
2313 if(this->GetType() == cmTarget::EXECUTABLE ||
2314 this->GetType() == cmTarget::STATIC_LIBRARY ||
2315 this->GetType() == cmTarget::SHARED_LIBRARY ||
2316 this->GetType() == cmTarget::MODULE_LIBRARY ||
2317 this->GetType() == cmTarget::UNKNOWN_LIBRARY)
2319 if(strcmp(prop,"LOCATION") == 0)
2321 // Set the LOCATION property of the target.
2323 // For an imported target this is the location of an arbitrary
2324 // available configuration.
2326 // For a non-imported target this is deprecated because it
2327 // cannot take into account the per-configuration name of the
2328 // target because the configuration type may not be known at
2329 // CMake time.
2330 this->SetProperty("LOCATION", this->GetLocation(0));
2333 // Support "LOCATION_<CONFIG>".
2334 if(strncmp(prop, "LOCATION_", 9) == 0)
2336 std::string configName = prop+9;
2337 this->SetProperty(prop, this->GetLocation(configName.c_str()));
2339 else
2341 // Support "<CONFIG>_LOCATION" for compatiblity.
2342 int len = static_cast<int>(strlen(prop));
2343 if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
2345 std::string configName(prop, len-9);
2346 if(configName != "IMPORTED")
2348 this->SetProperty(prop, this->GetLocation(configName.c_str()));
2354 if (strcmp(prop,"IMPORTED") == 0)
2356 return this->IsImported()?"TRUE":"FALSE";
2359 if(!strcmp(prop,"SOURCES"))
2361 cmOStringStream ss;
2362 const char* sep = "";
2363 for(std::vector<cmSourceFile*>::const_iterator
2364 i = this->SourceFiles.begin();
2365 i != this->SourceFiles.end(); ++i)
2367 // Separate from the previous list entries.
2368 ss << sep;
2369 sep = ";";
2371 // Construct what is known about this source file location.
2372 cmSourceFileLocation const& location = (*i)->GetLocation();
2373 std::string sname = location.GetDirectory();
2374 if(!sname.empty())
2376 sname += "/";
2378 sname += location.GetName();
2380 // Append this list entry.
2381 ss << sname;
2383 this->SetProperty("SOURCES", ss.str().c_str());
2386 // the type property returns what type the target is
2387 if (!strcmp(prop,"TYPE"))
2389 switch( this->GetType() )
2391 case cmTarget::STATIC_LIBRARY:
2392 return "STATIC_LIBRARY";
2393 // break; /* unreachable */
2394 case cmTarget::MODULE_LIBRARY:
2395 return "MODULE_LIBRARY";
2396 // break; /* unreachable */
2397 case cmTarget::SHARED_LIBRARY:
2398 return "SHARED_LIBRARY";
2399 // break; /* unreachable */
2400 case cmTarget::EXECUTABLE:
2401 return "EXECUTABLE";
2402 // break; /* unreachable */
2403 case cmTarget::UTILITY:
2404 return "UTILITY";
2405 // break; /* unreachable */
2406 case cmTarget::GLOBAL_TARGET:
2407 return "GLOBAL_TARGET";
2408 // break; /* unreachable */
2409 case cmTarget::INSTALL_FILES:
2410 return "INSTALL_FILES";
2411 // break; /* unreachable */
2412 case cmTarget::INSTALL_PROGRAMS:
2413 return "INSTALL_PROGRAMS";
2414 // break; /* unreachable */
2415 case cmTarget::INSTALL_DIRECTORY:
2416 return "INSTALL_DIRECTORY";
2417 // break; /* unreachable */
2418 case cmTarget::UNKNOWN_LIBRARY:
2419 return "UNKNOWN_LIBRARY";
2420 // break; /* unreachable */
2422 return 0;
2424 bool chain = false;
2425 const char *retVal =
2426 this->Properties.GetPropertyValue(prop, scope, chain);
2427 if (chain)
2429 return this->Makefile->GetProperty(prop,scope);
2431 return retVal;
2434 //----------------------------------------------------------------------------
2435 bool cmTarget::GetPropertyAsBool(const char* prop)
2437 return cmSystemTools::IsOn(this->GetProperty(prop));
2440 //----------------------------------------------------------------------------
2441 class cmTargetCollectLinkLanguages
2443 public:
2444 cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
2445 std::set<cmStdString>& languages):
2446 Config(config), Languages(languages) { this->Visited.insert(target); }
2447 void Visit(cmTarget* target)
2449 if(!target || !this->Visited.insert(target).second)
2451 return;
2454 cmTarget::LinkInterface const* iface =
2455 target->GetLinkInterface(this->Config);
2456 if(!iface) { return; }
2458 for(std::vector<std::string>::const_iterator
2459 li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
2461 this->Languages.insert(*li);
2464 cmMakefile* mf = target->GetMakefile();
2465 for(std::vector<std::string>::const_iterator
2466 li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
2468 this->Visit(mf->FindTargetToUse(li->c_str()));
2471 private:
2472 const char* Config;
2473 std::set<cmStdString>& Languages;
2474 std::set<cmTarget*> Visited;
2477 //----------------------------------------------------------------------------
2478 const char* cmTarget::GetLinkerLanguage(const char* config)
2480 const char* lang = this->GetLinkClosure(config)->LinkerLanguage.c_str();
2481 return *lang? lang : 0;
2484 //----------------------------------------------------------------------------
2485 cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config)
2487 std::string key = cmSystemTools::UpperCase(config? config : "");
2488 cmTargetInternals::LinkClosureMapType::iterator
2489 i = this->Internal->LinkClosureMap.find(key);
2490 if(i == this->Internal->LinkClosureMap.end())
2492 LinkClosure lc;
2493 this->ComputeLinkClosure(config, lc);
2494 cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
2495 i = this->Internal->LinkClosureMap.insert(entry).first;
2497 return &i->second;
2500 //----------------------------------------------------------------------------
2501 class cmTargetSelectLinker
2503 int Preference;
2504 cmTarget* Target;
2505 cmMakefile* Makefile;
2506 cmGlobalGenerator* GG;
2507 std::set<cmStdString> Preferred;
2508 public:
2509 cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
2511 this->Makefile = this->Target->GetMakefile();
2512 this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
2514 void Consider(const char* lang)
2516 int preference = this->GG->GetLinkerPreference(lang);
2517 if(preference > this->Preference)
2519 this->Preference = preference;
2520 this->Preferred.clear();
2522 if(preference == this->Preference)
2524 this->Preferred.insert(lang);
2527 std::string Choose()
2529 if(this->Preferred.empty())
2531 return "";
2533 else if(this->Preferred.size() > 1)
2535 cmOStringStream e;
2536 e << "Target " << this->Target->GetName()
2537 << " contains multiple languages with the highest linker preference"
2538 << " (" << this->Preference << "):\n";
2539 for(std::set<cmStdString>::const_iterator
2540 li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
2542 e << " " << *li << "\n";
2544 e << "Set the LINKER_LANGUAGE property for this target.";
2545 cmake* cm = this->Makefile->GetCMakeInstance();
2546 cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
2547 this->Target->GetBacktrace());
2549 return *this->Preferred.begin();
2553 //----------------------------------------------------------------------------
2554 void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc)
2556 // Get languages built in this target.
2557 std::set<cmStdString> languages;
2558 LinkImplementation const* impl = this->GetLinkImplementation(config);
2559 for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
2560 li != impl->Languages.end(); ++li)
2562 languages.insert(*li);
2565 // Add interface languages from linked targets.
2566 cmTargetCollectLinkLanguages cll(this, config, languages);
2567 for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
2568 li != impl->Libraries.end(); ++li)
2570 cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
2573 // Store the transitive closure of languages.
2574 for(std::set<cmStdString>::const_iterator li = languages.begin();
2575 li != languages.end(); ++li)
2577 lc.Languages.push_back(*li);
2580 // Choose the language whose linker should be used.
2581 if(this->GetProperty("HAS_CXX"))
2583 lc.LinkerLanguage = "CXX";
2585 else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
2587 lc.LinkerLanguage = linkerLang;
2589 else
2591 // Find the language with the highest preference value.
2592 cmTargetSelectLinker tsl(this);
2594 // First select from the languages compiled directly in this target.
2595 for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
2596 li != impl->Languages.end(); ++li)
2598 tsl.Consider(li->c_str());
2601 // Now consider languages that propagate from linked targets.
2602 for(std::set<cmStdString>::const_iterator sit = languages.begin();
2603 sit != languages.end(); ++sit)
2605 std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
2606 if(this->Makefile->IsOn(propagates.c_str()))
2608 tsl.Consider(sit->c_str());
2612 lc.LinkerLanguage = tsl.Choose();
2616 //----------------------------------------------------------------------------
2617 const char* cmTarget::GetCreateRuleVariable()
2619 switch(this->GetType())
2621 case cmTarget::STATIC_LIBRARY:
2622 return "_CREATE_STATIC_LIBRARY";
2623 case cmTarget::SHARED_LIBRARY:
2624 return "_CREATE_SHARED_LIBRARY";
2625 case cmTarget::MODULE_LIBRARY:
2626 return "_CREATE_SHARED_MODULE";
2627 case cmTarget::EXECUTABLE:
2628 return "_LINK_EXECUTABLE";
2629 default:
2630 break;
2632 return "";
2635 //----------------------------------------------------------------------------
2636 const char* cmTarget::GetSuffixVariableInternal(bool implib)
2638 switch(this->GetType())
2640 case cmTarget::STATIC_LIBRARY:
2641 return "CMAKE_STATIC_LIBRARY_SUFFIX";
2642 case cmTarget::SHARED_LIBRARY:
2643 return (implib
2644 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2645 : "CMAKE_SHARED_LIBRARY_SUFFIX");
2646 case cmTarget::MODULE_LIBRARY:
2647 return (implib
2648 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2649 : "CMAKE_SHARED_MODULE_SUFFIX");
2650 case cmTarget::EXECUTABLE:
2651 return (implib
2652 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2653 : "CMAKE_EXECUTABLE_SUFFIX");
2654 default:
2655 break;
2657 return "";
2661 //----------------------------------------------------------------------------
2662 const char* cmTarget::GetPrefixVariableInternal(bool implib)
2664 switch(this->GetType())
2666 case cmTarget::STATIC_LIBRARY:
2667 return "CMAKE_STATIC_LIBRARY_PREFIX";
2668 case cmTarget::SHARED_LIBRARY:
2669 return (implib
2670 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2671 : "CMAKE_SHARED_LIBRARY_PREFIX");
2672 case cmTarget::MODULE_LIBRARY:
2673 return (implib
2674 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2675 : "CMAKE_SHARED_MODULE_PREFIX");
2676 case cmTarget::EXECUTABLE:
2677 return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
2678 default:
2679 break;
2681 return "";
2684 //----------------------------------------------------------------------------
2685 std::string cmTarget::GetPDBName(const char* config)
2687 std::string prefix;
2688 std::string base;
2689 std::string suffix;
2690 this->GetFullNameInternal(config, false, prefix, base, suffix);
2691 return prefix+base+".pdb";
2694 //----------------------------------------------------------------------------
2695 std::string cmTarget::GetSOName(const char* config)
2697 if(this->IsImported())
2699 // Lookup the imported soname.
2700 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
2702 if(info->NoSOName)
2704 // The imported library has no builtin soname so the name
2705 // searched at runtime will be just the filename.
2706 return cmSystemTools::GetFilenameName(info->Location);
2708 else
2710 // Use the soname given if any.
2711 return info->SOName;
2714 else
2716 return "";
2719 else
2721 // Compute the soname that will be built.
2722 std::string name;
2723 std::string soName;
2724 std::string realName;
2725 std::string impName;
2726 std::string pdbName;
2727 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
2728 return soName;
2732 //----------------------------------------------------------------------------
2733 bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
2735 if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
2737 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
2739 return info->NoSOName;
2742 return false;
2745 //----------------------------------------------------------------------------
2746 std::string cmTarget::NormalGetRealName(const char* config)
2748 // This should not be called for imported targets.
2749 // TODO: Split cmTarget into a class hierarchy to get compile-time
2750 // enforcement of the limited imported target API.
2751 if(this->IsImported())
2753 std::string msg = "NormalGetRealName called on imported target: ";
2754 msg += this->GetName();
2755 this->GetMakefile()->
2756 IssueMessage(cmake::INTERNAL_ERROR,
2757 msg.c_str());
2760 if(this->GetType() == cmTarget::EXECUTABLE)
2762 // Compute the real name that will be built.
2763 std::string name;
2764 std::string realName;
2765 std::string impName;
2766 std::string pdbName;
2767 this->GetExecutableNames(name, realName, impName, pdbName, config);
2768 return realName;
2770 else
2772 // Compute the real name that will be built.
2773 std::string name;
2774 std::string soName;
2775 std::string realName;
2776 std::string impName;
2777 std::string pdbName;
2778 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
2779 return realName;
2783 //----------------------------------------------------------------------------
2784 std::string cmTarget::GetFullName(const char* config, bool implib)
2786 if(this->IsImported())
2788 return this->GetFullNameImported(config, implib);
2790 else
2792 return this->GetFullNameInternal(config, implib);
2796 //----------------------------------------------------------------------------
2797 std::string cmTarget::GetFullNameImported(const char* config, bool implib)
2799 return cmSystemTools::GetFilenameName(
2800 this->ImportedGetFullPath(config, implib));
2803 //----------------------------------------------------------------------------
2804 void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
2805 std::string& suffix, const char* config,
2806 bool implib)
2808 this->GetFullNameInternal(config, implib, prefix, base, suffix);
2811 //----------------------------------------------------------------------------
2812 std::string cmTarget::GetFullPath(const char* config, bool implib,
2813 bool realname)
2815 if(this->IsImported())
2817 return this->ImportedGetFullPath(config, implib);
2819 else
2821 return this->NormalGetFullPath(config, implib, realname);
2825 //----------------------------------------------------------------------------
2826 std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
2827 bool realname)
2829 // Start with the output directory for the target.
2830 std::string fpath = this->GetDirectory(config, implib);
2831 fpath += "/";
2833 if(this->IsAppBundleOnApple())
2835 fpath += this->GetFullName(config, false);
2836 fpath += ".app/Contents/MacOS/";
2838 if(this->IsFrameworkOnApple())
2840 fpath += this->GetFullName(config, false);
2841 fpath += ".framework/Versions/";
2842 fpath += this->GetFrameworkVersion();
2843 fpath += "/";
2846 // Add the full name of the target.
2847 if(implib)
2849 fpath += this->GetFullName(config, true);
2851 else if(realname)
2853 fpath += this->NormalGetRealName(config);
2855 else
2857 fpath += this->GetFullName(config, false);
2859 return fpath;
2862 //----------------------------------------------------------------------------
2863 std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
2865 std::string result;
2866 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
2868 result = implib? info->ImportLibrary : info->Location;
2870 if(result.empty())
2872 result = this->GetName();
2873 result += "-NOTFOUND";
2875 return result;
2878 //----------------------------------------------------------------------------
2879 std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
2881 std::string prefix;
2882 std::string base;
2883 std::string suffix;
2884 this->GetFullNameInternal(config, implib, prefix, base, suffix);
2885 return prefix+base+suffix;
2888 //----------------------------------------------------------------------------
2889 void cmTarget::GetFullNameInternal(const char* config,
2890 bool implib,
2891 std::string& outPrefix,
2892 std::string& outBase,
2893 std::string& outSuffix)
2895 // Use just the target name for non-main target types.
2896 if(this->GetType() != cmTarget::STATIC_LIBRARY &&
2897 this->GetType() != cmTarget::SHARED_LIBRARY &&
2898 this->GetType() != cmTarget::MODULE_LIBRARY &&
2899 this->GetType() != cmTarget::EXECUTABLE)
2901 outPrefix = "";
2902 outBase = this->GetName();
2903 outSuffix = "";
2904 return;
2907 // Return an empty name for the import library if this platform
2908 // does not support import libraries.
2909 if(implib &&
2910 !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
2912 outPrefix = "";
2913 outBase = "";
2914 outSuffix = "";
2915 return;
2918 // The implib option is only allowed for shared libraries, module
2919 // libraries, and executables.
2920 if(this->GetType() != cmTarget::SHARED_LIBRARY &&
2921 this->GetType() != cmTarget::MODULE_LIBRARY &&
2922 this->GetType() != cmTarget::EXECUTABLE)
2924 implib = false;
2927 // Compute the full name for main target types.
2928 const char* targetPrefix = (implib
2929 ? this->GetProperty("IMPORT_PREFIX")
2930 : this->GetProperty("PREFIX"));
2931 const char* targetSuffix = (implib
2932 ? this->GetProperty("IMPORT_SUFFIX")
2933 : this->GetProperty("SUFFIX"));
2934 const char* configPostfix = 0;
2935 if(config && *config)
2937 std::string configProp = cmSystemTools::UpperCase(config);
2938 configProp += "_POSTFIX";
2939 configPostfix = this->GetProperty(configProp.c_str());
2940 // Mac application bundles and frameworks have no postfix.
2941 if(configPostfix &&
2942 (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
2944 configPostfix = 0;
2947 const char* prefixVar = this->GetPrefixVariableInternal(implib);
2948 const char* suffixVar = this->GetSuffixVariableInternal(implib);
2950 // Check for language-specific default prefix and suffix.
2951 if(const char* ll = this->GetLinkerLanguage(config))
2953 if(!targetSuffix && suffixVar && *suffixVar)
2955 std::string langSuff = suffixVar + std::string("_") + ll;
2956 targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
2958 if(!targetPrefix && prefixVar && *prefixVar)
2960 std::string langPrefix = prefixVar + std::string("_") + ll;
2961 targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
2965 // if there is no prefix on the target use the cmake definition
2966 if(!targetPrefix && prefixVar)
2968 targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
2970 // if there is no suffix on the target use the cmake definition
2971 if(!targetSuffix && suffixVar)
2973 targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
2976 // frameworks do not have a prefix or a suffix
2977 if(this->IsFrameworkOnApple())
2979 targetPrefix = 0;
2980 targetSuffix = 0;
2983 // Begin the final name with the prefix.
2984 outPrefix = targetPrefix?targetPrefix:"";
2986 // Append the target name or property-specified name.
2987 outBase += this->GetOutputName(config, implib);
2989 // Append the per-configuration postfix.
2990 outBase += configPostfix?configPostfix:"";
2992 // Name shared libraries with their version number on some platforms.
2993 if(const char* version = this->GetProperty("VERSION"))
2995 if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
2996 this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
2998 outBase += "-";
2999 outBase += version;
3003 // Append the suffix.
3004 outSuffix = targetSuffix?targetSuffix:"";
3007 //----------------------------------------------------------------------------
3008 void cmTarget::GetLibraryNames(std::string& name,
3009 std::string& soName,
3010 std::string& realName,
3011 std::string& impName,
3012 std::string& pdbName,
3013 const char* config)
3015 // This should not be called for imported targets.
3016 // TODO: Split cmTarget into a class hierarchy to get compile-time
3017 // enforcement of the limited imported target API.
3018 if(this->IsImported())
3020 std::string msg = "GetLibraryNames called on imported target: ";
3021 msg += this->GetName();
3022 this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
3023 msg.c_str());
3024 return;
3027 // Construct the name of the soname flag variable for this language.
3028 const char* ll = this->GetLinkerLanguage(config);
3029 std::string sonameFlag = "CMAKE_SHARED_LIBRARY_SONAME";
3030 if(ll)
3032 sonameFlag += "_";
3033 sonameFlag += ll;
3035 sonameFlag += "_FLAG";
3037 // Check for library version properties.
3038 const char* version = this->GetProperty("VERSION");
3039 const char* soversion = this->GetProperty("SOVERSION");
3040 if((this->GetType() != cmTarget::SHARED_LIBRARY &&
3041 this->GetType() != cmTarget::MODULE_LIBRARY) ||
3042 !this->Makefile->GetDefinition(sonameFlag.c_str()) ||
3043 this->IsFrameworkOnApple())
3045 // Versioning is supported only for shared libraries and modules,
3046 // and then only when the platform supports an soname flag.
3047 version = 0;
3048 soversion = 0;
3050 if(version && !soversion)
3052 // The soversion must be set if the library version is set. Use
3053 // the library version as the soversion.
3054 soversion = version;
3057 // Get the components of the library name.
3058 std::string prefix;
3059 std::string base;
3060 std::string suffix;
3061 this->GetFullNameInternal(config, false, prefix, base, suffix);
3063 // The library name.
3064 name = prefix+base+suffix;
3066 // The library's soname.
3067 #if defined(__APPLE__)
3068 soName = prefix+base;
3069 #else
3070 soName = name;
3071 #endif
3072 if(soversion)
3074 soName += ".";
3075 soName += soversion;
3077 #if defined(__APPLE__)
3078 soName += suffix;
3079 #endif
3081 // The library's real name on disk.
3082 #if defined(__APPLE__)
3083 realName = prefix+base;
3084 #else
3085 realName = name;
3086 #endif
3087 if(version)
3089 realName += ".";
3090 realName += version;
3092 else if(soversion)
3094 realName += ".";
3095 realName += soversion;
3097 #if defined(__APPLE__)
3098 realName += suffix;
3099 #endif
3101 // The import library name.
3102 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3103 this->GetType() == cmTarget::MODULE_LIBRARY)
3105 impName = this->GetFullNameInternal(config, true);
3107 else
3109 impName = "";
3112 // The program database file name.
3113 pdbName = prefix+base+".pdb";
3116 //----------------------------------------------------------------------------
3117 void cmTarget::GetExecutableNames(std::string& name,
3118 std::string& realName,
3119 std::string& impName,
3120 std::string& pdbName,
3121 const char* config)
3123 // This should not be called for imported targets.
3124 // TODO: Split cmTarget into a class hierarchy to get compile-time
3125 // enforcement of the limited imported target API.
3126 if(this->IsImported())
3128 std::string msg =
3129 "GetExecutableNames called on imported target: ";
3130 msg += this->GetName();
3131 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
3134 // This versioning is supported only for executables and then only
3135 // when the platform supports symbolic links.
3136 #if defined(_WIN32) && !defined(__CYGWIN__)
3137 const char* version = 0;
3138 #else
3139 // Check for executable version properties.
3140 const char* version = this->GetProperty("VERSION");
3141 if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
3143 version = 0;
3145 #endif
3147 // Get the components of the executable name.
3148 std::string prefix;
3149 std::string base;
3150 std::string suffix;
3151 this->GetFullNameInternal(config, false, prefix, base, suffix);
3153 // The executable name.
3154 name = prefix+base+suffix;
3156 // The executable's real name on disk.
3157 #if defined(__CYGWIN__)
3158 realName = prefix+base;
3159 #else
3160 realName = name;
3161 #endif
3162 if(version)
3164 realName += "-";
3165 realName += version;
3167 #if defined(__CYGWIN__)
3168 realName += suffix;
3169 #endif
3171 // The import library name.
3172 impName = this->GetFullNameInternal(config, true);
3174 // The program database file name.
3175 pdbName = prefix+base+".pdb";
3178 //----------------------------------------------------------------------------
3179 void cmTarget::GenerateTargetManifest(const char* config)
3181 cmMakefile* mf = this->Makefile;
3182 cmLocalGenerator* lg = mf->GetLocalGenerator();
3183 cmGlobalGenerator* gg = lg->GetGlobalGenerator();
3185 // Get the names.
3186 std::string name;
3187 std::string soName;
3188 std::string realName;
3189 std::string impName;
3190 std::string pdbName;
3191 if(this->GetType() == cmTarget::EXECUTABLE)
3193 this->GetExecutableNames(name, realName, impName, pdbName, config);
3195 else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
3196 this->GetType() == cmTarget::SHARED_LIBRARY ||
3197 this->GetType() == cmTarget::MODULE_LIBRARY)
3199 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
3201 else
3203 return;
3206 // Get the directory.
3207 std::string dir = this->GetDirectory(config, false);
3209 // Add each name.
3210 std::string f;
3211 if(!name.empty())
3213 f = dir;
3214 f += "/";
3215 f += name;
3216 gg->AddToManifest(config? config:"", f);
3218 if(!soName.empty())
3220 f = dir;
3221 f += "/";
3222 f += soName;
3223 gg->AddToManifest(config? config:"", f);
3225 if(!realName.empty())
3227 f = dir;
3228 f += "/";
3229 f += realName;
3230 gg->AddToManifest(config? config:"", f);
3232 if(!pdbName.empty())
3234 f = dir;
3235 f += "/";
3236 f += pdbName;
3237 gg->AddToManifest(config? config:"", f);
3239 if(!impName.empty())
3241 f = this->GetDirectory(config, true);
3242 f += "/";
3243 f += impName;
3244 gg->AddToManifest(config? config:"", f);
3248 //----------------------------------------------------------------------------
3249 void cmTarget::SetPropertyDefault(const char* property,
3250 const char* default_value)
3252 // Compute the name of the variable holding the default value.
3253 std::string var = "CMAKE_";
3254 var += property;
3256 if(const char* value = this->Makefile->GetDefinition(var.c_str()))
3258 this->SetProperty(property, value);
3260 else if(default_value)
3262 this->SetProperty(property, default_value);
3266 //----------------------------------------------------------------------------
3267 bool cmTarget::HaveBuildTreeRPATH()
3269 return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
3270 !this->LinkLibraries.empty());
3273 //----------------------------------------------------------------------------
3274 bool cmTarget::HaveInstallTreeRPATH()
3276 const char* install_rpath = this->GetProperty("INSTALL_RPATH");
3277 return install_rpath && *install_rpath;
3280 //----------------------------------------------------------------------------
3281 bool cmTarget::NeedRelinkBeforeInstall(const char* config)
3283 // Only executables and shared libraries can have an rpath and may
3284 // need relinking.
3285 if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
3286 this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
3287 this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
3289 return false;
3292 // If there is no install location this target will not be installed
3293 // and therefore does not need relinking.
3294 if(!this->GetHaveInstallRule())
3296 return false;
3299 // If skipping all rpaths completely then no relinking is needed.
3300 if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
3302 return false;
3305 // If building with the install-tree rpath no relinking is needed.
3306 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3308 return false;
3311 // If chrpath is going to be used no relinking is needed.
3312 if(this->IsChrpathUsed(config))
3314 return false;
3317 // Check for rpath support on this platform.
3318 if(const char* ll = this->GetLinkerLanguage(config))
3320 std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
3321 flagVar += ll;
3322 flagVar += "_FLAG";
3323 if(!this->Makefile->IsSet(flagVar.c_str()))
3325 // There is no rpath support on this platform so nothing needs
3326 // relinking.
3327 return false;
3330 else
3332 // No linker language is known. This error will be reported by
3333 // other code.
3334 return false;
3337 // If either a build or install tree rpath is set then the rpath
3338 // will likely change between the build tree and install tree and
3339 // this target must be relinked.
3340 return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
3343 //----------------------------------------------------------------------------
3344 std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
3345 bool for_xcode)
3347 // If building directly for installation then the build tree install_name
3348 // is the same as the install tree.
3349 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3351 return GetInstallNameDirForInstallTree(config, for_xcode);
3354 // Use the build tree directory for the target.
3355 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3356 !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
3357 !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
3359 std::string dir = this->GetDirectory(config);
3360 dir += "/";
3361 if(this->IsFrameworkOnApple() && !for_xcode)
3363 dir += this->GetFullName(config, false);
3364 dir += ".framework/Versions/";
3365 dir += this->GetFrameworkVersion();
3366 dir += "/";
3368 return dir;
3370 else
3372 return "";
3376 //----------------------------------------------------------------------------
3377 std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
3378 bool for_xcode)
3380 // Lookup the target property.
3381 const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
3382 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3383 !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
3384 install_name_dir && *install_name_dir)
3386 std::string dir = install_name_dir;
3387 dir += "/";
3388 if(this->IsFrameworkOnApple() && !for_xcode)
3390 dir += this->GetFullName(config, false);
3391 dir += ".framework/Versions/";
3392 dir += this->GetFrameworkVersion();
3393 dir += "/";
3395 return dir;
3397 else
3399 return "";
3403 //----------------------------------------------------------------------------
3404 const char* cmTarget::GetOutputTargetType(bool implib)
3406 switch(this->GetType())
3408 case cmTarget::SHARED_LIBRARY:
3409 if(this->DLLPlatform)
3411 if(implib)
3413 // A DLL import library is treated as an archive target.
3414 return "ARCHIVE";
3416 else
3418 // A DLL shared library is treated as a runtime target.
3419 return "RUNTIME";
3422 else
3424 // For non-DLL platforms shared libraries are treated as
3425 // library targets.
3426 return "LIBRARY";
3428 case cmTarget::STATIC_LIBRARY:
3429 // Static libraries are always treated as archive targets.
3430 return "ARCHIVE";
3431 case cmTarget::MODULE_LIBRARY:
3432 if(implib)
3434 // Module libraries are always treated as library targets.
3435 return "ARCHIVE";
3437 else
3439 // Module import libraries are treated as archive targets.
3440 return "LIBRARY";
3442 case cmTarget::EXECUTABLE:
3443 if(implib)
3445 // Executable import libraries are treated as archive targets.
3446 return "ARCHIVE";
3448 else
3450 // Executables are always treated as runtime targets.
3451 return "RUNTIME";
3453 default:
3454 break;
3456 return "";
3459 //----------------------------------------------------------------------------
3460 void cmTarget::ComputeOutputDir(const char* config,
3461 bool implib, std::string& out)
3463 // Look for a target property defining the target output directory
3464 // based on the target type.
3465 const char* propertyName = 0;
3466 std::string propertyNameStr = this->GetOutputTargetType(implib);
3467 if(!propertyNameStr.empty())
3469 propertyNameStr += "_OUTPUT_DIRECTORY";
3470 propertyName = propertyNameStr.c_str();
3473 // Select an output directory.
3474 if(const char* outdir = this->GetProperty(propertyName))
3476 // Use the user-specified output directory.
3477 out = outdir;
3479 else if(this->GetType() == cmTarget::EXECUTABLE)
3481 // Lookup the output path for executables.
3482 out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
3484 else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
3485 this->GetType() == cmTarget::SHARED_LIBRARY ||
3486 this->GetType() == cmTarget::MODULE_LIBRARY)
3488 // Lookup the output path for libraries.
3489 out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
3491 if(out.empty())
3493 // Default to the current output directory.
3494 out = ".";
3497 // Convert the output path to a full path in case it is
3498 // specified as a relative path. Treat a relative path as
3499 // relative to the current output directory for this makefile.
3500 out = (cmSystemTools::CollapseFullPath
3501 (out.c_str(), this->Makefile->GetStartOutputDirectory()));
3503 // The generator may add the configuration's subdirectory.
3504 if(config && *config)
3506 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
3507 AppendDirectoryForConfig("/", config, "", out);
3511 //----------------------------------------------------------------------------
3512 std::string cmTarget::GetOutputName(const char* config, bool implib)
3514 std::vector<std::string> props;
3515 std::string type = this->GetOutputTargetType(implib);
3516 std::string configUpper = cmSystemTools::UpperCase(config? config : "");
3517 if(!type.empty() && !configUpper.empty())
3519 // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
3520 props.push_back(type + "_OUTPUT_NAME_" + configUpper);
3522 if(!type.empty())
3524 // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
3525 props.push_back(type + "_OUTPUT_NAME");
3527 if(!configUpper.empty())
3529 // OUTPUT_NAME_<CONFIG>
3530 props.push_back("OUTPUT_NAME_" + configUpper);
3531 // <CONFIG>_OUTPUT_NAME
3532 props.push_back(configUpper + "_OUTPUT_NAME");
3534 // OUTPUT_NAME
3535 props.push_back("OUTPUT_NAME");
3537 for(std::vector<std::string>::const_iterator i = props.begin();
3538 i != props.end(); ++i)
3540 if(const char* outName = this->GetProperty(i->c_str()))
3542 return outName;
3545 return this->GetName();
3548 //----------------------------------------------------------------------------
3549 std::string cmTarget::GetFrameworkVersion()
3551 if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
3553 return fversion;
3555 else if(const char* tversion = this->GetProperty("VERSION"))
3557 return tversion;
3559 else
3561 return "A";
3565 //----------------------------------------------------------------------------
3566 const char* cmTarget::GetExportMacro()
3568 // Define the symbol for targets that export symbols.
3569 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3570 this->GetType() == cmTarget::MODULE_LIBRARY ||
3571 this->IsExecutableWithExports())
3573 if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
3575 this->ExportMacro = custom_export_name;
3577 else
3579 std::string in = this->GetName();
3580 in += "_EXPORTS";
3581 this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
3583 return this->ExportMacro.c_str();
3585 else
3587 return 0;
3591 //----------------------------------------------------------------------------
3592 void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
3594 for(std::vector<cmSourceFile*>::const_iterator
3595 i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
3597 if(const char* lang = (*i)->GetLanguage())
3599 languages.insert(lang);
3604 //----------------------------------------------------------------------------
3605 bool cmTarget::IsChrpathUsed(const char* config)
3607 #if defined(CMAKE_USE_ELF_PARSER)
3608 // Only certain target types have an rpath.
3609 if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
3610 this->GetType() == cmTarget::MODULE_LIBRARY ||
3611 this->GetType() == cmTarget::EXECUTABLE))
3613 return false;
3616 // If the target will not be installed we do not need to change its
3617 // rpath.
3618 if(!this->GetHaveInstallRule())
3620 return false;
3623 // Skip chrpath if skipping rpath altogether.
3624 if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
3626 return false;
3629 // Skip chrpath if it does not need to be changed at install time.
3630 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3632 return false;
3635 // Allow the user to disable builtin chrpath explicitly.
3636 if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
3638 return false;
3641 // Enable if the rpath flag uses a separator and the target uses ELF
3642 // binaries.
3643 if(const char* ll = this->GetLinkerLanguage(config))
3645 std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
3646 sepVar += ll;
3647 sepVar += "_FLAG_SEP";
3648 const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
3649 if(sep && *sep)
3651 // TODO: Add ELF check to ABI detection and get rid of
3652 // CMAKE_EXECUTABLE_FORMAT.
3653 if(const char* fmt =
3654 this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
3656 return strcmp(fmt, "ELF") == 0;
3660 #endif
3661 static_cast<void>(config);
3662 return false;
3665 //----------------------------------------------------------------------------
3666 cmTarget::ImportInfo const*
3667 cmTarget::GetImportInfo(const char* config)
3669 // There is no imported information for non-imported targets.
3670 if(!this->IsImported())
3672 return 0;
3675 // Lookup/compute/cache the import information for this
3676 // configuration.
3677 std::string config_upper;
3678 if(config && *config)
3680 config_upper = cmSystemTools::UpperCase(config);
3682 else
3684 config_upper = "NOCONFIG";
3686 typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
3687 ImportInfoMapType::const_iterator i =
3688 this->Internal->ImportInfoMap.find(config_upper);
3689 if(i == this->Internal->ImportInfoMap.end())
3691 ImportInfo info;
3692 this->ComputeImportInfo(config_upper, info);
3693 ImportInfoMapType::value_type entry(config_upper, info);
3694 i = this->Internal->ImportInfoMap.insert(entry).first;
3697 // If the location is empty then the target is not available for
3698 // this configuration.
3699 if(i->second.Location.empty() && i->second.ImportLibrary.empty())
3701 return 0;
3704 // Return the import information.
3705 return &i->second;
3708 //----------------------------------------------------------------------------
3709 void cmTarget::ComputeImportInfo(std::string const& desired_config,
3710 ImportInfo& info)
3712 // This method finds information about an imported target from its
3713 // properties. The "IMPORTED_" namespace is reserved for properties
3714 // defined by the project exporting the target.
3716 // Initialize members.
3717 info.NoSOName = false;
3719 // Track the configuration-specific property suffix.
3720 std::string suffix = "_";
3721 suffix += desired_config;
3723 // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
3724 // library or an executable with exports.
3725 bool allowImp = this->HasImportLibrary();
3727 // Look for a mapping from the current project's configuration to
3728 // the imported project's configuration.
3729 std::vector<std::string> mappedConfigs;
3731 std::string mapProp = "MAP_IMPORTED_CONFIG_";
3732 mapProp += desired_config;
3733 if(const char* mapValue = this->GetProperty(mapProp.c_str()))
3735 cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
3739 // If a mapping was found, check its configurations.
3740 const char* loc = 0;
3741 const char* imp = 0;
3742 for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
3743 !loc && !imp && mci != mappedConfigs.end(); ++mci)
3745 // Look for this configuration.
3746 std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
3747 std::string locProp = "IMPORTED_LOCATION_";
3748 locProp += mcUpper;
3749 loc = this->GetProperty(locProp.c_str());
3750 if(allowImp)
3752 std::string impProp = "IMPORTED_IMPLIB_";
3753 impProp += mcUpper;
3754 imp = this->GetProperty(impProp.c_str());
3757 // If it was found, use it for all properties below.
3758 if(loc || imp)
3760 suffix = "_";
3761 suffix += mcUpper;
3765 // If we needed to find one of the mapped configurations but did not
3766 // then the target is not found. The project does not want any
3767 // other configuration.
3768 if(!mappedConfigs.empty() && !loc && !imp)
3770 return;
3773 // If we have not yet found it then there are no mapped
3774 // configurations. Look for an exact-match.
3775 if(!loc && !imp)
3777 std::string locProp = "IMPORTED_LOCATION";
3778 locProp += suffix;
3779 loc = this->GetProperty(locProp.c_str());
3780 if(allowImp)
3782 std::string impProp = "IMPORTED_IMPLIB";
3783 impProp += suffix;
3784 imp = this->GetProperty(impProp.c_str());
3788 // If we have not yet found it then there are no mapped
3789 // configurations and no exact match.
3790 if(!loc && !imp)
3792 // The suffix computed above is not useful.
3793 suffix = "";
3795 // Look for a configuration-less location. This may be set by
3796 // manually-written code.
3797 loc = this->GetProperty("IMPORTED_LOCATION");
3798 if(allowImp)
3800 imp = this->GetProperty("IMPORTED_IMPLIB");
3804 // If we have not yet found it then the project is willing to try
3805 // any available configuration.
3806 if(!loc && !imp)
3808 std::vector<std::string> availableConfigs;
3809 if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
3811 cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
3813 for(std::vector<std::string>::const_iterator
3814 aci = availableConfigs.begin();
3815 !loc && !imp && aci != availableConfigs.end(); ++aci)
3817 suffix = "_";
3818 suffix += cmSystemTools::UpperCase(*aci);
3819 std::string locProp = "IMPORTED_LOCATION";
3820 locProp += suffix;
3821 loc = this->GetProperty(locProp.c_str());
3822 if(allowImp)
3824 std::string impProp = "IMPORTED_IMPLIB";
3825 impProp += suffix;
3826 imp = this->GetProperty(impProp.c_str());
3831 // If we have not yet found it then the target is not available.
3832 if(!loc && !imp)
3834 return;
3837 // A provided configuration has been chosen. Load the
3838 // configuration's properties.
3840 // Get the location.
3841 if(loc)
3843 info.Location = loc;
3845 else
3847 std::string impProp = "IMPORTED_LOCATION";
3848 impProp += suffix;
3849 if(const char* config_location = this->GetProperty(impProp.c_str()))
3851 info.Location = config_location;
3853 else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
3855 info.Location = location;
3859 // Get the soname.
3860 if(this->GetType() == cmTarget::SHARED_LIBRARY)
3862 std::string soProp = "IMPORTED_SONAME";
3863 soProp += suffix;
3864 if(const char* config_soname = this->GetProperty(soProp.c_str()))
3866 info.SOName = config_soname;
3868 else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
3870 info.SOName = soname;
3874 // Get the "no-soname" mark.
3875 if(this->GetType() == cmTarget::SHARED_LIBRARY)
3877 std::string soProp = "IMPORTED_NO_SONAME";
3878 soProp += suffix;
3879 if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
3881 info.NoSOName = cmSystemTools::IsOn(config_no_soname);
3883 else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
3885 info.NoSOName = cmSystemTools::IsOn(no_soname);
3889 // Get the import library.
3890 if(imp)
3892 info.ImportLibrary = imp;
3894 else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3895 this->IsExecutableWithExports())
3897 std::string impProp = "IMPORTED_IMPLIB";
3898 impProp += suffix;
3899 if(const char* config_implib = this->GetProperty(impProp.c_str()))
3901 info.ImportLibrary = config_implib;
3903 else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
3905 info.ImportLibrary = implib;
3909 // Get the link interface.
3911 std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
3912 linkProp += suffix;
3913 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
3915 cmSystemTools::ExpandListArgument(config_libs,
3916 info.LinkInterface.Libraries);
3918 else if(const char* libs =
3919 this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
3921 cmSystemTools::ExpandListArgument(libs,
3922 info.LinkInterface.Libraries);
3926 // Get the link dependencies.
3928 std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
3929 linkProp += suffix;
3930 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
3932 cmSystemTools::ExpandListArgument(config_libs,
3933 info.LinkInterface.SharedDeps);
3935 else if(const char* libs =
3936 this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
3938 cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
3942 // Get the link languages.
3943 if(this->GetType() == cmTarget::STATIC_LIBRARY)
3945 std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
3946 linkProp += suffix;
3947 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
3949 cmSystemTools::ExpandListArgument(config_libs,
3950 info.LinkInterface.Languages);
3952 else if(const char* libs =
3953 this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
3955 cmSystemTools::ExpandListArgument(libs,
3956 info.LinkInterface.Languages);
3960 // Get the cyclic repetition count.
3961 if(this->GetType() == cmTarget::STATIC_LIBRARY)
3963 std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
3964 linkProp += suffix;
3965 if(const char* config_reps = this->GetProperty(linkProp.c_str()))
3967 sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
3969 else if(const char* reps =
3970 this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
3972 sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
3977 //----------------------------------------------------------------------------
3978 cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config)
3980 // Imported targets have their own link interface.
3981 if(this->IsImported())
3983 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
3985 return &info->LinkInterface;
3987 return 0;
3990 // Link interfaces are not supported for executables that do not
3991 // export symbols.
3992 if(this->GetType() == cmTarget::EXECUTABLE &&
3993 !this->IsExecutableWithExports())
3995 return 0;
3998 // Lookup any existing link interface for this configuration.
3999 std::string key = cmSystemTools::UpperCase(config? config : "");
4000 cmTargetInternals::LinkInterfaceMapType::iterator
4001 i = this->Internal->LinkInterfaceMap.find(key);
4002 if(i == this->Internal->LinkInterfaceMap.end())
4004 // Compute the link interface for this configuration.
4005 cmTargetInternals::OptionalLinkInterface iface;
4006 iface.Exists = this->ComputeLinkInterface(config, iface);
4008 // Store the information for this configuration.
4009 cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
4010 i = this->Internal->LinkInterfaceMap.insert(entry).first;
4013 return i->second.Exists? &i->second : 0;
4016 //----------------------------------------------------------------------------
4017 bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface)
4019 // Construct the property name suffix for this configuration.
4020 std::string suffix = "_";
4021 if(config && *config)
4023 suffix += cmSystemTools::UpperCase(config);
4025 else
4027 suffix += "NOCONFIG";
4030 // An explicit list of interface libraries may be set for shared
4031 // libraries and executables that export symbols.
4032 const char* explicitLibraries = 0;
4033 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
4034 this->IsExecutableWithExports())
4036 // Lookup the per-configuration property.
4037 std::string propName = "LINK_INTERFACE_LIBRARIES";
4038 propName += suffix;
4039 explicitLibraries = this->GetProperty(propName.c_str());
4041 // If not set, try the generic property.
4042 if(!explicitLibraries)
4044 explicitLibraries = this->GetProperty("LINK_INTERFACE_LIBRARIES");
4048 // There is no implicit link interface for executables, so if none
4049 // was explicitly set, there is no link interface.
4050 if(!explicitLibraries && this->GetType() == cmTarget::EXECUTABLE)
4052 return false;
4055 if(explicitLibraries)
4057 // The interface libraries have been explicitly set.
4058 cmSystemTools::ExpandListArgument(explicitLibraries, iface.Libraries);
4060 if(this->GetType() == cmTarget::SHARED_LIBRARY)
4062 // Shared libraries may have runtime implementation dependencies
4063 // on other shared libraries that are not in the interface.
4064 std::set<cmStdString> emitted;
4065 for(std::vector<std::string>::const_iterator
4066 li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
4068 emitted.insert(*li);
4070 LinkImplementation const* impl = this->GetLinkImplementation(config);
4071 for(std::vector<std::string>::const_iterator
4072 li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
4074 if(emitted.insert(*li).second)
4076 if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
4078 // This is a runtime dependency on another shared library.
4079 if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
4081 iface.SharedDeps.push_back(*li);
4084 else
4086 // TODO: Recognize shared library file names. Perhaps this
4087 // should be moved to cmComputeLinkInformation, but that creates
4088 // a chicken-and-egg problem since this list is needed for its
4089 // construction.
4095 else
4097 // The link implementation is the default link interface.
4098 LinkImplementation const* impl = this->GetLinkImplementation(config);
4099 iface.Libraries = impl->Libraries;
4100 iface.WrongConfigLibraries = impl->WrongConfigLibraries;
4101 if(this->GetType() == cmTarget::STATIC_LIBRARY)
4103 // Targets using this archive need its language runtime libraries.
4104 iface.Languages = impl->Languages;
4108 if(this->GetType() == cmTarget::STATIC_LIBRARY)
4110 // How many repetitions are needed if this library has cyclic
4111 // dependencies?
4112 std::string propName = "LINK_INTERFACE_MULTIPLICITY";
4113 propName += suffix;
4114 if(const char* config_reps = this->GetProperty(propName.c_str()))
4116 sscanf(config_reps, "%u", &iface.Multiplicity);
4118 else if(const char* reps =
4119 this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
4121 sscanf(reps, "%u", &iface.Multiplicity);
4125 return true;
4128 //----------------------------------------------------------------------------
4129 cmTarget::LinkImplementation const*
4130 cmTarget::GetLinkImplementation(const char* config)
4132 // There is no link implementation for imported targets.
4133 if(this->IsImported())
4135 return 0;
4138 // Lookup any existing link implementation for this configuration.
4139 std::string key = cmSystemTools::UpperCase(config? config : "");
4140 cmTargetInternals::LinkImplMapType::iterator
4141 i = this->Internal->LinkImplMap.find(key);
4142 if(i == this->Internal->LinkImplMap.end())
4144 // Compute the link implementation for this configuration.
4145 LinkImplementation impl;
4146 this->ComputeLinkImplementation(config, impl);
4148 // Store the information for this configuration.
4149 cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
4150 i = this->Internal->LinkImplMap.insert(entry).first;
4153 return &i->second;
4156 //----------------------------------------------------------------------------
4157 void cmTarget::ComputeLinkImplementation(const char* config,
4158 LinkImplementation& impl)
4160 // Compute which library configuration to link.
4161 cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
4163 // Collect libraries directly linked in this configuration.
4164 LinkLibraryVectorType const& llibs = this->GetOriginalLinkLibraries();
4165 for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
4166 li != llibs.end(); ++li)
4168 // Skip entries that resolve to the target itself or are empty.
4169 std::string item = this->CheckCMP0004(li->first);
4170 if(item == this->GetName() || item.empty())
4172 continue;
4175 if(li->second == cmTarget::GENERAL || li->second == linkType)
4177 // The entry is meant for this configuration.
4178 impl.Libraries.push_back(item);
4180 else
4182 // Support OLD behavior for CMP0003.
4183 impl.WrongConfigLibraries.push_back(item);
4187 // This target needs runtime libraries for its source languages.
4188 std::set<cmStdString> languages;
4189 this->GetLanguages(languages);
4190 for(std::set<cmStdString>::iterator li = languages.begin();
4191 li != languages.end(); ++li)
4193 impl.Languages.push_back(*li);
4197 //----------------------------------------------------------------------------
4198 std::string cmTarget::CheckCMP0004(std::string const& item)
4200 // Strip whitespace off the library names because we used to do this
4201 // in case variables were expanded at generate time. We no longer
4202 // do the expansion but users link to libraries like " ${VAR} ".
4203 std::string lib = item;
4204 std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
4205 if(pos != lib.npos)
4207 lib = lib.substr(pos, lib.npos);
4209 pos = lib.find_last_not_of(" \t\r\n");
4210 if(pos != lib.npos)
4212 lib = lib.substr(0, pos+1);
4214 if(lib != item)
4216 cmake* cm = this->Makefile->GetCMakeInstance();
4217 switch(this->PolicyStatusCMP0004)
4219 case cmPolicies::WARN:
4221 cmOStringStream w;
4222 w << (this->Makefile->GetPolicies()
4223 ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
4224 << "Target \"" << this->GetName() << "\" links to item \""
4225 << item << "\" which has leading or trailing whitespace.";
4226 cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
4227 this->GetBacktrace());
4229 case cmPolicies::OLD:
4230 break;
4231 case cmPolicies::NEW:
4233 cmOStringStream e;
4234 e << "Target \"" << this->GetName() << "\" links to item \""
4235 << item << "\" which has leading or trailing whitespace. "
4236 << "This is now an error according to policy CMP0004.";
4237 cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
4239 break;
4240 case cmPolicies::REQUIRED_IF_USED:
4241 case cmPolicies::REQUIRED_ALWAYS:
4243 cmOStringStream e;
4244 e << (this->Makefile->GetPolicies()
4245 ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
4246 << "Target \"" << this->GetName() << "\" links to item \""
4247 << item << "\" which has leading or trailing whitespace.";
4248 cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
4250 break;
4253 return lib;
4256 //----------------------------------------------------------------------------
4257 cmComputeLinkInformation*
4258 cmTarget::GetLinkInformation(const char* config)
4260 // Lookup any existing information for this configuration.
4261 std::map<cmStdString, cmComputeLinkInformation*>::iterator
4262 i = this->LinkInformation.find(config?config:"");
4263 if(i == this->LinkInformation.end())
4265 // Compute information for this configuration.
4266 cmComputeLinkInformation* info =
4267 new cmComputeLinkInformation(this, config);
4268 if(!info || !info->Compute())
4270 delete info;
4271 info = 0;
4274 // Store the information for this configuration.
4275 std::map<cmStdString, cmComputeLinkInformation*>::value_type
4276 entry(config?config:"", info);
4277 i = this->LinkInformation.insert(entry).first;
4279 return i->second;
4282 //----------------------------------------------------------------------------
4283 cmTargetLinkInformationMap
4284 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
4286 // Ideally cmTarget instances should never be copied. However until
4287 // we can make a sweep to remove that, this copy constructor avoids
4288 // allowing the resources (LinkInformation) from getting copied. In
4289 // the worst case this will lead to extra cmComputeLinkInformation
4290 // instances. We also enforce in debug mode that the map be emptied
4291 // when copied.
4292 static_cast<void>(r);
4293 assert(r.empty());
4296 //----------------------------------------------------------------------------
4297 cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
4299 for(derived::iterator i = this->begin(); i != this->end(); ++i)
4301 delete i->second;
4305 //----------------------------------------------------------------------------
4306 cmTargetInternalPointer::cmTargetInternalPointer()
4308 this->Pointer = new cmTargetInternals;
4311 //----------------------------------------------------------------------------
4312 cmTargetInternalPointer
4313 ::cmTargetInternalPointer(cmTargetInternalPointer const&)
4315 // Ideally cmTarget instances should never be copied. However until
4316 // we can make a sweep to remove that, this copy constructor avoids
4317 // allowing the resources (Internals) to be copied.
4318 this->Pointer = new cmTargetInternals;
4321 //----------------------------------------------------------------------------
4322 cmTargetInternalPointer::~cmTargetInternalPointer()
4324 delete this->Pointer;
4327 //----------------------------------------------------------------------------
4328 cmTargetInternalPointer&
4329 cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
4331 if(this == &r) { return *this; } // avoid warning on HP about self check
4332 // Ideally cmTarget instances should never be copied. However until
4333 // we can make a sweep to remove that, this copy constructor avoids
4334 // allowing the resources (Internals) to be copied.
4335 cmTargetInternals* oldPointer = this->Pointer;
4336 this->Pointer = new cmTargetInternals;
4337 delete oldPointer;
4338 return *this;