1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
14 #include "cmMakefile.h"
15 #include "cmSourceFile.h"
16 #include "cmLocalGenerator.h"
17 #include "cmGlobalGenerator.h"
18 #include "cmComputeLinkInformation.h"
19 #include "cmDocumentCompileDefinitions.h"
20 #include "cmDocumentLocationUndefined.h"
21 #include "cmListFileCache.h"
22 #include "cmGeneratorExpression.h"
23 #include <cmsys/RegularExpression.hxx>
27 #include <stdlib.h> // required for atof
30 const char* cmTarget::GetTargetTypeName(TargetType targetType)
34 case cmTarget::STATIC_LIBRARY:
35 return "STATIC_LIBRARY";
36 case cmTarget::MODULE_LIBRARY:
37 return "MODULE_LIBRARY";
38 case cmTarget::SHARED_LIBRARY:
39 return "SHARED_LIBRARY";
40 case cmTarget::OBJECT_LIBRARY:
41 return "OBJECT_LIBRARY";
42 case cmTarget::EXECUTABLE:
44 case cmTarget::UTILITY:
46 case cmTarget::GLOBAL_TARGET:
47 return "GLOBAL_TARGET";
48 case cmTarget::UNKNOWN_LIBRARY:
49 return "UNKNOWN_LIBRARY";
51 assert(0 && "Unexpected target type");
55 //----------------------------------------------------------------------------
56 struct cmTarget::OutputInfo
62 //----------------------------------------------------------------------------
63 struct cmTarget::ImportInfo
68 std::string ImportLibrary;
69 cmTarget::LinkInterface LinkInterface;
72 //----------------------------------------------------------------------------
73 class cmTargetInternals
78 this->SourceFileFlagsConstructed = false;
80 cmTargetInternals(cmTargetInternals const& r)
82 this->SourceFileFlagsConstructed = false;
83 // Only some of these entries are part of the object state.
84 // Others not copied here are result caches.
85 this->SourceEntries = r.SourceEntries;
87 typedef cmTarget::SourceFileFlags SourceFileFlags;
88 std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
89 bool SourceFileFlagsConstructed;
91 // The backtrace when the target was created.
92 cmListFileBacktrace Backtrace;
94 // Cache link interface computation from each configuration.
95 struct OptionalLinkInterface: public cmTarget::LinkInterface
97 OptionalLinkInterface(): Exists(false) {}
100 typedef std::map<cmStdString, OptionalLinkInterface> LinkInterfaceMapType;
101 LinkInterfaceMapType LinkInterfaceMap;
103 typedef std::map<cmStdString, cmTarget::OutputInfo> OutputInfoMapType;
104 OutputInfoMapType OutputInfoMap;
106 typedef std::map<cmStdString, cmTarget::ImportInfo> ImportInfoMapType;
107 ImportInfoMapType ImportInfoMap;
109 // Cache link implementation computation from each configuration.
110 typedef std::map<cmStdString, cmTarget::LinkImplementation> LinkImplMapType;
111 LinkImplMapType LinkImplMap;
113 typedef std::map<cmStdString, cmTarget::LinkClosure> LinkClosureMapType;
114 LinkClosureMapType LinkClosureMap;
116 struct SourceEntry { std::vector<cmSourceFile*> Depends; };
117 typedef std::map<cmSourceFile*, SourceEntry> SourceEntriesType;
118 SourceEntriesType SourceEntries;
121 //----------------------------------------------------------------------------
125 this->PolicyStatusCMP0003 = cmPolicies::WARN;
126 this->PolicyStatusCMP0004 = cmPolicies::WARN;
127 this->PolicyStatusCMP0008 = cmPolicies::WARN;
128 this->LinkLibrariesAnalyzed = false;
129 this->HaveInstallRule = false;
130 this->DLLPlatform = false;
131 this->IsApple = false;
132 this->IsImportedTarget = false;
135 //----------------------------------------------------------------------------
136 void cmTarget::DefineProperties(cmake *cm)
139 ("AUTOMOC", cmProperty::TARGET,
140 "Should the target be processed with automoc (for Qt projects).",
141 "AUTOMOC is a boolean specifying whether CMake will handle "
142 "the Qt moc preprocessor automatically, i.e. without having to use "
143 "the QT4_WRAP_CPP() macro. Currently Qt4 is supported. "
144 "When this property is set to TRUE, CMake will scan the source files "
145 "at build time and invoke moc accordingly. "
146 "If an #include statement like #include \"moc_foo.cpp\" is found, "
147 "the Q_OBJECT class declaration is expected in the header, and moc is "
148 "run on the header file. "
149 "If an #include statement like #include \"foo.moc\" is found, "
150 "then a Q_OBJECT is expected in the current source file and moc "
151 "is run on the file itself. "
152 "Additionally, all header files are parsed for Q_OBJECT macros, "
153 "and if found, moc is also executed on those files. The resulting "
154 "moc files, which are not included as shown above in any of the source "
155 "files are included in a generated <targetname>_automoc.cpp file, "
156 "which is compiled as part of the target."
157 "This property is initialized by the value of the variable "
158 "CMAKE_AUTOMOC if it is set when a target is created.\n"
159 "Additional command line options for moc can be set via the "
160 "AUTOMOC_MOC_OPTIONS property.\n"
161 "By setting the CMAKE_AUTOMOC_RELAXED_MODE variable to TRUE the rules "
162 "for searching the files which will be processed by moc can be relaxed. "
163 "See the documentation for this variable for more details.");
166 ("AUTOMOC_MOC_OPTIONS", cmProperty::TARGET,
167 "Additional options for moc when using automoc (see the AUTOMOC property)",
168 "This property is only used if the AUTOMOC property is set to TRUE for "
169 "this target. In this case, it holds additional command line options "
170 "which will be used when moc is executed during the build, i.e. it is "
171 "equivalent to the optional OPTIONS argument of the qt4_wrap_cpp() "
173 "By default it is empty.");
176 ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
177 "Should build tree targets have install tree rpaths.",
178 "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
179 "the target in the build tree with the INSTALL_RPATH. This takes "
180 "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
181 "before installation. "
182 "This property is initialized by the value of the variable "
183 "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
186 ("COMPILE_FLAGS", cmProperty::TARGET,
187 "Additional flags to use when compiling this target's sources.",
188 "The COMPILE_FLAGS property sets additional compiler flags used "
189 "to build sources within the target. Use COMPILE_DEFINITIONS "
190 "to pass additional preprocessor definitions.");
193 ("COMPILE_DEFINITIONS", cmProperty::TARGET,
194 "Preprocessor definitions for compiling a target's sources.",
195 "The COMPILE_DEFINITIONS property may be set to a "
196 "semicolon-separated list of preprocessor "
197 "definitions using the syntax VAR or VAR=value. Function-style "
198 "definitions are not supported. CMake will automatically escape "
199 "the value correctly for the native build system (note that CMake "
200 "language syntax may require escapes to specify some values). "
201 "This property may be set on a per-configuration basis using the name "
202 "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
203 "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
204 "CMake will automatically drop some definitions that "
205 "are not supported by the native build tool. "
206 "The VS6 IDE does not support definition values with spaces "
207 "(but NMake does).\n"
208 CM_DOCUMENT_COMPILE_DEFINITIONS_DISCLAIMER);
211 ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
212 "Per-configuration preprocessor definitions on a target.",
213 "This is the configuration-specific version of COMPILE_DEFINITIONS.");
216 ("DEFINE_SYMBOL", cmProperty::TARGET,
217 "Define a symbol when compiling this target's sources.",
218 "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
219 "compiling sources in a shared library. "
220 "If not set here then it is set to target_EXPORTS by default "
221 "(with some substitutions if the target is not a valid C "
222 "identifier). This is useful for headers to know whether they are "
223 "being included from inside their library our outside to properly "
224 "setup dllexport/dllimport decorations. ");
227 ("DEBUG_POSTFIX", cmProperty::TARGET,
228 "See target property <CONFIG>_POSTFIX.",
229 "This property is a special case of the more-general <CONFIG>_POSTFIX "
230 "property for the DEBUG configuration.");
233 ("<CONFIG>_POSTFIX", cmProperty::TARGET,
234 "Postfix to append to the target file name for configuration <CONFIG>.",
235 "When building with configuration <CONFIG> the value of this property "
236 "is appended to the target file name built on disk. "
237 "For non-executable targets, this property is initialized by the value "
238 "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
240 "This property is ignored on the Mac for Frameworks and App Bundles.");
243 ("EchoString", cmProperty::TARGET,
244 "A message to be displayed when the target is built.",
245 "A message to display on some generators (such as makefiles) when "
246 "the target is built.");
249 ("BUNDLE", cmProperty::TARGET,
250 "This target is a CFBundle on the Mac.",
251 "If a module library target has this property set to true it will "
252 "be built as a CFBundle when built on the mac. It will have the "
253 "directory structure required for a CFBundle and will be suitable "
254 "to be used for creating Browser Plugins or other application "
258 ("BUNDLE_EXTENSION", cmProperty::TARGET,
259 "The file extension used to name a BUNDLE target on the Mac.",
260 "The default value is \"bundle\" - you can also use \"plugin\" or "
261 "whatever file extension is required by the host app for your "
265 ("FRAMEWORK", cmProperty::TARGET,
266 "This target is a framework on the Mac.",
267 "If a shared library target has this property set to true it will "
268 "be built as a framework when built on the mac. It will have the "
269 "directory structure required for a framework and will be suitable "
270 "to be used with the -framework option");
273 ("HAS_CXX", cmProperty::TARGET,
274 "Link the target using the C++ linker tool (obsolete).",
275 "This is equivalent to setting the LINKER_LANGUAGE property to CXX. "
276 "See that property's documentation for details.");
279 ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
280 "Specify #include line transforms for dependencies in a target.",
281 "This property specifies rules to transform macro-like #include lines "
282 "during implicit dependency scanning of C and C++ source files. "
283 "The list of rules must be semicolon-separated with each entry of "
284 "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
285 "During dependency scanning occurrences of A_MACRO(...) on #include "
286 "lines will be replaced by the value given with the macro argument "
287 "substituted for '%'. For example, the entry\n"
288 " MYDIR(%)=<mydir/%>\n"
289 "will convert lines of the form\n"
290 " #include MYDIR(myheader.h)\n"
292 " #include <mydir/myheader.h>\n"
293 "allowing the dependency to be followed.\n"
294 "This property applies to sources in the target on which it is set.");
297 ("IMPORT_PREFIX", cmProperty::TARGET,
298 "What comes before the import library name.",
299 "Similar to the target property PREFIX, but used for import libraries "
300 "(typically corresponding to a DLL) instead of regular libraries. "
301 "A target property that can be set to override the prefix "
302 "(such as \"lib\") on an import library name.");
305 ("IMPORT_SUFFIX", cmProperty::TARGET,
306 "What comes after the import library name.",
307 "Similar to the target property SUFFIX, but used for import libraries "
308 "(typically corresponding to a DLL) instead of regular libraries. "
309 "A target property that can be set to override the suffix "
310 "(such as \".lib\") on an import library name.");
313 ("IMPORTED", cmProperty::TARGET,
314 "Read-only indication of whether a target is IMPORTED.",
315 "The boolean value of this property is true for targets created with "
316 "the IMPORTED option to add_executable or add_library. "
317 "It is false for targets built within the project.");
320 ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
321 "Configurations provided for an IMPORTED target.",
322 "Set this to the list of configuration names available for an "
324 "The names correspond to configurations defined in the project from "
325 "which the target is imported. "
326 "If the importing project uses a different set of configurations "
327 "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
329 "Ignored for non-imported targets.");
332 ("IMPORTED_IMPLIB", cmProperty::TARGET,
333 "Full path to the import library for an IMPORTED target.",
334 "Set this to the location of the \".lib\" part of a windows DLL. "
335 "Ignored for non-imported targets.");
338 ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
339 "<CONFIG>-specific version of IMPORTED_IMPLIB property.",
340 "Configuration names correspond to those provided by the project "
341 "from which the target is imported.");
344 ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
345 "Dependent shared libraries of an imported shared library.",
346 "Shared libraries may be linked to other shared libraries as part "
347 "of their implementation. On some platforms the linker searches "
348 "for the dependent libraries of shared libraries they are including "
350 "Set this property to the list of dependent shared libraries of an "
353 "should be disjoint from the list of interface libraries in the "
354 "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring "
355 "dependent shared libraries to be found at link time CMake uses this "
356 "list to add appropriate files or paths to the link command line. "
357 "Ignored for non-imported targets.");
360 ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
361 "<CONFIG>-specific version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
362 "Configuration names correspond to those provided by the project "
363 "from which the target is imported. "
364 "If set, this property completely overrides the generic property "
365 "for the named configuration.");
368 ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
369 "Transitive link interface of an IMPORTED target.",
370 "Set this to the list of libraries whose interface is included when "
371 "an IMPORTED library target is linked to another target. "
372 "The libraries will be included on the link line for the target. "
373 "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
374 "to all imported target types, including STATIC libraries. "
375 "This property is ignored for non-imported targets.");
378 ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
379 "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
380 "Configuration names correspond to those provided by the project "
381 "from which the target is imported. "
382 "If set, this property completely overrides the generic property "
383 "for the named configuration.");
386 ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET,
387 "Languages compiled into an IMPORTED static library.",
388 "Set this to the list of languages of source files compiled to "
389 "produce a STATIC IMPORTED library (such as \"C\" or \"CXX\"). "
390 "CMake accounts for these languages when computing how to link a "
391 "target to the imported library. "
392 "For example, when a C executable links to an imported C++ static "
393 "library CMake chooses the C++ linker to satisfy language runtime "
394 "dependencies of the static library. "
396 "This property is ignored for targets that are not STATIC libraries. "
397 "This property is ignored for non-imported targets.");
400 ("IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>", cmProperty::TARGET,
401 "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LANGUAGES.",
402 "Configuration names correspond to those provided by the project "
403 "from which the target is imported. "
404 "If set, this property completely overrides the generic property "
405 "for the named configuration.");
408 ("IMPORTED_LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
409 "Repetition count for cycles of IMPORTED static libraries.",
410 "This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.");
412 ("IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
413 "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_MULTIPLICITY.",
414 "If set, this property completely overrides the generic property "
415 "for the named configuration.");
418 ("IMPORTED_LOCATION", cmProperty::TARGET,
419 "Full path to the main file on disk for an IMPORTED target.",
420 "Set this to the location of an IMPORTED target file on disk. "
421 "For executables this is the location of the executable file. "
422 "For bundles on OS X this is the location of the executable file "
423 "inside Contents/MacOS under the application bundle folder. "
424 "For static libraries and modules this is the location of the "
425 "library or module. "
426 "For shared libraries on non-DLL platforms this is the location of "
427 "the shared library. "
428 "For frameworks on OS X this is the location of the library file "
429 "symlink just inside the framework folder. "
430 "For DLLs this is the location of the \".dll\" part of the library. "
431 "For UNKNOWN libraries this is the location of the file to be linked. "
432 "Ignored for non-imported targets."
434 "Projects may skip IMPORTED_LOCATION if the configuration-specific "
435 "property IMPORTED_LOCATION_<CONFIG> is set. "
436 "To get the location of an imported target read one of the "
437 "LOCATION or LOCATION_<CONFIG> properties.");
440 ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
441 "<CONFIG>-specific version of IMPORTED_LOCATION property.",
442 "Configuration names correspond to those provided by the project "
443 "from which the target is imported.");
446 ("IMPORTED_SONAME", cmProperty::TARGET,
447 "The \"soname\" of an IMPORTED target of shared library type.",
448 "Set this to the \"soname\" embedded in an imported shared library. "
449 "This is meaningful only on platforms supporting the feature. "
450 "Ignored for non-imported targets.");
453 ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
454 "<CONFIG>-specific version of IMPORTED_SONAME property.",
455 "Configuration names correspond to those provided by the project "
456 "from which the target is imported.");
459 ("IMPORTED_NO_SONAME", cmProperty::TARGET,
460 "Specifies that an IMPORTED shared library target has no \"soname\". ",
461 "Set this property to true for an imported shared library file that "
462 "has no \"soname\" field. "
463 "CMake may adjust generated link commands for some platforms to prevent "
464 "the linker from using the path to the library in place of its missing "
466 "Ignored for non-imported targets.");
469 ("IMPORTED_NO_SONAME_<CONFIG>", cmProperty::TARGET,
470 "<CONFIG>-specific version of IMPORTED_NO_SONAME property.",
471 "Configuration names correspond to those provided by the project "
472 "from which the target is imported.");
475 ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
476 "Exclude the target from the all target.",
477 "A property on a target that indicates if the target is excluded "
478 "from the default build target. If it is not, then with a Makefile "
479 "for example typing make will cause this target to be built. "
480 "The same concept applies to the default build of other generators. "
481 "Installing a target with EXCLUDE_FROM_ALL set to true has "
482 "undefined behavior.");
485 ("INCLUDE_DIRECTORIES", cmProperty::TARGET,
486 "List of preprocessor include file search directories.",
487 "This property specifies the list of directories given "
488 "so far to the include_directories command. "
489 "This property exists on directories and targets. "
490 "In addition to accepting values from the include_directories "
491 "command, values may be set directly on any directory or any "
492 "target using the set_property command. "
493 "A target gets its initial value for this property from the value "
494 "of the directory property. "
495 "A directory gets its initial value from its parent directory if "
497 "Both directory and target property values are adjusted by calls "
498 "to the include_directories command."
500 "The target property values are used by the generators to set "
501 "the include paths for the compiler. "
502 "See also the include_directories command.");
505 ("INSTALL_NAME_DIR", cmProperty::TARGET,
506 "Mac OSX directory name for installed targets.",
507 "INSTALL_NAME_DIR is a string specifying the "
508 "directory portion of the \"install_name\" field of shared libraries "
509 "on Mac OSX to use in the installed targets. ");
512 ("INSTALL_RPATH", cmProperty::TARGET,
513 "The rpath to use for installed targets.",
514 "A semicolon-separated list specifying the rpath "
515 "to use in installed targets (for platforms that support it). "
516 "This property is initialized by the value of the variable "
517 "CMAKE_INSTALL_RPATH if it is set when a target is created.");
520 ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
521 "Add paths to linker search and installed rpath.",
522 "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
523 "append directories in the linker search path and outside the "
524 "project to the INSTALL_RPATH. "
525 "This property is initialized by the value of the variable "
526 "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
530 ("INTERPROCEDURAL_OPTIMIZATION", cmProperty::TARGET,
531 "Enable interprocedural optimization for a target.",
532 "If set to true, enables interprocedural optimizations "
533 "if they are known to be supported by the compiler.");
536 ("INTERPROCEDURAL_OPTIMIZATION_<CONFIG>", cmProperty::TARGET,
537 "Per-configuration interprocedural optimization for a target.",
538 "This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION. "
539 "If set, this property overrides the generic property "
540 "for the named configuration.");
543 ("LABELS", cmProperty::TARGET,
544 "Specify a list of text labels associated with a target.",
545 "Target label semantics are currently unspecified.");
548 ("LINK_FLAGS", cmProperty::TARGET,
549 "Additional flags to use when linking this target.",
550 "The LINK_FLAGS property can be used to add extra flags to the "
551 "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
552 "configuration <CONFIG>, "
553 "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
556 ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
557 "Per-configuration linker flags for a target.",
558 "This is the configuration-specific version of LINK_FLAGS.");
560 #define CM_LINK_SEARCH_SUMMARY \
561 "Some linkers support switches such as -Bstatic and -Bdynamic " \
562 "to determine whether to use static or shared libraries for -lXXX " \
563 "options. CMake uses these options to set the link type for " \
564 "libraries whose full paths are not known or (in some cases) are in " \
565 "implicit link directories for the platform. "
568 ("LINK_SEARCH_START_STATIC", cmProperty::TARGET,
569 "Assume the linker looks for static libraries by default.",
570 CM_LINK_SEARCH_SUMMARY
571 "By default the linker search type is assumed to be -Bdynamic at "
572 "the beginning of the library list. This property switches the "
573 "assumption to -Bstatic. It is intended for use when linking an "
574 "executable statically (e.g. with the GNU -static option). "
575 "See also LINK_SEARCH_END_STATIC.");
578 ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
579 "End a link line such that static system libraries are used.",
580 CM_LINK_SEARCH_SUMMARY
581 "By default CMake adds an option at the end of the library list (if "
582 "necessary) to set the linker search type back to its starting type. "
583 "This property switches the final linker search type to -Bstatic "
584 "regardless of how it started. "
585 "See also LINK_SEARCH_START_STATIC.");
588 ("LINKER_LANGUAGE", cmProperty::TARGET,
589 "Specifies language whose compiler will invoke the linker.",
590 "For executables, shared libraries, and modules, this sets the "
591 "language whose compiler is used to link the target "
592 "(such as \"C\" or \"CXX\"). "
593 "A typical value for an executable is the language of the source "
594 "file providing the program entry point (main). "
595 "If not set, the language with the highest linker preference "
596 "value is the default. "
597 "See documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables.");
600 ("LOCATION", cmProperty::TARGET,
601 "Read-only location of a target on disk.",
602 "For an imported target, this read-only property returns the value of "
603 "the LOCATION_<CONFIG> property for an unspecified configuration "
604 "<CONFIG> provided by the target.\n"
605 "For a non-imported target, this property is provided for compatibility "
606 "with CMake 2.4 and below. "
607 "It was meant to get the location of an executable target's output file "
608 "for use in add_custom_command. "
609 "The path may contain a build-system-specific portion that "
610 "is replaced at build time with the configuration getting built "
611 "(such as \"$(ConfigurationName)\" in VS). "
612 "In CMake 2.6 and above add_custom_command automatically recognizes a "
613 "target name in its COMMAND and DEPENDS options and computes the "
615 "In CMake 2.8.4 and above add_custom_command recognizes generator "
616 "expressions to refer to target locations anywhere in the command. "
617 "Therefore this property is not needed for creating custom commands."
618 CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
621 ("LOCATION_<CONFIG>", cmProperty::TARGET,
622 "Read-only property providing a target location on disk.",
623 "A read-only property that indicates where a target's main file is "
624 "located on disk for the configuration <CONFIG>. "
625 "The property is defined only for library and executable targets. "
626 "An imported target may provide a set of configurations different "
627 "from that of the importing project. "
628 "By default CMake looks for an exact-match but otherwise uses an "
629 "arbitrary available configuration. "
630 "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
631 "configurations explicitly."
632 CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
635 ("LINK_DEPENDS", cmProperty::TARGET,
636 "Additional files on which a target binary depends for linking.",
637 "Specifies a semicolon-separated list of full-paths to files on which "
638 "the link rule for this target depends. "
639 "The target binary will be linked if any of the named files is newer "
642 "This property is ignored by non-Makefile generators. "
643 "It is intended to specify dependencies on \"linker scripts\" for "
644 "custom Makefile link rules.");
647 ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
648 "List public interface libraries for a shared library or executable.",
649 "By default linking to a shared library target transitively "
650 "links to targets with which the library itself was linked. "
651 "For an executable with exports (see the ENABLE_EXPORTS property) "
652 "no default transitive link dependencies are used. "
653 "This property replaces the default transitive link dependencies with "
655 "When the target is linked into another target the libraries "
656 "listed (and recursively their link interface libraries) will be "
657 "provided to the other target also. "
658 "If the list is empty then no transitive link dependencies will be "
659 "incorporated when this target is linked into another target even if "
660 "the default set is non-empty. "
661 "This property is initialized by the value of the variable "
662 "CMAKE_LINK_INTERFACE_LIBRARIES if it is set when a target is "
664 "This property is ignored for STATIC libraries.");
667 ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
668 "Per-configuration list of public interface libraries for a target.",
669 "This is the configuration-specific version of "
670 "LINK_INTERFACE_LIBRARIES. "
671 "If set, this property completely overrides the generic property "
672 "for the named configuration.");
675 ("LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
676 "Repetition count for STATIC libraries with cyclic dependencies.",
677 "When linking to a STATIC library target with cyclic dependencies the "
678 "linker may need to scan more than once through the archives in the "
679 "strongly connected component of the dependency graph. "
680 "CMake by default constructs the link line so that the linker will "
681 "scan through the component at least twice. "
682 "This property specifies the minimum number of scans if it is larger "
684 "CMake uses the largest value specified by any target in a component.");
686 ("LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
687 "Per-configuration repetition count for cycles of STATIC libraries.",
688 "This is the configuration-specific version of "
689 "LINK_INTERFACE_MULTIPLICITY. "
690 "If set, this property completely overrides the generic property "
691 "for the named configuration.");
694 ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
695 "Map from project configuration to IMPORTED target's configuration.",
696 "Set this to the list of configurations of an imported target that "
697 "may be used for the current project's <CONFIG> configuration. "
698 "Targets imported from another project may not provide the same set "
699 "of configuration names available in the current project. "
700 "Setting this property tells CMake what imported configurations are "
701 "suitable for use when building the <CONFIG> configuration. "
702 "The first configuration in the list found to be provided by the "
703 "imported target is selected. If this property is set and no matching "
704 "configurations are available, then the imported target is considered "
705 "to be not found. This property is ignored for non-imported targets.",
706 false /* TODO: make this chained */ );
709 ("OSX_ARCHITECTURES", cmProperty::TARGET,
710 "Target specific architectures for OS X.",
711 "The OSX_ARCHITECTURES property sets the target binary architecture "
712 "for targets on OS X. "
713 "This property is initialized by the value of the variable "
714 "CMAKE_OSX_ARCHITECTURES if it is set when a target is created. "
715 "Use OSX_ARCHITECTURES_<CONFIG> to set the binary architectures on a "
716 "per-configuration basis. "
717 "<CONFIG> is an upper-case name (ex: \"OSX_ARCHITECTURES_DEBUG\").");
720 ("OSX_ARCHITECTURES_<CONFIG>", cmProperty::TARGET,
721 "Per-configuration OS X binary architectures for a target.",
722 "This property is the configuration-specific version of "
723 "OSX_ARCHITECTURES.");
726 ("OUTPUT_NAME", cmProperty::TARGET,
727 "Output name for target files.",
728 "This sets the base name for output files created for an executable or "
730 "If not set, the logical target name is used by default.");
733 ("OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
734 "Per-configuration target file base name.",
735 "This is the configuration-specific version of OUTPUT_NAME.");
738 ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET,
739 "Old per-configuration target file base name.",
740 "This is a configuration-specific version of OUTPUT_NAME. "
741 "Use OUTPUT_NAME_<CONFIG> instead.");
744 ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
745 "Deprecated install support.",
746 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
747 "old way to specify CMake scripts to run before and after "
748 "installing a target. They are used only when the old "
749 "INSTALL_TARGETS command is used to install the target. Use the "
750 "INSTALL command instead.");
753 ("PREFIX", cmProperty::TARGET,
754 "What comes before the library name.",
755 "A target property that can be set to override the prefix "
756 "(such as \"lib\") on a library name.");
759 ("POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
760 "Whether to create a position-independent target",
761 "The POSITION_INDEPENDENT_CODE property determines whether position "
762 "independent executables or shared libraries will be created. "
763 "This property is true by default for SHARED and MODULE library "
764 "targets and false otherwise.");
767 ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
768 "Deprecated install support.",
769 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
770 "old way to specify CMake scripts to run before and after "
771 "installing a target. They are used only when the old "
772 "INSTALL_TARGETS command is used to install the target. Use the "
773 "INSTALL command instead.");
776 ("PRIVATE_HEADER", cmProperty::TARGET,
777 "Specify private header files in a FRAMEWORK shared library target.",
778 "Shared library targets marked with the FRAMEWORK property generate "
779 "frameworks on OS X and normal shared libraries on other platforms. "
780 "This property may be set to a list of header files to be placed "
781 "in the PrivateHeaders directory inside the framework folder. "
782 "On non-Apple platforms these headers may be installed using the "
783 "PRIVATE_HEADER option to the install(TARGETS) command.");
786 ("PUBLIC_HEADER", cmProperty::TARGET,
787 "Specify public header files in a FRAMEWORK shared library target.",
788 "Shared library targets marked with the FRAMEWORK property generate "
789 "frameworks on OS X and normal shared libraries on other platforms. "
790 "This property may be set to a list of header files to be placed "
791 "in the Headers directory inside the framework folder. "
792 "On non-Apple platforms these headers may be installed using the "
793 "PUBLIC_HEADER option to the install(TARGETS) command.");
796 ("RESOURCE", cmProperty::TARGET,
797 "Specify resource files in a FRAMEWORK shared library target.",
798 "Shared library targets marked with the FRAMEWORK property generate "
799 "frameworks on OS X and normal shared libraries on other platforms. "
800 "This property may be set to a list of files to be placed "
801 "in the Resources directory inside the framework folder. "
802 "On non-Apple platforms these files may be installed using the "
803 "RESOURCE option to the install(TARGETS) command.");
806 ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
807 "Specify a launcher for compile rules.",
808 "See the global property of the same name for details. "
809 "This overrides the global and directory property for a target.",
812 ("RULE_LAUNCH_LINK", cmProperty::TARGET,
813 "Specify a launcher for link rules.",
814 "See the global property of the same name for details. "
815 "This overrides the global and directory property for a target.",
818 ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
819 "Specify a launcher for custom rules.",
820 "See the global property of the same name for details. "
821 "This overrides the global and directory property for a target.",
825 ("SKIP_BUILD_RPATH", cmProperty::TARGET,
826 "Should rpaths be used for the build tree.",
827 "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
828 "generation of an rpath allowing the target to run from the "
830 "This property is initialized by the value of the variable "
831 "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
834 ("NO_SONAME", cmProperty::TARGET,
835 "Whether to set \"soname\" when linking a shared library or module.",
836 "Enable this boolean property if a generated shared library or module "
837 "should not have \"soname\" set. Default is to set \"soname\" on all "
838 "shared libraries and modules as long as the platform supports it. "
839 "Generally, use this property only for leaf private libraries or "
840 "plugins. If you use it on normal shared libraries which other targets "
841 "link against, on some platforms a linker will insert a full path to "
842 "the library (as specified at link time) into the dynamic section of "
843 "the dependent binary. Therefore, once installed, dynamic loader may "
844 "eventually fail to locate the library for the binary.");
847 ("SOVERSION", cmProperty::TARGET,
848 "What version number is this target.",
849 "For shared libraries VERSION and SOVERSION can be used to specify "
850 "the build version and api version respectively. When building or "
851 "installing appropriate symlinks are created if the platform "
852 "supports symlinks and the linker supports so-names. "
853 "If only one of both is specified the missing is assumed to have "
854 "the same version number. "
855 "SOVERSION is ignored if NO_SONAME property is set. "
856 "For shared libraries and executables on Windows the VERSION "
857 "attribute is parsed to extract a \"major.minor\" version number. "
858 "These numbers are used as the image version of the binary. ");
861 ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
862 "Extra flags to use when linking static libraries.",
863 "Extra flags to use when linking a static library.");
866 ("STATIC_LIBRARY_FLAGS_<CONFIG>", cmProperty::TARGET,
867 "Per-configuration flags for creating a static library.",
868 "This is the configuration-specific version of STATIC_LIBRARY_FLAGS.");
871 ("SUFFIX", cmProperty::TARGET,
872 "What comes after the target name.",
873 "A target property that can be set to override the suffix "
874 "(such as \".so\" or \".exe\") on the name of a library, module or "
878 ("TYPE", cmProperty::TARGET,
879 "The type of the target.",
880 "This read-only property can be used to test the type of the given "
881 "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
882 "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
885 ("VERSION", cmProperty::TARGET,
886 "What version number is this target.",
887 "For shared libraries VERSION and SOVERSION can be used to specify "
888 "the build version and api version respectively. When building or "
889 "installing appropriate symlinks are created if the platform "
890 "supports symlinks and the linker supports so-names. "
891 "If only one of both is specified the missing is assumed to have "
892 "the same version number. "
893 "For executables VERSION can be used to specify the build version. "
894 "When building or installing appropriate symlinks are created if "
895 "the platform supports symlinks. "
896 "For shared libraries and executables on Windows the VERSION "
897 "attribute is parsed to extract a \"major.minor\" version number. "
898 "These numbers are used as the image version of the binary. ");
902 ("WIN32_EXECUTABLE", cmProperty::TARGET,
903 "Build an executable with a WinMain entry point on windows.",
904 "When this property is set to true the executable when linked "
905 "on Windows will be created with a WinMain() entry point instead "
907 "This makes it a GUI executable instead of a console application. "
908 "See the CMAKE_MFC_FLAG variable documentation to configure use "
909 "of MFC for WinMain executables. "
910 "This property is initialized by the value of the variable "
911 "CMAKE_WIN32_EXECUTABLE if it is set when a target is created.");
914 ("MACOSX_BUNDLE", cmProperty::TARGET,
915 "Build an executable as an application bundle on Mac OS X.",
916 "When this property is set to true the executable when built "
917 "on Mac OS X will be created as an application bundle. "
918 "This makes it a GUI executable that can be launched from "
920 "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
921 "about creation of the Info.plist file for the application bundle. "
922 "This property is initialized by the value of the variable "
923 "CMAKE_MACOSX_BUNDLE if it is set when a target is created.");
926 ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
927 "Specify a custom Info.plist template for a Mac OS X App Bundle.",
928 "An executable target with MACOSX_BUNDLE enabled will be built as an "
929 "application bundle on Mac OS X. "
930 "By default its Info.plist file is created by configuring a template "
931 "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
932 "This property specifies an alternative template file name which "
933 "may be a full path.\n"
934 "The following target properties may be set to specify content to "
935 "be configured into the file:\n"
936 " MACOSX_BUNDLE_INFO_STRING\n"
937 " MACOSX_BUNDLE_ICON_FILE\n"
938 " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
939 " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
940 " MACOSX_BUNDLE_BUNDLE_NAME\n"
941 " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
942 " MACOSX_BUNDLE_BUNDLE_VERSION\n"
943 " MACOSX_BUNDLE_COPYRIGHT\n"
944 "CMake variables of the same name may be set to affect all targets "
945 "in a directory that do not have each specific property set. "
946 "If a custom Info.plist is specified by this property it may of course "
947 "hard-code all the settings instead of using the target properties.");
950 ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
951 "Specify a custom Info.plist template for a Mac OS X Framework.",
952 "An library target with FRAMEWORK enabled will be built as a "
953 "framework on Mac OS X. "
954 "By default its Info.plist file is created by configuring a template "
955 "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
956 "This property specifies an alternative template file name which "
957 "may be a full path.\n"
958 "The following target properties may be set to specify content to "
959 "be configured into the file:\n"
960 " MACOSX_FRAMEWORK_ICON_FILE\n"
961 " MACOSX_FRAMEWORK_IDENTIFIER\n"
962 " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
963 " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
964 "CMake variables of the same name may be set to affect all targets "
965 "in a directory that do not have each specific property set. "
966 "If a custom Info.plist is specified by this property it may of course "
967 "hard-code all the settings instead of using the target properties.");
970 ("ENABLE_EXPORTS", cmProperty::TARGET,
971 "Specify whether an executable exports symbols for loadable modules.",
972 "Normally an executable does not export any symbols because it is "
973 "the final program. It is possible for an executable to export "
974 "symbols to be used by loadable modules. When this property is "
975 "set to true CMake will allow other targets to \"link\" to the "
976 "executable with the TARGET_LINK_LIBRARIES command. "
977 "On all platforms a target-level dependency on the executable is "
978 "created for targets that link to it. "
979 "For DLL platforms an import library will be created for the "
980 "exported symbols and then used for linking. "
981 "All Windows-based systems including Cygwin are DLL platforms. "
982 "For non-DLL platforms that require all symbols to be resolved at "
983 "link time, such as Mac OS X, the module will \"link\" to the "
984 "executable using a flag like \"-bundle_loader\". "
985 "For other non-DLL platforms the link rule is simply ignored since "
986 "the dynamic loader will automatically bind symbols when the "
991 ("Fortran_FORMAT", cmProperty::TARGET,
992 "Set to FIXED or FREE to indicate the Fortran source layout.",
993 "This property tells CMake whether the Fortran source files "
994 "in a target use fixed-format or free-format. "
995 "CMake will pass the corresponding format flag to the compiler. "
996 "Use the source-specific Fortran_FORMAT property to change the "
997 "format of a specific source file. "
998 "If the variable CMAKE_Fortran_FORMAT is set when a target "
999 "is created its value is used to initialize this property.");
1002 ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
1003 "Specify output directory for Fortran modules provided by the target.",
1004 "If the target contains Fortran source files that provide modules "
1005 "and the compiler supports a module output directory this specifies "
1006 "the directory in which the modules will be placed. "
1007 "When this property is not set the modules will be placed in the "
1008 "build directory corresponding to the target's source directory. "
1009 "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
1010 "is created its value is used to initialize this property."
1012 "Note that some compilers will automatically search the module output "
1013 "directory for modules USEd during compilation but others will not. "
1014 "If your sources USE modules their location must be specified by "
1015 "INCLUDE_DIRECTORIES regardless of this property.");
1018 ("GNUtoMS", cmProperty::TARGET,
1019 "Convert GNU import library (.dll.a) to MS format (.lib).",
1020 "When linking a shared library or executable that exports symbols "
1021 "using GNU tools on Windows (MinGW/MSYS) with Visual Studio installed "
1022 "convert the import library (.dll.a) from GNU to MS format (.lib). "
1023 "Both import libraries will be installed by install(TARGETS) and "
1024 "exported by install(EXPORT) and export() to be linked by applications "
1025 "with either GNU- or MS-compatible tools."
1027 "If the variable CMAKE_GNUtoMS is set when a target "
1028 "is created its value is used to initialize this property. "
1029 "The variable must be set prior to the first command that enables "
1030 "a language such as project() or enable_language(). "
1031 "CMake provides the variable as an option to the user automatically "
1032 "when configuring on Windows with GNU tools.");
1035 ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
1036 "Set Xcode target attributes directly.",
1037 "Tell the Xcode generator to set '<an-attribute>' to a given value "
1038 "in the generated Xcode project. Ignored on other generators.");
1041 ("GENERATOR_FILE_NAME", cmProperty::TARGET,
1042 "Generator's file for this target.",
1043 "An internal property used by some generators to record the name of "
1044 "project or dsp file associated with this target.");
1047 ("SOURCES", cmProperty::TARGET,
1048 "Source names specified for a target.",
1049 "Read-only list of sources specified for a target. "
1050 "The names returned are suitable for passing to the "
1051 "set_source_files_properties command.");
1054 ("FOLDER", cmProperty::TARGET,
1055 "Set the folder name. Use to organize targets in an IDE.",
1056 "Targets with no FOLDER property will appear as top level "
1057 "entities in IDEs like Visual Studio. Targets with the same "
1058 "FOLDER property value will appear next to each other in a "
1059 "folder of that name. To nest folders, use FOLDER values such "
1060 "as 'GUI/Dialogs' with '/' characters separating folder levels.");
1063 ("PROJECT_LABEL", cmProperty::TARGET,
1064 "Change the name of a target in an IDE.",
1065 "Can be used to change the name of the target in an IDE "
1066 "like Visual Studio. ");
1068 ("VS_KEYWORD", cmProperty::TARGET,
1069 "Visual Studio project keyword.",
1070 "Can be set to change the visual studio keyword, for example "
1071 "QT integration works better if this is set to Qt4VSv1.0. ");
1073 ("VS_SCC_PROVIDER", cmProperty::TARGET,
1074 "Visual Studio Source Code Control Provider.",
1075 "Can be set to change the visual studio source code control "
1076 "provider property.");
1078 ("VS_SCC_LOCALPATH", cmProperty::TARGET,
1079 "Visual Studio Source Code Control Local Path.",
1080 "Can be set to change the visual studio source code control "
1081 "local path property.");
1083 ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
1084 "Visual Studio Source Code Control Project.",
1085 "Can be set to change the visual studio source code control "
1086 "project name property.");
1088 ("VS_SCC_AUXPATH", cmProperty::TARGET,
1089 "Visual Studio Source Code Control Aux Path.",
1090 "Can be set to change the visual studio source code control "
1091 "auxpath property.");
1093 ("VS_GLOBAL_PROJECT_TYPES", cmProperty::TARGET,
1094 "Visual Studio project type(s).",
1095 "Can be set to one or more UUIDs recognized by Visual Studio "
1096 "to indicate the type of project. This value is copied "
1097 "verbatim into the generated project file. Example for a "
1098 "managed C++ unit testing project:\n"
1099 " {3AC096D0-A1C2-E12C-1390-A8335801FDAB};"
1100 "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\n"
1101 "UUIDs are semicolon-delimited.");
1103 ("VS_GLOBAL_KEYWORD", cmProperty::TARGET,
1104 "Visual Studio project keyword.",
1105 "Sets the \"keyword\" attribute for a generated Visual Studio "
1106 "project. Defaults to \"Win32Proj\". You may wish to override "
1107 "this value with \"ManagedCProj\", for example, in a Visual "
1108 "Studio managed C++ unit test project.");
1110 ("VS_DOTNET_REFERENCES", cmProperty::TARGET,
1111 "Visual Studio managed project .NET references",
1112 "Adds one or more semicolon-delimited .NET references to a "
1113 "generated Visual Studio project. For example, \"System;"
1114 "System.Windows.Forms\".");
1116 ("VS_WINRT_EXTENSIONS", cmProperty::TARGET,
1117 "Visual Studio project C++/CX language extensions for Windows Runtime",
1118 "Can be set to enable C++/CX language extensions.");
1120 ("VS_WINRT_REFERENCES", cmProperty::TARGET,
1121 "Visual Studio project Windows Runtime Metadata references",
1122 "Adds one or more semicolon-delimited WinRT references to a "
1123 "generated Visual Studio project. For example, \"Windows;"
1124 "Windows.UI.Core\".");
1126 ("VS_GLOBAL_<variable>", cmProperty::TARGET,
1127 "Visual Studio project-specific global variable.",
1128 "Tell the Visual Studio generator to set the global variable "
1129 "'<variable>' to a given value in the generated Visual Studio "
1130 "project. Ignored on other generators. Qt integration works "
1131 "better if VS_GLOBAL_QtVersion is set to the version "
1132 "FindQt4.cmake found. For example, \"4.7.3\"");
1134 #define CM_TARGET_FILE_TYPES_DOC \
1135 "There are three kinds of target files that may be built: " \
1136 "archive, library, and runtime. " \
1137 "Executables are always treated as runtime targets. " \
1138 "Static libraries are always treated as archive targets. " \
1139 "Module libraries are always treated as library targets. " \
1140 "For non-DLL platforms shared libraries are treated as library " \
1142 "For DLL platforms the DLL part of a shared library is treated as " \
1143 "a runtime target and the corresponding import library is treated as " \
1144 "an archive target. " \
1145 "All Windows-based systems including Cygwin are DLL platforms."
1147 #define CM_TARGET_OUTDIR_DOC(TYPE, type) \
1148 "This property specifies the directory into which " #type " target " \
1149 "files should be built. " \
1150 "Multi-configuration generators (VS, Xcode) append " \
1151 "a per-configuration subdirectory to the specified directory. " \
1152 CM_TARGET_FILE_TYPES_DOC " " \
1153 "This property is initialized by the value of the variable " \
1154 "CMAKE_" #TYPE "_OUTPUT_DIRECTORY if it is set when a target is created."
1156 #define CM_TARGET_OUTDIR_CONFIG_DOC(TYPE) \
1157 "This is a per-configuration version of " #TYPE "_OUTPUT_DIRECTORY, " \
1158 "but multi-configuration generators (VS, Xcode) do NOT append " \
1159 "a per-configuration subdirectory to the specified directory. " \
1160 "This property is initialized by the value of the variable " \
1161 "CMAKE_" #TYPE "_OUTPUT_DIRECTORY_<CONFIG> " \
1162 "if it is set when a target is created."
1165 ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
1166 "Output directory in which to build ARCHIVE target files.",
1167 CM_TARGET_OUTDIR_DOC(ARCHIVE, archive));
1169 ("ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1170 "Per-configuration output directory for ARCHIVE target files.",
1171 CM_TARGET_OUTDIR_CONFIG_DOC(ARCHIVE));
1173 ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
1174 "Output directory in which to build LIBRARY target files.",
1175 CM_TARGET_OUTDIR_DOC(LIBRARY, library));
1177 ("LIBRARY_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1178 "Per-configuration output directory for LIBRARY target files.",
1179 CM_TARGET_OUTDIR_CONFIG_DOC(LIBRARY));
1181 ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
1182 "Output directory in which to build RUNTIME target files.",
1183 CM_TARGET_OUTDIR_DOC(RUNTIME, runtime));
1185 ("RUNTIME_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1186 "Per-configuration output directory for RUNTIME target files.",
1187 CM_TARGET_OUTDIR_CONFIG_DOC(RUNTIME));
1190 ("ARCHIVE_OUTPUT_NAME", cmProperty::TARGET,
1191 "Output name for ARCHIVE target files.",
1192 "This property specifies the base name for archive target files. "
1193 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
1194 CM_TARGET_FILE_TYPES_DOC);
1196 ("ARCHIVE_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1197 "Per-configuration output name for ARCHIVE target files.",
1198 "This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.");
1200 ("LIBRARY_OUTPUT_NAME", cmProperty::TARGET,
1201 "Output name for LIBRARY target files.",
1202 "This property specifies the base name for library target files. "
1203 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
1204 CM_TARGET_FILE_TYPES_DOC);
1206 ("LIBRARY_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1207 "Per-configuration output name for LIBRARY target files.",
1208 "This is the configuration-specific version of LIBRARY_OUTPUT_NAME.");
1210 ("RUNTIME_OUTPUT_NAME", cmProperty::TARGET,
1211 "Output name for RUNTIME target files.",
1212 "This property specifies the base name for runtime target files. "
1213 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
1214 CM_TARGET_FILE_TYPES_DOC);
1216 ("RUNTIME_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1217 "Per-configuration output name for RUNTIME target files.",
1218 "This is the configuration-specific version of RUNTIME_OUTPUT_NAME.");
1221 void cmTarget::SetType(TargetType type, const char* name)
1224 // only add dependency information for library targets
1225 this->TargetTypeValue = type;
1226 if(this->TargetTypeValue >= STATIC_LIBRARY
1227 && this->TargetTypeValue <= MODULE_LIBRARY)
1229 this->RecordDependencies = true;
1233 this->RecordDependencies = false;
1237 //----------------------------------------------------------------------------
1238 void cmTarget::SetMakefile(cmMakefile* mf)
1240 // Set our makefile.
1241 this->Makefile = mf;
1243 // set the cmake instance of the properties
1244 this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
1246 // Check whether this is a DLL platform.
1247 this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
1248 this->Makefile->IsOn("CYGWIN") ||
1249 this->Makefile->IsOn("MINGW"));
1251 // Check whether we are targeting an Apple platform.
1252 this->IsApple = this->Makefile->IsOn("APPLE");
1254 // Setup default property values.
1255 this->SetPropertyDefault("INSTALL_NAME_DIR", "");
1256 this->SetPropertyDefault("INSTALL_RPATH", "");
1257 this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
1258 this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
1259 this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
1260 this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
1261 this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
1262 this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
1263 this->SetPropertyDefault("Fortran_FORMAT", 0);
1264 this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
1265 this->SetPropertyDefault("GNUtoMS", 0);
1266 this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
1267 this->SetPropertyDefault("AUTOMOC", 0);
1268 this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
1269 this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
1270 this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
1271 this->SetPropertyDefault("MACOSX_BUNDLE", 0);
1273 // Collect the set of configuration types.
1274 std::vector<std::string> configNames;
1275 mf->GetConfigurations(configNames);
1277 // Setup per-configuration property default values.
1278 const char* configProps[] = {
1279 "ARCHIVE_OUTPUT_DIRECTORY_",
1280 "LIBRARY_OUTPUT_DIRECTORY_",
1281 "RUNTIME_OUTPUT_DIRECTORY_",
1283 for(std::vector<std::string>::iterator ci = configNames.begin();
1284 ci != configNames.end(); ++ci)
1286 std::string configUpper = cmSystemTools::UpperCase(*ci);
1287 for(const char** p = configProps; *p; ++p)
1289 std::string property = *p;
1290 property += configUpper;
1291 this->SetPropertyDefault(property.c_str(), 0);
1294 // Initialize per-configuration name postfix property from the
1295 // variable only for non-executable targets. This preserves
1296 // compatibility with previous CMake versions in which executables
1297 // did not support this variable. Projects may still specify the
1298 // property directly. TODO: Make this depend on backwards
1299 // compatibility setting.
1300 if(this->TargetTypeValue != cmTarget::EXECUTABLE)
1302 std::string property = cmSystemTools::UpperCase(*ci);
1303 property += "_POSTFIX";
1304 this->SetPropertyDefault(property.c_str(), 0);
1308 // Save the backtrace of target construction.
1309 this->Makefile->GetBacktrace(this->Internal->Backtrace);
1311 // Initialize the INCLUDE_DIRECTORIES property based on the current value
1312 // of the same directory property:
1313 this->SetProperty("INCLUDE_DIRECTORIES",
1314 this->Makefile->GetProperty("INCLUDE_DIRECTORIES"));
1316 if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
1317 || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
1319 this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
1321 this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
1323 // Record current policies for later use.
1324 this->PolicyStatusCMP0003 =
1325 this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
1326 this->PolicyStatusCMP0004 =
1327 this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
1328 this->PolicyStatusCMP0008 =
1329 this->Makefile->GetPolicyStatus(cmPolicies::CMP0008);
1332 //----------------------------------------------------------------------------
1333 void cmTarget::FinishConfigure()
1335 // Erase any cached link information that might have been comptued
1336 // on-demand during the configuration. This ensures that build
1337 // system generation uses up-to-date information even if other cache
1338 // invalidation code in this source file is buggy.
1339 this->ClearLinkMaps();
1341 // Do old-style link dependency analysis.
1342 this->AnalyzeLibDependencies(*this->Makefile);
1345 //----------------------------------------------------------------------------
1346 void cmTarget::ClearLinkMaps()
1348 this->Internal->LinkImplMap.clear();
1349 this->Internal->LinkInterfaceMap.clear();
1350 this->Internal->LinkClosureMap.clear();
1353 //----------------------------------------------------------------------------
1354 cmListFileBacktrace const& cmTarget::GetBacktrace() const
1356 return this->Internal->Backtrace;
1359 //----------------------------------------------------------------------------
1360 std::string cmTarget::GetSupportDirectory() const
1362 std::string dir = this->Makefile->GetCurrentOutputDirectory();
1363 dir += cmake::GetCMakeFilesDirectory();
1374 //----------------------------------------------------------------------------
1375 bool cmTarget::IsExecutableWithExports()
1377 return (this->GetType() == cmTarget::EXECUTABLE &&
1378 this->GetPropertyAsBool("ENABLE_EXPORTS"));
1381 //----------------------------------------------------------------------------
1382 bool cmTarget::IsLinkable()
1384 return (this->GetType() == cmTarget::STATIC_LIBRARY ||
1385 this->GetType() == cmTarget::SHARED_LIBRARY ||
1386 this->GetType() == cmTarget::MODULE_LIBRARY ||
1387 this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
1388 this->IsExecutableWithExports());
1391 //----------------------------------------------------------------------------
1392 bool cmTarget::HasImportLibrary()
1394 return (this->DLLPlatform &&
1395 (this->GetType() == cmTarget::SHARED_LIBRARY ||
1396 this->IsExecutableWithExports()));
1399 //----------------------------------------------------------------------------
1400 bool cmTarget::IsFrameworkOnApple()
1402 return (this->GetType() == cmTarget::SHARED_LIBRARY &&
1403 this->Makefile->IsOn("APPLE") &&
1404 this->GetPropertyAsBool("FRAMEWORK"));
1407 //----------------------------------------------------------------------------
1408 bool cmTarget::IsAppBundleOnApple()
1410 return (this->GetType() == cmTarget::EXECUTABLE &&
1411 this->Makefile->IsOn("APPLE") &&
1412 this->GetPropertyAsBool("MACOSX_BUNDLE"));
1415 //----------------------------------------------------------------------------
1416 bool cmTarget::IsCFBundleOnApple()
1418 return (this->GetType() == cmTarget::MODULE_LIBRARY &&
1419 this->Makefile->IsOn("APPLE") &&
1420 this->GetPropertyAsBool("BUNDLE"));
1423 //----------------------------------------------------------------------------
1424 class cmTargetTraceDependencies
1427 cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
1428 const char* vsProjectFile);
1432 cmTargetInternals* Internal;
1433 cmMakefile* Makefile;
1434 cmGlobalGenerator* GlobalGenerator;
1435 typedef cmTargetInternals::SourceEntry SourceEntry;
1436 SourceEntry* CurrentEntry;
1437 std::queue<cmSourceFile*> SourceQueue;
1438 std::set<cmSourceFile*> SourcesQueued;
1439 typedef std::map<cmStdString, cmSourceFile*> NameMapType;
1440 NameMapType NameMap;
1442 void QueueSource(cmSourceFile* sf);
1443 void FollowName(std::string const& name);
1444 void FollowNames(std::vector<std::string> const& names);
1445 bool IsUtility(std::string const& dep);
1446 void CheckCustomCommand(cmCustomCommand const& cc);
1447 void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
1450 //----------------------------------------------------------------------------
1451 cmTargetTraceDependencies
1452 ::cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
1453 const char* vsProjectFile):
1454 Target(target), Internal(internal)
1457 this->Makefile = this->Target->GetMakefile();
1458 this->GlobalGenerator =
1459 this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
1460 this->CurrentEntry = 0;
1462 // Queue all the source files already specified for the target.
1463 std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
1464 for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
1465 si != sources.end(); ++si)
1467 this->QueueSource(*si);
1470 // Queue the VS project file to check dependencies on the rule to
1474 this->FollowName(vsProjectFile);
1477 // Queue pre-build, pre-link, and post-build rule dependencies.
1478 this->CheckCustomCommands(this->Target->GetPreBuildCommands());
1479 this->CheckCustomCommands(this->Target->GetPreLinkCommands());
1480 this->CheckCustomCommands(this->Target->GetPostBuildCommands());
1483 //----------------------------------------------------------------------------
1484 void cmTargetTraceDependencies::Trace()
1486 // Process one dependency at a time until the queue is empty.
1487 while(!this->SourceQueue.empty())
1489 // Get the next source from the queue.
1490 cmSourceFile* sf = this->SourceQueue.front();
1491 this->SourceQueue.pop();
1492 this->CurrentEntry = &this->Internal->SourceEntries[sf];
1494 // Queue dependencies added explicitly by the user.
1495 if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
1497 std::vector<std::string> objDeps;
1498 cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
1499 this->FollowNames(objDeps);
1502 // Queue the source needed to generate this file, if any.
1503 this->FollowName(sf->GetFullPath());
1505 // Queue dependencies added programatically by commands.
1506 this->FollowNames(sf->GetDepends());
1508 // Queue custom command dependencies.
1509 if(cmCustomCommand const* cc = sf->GetCustomCommand())
1511 this->CheckCustomCommand(*cc);
1514 this->CurrentEntry = 0;
1517 //----------------------------------------------------------------------------
1518 void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
1520 if(this->SourcesQueued.insert(sf).second)
1522 this->SourceQueue.push(sf);
1524 // Make sure this file is in the target.
1525 this->Target->AddSourceFile(sf);
1529 //----------------------------------------------------------------------------
1530 void cmTargetTraceDependencies::FollowName(std::string const& name)
1532 NameMapType::iterator i = this->NameMap.find(name);
1533 if(i == this->NameMap.end())
1535 // Check if we know how to generate this file.
1536 cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
1537 NameMapType::value_type entry(name, sf);
1538 i = this->NameMap.insert(entry).first;
1540 if(cmSourceFile* sf = i->second)
1542 // Record the dependency we just followed.
1543 if(this->CurrentEntry)
1545 this->CurrentEntry->Depends.push_back(sf);
1548 this->QueueSource(sf);
1552 //----------------------------------------------------------------------------
1554 cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
1556 for(std::vector<std::string>::const_iterator i = names.begin();
1557 i != names.end(); ++i)
1559 this->FollowName(*i);
1563 //----------------------------------------------------------------------------
1564 bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
1566 // Dependencies on targets (utilities) are supposed to be named by
1567 // just the target name. However for compatibility we support
1568 // naming the output file generated by the target (assuming there is
1569 // no output-name property which old code would not have set). In
1570 // that case the target name will be the file basename of the
1572 std::string util = cmSystemTools::GetFilenameName(dep);
1573 if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
1575 util = cmSystemTools::GetFilenameWithoutLastExtension(util);
1578 // Check for a target with this name.
1579 if(cmTarget* t = this->Makefile->FindTargetToUse(util.c_str()))
1581 // If we find the target and the dep was given as a full path,
1582 // then make sure it was not a full path to something else, and
1583 // the fact that the name matched a target was just a coincidence.
1584 if(cmSystemTools::FileIsFullPath(dep.c_str()))
1586 if(t->GetType() >= cmTarget::EXECUTABLE &&
1587 t->GetType() <= cmTarget::MODULE_LIBRARY)
1589 // This is really only for compatibility so we do not need to
1590 // worry about configuration names and output names.
1591 std::string tLocation = t->GetLocation(0);
1592 tLocation = cmSystemTools::GetFilenamePath(tLocation);
1593 std::string depLocation = cmSystemTools::GetFilenamePath(dep);
1594 depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
1595 tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
1596 if(depLocation == tLocation)
1598 this->Target->AddUtility(util.c_str());
1605 // The original name of the dependency was not a full path. It
1606 // must name a target, so add the target-level dependency.
1607 this->Target->AddUtility(util.c_str());
1612 // The dependency does not name a target built in this project.
1616 //----------------------------------------------------------------------------
1618 cmTargetTraceDependencies
1619 ::CheckCustomCommand(cmCustomCommand const& cc)
1621 // Transform command names that reference targets built in this
1622 // project to corresponding target-level dependencies.
1623 cmGeneratorExpression ge(this->Makefile, 0, cc.GetBacktrace(), true);
1624 for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
1625 cit != cc.GetCommandLines().end(); ++cit)
1627 std::string const& command = *cit->begin();
1628 // Check for a target with this name.
1629 if(cmTarget* t = this->Makefile->FindTargetToUse(command.c_str()))
1631 if(t->GetType() == cmTarget::EXECUTABLE)
1633 // The command refers to an executable target built in
1634 // this project. Add the target-level dependency to make
1635 // sure the executable is up to date before this custom
1636 // command possibly runs.
1637 this->Target->AddUtility(command.c_str());
1641 // Check for target references in generator expressions.
1642 for(cmCustomCommandLine::const_iterator cli = cit->begin();
1643 cli != cit->end(); ++cli)
1649 // Add target-level dependencies referenced by generator expressions.
1650 std::set<cmTarget*> targets = ge.GetTargets();
1651 for(std::set<cmTarget*>::iterator ti = targets.begin();
1652 ti != targets.end(); ++ti)
1654 this->Target->AddUtility((*ti)->GetName());
1657 // Queue the custom command dependencies.
1658 std::vector<std::string> const& depends = cc.GetDepends();
1659 for(std::vector<std::string>::const_iterator di = depends.begin();
1660 di != depends.end(); ++di)
1662 std::string const& dep = *di;
1663 if(!this->IsUtility(dep))
1665 // The dependency does not name a target and may be a file we
1666 // know how to generate. Queue it.
1667 this->FollowName(dep);
1672 //----------------------------------------------------------------------------
1674 cmTargetTraceDependencies
1675 ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
1677 for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
1678 cli != commands.end(); ++cli)
1680 this->CheckCustomCommand(*cli);
1684 //----------------------------------------------------------------------------
1685 void cmTarget::TraceDependencies(const char* vsProjectFile)
1687 // CMake-generated targets have no dependencies to trace. Normally tracing
1688 // would find nothing anyway, but when building CMake itself the "install"
1689 // target command ends up referencing the "cmake" target but we do not
1690 // really want the dependency because "install" depend on "all" anyway.
1691 if(this->GetType() == cmTarget::GLOBAL_TARGET)
1696 // Use a helper object to trace the dependencies.
1697 cmTargetTraceDependencies tracer(this, this->Internal.Get(), vsProjectFile);
1701 //----------------------------------------------------------------------------
1702 bool cmTarget::FindSourceFiles()
1704 for(std::vector<cmSourceFile*>::const_iterator
1705 si = this->SourceFiles.begin();
1706 si != this->SourceFiles.end(); ++si)
1709 if((*si)->GetFullPath(&e).empty())
1713 cmake* cm = this->Makefile->GetCMakeInstance();
1714 cm->IssueMessage(cmake::FATAL_ERROR, e,
1715 this->GetBacktrace());
1723 //----------------------------------------------------------------------------
1724 std::vector<cmSourceFile*> const& cmTarget::GetSourceFiles()
1726 return this->SourceFiles;
1729 //----------------------------------------------------------------------------
1730 void cmTarget::AddSourceFile(cmSourceFile* sf)
1732 typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
1733 SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
1734 if(i == this->Internal->SourceEntries.end())
1736 typedef cmTargetInternals::SourceEntry SourceEntry;
1737 SourceEntriesType::value_type entry(sf, SourceEntry());
1738 i = this->Internal->SourceEntries.insert(entry).first;
1739 this->SourceFiles.push_back(sf);
1743 //----------------------------------------------------------------------------
1744 std::vector<cmSourceFile*> const*
1745 cmTarget::GetSourceDepends(cmSourceFile* sf)
1747 typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
1748 SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
1749 if(i != this->Internal->SourceEntries.end())
1751 return &i->second.Depends;
1756 //----------------------------------------------------------------------------
1757 void cmTarget::AddSources(std::vector<std::string> const& srcs)
1759 for(std::vector<std::string>::const_iterator i = srcs.begin();
1760 i != srcs.end(); ++i)
1762 const char* src = i->c_str();
1763 if(src[0] == '$' && src[1] == '<')
1765 this->ProcessSourceExpression(*i);
1769 this->AddSource(src);
1774 //----------------------------------------------------------------------------
1775 cmSourceFile* cmTarget::AddSource(const char* s)
1777 std::string src = s;
1779 // For backwards compatibility replace varibles in source names.
1780 // This should eventually be removed.
1781 this->Makefile->ExpandVariablesInString(src);
1783 cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
1784 this->AddSourceFile(sf);
1788 //----------------------------------------------------------------------------
1789 void cmTarget::ProcessSourceExpression(std::string const& expr)
1791 if(strncmp(expr.c_str(), "$<TARGET_OBJECTS:", 17) == 0 &&
1792 expr[expr.size()-1] == '>')
1794 std::string objLibName = expr.substr(17, expr.size()-18);
1795 this->ObjectLibraries.push_back(objLibName);
1800 e << "Unrecognized generator expression:\n"
1802 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
1806 //----------------------------------------------------------------------------
1807 struct cmTarget::SourceFileFlags
1808 cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
1810 struct SourceFileFlags flags;
1811 this->ConstructSourceFileFlags();
1812 std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
1813 this->Internal->SourceFlagsMap.find(sf);
1814 if(si != this->Internal->SourceFlagsMap.end())
1821 //----------------------------------------------------------------------------
1822 void cmTarget::ConstructSourceFileFlags()
1824 if(this->Internal->SourceFileFlagsConstructed)
1828 this->Internal->SourceFileFlagsConstructed = true;
1830 // Process public headers to mark the source files.
1831 if(const char* files = this->GetProperty("PUBLIC_HEADER"))
1833 std::vector<std::string> relFiles;
1834 cmSystemTools::ExpandListArgument(files, relFiles);
1835 for(std::vector<std::string>::iterator it = relFiles.begin();
1836 it != relFiles.end(); ++it)
1838 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1840 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1841 flags.MacFolder = "Headers";
1842 flags.Type = cmTarget::SourceFileTypePublicHeader;
1847 // Process private headers after public headers so that they take
1848 // precedence if a file is listed in both.
1849 if(const char* files = this->GetProperty("PRIVATE_HEADER"))
1851 std::vector<std::string> relFiles;
1852 cmSystemTools::ExpandListArgument(files, relFiles);
1853 for(std::vector<std::string>::iterator it = relFiles.begin();
1854 it != relFiles.end(); ++it)
1856 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1858 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1859 flags.MacFolder = "PrivateHeaders";
1860 flags.Type = cmTarget::SourceFileTypePrivateHeader;
1865 // Mark sources listed as resources.
1866 if(const char* files = this->GetProperty("RESOURCE"))
1868 std::vector<std::string> relFiles;
1869 cmSystemTools::ExpandListArgument(files, relFiles);
1870 for(std::vector<std::string>::iterator it = relFiles.begin();
1871 it != relFiles.end(); ++it)
1873 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1875 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1876 flags.MacFolder = "Resources";
1877 flags.Type = cmTarget::SourceFileTypeResource;
1882 // Handle the MACOSX_PACKAGE_LOCATION property on source files that
1883 // were not listed in one of the other lists.
1884 std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
1885 for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
1886 si != sources.end(); ++si)
1888 cmSourceFile* sf = *si;
1889 if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
1891 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1892 if(flags.Type == cmTarget::SourceFileTypeNormal)
1894 flags.MacFolder = location;
1895 if(strcmp(location, "Resources") == 0)
1897 flags.Type = cmTarget::SourceFileTypeResource;
1901 flags.Type = cmTarget::SourceFileTypeMacContent;
1908 //----------------------------------------------------------------------------
1909 void cmTarget::MergeLinkLibraries( cmMakefile& mf,
1910 const char *selfname,
1911 const LinkLibraryVectorType& libs )
1913 // Only add on libraries we haven't added on before.
1914 // Assumption: the global link libraries could only grow, never shrink
1915 LinkLibraryVectorType::const_iterator i = libs.begin();
1916 i += this->PrevLinkedLibraries.size();
1917 for( ; i != libs.end(); ++i )
1919 // We call this so that the dependencies get written to the cache
1920 this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
1922 this->PrevLinkedLibraries = libs;
1925 //----------------------------------------------------------------------------
1926 void cmTarget::AddLinkDirectory(const char* d)
1928 // Make sure we don't add unnecessary search directories.
1929 if(this->LinkDirectoriesEmmitted.insert(d).second)
1931 this->LinkDirectories.push_back(d);
1935 //----------------------------------------------------------------------------
1936 const std::vector<std::string>& cmTarget::GetLinkDirectories()
1938 return this->LinkDirectories;
1941 //----------------------------------------------------------------------------
1942 cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
1944 // No configuration is always optimized.
1945 if(!(config && *config))
1947 return cmTarget::OPTIMIZED;
1950 // Get the list of configurations considered to be DEBUG.
1951 std::vector<std::string> const& debugConfigs =
1952 this->Makefile->GetCMakeInstance()->GetDebugConfigs();
1954 // Check if any entry in the list matches this configuration.
1955 std::string configUpper = cmSystemTools::UpperCase(config);
1956 for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
1957 i != debugConfigs.end(); ++i)
1959 if(*i == configUpper)
1961 return cmTarget::DEBUG;
1965 // The current configuration is not a debug configuration.
1966 return cmTarget::OPTIMIZED;
1969 //----------------------------------------------------------------------------
1970 void cmTarget::ClearDependencyInformation( cmMakefile& mf,
1971 const char* target )
1973 // Clear the dependencies. The cache variable must exist iff we are
1974 // recording dependency information for this target.
1975 std::string depname = target;
1976 depname += "_LIB_DEPENDS";
1977 if (this->RecordDependencies)
1979 mf.AddCacheDefinition(depname.c_str(), "",
1980 "Dependencies for target", cmCacheManager::STATIC);
1984 if (mf.GetDefinition( depname.c_str() ))
1986 std::string message = "Target ";
1988 message += " has dependency information when it shouldn't.\n";
1989 message += "Your cache is probably stale. Please remove the entry\n ";
1991 message += "\nfrom the cache.";
1992 cmSystemTools::Error( message.c_str() );
1997 //----------------------------------------------------------------------------
1998 bool cmTarget::NameResolvesToFramework(const std::string& libname)
2000 return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
2001 NameResolvesToFramework(libname);
2004 //----------------------------------------------------------------------------
2005 bool cmTarget::AddFramework(const std::string& libname, LinkLibraryType llt)
2007 (void)llt; // TODO: What is this?
2008 if(this->NameResolvesToFramework(libname.c_str()))
2010 std::string frameworkDir = libname;
2011 frameworkDir += "/../";
2012 frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
2013 std::vector<std::string>::iterator i =
2014 std::find(this->Frameworks.begin(),
2015 this->Frameworks.end(), frameworkDir);
2016 if(i == this->Frameworks.end())
2018 this->Frameworks.push_back(frameworkDir);
2025 //----------------------------------------------------------------------------
2026 void cmTarget::AddLinkLibrary(cmMakefile& mf,
2027 const char *target, const char* lib,
2028 LinkLibraryType llt)
2030 // Never add a self dependency, even if the user asks for it.
2031 if(strcmp( target, lib ) == 0)
2035 this->AddFramework(lib, llt);
2036 cmTarget::LibraryID tmp;
2039 this->LinkLibraries.push_back( tmp );
2040 this->OriginalLinkLibraries.push_back(tmp);
2041 this->ClearLinkMaps();
2043 // Add the explicit dependency information for this target. This is
2044 // simply a set of libraries separated by ";". There should always
2045 // be a trailing ";". These library names are not canonical, in that
2046 // they may be "-framework x", "-ly", "/path/libz.a", etc.
2047 // We shouldn't remove duplicates here because external libraries
2048 // may be purposefully duplicated to handle recursive dependencies,
2049 // and we removing one instance will break the link line. Duplicates
2050 // will be appropriately eliminated at emit time.
2051 if(this->RecordDependencies)
2053 std::string targetEntry = target;
2054 targetEntry += "_LIB_DEPENDS";
2055 std::string dependencies;
2056 const char* old_val = mf.GetDefinition( targetEntry.c_str() );
2059 dependencies += old_val;
2063 case cmTarget::GENERAL:
2064 dependencies += "general";
2066 case cmTarget::DEBUG:
2067 dependencies += "debug";
2069 case cmTarget::OPTIMIZED:
2070 dependencies += "optimized";
2073 dependencies += ";";
2074 dependencies += lib;
2075 dependencies += ";";
2076 mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
2077 "Dependencies for the target",
2078 cmCacheManager::STATIC );
2083 //----------------------------------------------------------------------------
2085 cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
2087 // There are two key parts of the dependency analysis: (1)
2088 // determining the libraries in the link line, and (2) constructing
2089 // the dependency graph for those libraries.
2091 // The latter is done using the cache entries that record the
2092 // dependencies of each library.
2094 // The former is a more thorny issue, since it is not clear how to
2095 // determine if two libraries listed on the link line refer to the a
2096 // single library or not. For example, consider the link "libraries"
2097 // /usr/lib/libtiff.so -ltiff
2098 // Is this one library or two? The solution implemented here is the
2099 // simplest (and probably the only practical) one: two libraries are
2100 // the same if their "link strings" are identical. Thus, the two
2101 // libraries above are considered distinct. This also means that for
2102 // dependency analysis to be effective, the CMake user must specify
2103 // libraries build by his project without using any linker flags or
2104 // file extensions. That is,
2105 // LINK_LIBRARIES( One Two )
2107 // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
2108 // The former is probably what most users would do, but it never
2109 // hurts to document the assumptions. :-) Therefore, in the analysis
2110 // code, the "canonical name" of a library is simply its name as
2111 // given to a LINK_LIBRARIES command.
2113 // Also, we will leave the original link line intact; we will just add any
2114 // dependencies that were missing.
2116 // There is a problem with recursive external libraries
2117 // (i.e. libraries with no dependency information that are
2118 // recursively dependent). We must make sure that the we emit one of
2119 // the libraries twice to satisfy the recursion, but we shouldn't
2120 // emit it more times than necessary. In particular, we must make
2121 // sure that handling this improbable case doesn't cost us when
2122 // dealing with the common case of non-recursive libraries. The
2123 // solution is to assume that the recursion is satisfied at one node
2124 // of the dependency tree. To illustrate, assume libA and libB are
2125 // extrenal and mutually dependent. Suppose libX depends on
2126 // libA, and libY on libA and libX. Then
2127 // TARGET_LINK_LIBRARIES( Y X A B A )
2128 // TARGET_LINK_LIBRARIES( X A B A )
2129 // TARGET_LINK_LIBRARIES( Exec Y )
2130 // would result in "-lY -lX -lA -lB -lA". This is the correct way to
2131 // specify the dependencies, since the mutual dependency of A and B
2132 // is resolved *every time libA is specified*.
2135 // TARGET_LINK_LIBRARIES( Y X A B A )
2136 // TARGET_LINK_LIBRARIES( X A B )
2137 // TARGET_LINK_LIBRARIES( Exec Y )
2138 // would result in "-lY -lX -lA -lB", and the mutual dependency
2139 // information is lost. This is because in some case (Y), the mutual
2140 // dependency of A and B is listed, while in another other case (X),
2141 // it is not. Depending on which line actually emits A, the mutual
2142 // dependency may or may not be on the final link line. We can't
2143 // handle this pathalogical case cleanly without emitting extra
2144 // libraries for the normal cases. Besides, the dependency
2145 // information for X is wrong anyway: if we build an executable
2146 // depending on X alone, we would not have the mutual dependency on
2147 // A and B resolved.
2150 // -- The current algorithm will not always pick the "optimal" link line
2151 // when recursive dependencies are present. It will instead break the
2152 // cycles at an aribtrary point. The majority of projects won't have
2153 // cyclic dependencies, so this is probably not a big deal. Note that
2154 // the link line is always correct, just not necessary optimal.
2157 // Expand variables in link library names. This is for backwards
2158 // compatibility with very early CMake versions and should
2159 // eventually be removed. This code was moved here from the end of
2160 // old source list processing code which was called just before this
2162 for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
2163 p != this->LinkLibraries.end(); ++p)
2165 this->Makefile->ExpandVariablesInString(p->first, true, true);
2169 typedef std::vector< std::string > LinkLine;
2171 // The dependency map.
2172 DependencyMap dep_map;
2174 // 1. Build the dependency graph
2176 for(LinkLibraryVectorType::reverse_iterator lib
2177 = this->LinkLibraries.rbegin();
2178 lib != this->LinkLibraries.rend(); ++lib)
2180 this->GatherDependencies( mf, *lib, dep_map);
2183 // 2. Remove any dependencies that are already satisfied in the original
2186 for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
2187 lib != this->LinkLibraries.end(); ++lib)
2189 for( LinkLibraryVectorType::iterator lib2 = lib;
2190 lib2 != this->LinkLibraries.end(); ++lib2)
2192 this->DeleteDependency( dep_map, *lib, *lib2);
2197 // 3. Create the new link line by simply emitting any dependencies that are
2198 // missing. Start from the back and keep adding.
2200 std::set<DependencyMap::key_type> done, visited;
2201 std::vector<DependencyMap::key_type> newLinkLibraries;
2202 for(LinkLibraryVectorType::reverse_iterator lib =
2203 this->LinkLibraries.rbegin();
2204 lib != this->LinkLibraries.rend(); ++lib)
2206 // skip zero size library entries, this may happen
2207 // if a variable expands to nothing.
2208 if (lib->first.size() != 0)
2210 this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
2214 // 4. Add the new libraries to the link line.
2216 for( std::vector<DependencyMap::key_type>::reverse_iterator k =
2217 newLinkLibraries.rbegin();
2218 k != newLinkLibraries.rend(); ++k )
2220 // get the llt from the dep_map
2221 this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
2223 this->LinkLibrariesAnalyzed = true;
2226 //----------------------------------------------------------------------------
2227 void cmTarget::InsertDependency( DependencyMap& depMap,
2228 const LibraryID& lib,
2229 const LibraryID& dep)
2231 depMap[lib].push_back(dep);
2234 //----------------------------------------------------------------------------
2235 void cmTarget::DeleteDependency( DependencyMap& depMap,
2236 const LibraryID& lib,
2237 const LibraryID& dep)
2239 // Make sure there is an entry in the map for lib. If so, delete all
2240 // dependencies to dep. There may be repeated entries because of
2241 // external libraries that are specified multiple times.
2242 DependencyMap::iterator map_itr = depMap.find( lib );
2243 if( map_itr != depMap.end() )
2245 DependencyList& depList = map_itr->second;
2246 DependencyList::iterator itr;
2247 while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
2250 depList.erase( itr );
2255 //----------------------------------------------------------------------------
2256 void cmTarget::Emit(const LibraryID lib,
2257 const DependencyMap& dep_map,
2258 std::set<LibraryID>& emitted,
2259 std::set<LibraryID>& visited,
2260 DependencyList& link_line )
2262 // It's already been emitted
2263 if( emitted.find(lib) != emitted.end() )
2268 // Emit the dependencies only if this library node hasn't been
2269 // visited before. If it has, then we have a cycle. The recursion
2270 // that got us here should take care of everything.
2272 if( visited.insert(lib).second )
2274 if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
2276 const DependencyList& dep_on = dep_map.find( lib )->second;
2277 DependencyList::const_reverse_iterator i;
2279 // To cater for recursive external libraries, we must emit
2280 // duplicates on this link line *unless* they were emitted by
2281 // some other node, in which case we assume that the recursion
2282 // was resolved then. We making the simplifying assumption that
2283 // any duplicates on a single link line are on purpose, and must
2286 // This variable will keep track of the libraries that were
2287 // emitted directory from the current node, and not from a
2288 // recursive call. This way, if we come across a library that
2289 // has already been emitted, we repeat it iff it has been
2291 std::set<DependencyMap::key_type> emitted_here;
2292 for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
2294 if( emitted_here.find(*i) != emitted_here.end() )
2296 // a repeat. Must emit.
2298 link_line.push_back( *i );
2302 // Emit only if no-one else has
2303 if( emitted.find(*i) == emitted.end() )
2305 // emit dependencies
2306 Emit( *i, dep_map, emitted, visited, link_line );
2309 emitted_here.insert(*i);
2310 link_line.push_back( *i );
2318 //----------------------------------------------------------------------------
2319 void cmTarget::GatherDependencies( const cmMakefile& mf,
2320 const LibraryID& lib,
2321 DependencyMap& dep_map)
2323 // If the library is already in the dependency map, then it has
2324 // already been fully processed.
2325 if( dep_map.find(lib) != dep_map.end() )
2330 const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
2331 if( deps && strcmp(deps,"") != 0 )
2333 // Make sure this library is in the map, even if it has an empty
2334 // set of dependencies. This distinguishes the case of explicitly
2335 // no dependencies with that of unspecified dependencies.
2338 // Parse the dependency information, which is a set of
2339 // type, library pairs separated by ";". There is always a trailing ";".
2340 cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
2341 std::string depline = deps;
2342 std::string::size_type start = 0;
2343 std::string::size_type end;
2344 end = depline.find( ";", start );
2345 while( end != std::string::npos )
2347 std::string l = depline.substr( start, end-start );
2352 llt = cmTarget::DEBUG;
2354 else if (l == "optimized")
2356 llt = cmTarget::OPTIMIZED;
2358 else if (l == "general")
2360 llt = cmTarget::GENERAL;
2364 LibraryID lib2(l,llt);
2365 this->InsertDependency( dep_map, lib, lib2);
2366 this->GatherDependencies( mf, lib2, dep_map);
2367 llt = cmTarget::GENERAL;
2370 start = end+1; // skip the ;
2371 end = depline.find( ";", start );
2373 // cannot depend on itself
2374 this->DeleteDependency( dep_map, lib, lib);
2378 //----------------------------------------------------------------------------
2379 void cmTarget::SetProperty(const char* prop, const char* value)
2386 this->Properties.SetProperty(prop, value, cmProperty::TARGET);
2387 this->MaybeInvalidatePropertyCache(prop);
2390 //----------------------------------------------------------------------------
2391 void cmTarget::AppendProperty(const char* prop, const char* value,
2398 this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
2399 this->MaybeInvalidatePropertyCache(prop);
2402 //----------------------------------------------------------------------------
2403 void cmTarget::MaybeInvalidatePropertyCache(const char* prop)
2405 // Wipe wipe out maps caching information affected by this property.
2406 if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
2408 this->Internal->ImportInfoMap.clear();
2410 if(!this->IsImported() && strncmp(prop, "LINK_INTERFACE_", 15) == 0)
2412 this->ClearLinkMaps();
2416 //----------------------------------------------------------------------------
2417 static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
2418 const char* prop, const char* value, cmMakefile* context, bool imported
2421 // Look for link-type keywords in the value.
2422 static cmsys::RegularExpression
2423 keys("(^|;)(debug|optimized|general)(;|$)");
2424 if(!keys.find(value))
2429 // Support imported and non-imported versions of the property.
2430 const char* base = (imported?
2431 "IMPORTED_LINK_INTERFACE_LIBRARIES" :
2432 "LINK_INTERFACE_LIBRARIES");
2436 e << "Property " << prop << " may not contain link-type keyword \""
2437 << keys.match(2) << "\". "
2438 << "The " << base << " property has a per-configuration "
2439 << "version called " << base << "_<CONFIG> which may be "
2440 << "used to specify per-configuration rules.";
2444 << "Alternatively, an IMPORTED library may be created, configured "
2445 << "with a per-configuration location, and then named in the "
2446 << "property value. "
2447 << "See the add_library command's IMPORTED mode for details."
2449 << "If you have a list of libraries that already contains the "
2450 << "keyword, use the target_link_libraries command with its "
2451 << "LINK_INTERFACE_LIBRARIES mode to set the property. "
2452 << "The command automatically recognizes link-type keywords and sets "
2453 << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
2454 << "properties accordingly.";
2456 context->IssueMessage(cmake::FATAL_ERROR, e.str());
2459 //----------------------------------------------------------------------------
2460 void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
2462 // Certain properties need checking.
2463 if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
2465 if(const char* value = this->GetProperty(prop))
2467 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
2470 if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
2472 if(const char* value = this->GetProperty(prop))
2474 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
2479 //----------------------------------------------------------------------------
2480 void cmTarget::MarkAsImported()
2482 this->IsImportedTarget = true;
2485 //----------------------------------------------------------------------------
2486 bool cmTarget::HaveWellDefinedOutputFiles()
2489 this->GetType() == cmTarget::STATIC_LIBRARY ||
2490 this->GetType() == cmTarget::SHARED_LIBRARY ||
2491 this->GetType() == cmTarget::MODULE_LIBRARY ||
2492 this->GetType() == cmTarget::EXECUTABLE;
2495 //----------------------------------------------------------------------------
2496 cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
2498 // There is no output information for imported targets.
2499 if(this->IsImported())
2504 // Only libraries and executables have well-defined output files.
2505 if(!this->HaveWellDefinedOutputFiles())
2507 std::string msg = "cmTarget::GetOutputInfo called for ";
2508 msg += this->GetName();
2509 msg += " which has type ";
2510 msg += cmTarget::GetTargetTypeName(this->GetType());
2511 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
2516 // Lookup/compute/cache the output information for this configuration.
2517 std::string config_upper;
2518 if(config && *config)
2520 config_upper = cmSystemTools::UpperCase(config);
2522 typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
2523 OutputInfoMapType::const_iterator i =
2524 this->Internal->OutputInfoMap.find(config_upper);
2525 if(i == this->Internal->OutputInfoMap.end())
2528 this->ComputeOutputDir(config, false, info.OutDir);
2529 this->ComputeOutputDir(config, true, info.ImpDir);
2530 OutputInfoMapType::value_type entry(config_upper, info);
2531 i = this->Internal->OutputInfoMap.insert(entry).first;
2536 //----------------------------------------------------------------------------
2537 std::string cmTarget::GetDirectory(const char* config, bool implib)
2539 if (this->IsImported())
2541 // Return the directory from which the target is imported.
2543 cmSystemTools::GetFilenamePath(
2544 this->ImportedGetFullPath(config, implib));
2546 else if(OutputInfo const* info = this->GetOutputInfo(config))
2548 // Return the directory in which the target will be built.
2549 return implib? info->ImpDir : info->OutDir;
2554 //----------------------------------------------------------------------------
2555 const char* cmTarget::GetLocation(const char* config)
2557 if (this->IsImported())
2559 return this->ImportedGetLocation(config);
2563 return this->NormalGetLocation(config);
2567 //----------------------------------------------------------------------------
2568 const char* cmTarget::ImportedGetLocation(const char* config)
2570 this->Location = this->ImportedGetFullPath(config, false);
2571 return this->Location.c_str();
2574 //----------------------------------------------------------------------------
2575 const char* cmTarget::NormalGetLocation(const char* config)
2577 // Handle the configuration-specific case first.
2580 this->Location = this->GetFullPath(config, false);
2581 return this->Location.c_str();
2584 // Now handle the deprecated build-time configuration location.
2585 this->Location = this->GetDirectory();
2586 if(!this->Location.empty())
2588 this->Location += "/";
2590 const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
2591 if(cfgid && strcmp(cfgid, ".") != 0)
2593 this->Location += cfgid;
2594 this->Location += "/";
2596 this->Location = this->BuildMacContentDirectory(this->Location, config);
2597 this->Location += this->GetFullName(config, false);
2598 return this->Location.c_str();
2601 //----------------------------------------------------------------------------
2602 void cmTarget::GetTargetVersion(int& major, int& minor)
2605 this->GetTargetVersion(false, major, minor, patch);
2608 //----------------------------------------------------------------------------
2609 void cmTarget::GetTargetVersion(bool soversion,
2610 int& major, int& minor, int& patch)
2612 // Set the default values.
2617 // Look for a VERSION or SOVERSION property.
2618 const char* prop = soversion? "SOVERSION" : "VERSION";
2619 if(const char* version = this->GetProperty(prop))
2621 // Try to parse the version number and store the results that were
2622 // successfully parsed.
2626 switch(sscanf(version, "%d.%d.%d",
2627 &parsed_major, &parsed_minor, &parsed_patch))
2629 case 3: patch = parsed_patch; // no break!
2630 case 2: minor = parsed_minor; // no break!
2631 case 1: major = parsed_major; // no break!
2637 //----------------------------------------------------------------------------
2638 const char* cmTarget::GetFeature(const char* feature, const char* config)
2640 if(config && *config)
2642 std::string featureConfig = feature;
2643 featureConfig += "_";
2644 featureConfig += cmSystemTools::UpperCase(config);
2645 if(const char* value = this->GetProperty(featureConfig.c_str()))
2650 if(const char* value = this->GetProperty(feature))
2654 return this->Makefile->GetFeature(feature, config);
2657 //----------------------------------------------------------------------------
2658 const char *cmTarget::GetProperty(const char* prop)
2660 return this->GetProperty(prop, cmProperty::TARGET);
2663 //----------------------------------------------------------------------------
2664 const char *cmTarget::GetProperty(const char* prop,
2665 cmProperty::ScopeType scope)
2672 // Watch for special "computed" properties that are dependent on
2673 // other properties or variables. Always recompute them.
2674 if(this->GetType() == cmTarget::EXECUTABLE ||
2675 this->GetType() == cmTarget::STATIC_LIBRARY ||
2676 this->GetType() == cmTarget::SHARED_LIBRARY ||
2677 this->GetType() == cmTarget::MODULE_LIBRARY ||
2678 this->GetType() == cmTarget::UNKNOWN_LIBRARY)
2680 if(strcmp(prop,"LOCATION") == 0)
2682 // Set the LOCATION property of the target.
2684 // For an imported target this is the location of an arbitrary
2685 // available configuration.
2687 // For a non-imported target this is deprecated because it
2688 // cannot take into account the per-configuration name of the
2689 // target because the configuration type may not be known at
2691 this->SetProperty("LOCATION", this->GetLocation(0));
2694 // Support "LOCATION_<CONFIG>".
2695 if(strncmp(prop, "LOCATION_", 9) == 0)
2697 std::string configName = prop+9;
2698 this->SetProperty(prop, this->GetLocation(configName.c_str()));
2702 // Support "<CONFIG>_LOCATION" for compatiblity.
2703 int len = static_cast<int>(strlen(prop));
2704 if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
2706 std::string configName(prop, len-9);
2707 if(configName != "IMPORTED")
2709 this->SetProperty(prop, this->GetLocation(configName.c_str()));
2715 if (strcmp(prop,"IMPORTED") == 0)
2717 return this->IsImported()?"TRUE":"FALSE";
2720 if(!strcmp(prop,"SOURCES"))
2723 const char* sep = "";
2724 for(std::vector<cmSourceFile*>::const_iterator
2725 i = this->SourceFiles.begin();
2726 i != this->SourceFiles.end(); ++i)
2728 // Separate from the previous list entries.
2732 // Construct what is known about this source file location.
2733 cmSourceFileLocation const& location = (*i)->GetLocation();
2734 std::string sname = location.GetDirectory();
2739 sname += location.GetName();
2741 // Append this list entry.
2744 this->SetProperty("SOURCES", ss.str().c_str());
2747 // the type property returns what type the target is
2748 if (!strcmp(prop,"TYPE"))
2750 return cmTarget::GetTargetTypeName(this->GetType());
2753 const char *retVal =
2754 this->Properties.GetPropertyValue(prop, scope, chain);
2757 return this->Makefile->GetProperty(prop,scope);
2762 //----------------------------------------------------------------------------
2763 bool cmTarget::GetPropertyAsBool(const char* prop)
2765 return cmSystemTools::IsOn(this->GetProperty(prop));
2768 //----------------------------------------------------------------------------
2769 class cmTargetCollectLinkLanguages
2772 cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
2773 std::set<cmStdString>& languages):
2774 Config(config), Languages(languages) { this->Visited.insert(target); }
2775 void Visit(cmTarget* target)
2777 if(!target || !this->Visited.insert(target).second)
2782 cmTarget::LinkInterface const* iface =
2783 target->GetLinkInterface(this->Config);
2784 if(!iface) { return; }
2786 for(std::vector<std::string>::const_iterator
2787 li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
2789 this->Languages.insert(*li);
2792 cmMakefile* mf = target->GetMakefile();
2793 for(std::vector<std::string>::const_iterator
2794 li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
2796 this->Visit(mf->FindTargetToUse(li->c_str()));
2801 std::set<cmStdString>& Languages;
2802 std::set<cmTarget*> Visited;
2805 //----------------------------------------------------------------------------
2806 const char* cmTarget::GetLinkerLanguage(const char* config)
2808 const char* lang = this->GetLinkClosure(config)->LinkerLanguage.c_str();
2809 return *lang? lang : 0;
2812 //----------------------------------------------------------------------------
2813 cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config)
2815 std::string key = cmSystemTools::UpperCase(config? config : "");
2816 cmTargetInternals::LinkClosureMapType::iterator
2817 i = this->Internal->LinkClosureMap.find(key);
2818 if(i == this->Internal->LinkClosureMap.end())
2821 this->ComputeLinkClosure(config, lc);
2822 cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
2823 i = this->Internal->LinkClosureMap.insert(entry).first;
2828 //----------------------------------------------------------------------------
2829 class cmTargetSelectLinker
2833 cmMakefile* Makefile;
2834 cmGlobalGenerator* GG;
2835 std::set<cmStdString> Preferred;
2837 cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
2839 this->Makefile = this->Target->GetMakefile();
2840 this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
2842 void Consider(const char* lang)
2844 int preference = this->GG->GetLinkerPreference(lang);
2845 if(preference > this->Preference)
2847 this->Preference = preference;
2848 this->Preferred.clear();
2850 if(preference == this->Preference)
2852 this->Preferred.insert(lang);
2855 std::string Choose()
2857 if(this->Preferred.empty())
2861 else if(this->Preferred.size() > 1)
2864 e << "Target " << this->Target->GetName()
2865 << " contains multiple languages with the highest linker preference"
2866 << " (" << this->Preference << "):\n";
2867 for(std::set<cmStdString>::const_iterator
2868 li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
2870 e << " " << *li << "\n";
2872 e << "Set the LINKER_LANGUAGE property for this target.";
2873 cmake* cm = this->Makefile->GetCMakeInstance();
2874 cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
2875 this->Target->GetBacktrace());
2877 return *this->Preferred.begin();
2881 //----------------------------------------------------------------------------
2882 void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc)
2884 // Get languages built in this target.
2885 std::set<cmStdString> languages;
2886 LinkImplementation const* impl = this->GetLinkImplementation(config);
2887 for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
2888 li != impl->Languages.end(); ++li)
2890 languages.insert(*li);
2893 // Add interface languages from linked targets.
2894 cmTargetCollectLinkLanguages cll(this, config, languages);
2895 for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
2896 li != impl->Libraries.end(); ++li)
2898 cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
2901 // Store the transitive closure of languages.
2902 for(std::set<cmStdString>::const_iterator li = languages.begin();
2903 li != languages.end(); ++li)
2905 lc.Languages.push_back(*li);
2908 // Choose the language whose linker should be used.
2909 if(this->GetProperty("HAS_CXX"))
2911 lc.LinkerLanguage = "CXX";
2913 else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
2915 lc.LinkerLanguage = linkerLang;
2919 // Find the language with the highest preference value.
2920 cmTargetSelectLinker tsl(this);
2922 // First select from the languages compiled directly in this target.
2923 for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
2924 li != impl->Languages.end(); ++li)
2926 tsl.Consider(li->c_str());
2929 // Now consider languages that propagate from linked targets.
2930 for(std::set<cmStdString>::const_iterator sit = languages.begin();
2931 sit != languages.end(); ++sit)
2933 std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
2934 if(this->Makefile->IsOn(propagates.c_str()))
2936 tsl.Consider(sit->c_str());
2940 lc.LinkerLanguage = tsl.Choose();
2944 //----------------------------------------------------------------------------
2945 const char* cmTarget::GetCreateRuleVariable()
2947 switch(this->GetType())
2949 case cmTarget::STATIC_LIBRARY:
2950 return "_CREATE_STATIC_LIBRARY";
2951 case cmTarget::SHARED_LIBRARY:
2952 return "_CREATE_SHARED_LIBRARY";
2953 case cmTarget::MODULE_LIBRARY:
2954 return "_CREATE_SHARED_MODULE";
2955 case cmTarget::EXECUTABLE:
2956 return "_LINK_EXECUTABLE";
2963 //----------------------------------------------------------------------------
2964 const char* cmTarget::GetSuffixVariableInternal(bool implib)
2966 switch(this->GetType())
2968 case cmTarget::STATIC_LIBRARY:
2969 return "CMAKE_STATIC_LIBRARY_SUFFIX";
2970 case cmTarget::SHARED_LIBRARY:
2972 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2973 : "CMAKE_SHARED_LIBRARY_SUFFIX");
2974 case cmTarget::MODULE_LIBRARY:
2976 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2977 : "CMAKE_SHARED_MODULE_SUFFIX");
2978 case cmTarget::EXECUTABLE:
2980 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2981 : "CMAKE_EXECUTABLE_SUFFIX");
2989 //----------------------------------------------------------------------------
2990 const char* cmTarget::GetPrefixVariableInternal(bool implib)
2992 switch(this->GetType())
2994 case cmTarget::STATIC_LIBRARY:
2995 return "CMAKE_STATIC_LIBRARY_PREFIX";
2996 case cmTarget::SHARED_LIBRARY:
2998 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2999 : "CMAKE_SHARED_LIBRARY_PREFIX");
3000 case cmTarget::MODULE_LIBRARY:
3002 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
3003 : "CMAKE_SHARED_MODULE_PREFIX");
3004 case cmTarget::EXECUTABLE:
3005 return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
3012 //----------------------------------------------------------------------------
3013 std::string cmTarget::GetPDBName(const char* config)
3018 this->GetFullNameInternal(config, false, prefix, base, suffix);
3019 return prefix+base+".pdb";
3022 //----------------------------------------------------------------------------
3023 bool cmTarget::HasSOName(const char* config)
3025 // soname is supported only for shared libraries and modules,
3026 // and then only when the platform supports an soname flag.
3027 return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
3028 this->GetType() == cmTarget::MODULE_LIBRARY) &&
3029 !this->GetPropertyAsBool("NO_SONAME") &&
3030 this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
3033 //----------------------------------------------------------------------------
3034 std::string cmTarget::GetSOName(const char* config)
3036 if(this->IsImported())
3038 // Lookup the imported soname.
3039 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
3043 // The imported library has no builtin soname so the name
3044 // searched at runtime will be just the filename.
3045 return cmSystemTools::GetFilenameName(info->Location);
3049 // Use the soname given if any.
3050 return info->SOName;
3060 // Compute the soname that will be built.
3063 std::string realName;
3064 std::string impName;
3065 std::string pdbName;
3066 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
3071 //----------------------------------------------------------------------------
3072 bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
3074 if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
3076 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
3078 return info->NoSOName;
3084 //----------------------------------------------------------------------------
3085 std::string cmTarget::NormalGetRealName(const char* config)
3087 // This should not be called for imported targets.
3088 // TODO: Split cmTarget into a class hierarchy to get compile-time
3089 // enforcement of the limited imported target API.
3090 if(this->IsImported())
3092 std::string msg = "NormalGetRealName called on imported target: ";
3093 msg += this->GetName();
3094 this->GetMakefile()->
3095 IssueMessage(cmake::INTERNAL_ERROR,
3099 if(this->GetType() == cmTarget::EXECUTABLE)
3101 // Compute the real name that will be built.
3103 std::string realName;
3104 std::string impName;
3105 std::string pdbName;
3106 this->GetExecutableNames(name, realName, impName, pdbName, config);
3111 // Compute the real name that will be built.
3114 std::string realName;
3115 std::string impName;
3116 std::string pdbName;
3117 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
3122 //----------------------------------------------------------------------------
3123 std::string cmTarget::GetFullName(const char* config, bool implib)
3125 if(this->IsImported())
3127 return this->GetFullNameImported(config, implib);
3131 return this->GetFullNameInternal(config, implib);
3135 //----------------------------------------------------------------------------
3136 std::string cmTarget::GetFullNameImported(const char* config, bool implib)
3138 return cmSystemTools::GetFilenameName(
3139 this->ImportedGetFullPath(config, implib));
3142 //----------------------------------------------------------------------------
3143 void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
3144 std::string& suffix, const char* config,
3147 this->GetFullNameInternal(config, implib, prefix, base, suffix);
3150 //----------------------------------------------------------------------------
3151 std::string cmTarget::GetFullPath(const char* config, bool implib,
3154 if(this->IsImported())
3156 return this->ImportedGetFullPath(config, implib);
3160 return this->NormalGetFullPath(config, implib, realname);
3164 //----------------------------------------------------------------------------
3165 std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
3168 std::string fpath = this->GetMacContentDirectory(config, implib);
3170 // Add the full name of the target.
3173 fpath += this->GetFullName(config, true);
3177 fpath += this->NormalGetRealName(config);
3181 fpath += this->GetFullName(config, false);
3186 //----------------------------------------------------------------------------
3187 std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
3190 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
3192 result = implib? info->ImportLibrary : info->Location;
3196 result = this->GetName();
3197 result += "-NOTFOUND";
3202 //----------------------------------------------------------------------------
3203 std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
3208 this->GetFullNameInternal(config, implib, prefix, base, suffix);
3209 return prefix+base+suffix;
3212 //----------------------------------------------------------------------------
3213 void cmTarget::GetFullNameInternal(const char* config,
3215 std::string& outPrefix,
3216 std::string& outBase,
3217 std::string& outSuffix)
3219 // Use just the target name for non-main target types.
3220 if(this->GetType() != cmTarget::STATIC_LIBRARY &&
3221 this->GetType() != cmTarget::SHARED_LIBRARY &&
3222 this->GetType() != cmTarget::MODULE_LIBRARY &&
3223 this->GetType() != cmTarget::EXECUTABLE)
3226 outBase = this->GetName();
3231 // Return an empty name for the import library if this platform
3232 // does not support import libraries.
3234 !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
3242 // The implib option is only allowed for shared libraries, module
3243 // libraries, and executables.
3244 if(this->GetType() != cmTarget::SHARED_LIBRARY &&
3245 this->GetType() != cmTarget::MODULE_LIBRARY &&
3246 this->GetType() != cmTarget::EXECUTABLE)
3251 // Compute the full name for main target types.
3252 const char* targetPrefix = (implib
3253 ? this->GetProperty("IMPORT_PREFIX")
3254 : this->GetProperty("PREFIX"));
3255 const char* targetSuffix = (implib
3256 ? this->GetProperty("IMPORT_SUFFIX")
3257 : this->GetProperty("SUFFIX"));
3258 const char* configPostfix = 0;
3259 if(config && *config)
3261 std::string configProp = cmSystemTools::UpperCase(config);
3262 configProp += "_POSTFIX";
3263 configPostfix = this->GetProperty(configProp.c_str());
3264 // Mac application bundles and frameworks have no postfix.
3266 (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
3271 const char* prefixVar = this->GetPrefixVariableInternal(implib);
3272 const char* suffixVar = this->GetSuffixVariableInternal(implib);
3274 // Check for language-specific default prefix and suffix.
3275 if(const char* ll = this->GetLinkerLanguage(config))
3277 if(!targetSuffix && suffixVar && *suffixVar)
3279 std::string langSuff = suffixVar + std::string("_") + ll;
3280 targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
3282 if(!targetPrefix && prefixVar && *prefixVar)
3284 std::string langPrefix = prefixVar + std::string("_") + ll;
3285 targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
3289 // if there is no prefix on the target use the cmake definition
3290 if(!targetPrefix && prefixVar)
3292 targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
3294 // if there is no suffix on the target use the cmake definition
3295 if(!targetSuffix && suffixVar)
3297 targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
3300 // frameworks do not have a prefix or a suffix
3301 if(this->IsFrameworkOnApple())
3307 // Begin the final name with the prefix.
3308 outPrefix = targetPrefix?targetPrefix:"";
3310 // Append the target name or property-specified name.
3311 outBase += this->GetOutputName(config, implib);
3313 // Append the per-configuration postfix.
3314 outBase += configPostfix?configPostfix:"";
3316 // Name shared libraries with their version number on some platforms.
3317 if(const char* soversion = this->GetProperty("SOVERSION"))
3319 if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
3320 this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
3323 outBase += soversion;
3327 // Append the suffix.
3328 outSuffix = targetSuffix?targetSuffix:"";
3331 //----------------------------------------------------------------------------
3332 void cmTarget::GetLibraryNames(std::string& name,
3333 std::string& soName,
3334 std::string& realName,
3335 std::string& impName,
3336 std::string& pdbName,
3339 // This should not be called for imported targets.
3340 // TODO: Split cmTarget into a class hierarchy to get compile-time
3341 // enforcement of the limited imported target API.
3342 if(this->IsImported())
3344 std::string msg = "GetLibraryNames called on imported target: ";
3345 msg += this->GetName();
3346 this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
3351 // Check for library version properties.
3352 const char* version = this->GetProperty("VERSION");
3353 const char* soversion = this->GetProperty("SOVERSION");
3354 if(!this->HasSOName(config) ||
3355 this->IsFrameworkOnApple())
3357 // Versioning is supported only for shared libraries and modules,
3358 // and then only when the platform supports an soname flag.
3362 if(version && !soversion)
3364 // The soversion must be set if the library version is set. Use
3365 // the library version as the soversion.
3366 soversion = version;
3368 if(!version && soversion)
3370 // Use the soversion as the library version.
3371 version = soversion;
3374 // Get the components of the library name.
3378 this->GetFullNameInternal(config, false, prefix, base, suffix);
3380 // The library name.
3381 name = prefix+base+suffix;
3383 // The library's soname.
3384 this->ComputeVersionedName(soName, prefix, base, suffix,
3387 // The library's real name on disk.
3388 this->ComputeVersionedName(realName, prefix, base, suffix,
3391 // The import library name.
3392 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3393 this->GetType() == cmTarget::MODULE_LIBRARY)
3395 impName = this->GetFullNameInternal(config, true);
3402 // The program database file name.
3403 pdbName = prefix+base+".pdb";
3406 //----------------------------------------------------------------------------
3407 void cmTarget::ComputeVersionedName(std::string& vName,
3408 std::string const& prefix,
3409 std::string const& base,
3410 std::string const& suffix,
3411 std::string const& name,
3412 const char* version)
3414 vName = this->IsApple? (prefix+base) : name;
3420 vName += this->IsApple? suffix : std::string();
3423 //----------------------------------------------------------------------------
3424 void cmTarget::GetExecutableNames(std::string& name,
3425 std::string& realName,
3426 std::string& impName,
3427 std::string& pdbName,
3430 // This should not be called for imported targets.
3431 // TODO: Split cmTarget into a class hierarchy to get compile-time
3432 // enforcement of the limited imported target API.
3433 if(this->IsImported())
3436 "GetExecutableNames called on imported target: ";
3437 msg += this->GetName();
3438 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
3441 // This versioning is supported only for executables and then only
3442 // when the platform supports symbolic links.
3443 #if defined(_WIN32) && !defined(__CYGWIN__)
3444 const char* version = 0;
3446 // Check for executable version properties.
3447 const char* version = this->GetProperty("VERSION");
3448 if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
3454 // Get the components of the executable name.
3458 this->GetFullNameInternal(config, false, prefix, base, suffix);
3460 // The executable name.
3461 name = prefix+base+suffix;
3463 // The executable's real name on disk.
3464 #if defined(__CYGWIN__)
3465 realName = prefix+base;
3472 realName += version;
3474 #if defined(__CYGWIN__)
3478 // The import library name.
3479 impName = this->GetFullNameInternal(config, true);
3481 // The program database file name.
3482 pdbName = prefix+base+".pdb";
3485 //----------------------------------------------------------------------------
3486 bool cmTarget::HasImplibGNUtoMS()
3488 return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
3491 //----------------------------------------------------------------------------
3492 bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
3493 std::string& out, const char* newExt)
3495 if(this->HasImplibGNUtoMS() &&
3496 gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
3498 out = gnuName.substr(0, gnuName.size()-6);
3499 out += newExt? newExt : ".lib";
3505 //----------------------------------------------------------------------------
3506 void cmTarget::GenerateTargetManifest(const char* config)
3508 cmMakefile* mf = this->Makefile;
3509 cmLocalGenerator* lg = mf->GetLocalGenerator();
3510 cmGlobalGenerator* gg = lg->GetGlobalGenerator();
3515 std::string realName;
3516 std::string impName;
3517 std::string pdbName;
3518 if(this->GetType() == cmTarget::EXECUTABLE)
3520 this->GetExecutableNames(name, realName, impName, pdbName, config);
3522 else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
3523 this->GetType() == cmTarget::SHARED_LIBRARY ||
3524 this->GetType() == cmTarget::MODULE_LIBRARY)
3526 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
3533 // Get the directory.
3534 std::string dir = this->GetDirectory(config, false);
3543 gg->AddToManifest(config? config:"", f);
3550 gg->AddToManifest(config? config:"", f);
3552 if(!realName.empty())
3557 gg->AddToManifest(config? config:"", f);
3559 if(!pdbName.empty())
3564 gg->AddToManifest(config? config:"", f);
3566 if(!impName.empty())
3568 f = this->GetDirectory(config, true);
3571 gg->AddToManifest(config? config:"", f);
3575 //----------------------------------------------------------------------------
3576 void cmTarget::SetPropertyDefault(const char* property,
3577 const char* default_value)
3579 // Compute the name of the variable holding the default value.
3580 std::string var = "CMAKE_";
3583 if(const char* value = this->Makefile->GetDefinition(var.c_str()))
3585 this->SetProperty(property, value);
3587 else if(default_value)
3589 this->SetProperty(property, default_value);
3593 //----------------------------------------------------------------------------
3594 bool cmTarget::HaveBuildTreeRPATH()
3596 return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
3597 !this->LinkLibraries.empty());
3600 //----------------------------------------------------------------------------
3601 bool cmTarget::HaveInstallTreeRPATH()
3603 const char* install_rpath = this->GetProperty("INSTALL_RPATH");
3604 return (install_rpath && *install_rpath) &&
3605 !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
3608 //----------------------------------------------------------------------------
3609 bool cmTarget::NeedRelinkBeforeInstall(const char* config)
3611 // Only executables and shared libraries can have an rpath and may
3613 if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
3614 this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
3615 this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
3620 // If there is no install location this target will not be installed
3621 // and therefore does not need relinking.
3622 if(!this->GetHaveInstallRule())
3627 // If skipping all rpaths completely then no relinking is needed.
3628 if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
3633 // If building with the install-tree rpath no relinking is needed.
3634 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3639 // If chrpath is going to be used no relinking is needed.
3640 if(this->IsChrpathUsed(config))
3645 // Check for rpath support on this platform.
3646 if(const char* ll = this->GetLinkerLanguage(config))
3648 std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
3651 if(!this->Makefile->IsSet(flagVar.c_str()))
3653 // There is no rpath support on this platform so nothing needs
3660 // No linker language is known. This error will be reported by
3665 // If either a build or install tree rpath is set then the rpath
3666 // will likely change between the build tree and install tree and
3667 // this target must be relinked.
3668 return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
3671 //----------------------------------------------------------------------------
3672 std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
3675 // If building directly for installation then the build tree install_name
3676 // is the same as the install tree.
3677 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3679 return GetInstallNameDirForInstallTree(config, for_xcode);
3682 // Use the build tree directory for the target.
3683 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3684 !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
3685 !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
3687 std::string dir = this->GetDirectory(config);
3689 if(this->IsFrameworkOnApple() && !for_xcode)
3691 dir += this->GetFrameworkDirectory(config);
3701 //----------------------------------------------------------------------------
3702 std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
3705 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
3709 if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
3710 !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
3712 const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
3713 if(install_name_dir && *install_name_dir)
3715 dir = install_name_dir;
3720 if(this->IsFrameworkOnApple() && !for_xcode)
3722 dir += this->GetFrameworkDirectory(config);
3733 //----------------------------------------------------------------------------
3734 const char* cmTarget::GetOutputTargetType(bool implib)
3736 switch(this->GetType())
3738 case cmTarget::SHARED_LIBRARY:
3739 if(this->DLLPlatform)
3743 // A DLL import library is treated as an archive target.
3748 // A DLL shared library is treated as a runtime target.
3754 // For non-DLL platforms shared libraries are treated as
3758 case cmTarget::STATIC_LIBRARY:
3759 // Static libraries are always treated as archive targets.
3761 case cmTarget::MODULE_LIBRARY:
3764 // Module libraries are always treated as library targets.
3769 // Module import libraries are treated as archive targets.
3772 case cmTarget::EXECUTABLE:
3775 // Executable import libraries are treated as archive targets.
3780 // Executables are always treated as runtime targets.
3789 //----------------------------------------------------------------------------
3790 bool cmTarget::ComputeOutputDir(const char* config,
3791 bool implib, std::string& out)
3793 bool usesDefaultOutputDir = false;
3795 // Look for a target property defining the target output directory
3796 // based on the target type.
3797 std::string targetTypeName = this->GetOutputTargetType(implib);
3798 const char* propertyName = 0;
3799 std::string propertyNameStr = targetTypeName;
3800 if(!propertyNameStr.empty())
3802 propertyNameStr += "_OUTPUT_DIRECTORY";
3803 propertyName = propertyNameStr.c_str();
3806 // Check for a per-configuration output directory target property.
3807 std::string configUpper = cmSystemTools::UpperCase(config? config : "");
3808 const char* configProp = 0;
3809 std::string configPropStr = targetTypeName;
3810 if(!configPropStr.empty())
3812 configPropStr += "_OUTPUT_DIRECTORY_";
3813 configPropStr += configUpper;
3814 configProp = configPropStr.c_str();
3817 // Select an output directory.
3818 if(const char* config_outdir = this->GetProperty(configProp))
3820 // Use the user-specified per-configuration output directory.
3821 out = config_outdir;
3823 // Skip per-configuration subdirectory.
3826 else if(const char* outdir = this->GetProperty(propertyName))
3828 // Use the user-specified output directory.
3831 else if(this->GetType() == cmTarget::EXECUTABLE)
3833 // Lookup the output path for executables.
3834 out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
3836 else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
3837 this->GetType() == cmTarget::SHARED_LIBRARY ||
3838 this->GetType() == cmTarget::MODULE_LIBRARY)
3840 // Lookup the output path for libraries.
3841 out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
3845 // Default to the current output directory.
3846 usesDefaultOutputDir = true;
3850 // Convert the output path to a full path in case it is
3851 // specified as a relative path. Treat a relative path as
3852 // relative to the current output directory for this makefile.
3853 out = (cmSystemTools::CollapseFullPath
3854 (out.c_str(), this->Makefile->GetStartOutputDirectory()));
3856 // The generator may add the configuration's subdirectory.
3857 if(config && *config)
3859 const char *platforms = this->Makefile->GetDefinition(
3860 "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
3861 std::string suffix =
3862 usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
3863 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
3864 AppendDirectoryForConfig("/", config, suffix.c_str(), out);
3867 return usesDefaultOutputDir;
3870 //----------------------------------------------------------------------------
3871 bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib)
3874 return this->ComputeOutputDir(config, implib, dir);
3877 //----------------------------------------------------------------------------
3878 std::string cmTarget::GetOutputName(const char* config, bool implib)
3880 std::vector<std::string> props;
3881 std::string type = this->GetOutputTargetType(implib);
3882 std::string configUpper = cmSystemTools::UpperCase(config? config : "");
3883 if(!type.empty() && !configUpper.empty())
3885 // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
3886 props.push_back(type + "_OUTPUT_NAME_" + configUpper);
3890 // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
3891 props.push_back(type + "_OUTPUT_NAME");
3893 if(!configUpper.empty())
3895 // OUTPUT_NAME_<CONFIG>
3896 props.push_back("OUTPUT_NAME_" + configUpper);
3897 // <CONFIG>_OUTPUT_NAME
3898 props.push_back(configUpper + "_OUTPUT_NAME");
3901 props.push_back("OUTPUT_NAME");
3903 for(std::vector<std::string>::const_iterator i = props.begin();
3904 i != props.end(); ++i)
3906 if(const char* outName = this->GetProperty(i->c_str()))
3911 return this->GetName();
3914 //----------------------------------------------------------------------------
3915 std::string cmTarget::GetFrameworkVersion()
3917 if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
3921 else if(const char* tversion = this->GetProperty("VERSION"))
3931 //----------------------------------------------------------------------------
3932 const char* cmTarget::GetExportMacro()
3934 // Define the symbol for targets that export symbols.
3935 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3936 this->GetType() == cmTarget::MODULE_LIBRARY ||
3937 this->IsExecutableWithExports())
3939 if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
3941 this->ExportMacro = custom_export_name;
3945 std::string in = this->GetName();
3947 this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
3949 return this->ExportMacro.c_str();
3957 //----------------------------------------------------------------------------
3958 void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
3960 for(std::vector<cmSourceFile*>::const_iterator
3961 i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
3963 if(const char* lang = (*i)->GetLanguage())
3965 languages.insert(lang);
3970 //----------------------------------------------------------------------------
3971 void cmTarget::GetAppleArchs(const char* config,
3972 std::vector<std::string>& archVec)
3974 const char* archs = 0;
3975 if(config && *config)
3977 std::string defVarName = "OSX_ARCHITECTURES_";
3978 defVarName += cmSystemTools::UpperCase(config);
3979 archs = this->GetProperty(defVarName.c_str());
3983 archs = this->GetProperty("OSX_ARCHITECTURES");
3987 cmSystemTools::ExpandListArgument(std::string(archs), archVec);
3991 //----------------------------------------------------------------------------
3992 bool cmTarget::IsChrpathUsed(const char* config)
3994 #if defined(CMAKE_USE_ELF_PARSER)
3995 // Only certain target types have an rpath.
3996 if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
3997 this->GetType() == cmTarget::MODULE_LIBRARY ||
3998 this->GetType() == cmTarget::EXECUTABLE))
4003 // If the target will not be installed we do not need to change its
4005 if(!this->GetHaveInstallRule())
4010 // Skip chrpath if skipping rpath altogether.
4011 if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
4016 // Skip chrpath if it does not need to be changed at install time.
4017 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
4022 // Allow the user to disable builtin chrpath explicitly.
4023 if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
4028 // Enable if the rpath flag uses a separator and the target uses ELF
4030 if(const char* ll = this->GetLinkerLanguage(config))
4032 std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
4034 sepVar += "_FLAG_SEP";
4035 const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
4038 // TODO: Add ELF check to ABI detection and get rid of
4039 // CMAKE_EXECUTABLE_FORMAT.
4040 if(const char* fmt =
4041 this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
4043 return strcmp(fmt, "ELF") == 0;
4048 static_cast<void>(config);
4052 //----------------------------------------------------------------------------
4053 cmTarget::ImportInfo const*
4054 cmTarget::GetImportInfo(const char* config)
4056 // There is no imported information for non-imported targets.
4057 if(!this->IsImported())
4062 // Lookup/compute/cache the import information for this
4064 std::string config_upper;
4065 if(config && *config)
4067 config_upper = cmSystemTools::UpperCase(config);
4071 config_upper = "NOCONFIG";
4073 typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
4074 ImportInfoMapType::const_iterator i =
4075 this->Internal->ImportInfoMap.find(config_upper);
4076 if(i == this->Internal->ImportInfoMap.end())
4079 this->ComputeImportInfo(config_upper, info);
4080 ImportInfoMapType::value_type entry(config_upper, info);
4081 i = this->Internal->ImportInfoMap.insert(entry).first;
4084 // If the location is empty then the target is not available for
4085 // this configuration.
4086 if(i->second.Location.empty() && i->second.ImportLibrary.empty())
4091 // Return the import information.
4095 //----------------------------------------------------------------------------
4096 void cmTarget::ComputeImportInfo(std::string const& desired_config,
4099 // This method finds information about an imported target from its
4100 // properties. The "IMPORTED_" namespace is reserved for properties
4101 // defined by the project exporting the target.
4103 // Initialize members.
4104 info.NoSOName = false;
4106 // Track the configuration-specific property suffix.
4107 std::string suffix = "_";
4108 suffix += desired_config;
4110 // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
4111 // library or an executable with exports.
4112 bool allowImp = this->HasImportLibrary();
4114 // Look for a mapping from the current project's configuration to
4115 // the imported project's configuration.
4116 std::vector<std::string> mappedConfigs;
4118 std::string mapProp = "MAP_IMPORTED_CONFIG_";
4119 mapProp += desired_config;
4120 if(const char* mapValue = this->GetProperty(mapProp.c_str()))
4122 cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
4126 // If a mapping was found, check its configurations.
4127 const char* loc = 0;
4128 const char* imp = 0;
4129 for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
4130 !loc && !imp && mci != mappedConfigs.end(); ++mci)
4132 // Look for this configuration.
4133 std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
4134 std::string locProp = "IMPORTED_LOCATION_";
4136 loc = this->GetProperty(locProp.c_str());
4139 std::string impProp = "IMPORTED_IMPLIB_";
4141 imp = this->GetProperty(impProp.c_str());
4144 // If it was found, use it for all properties below.
4152 // If we needed to find one of the mapped configurations but did not
4153 // then the target is not found. The project does not want any
4154 // other configuration.
4155 if(!mappedConfigs.empty() && !loc && !imp)
4160 // If we have not yet found it then there are no mapped
4161 // configurations. Look for an exact-match.
4164 std::string locProp = "IMPORTED_LOCATION";
4166 loc = this->GetProperty(locProp.c_str());
4169 std::string impProp = "IMPORTED_IMPLIB";
4171 imp = this->GetProperty(impProp.c_str());
4175 // If we have not yet found it then there are no mapped
4176 // configurations and no exact match.
4179 // The suffix computed above is not useful.
4182 // Look for a configuration-less location. This may be set by
4183 // manually-written code.
4184 loc = this->GetProperty("IMPORTED_LOCATION");
4187 imp = this->GetProperty("IMPORTED_IMPLIB");
4191 // If we have not yet found it then the project is willing to try
4192 // any available configuration.
4195 std::vector<std::string> availableConfigs;
4196 if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
4198 cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
4200 for(std::vector<std::string>::const_iterator
4201 aci = availableConfigs.begin();
4202 !loc && !imp && aci != availableConfigs.end(); ++aci)
4205 suffix += cmSystemTools::UpperCase(*aci);
4206 std::string locProp = "IMPORTED_LOCATION";
4208 loc = this->GetProperty(locProp.c_str());
4211 std::string impProp = "IMPORTED_IMPLIB";
4213 imp = this->GetProperty(impProp.c_str());
4218 // If we have not yet found it then the target is not available.
4224 // A provided configuration has been chosen. Load the
4225 // configuration's properties.
4227 // Get the location.
4230 info.Location = loc;
4234 std::string impProp = "IMPORTED_LOCATION";
4236 if(const char* config_location = this->GetProperty(impProp.c_str()))
4238 info.Location = config_location;
4240 else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
4242 info.Location = location;
4247 if(this->GetType() == cmTarget::SHARED_LIBRARY)
4249 std::string soProp = "IMPORTED_SONAME";
4251 if(const char* config_soname = this->GetProperty(soProp.c_str()))
4253 info.SOName = config_soname;
4255 else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
4257 info.SOName = soname;
4261 // Get the "no-soname" mark.
4262 if(this->GetType() == cmTarget::SHARED_LIBRARY)
4264 std::string soProp = "IMPORTED_NO_SONAME";
4266 if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
4268 info.NoSOName = cmSystemTools::IsOn(config_no_soname);
4270 else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
4272 info.NoSOName = cmSystemTools::IsOn(no_soname);
4276 // Get the import library.
4279 info.ImportLibrary = imp;
4281 else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
4282 this->IsExecutableWithExports())
4284 std::string impProp = "IMPORTED_IMPLIB";
4286 if(const char* config_implib = this->GetProperty(impProp.c_str()))
4288 info.ImportLibrary = config_implib;
4290 else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
4292 info.ImportLibrary = implib;
4296 // Get the link interface.
4298 std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
4300 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
4302 cmSystemTools::ExpandListArgument(config_libs,
4303 info.LinkInterface.Libraries);
4305 else if(const char* libs =
4306 this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
4308 cmSystemTools::ExpandListArgument(libs,
4309 info.LinkInterface.Libraries);
4313 // Get the link dependencies.
4315 std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
4317 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
4319 cmSystemTools::ExpandListArgument(config_libs,
4320 info.LinkInterface.SharedDeps);
4322 else if(const char* libs =
4323 this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
4325 cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
4329 // Get the link languages.
4330 if(this->GetType() == cmTarget::STATIC_LIBRARY)
4332 std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
4334 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
4336 cmSystemTools::ExpandListArgument(config_libs,
4337 info.LinkInterface.Languages);
4339 else if(const char* libs =
4340 this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
4342 cmSystemTools::ExpandListArgument(libs,
4343 info.LinkInterface.Languages);
4347 // Get the cyclic repetition count.
4348 if(this->GetType() == cmTarget::STATIC_LIBRARY)
4350 std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
4352 if(const char* config_reps = this->GetProperty(linkProp.c_str()))
4354 sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
4356 else if(const char* reps =
4357 this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
4359 sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
4364 //----------------------------------------------------------------------------
4365 cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config)
4367 // Imported targets have their own link interface.
4368 if(this->IsImported())
4370 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
4372 return &info->LinkInterface;
4377 // Link interfaces are not supported for executables that do not
4379 if(this->GetType() == cmTarget::EXECUTABLE &&
4380 !this->IsExecutableWithExports())
4385 // Lookup any existing link interface for this configuration.
4386 std::string key = cmSystemTools::UpperCase(config? config : "");
4387 cmTargetInternals::LinkInterfaceMapType::iterator
4388 i = this->Internal->LinkInterfaceMap.find(key);
4389 if(i == this->Internal->LinkInterfaceMap.end())
4391 // Compute the link interface for this configuration.
4392 cmTargetInternals::OptionalLinkInterface iface;
4393 iface.Exists = this->ComputeLinkInterface(config, iface);
4395 // Store the information for this configuration.
4396 cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
4397 i = this->Internal->LinkInterfaceMap.insert(entry).first;
4400 return i->second.Exists? &i->second : 0;
4403 //----------------------------------------------------------------------------
4404 bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface)
4406 // Construct the property name suffix for this configuration.
4407 std::string suffix = "_";
4408 if(config && *config)
4410 suffix += cmSystemTools::UpperCase(config);
4414 suffix += "NOCONFIG";
4417 // An explicit list of interface libraries may be set for shared
4418 // libraries and executables that export symbols.
4419 const char* explicitLibraries = 0;
4420 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
4421 this->IsExecutableWithExports())
4423 // Lookup the per-configuration property.
4424 std::string propName = "LINK_INTERFACE_LIBRARIES";
4426 explicitLibraries = this->GetProperty(propName.c_str());
4428 // If not set, try the generic property.
4429 if(!explicitLibraries)
4431 explicitLibraries = this->GetProperty("LINK_INTERFACE_LIBRARIES");
4435 // There is no implicit link interface for executables or modules
4436 // so if none was explicitly set then there is no link interface.
4437 // Note that CMake versions 2.2 and below allowed linking to modules.
4438 bool canLinkModules = this->Makefile->NeedBackwardsCompatibility(2,2);
4439 if(!explicitLibraries &&
4440 (this->GetType() == cmTarget::EXECUTABLE ||
4441 (this->GetType() == cmTarget::MODULE_LIBRARY && !canLinkModules)))
4446 if(explicitLibraries)
4448 // The interface libraries have been explicitly set.
4449 cmSystemTools::ExpandListArgument(explicitLibraries, iface.Libraries);
4451 if(this->GetType() == cmTarget::SHARED_LIBRARY)
4453 // Shared libraries may have runtime implementation dependencies
4454 // on other shared libraries that are not in the interface.
4455 std::set<cmStdString> emitted;
4456 for(std::vector<std::string>::const_iterator
4457 li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
4459 emitted.insert(*li);
4461 LinkImplementation const* impl = this->GetLinkImplementation(config);
4462 for(std::vector<std::string>::const_iterator
4463 li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
4465 if(emitted.insert(*li).second)
4467 if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
4469 // This is a runtime dependency on another shared library.
4470 if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
4472 iface.SharedDeps.push_back(*li);
4477 // TODO: Recognize shared library file names. Perhaps this
4478 // should be moved to cmComputeLinkInformation, but that creates
4479 // a chicken-and-egg problem since this list is needed for its
4488 // The link implementation is the default link interface.
4489 LinkImplementation const* impl = this->GetLinkImplementation(config);
4490 iface.Libraries = impl->Libraries;
4491 iface.WrongConfigLibraries = impl->WrongConfigLibraries;
4492 if(this->GetType() == cmTarget::STATIC_LIBRARY)
4494 // Targets using this archive need its language runtime libraries.
4495 iface.Languages = impl->Languages;
4499 if(this->GetType() == cmTarget::STATIC_LIBRARY)
4501 // How many repetitions are needed if this library has cyclic
4503 std::string propName = "LINK_INTERFACE_MULTIPLICITY";
4505 if(const char* config_reps = this->GetProperty(propName.c_str()))
4507 sscanf(config_reps, "%u", &iface.Multiplicity);
4509 else if(const char* reps =
4510 this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
4512 sscanf(reps, "%u", &iface.Multiplicity);
4519 //----------------------------------------------------------------------------
4520 cmTarget::LinkImplementation const*
4521 cmTarget::GetLinkImplementation(const char* config)
4523 // There is no link implementation for imported targets.
4524 if(this->IsImported())
4529 // Lookup any existing link implementation for this configuration.
4530 std::string key = cmSystemTools::UpperCase(config? config : "");
4531 cmTargetInternals::LinkImplMapType::iterator
4532 i = this->Internal->LinkImplMap.find(key);
4533 if(i == this->Internal->LinkImplMap.end())
4535 // Compute the link implementation for this configuration.
4536 LinkImplementation impl;
4537 this->ComputeLinkImplementation(config, impl);
4539 // Store the information for this configuration.
4540 cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
4541 i = this->Internal->LinkImplMap.insert(entry).first;
4547 //----------------------------------------------------------------------------
4548 void cmTarget::ComputeLinkImplementation(const char* config,
4549 LinkImplementation& impl)
4551 // Compute which library configuration to link.
4552 cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
4554 // Collect libraries directly linked in this configuration.
4555 LinkLibraryVectorType const& llibs = this->GetOriginalLinkLibraries();
4556 for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
4557 li != llibs.end(); ++li)
4559 // Skip entries that resolve to the target itself or are empty.
4560 std::string item = this->CheckCMP0004(li->first);
4561 if(item == this->GetName() || item.empty())
4566 if(li->second == cmTarget::GENERAL || li->second == linkType)
4568 // The entry is meant for this configuration.
4569 impl.Libraries.push_back(item);
4573 // Support OLD behavior for CMP0003.
4574 impl.WrongConfigLibraries.push_back(item);
4578 // This target needs runtime libraries for its source languages.
4579 std::set<cmStdString> languages;
4580 // Get languages used in our source files.
4581 this->GetLanguages(languages);
4582 // Get languages used in object library sources.
4583 for(std::vector<std::string>::iterator i = this->ObjectLibraries.begin();
4584 i != this->ObjectLibraries.end(); ++i)
4586 if(cmTarget* objLib = this->Makefile->FindTargetToUse(i->c_str()))
4588 if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
4590 objLib->GetLanguages(languages);
4594 // Copy the set of langauges to the link implementation.
4595 for(std::set<cmStdString>::iterator li = languages.begin();
4596 li != languages.end(); ++li)
4598 impl.Languages.push_back(*li);
4602 //----------------------------------------------------------------------------
4603 std::string cmTarget::CheckCMP0004(std::string const& item)
4605 // Strip whitespace off the library names because we used to do this
4606 // in case variables were expanded at generate time. We no longer
4607 // do the expansion but users link to libraries like " ${VAR} ".
4608 std::string lib = item;
4609 std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
4612 lib = lib.substr(pos, lib.npos);
4614 pos = lib.find_last_not_of(" \t\r\n");
4617 lib = lib.substr(0, pos+1);
4621 cmake* cm = this->Makefile->GetCMakeInstance();
4622 switch(this->PolicyStatusCMP0004)
4624 case cmPolicies::WARN:
4627 w << (this->Makefile->GetPolicies()
4628 ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
4629 << "Target \"" << this->GetName() << "\" links to item \""
4630 << item << "\" which has leading or trailing whitespace.";
4631 cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
4632 this->GetBacktrace());
4634 case cmPolicies::OLD:
4636 case cmPolicies::NEW:
4639 e << "Target \"" << this->GetName() << "\" links to item \""
4640 << item << "\" which has leading or trailing whitespace. "
4641 << "This is now an error according to policy CMP0004.";
4642 cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
4645 case cmPolicies::REQUIRED_IF_USED:
4646 case cmPolicies::REQUIRED_ALWAYS:
4649 e << (this->Makefile->GetPolicies()
4650 ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
4651 << "Target \"" << this->GetName() << "\" links to item \""
4652 << item << "\" which has leading or trailing whitespace.";
4653 cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
4661 //----------------------------------------------------------------------------
4662 cmComputeLinkInformation*
4663 cmTarget::GetLinkInformation(const char* config)
4665 // Lookup any existing information for this configuration.
4666 std::map<cmStdString, cmComputeLinkInformation*>::iterator
4667 i = this->LinkInformation.find(config?config:"");
4668 if(i == this->LinkInformation.end())
4670 // Compute information for this configuration.
4671 cmComputeLinkInformation* info =
4672 new cmComputeLinkInformation(this, config);
4673 if(!info || !info->Compute())
4679 // Store the information for this configuration.
4680 std::map<cmStdString, cmComputeLinkInformation*>::value_type
4681 entry(config?config:"", info);
4682 i = this->LinkInformation.insert(entry).first;
4687 //----------------------------------------------------------------------------
4688 std::vector<std::string> cmTarget::GetIncludeDirectories()
4690 std::vector<std::string> includes;
4691 const char *prop = this->GetProperty("INCLUDE_DIRECTORIES");
4694 cmSystemTools::ExpandListArgument(prop, includes);
4697 std::set<std::string> uniqueIncludes;
4698 std::vector<std::string> orderedAndUniqueIncludes;
4699 for(std::vector<std::string>::const_iterator
4700 li = includes.begin(); li != includes.end(); ++li)
4702 if(uniqueIncludes.insert(*li).second)
4704 orderedAndUniqueIncludes.push_back(*li);
4708 return orderedAndUniqueIncludes;
4711 //----------------------------------------------------------------------------
4712 std::string cmTarget::GetFrameworkDirectory(const char* config)
4715 fpath += this->GetFullName(config, false);
4716 fpath += ".framework/Versions/";
4717 fpath += this->GetFrameworkVersion();
4722 //----------------------------------------------------------------------------
4723 std::string cmTarget::BuildMacContentDirectory(const std::string& base,
4727 std::string fpath = base;
4728 if(this->IsAppBundleOnApple())
4730 fpath += this->GetFullName(config, false);
4731 fpath += ".app/Contents/";
4735 if(this->IsFrameworkOnApple())
4737 fpath += this->GetFrameworkDirectory(config);
4739 if(this->IsCFBundleOnApple())
4741 fpath += this->GetFullName(config, false);
4743 const char *ext = this->GetProperty("BUNDLE_EXTENSION");
4749 fpath += "/Contents/";
4756 //----------------------------------------------------------------------------
4757 std::string cmTarget::GetMacContentDirectory(const char* config,
4761 // Start with the output directory for the target.
4762 std::string fpath = this->GetDirectory(config, implib);
4764 fpath = this->BuildMacContentDirectory(fpath, config, includeMacOS);
4768 //----------------------------------------------------------------------------
4769 cmTargetLinkInformationMap
4770 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
4772 // Ideally cmTarget instances should never be copied. However until
4773 // we can make a sweep to remove that, this copy constructor avoids
4774 // allowing the resources (LinkInformation) from getting copied. In
4775 // the worst case this will lead to extra cmComputeLinkInformation
4776 // instances. We also enforce in debug mode that the map be emptied
4778 static_cast<void>(r);
4782 //----------------------------------------------------------------------------
4783 cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
4785 for(derived::iterator i = this->begin(); i != this->end(); ++i)
4791 //----------------------------------------------------------------------------
4792 cmTargetInternalPointer::cmTargetInternalPointer()
4794 this->Pointer = new cmTargetInternals;
4797 //----------------------------------------------------------------------------
4798 cmTargetInternalPointer
4799 ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
4801 // Ideally cmTarget instances should never be copied. However until
4802 // we can make a sweep to remove that, this copy constructor avoids
4803 // allowing the resources (Internals) to be copied.
4804 this->Pointer = new cmTargetInternals(*r.Pointer);
4807 //----------------------------------------------------------------------------
4808 cmTargetInternalPointer::~cmTargetInternalPointer()
4810 delete this->Pointer;
4813 //----------------------------------------------------------------------------
4814 cmTargetInternalPointer&
4815 cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
4817 if(this == &r) { return *this; } // avoid warning on HP about self check
4818 // Ideally cmTarget instances should never be copied. However until
4819 // we can make a sweep to remove that, this copy constructor avoids
4820 // allowing the resources (Internals) to be copied.
4821 cmTargetInternals* oldPointer = this->Pointer;
4822 this->Pointer = new cmTargetInternals(*r.Pointer);