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 "cmDocumentGeneratorExpressions.h"
21 #include "cmDocumentLocationUndefined.h"
22 #include "cmListFileCache.h"
23 #include "cmGeneratorExpression.h"
24 #include "cmGeneratorExpressionDAGChecker.h"
25 #include <cmsys/RegularExpression.hxx>
29 #include <stdlib.h> // required for atof
32 const char* cmTarget::GetTargetTypeName(TargetType targetType)
36 case cmTarget::STATIC_LIBRARY:
37 return "STATIC_LIBRARY";
38 case cmTarget::MODULE_LIBRARY:
39 return "MODULE_LIBRARY";
40 case cmTarget::SHARED_LIBRARY:
41 return "SHARED_LIBRARY";
42 case cmTarget::OBJECT_LIBRARY:
43 return "OBJECT_LIBRARY";
44 case cmTarget::EXECUTABLE:
46 case cmTarget::UTILITY:
48 case cmTarget::GLOBAL_TARGET:
49 return "GLOBAL_TARGET";
50 case cmTarget::UNKNOWN_LIBRARY:
51 return "UNKNOWN_LIBRARY";
53 assert(0 && "Unexpected target type");
57 //----------------------------------------------------------------------------
58 struct cmTarget::OutputInfo
65 //----------------------------------------------------------------------------
66 struct cmTarget::ImportInfo
71 std::string ImportLibrary;
72 cmTarget::LinkInterface LinkInterface;
75 struct TargetConfigPair : public std::pair<cmTarget*, std::string> {
76 TargetConfigPair(cmTarget* tgt, const std::string &config)
77 : std::pair<cmTarget*, std::string>(tgt, config) {}
80 //----------------------------------------------------------------------------
81 class cmTargetInternals
86 this->PolicyWarnedCMP0022 = false;
87 this->SourceFileFlagsConstructed = false;
89 cmTargetInternals(cmTargetInternals const& r)
91 this->PolicyWarnedCMP0022 = false;
92 this->SourceFileFlagsConstructed = false;
93 // Only some of these entries are part of the object state.
94 // Others not copied here are result caches.
95 this->SourceEntries = r.SourceEntries;
98 typedef cmTarget::SourceFileFlags SourceFileFlags;
99 std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
100 bool SourceFileFlagsConstructed;
102 // The backtrace when the target was created.
103 cmListFileBacktrace Backtrace;
105 // Cache link interface computation from each configuration.
106 struct OptionalLinkInterface: public cmTarget::LinkInterface
108 OptionalLinkInterface(): Exists(false) {}
111 typedef std::map<TargetConfigPair, OptionalLinkInterface>
112 LinkInterfaceMapType;
113 LinkInterfaceMapType LinkInterfaceMap;
114 bool PolicyWarnedCMP0022;
116 typedef std::map<cmStdString, cmTarget::OutputInfo> OutputInfoMapType;
117 OutputInfoMapType OutputInfoMap;
119 typedef std::map<TargetConfigPair, cmTarget::ImportInfo>
121 ImportInfoMapType ImportInfoMap;
123 // Cache link implementation computation from each configuration.
124 typedef std::map<TargetConfigPair,
125 cmTarget::LinkImplementation> LinkImplMapType;
126 LinkImplMapType LinkImplMap;
128 typedef std::map<TargetConfigPair, cmTarget::LinkClosure>
130 LinkClosureMapType LinkClosureMap;
132 struct SourceEntry { std::vector<cmSourceFile*> Depends; };
133 typedef std::map<cmSourceFile*, SourceEntry> SourceEntriesType;
134 SourceEntriesType SourceEntries;
136 struct TargetPropertyEntry {
137 TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
138 const std::string &targetName = std::string())
139 : ge(cge), TargetName(targetName)
141 const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
142 std::vector<std::string> CachedEntries;
143 const std::string TargetName;
145 std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
146 std::vector<TargetPropertyEntry*> CompileOptionsEntries;
147 std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
148 std::vector<cmValueWithOrigin> LinkInterfacePropertyEntries;
150 std::map<std::string, std::vector<TargetPropertyEntry*> >
151 CachedLinkInterfaceIncludeDirectoriesEntries;
152 std::map<std::string, std::vector<TargetPropertyEntry*> >
153 CachedLinkInterfaceCompileOptionsEntries;
154 std::map<std::string, std::vector<TargetPropertyEntry*> >
155 CachedLinkInterfaceCompileDefinitionsEntries;
157 std::map<std::string, bool> CacheLinkInterfaceIncludeDirectoriesDone;
158 std::map<std::string, bool> CacheLinkInterfaceCompileDefinitionsDone;
159 std::map<std::string, bool> CacheLinkInterfaceCompileOptionsDone;
162 //----------------------------------------------------------------------------
164 std::vector<cmTargetInternals::TargetPropertyEntry*> &entries)
166 for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
167 it = entries.begin(),
176 //----------------------------------------------------------------------------
178 std::map<std::string,
179 std::vector<cmTargetInternals::TargetPropertyEntry*> > &entries)
181 for (std::map<std::string,
182 std::vector<cmTargetInternals::TargetPropertyEntry*> >::iterator
183 it = entries.begin(), end = entries.end(); it != end; ++it)
185 deleteAndClear(it->second);
189 //----------------------------------------------------------------------------
190 cmTargetInternals::~cmTargetInternals()
192 deleteAndClear(this->CachedLinkInterfaceIncludeDirectoriesEntries);
193 deleteAndClear(this->CachedLinkInterfaceCompileOptionsEntries);
194 deleteAndClear(this->CachedLinkInterfaceCompileDefinitionsEntries);
197 //----------------------------------------------------------------------------
200 #define INITIALIZE_TARGET_POLICY_MEMBER(POLICY) \
201 this->PolicyStatus ## POLICY = cmPolicies::WARN;
203 CM_FOR_EACH_TARGET_POLICY(INITIALIZE_TARGET_POLICY_MEMBER)
205 #undef INITIALIZE_TARGET_POLICY_MEMBER
208 this->LinkLibrariesAnalyzed = false;
209 this->HaveInstallRule = false;
210 this->DLLPlatform = false;
211 this->IsApple = false;
212 this->IsImportedTarget = false;
213 this->BuildInterfaceIncludesAppended = false;
214 this->DebugIncludesDone = false;
215 this->DebugCompileOptionsDone = false;
216 this->DebugCompileDefinitionsDone = false;
219 //----------------------------------------------------------------------------
220 void cmTarget::DefineProperties(cmake *cm)
223 ("AUTOMOC", cmProperty::TARGET,
224 "Should the target be processed with automoc (for Qt projects).",
225 "AUTOMOC is a boolean specifying whether CMake will handle "
226 "the Qt moc preprocessor automatically, i.e. without having to use "
227 "the QT4_WRAP_CPP() or QT5_WRAP_CPP() macro. Currently Qt4 and Qt5 are "
229 "When this property is set to TRUE, CMake will scan the source files "
230 "at build time and invoke moc accordingly. "
231 "If an #include statement like #include \"moc_foo.cpp\" is found, "
232 "the Q_OBJECT class declaration is expected in the header, and moc is "
233 "run on the header file. "
234 "If an #include statement like #include \"foo.moc\" is found, "
235 "then a Q_OBJECT is expected in the current source file and moc "
236 "is run on the file itself. "
237 "Additionally, all header files are parsed for Q_OBJECT macros, "
238 "and if found, moc is also executed on those files. The resulting "
239 "moc files, which are not included as shown above in any of the source "
240 "files are included in a generated <targetname>_automoc.cpp file, "
241 "which is compiled as part of the target."
242 "This property is initialized by the value of the variable "
243 "CMAKE_AUTOMOC if it is set when a target is created.\n"
244 "Additional command line options for moc can be set via the "
245 "AUTOMOC_MOC_OPTIONS property.\n"
246 "By setting the CMAKE_AUTOMOC_RELAXED_MODE variable to TRUE the rules "
247 "for searching the files which will be processed by moc can be relaxed. "
248 "See the documentation for this variable for more details.\n"
249 "The global property AUTOMOC_TARGETS_FOLDER can be used to group the "
250 "automoc targets together in an IDE, e.g. in MSVS.");
253 ("AUTOMOC_MOC_OPTIONS", cmProperty::TARGET,
254 "Additional options for moc when using automoc (see the AUTOMOC property)",
255 "This property is only used if the AUTOMOC property is set to TRUE for "
256 "this target. In this case, it holds additional command line options "
257 "which will be used when moc is executed during the build, i.e. it is "
258 "equivalent to the optional OPTIONS argument of the qt4_wrap_cpp() "
260 "By default it is empty.");
263 ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
264 "Should build tree targets have install tree rpaths.",
265 "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
266 "the target in the build tree with the INSTALL_RPATH. This takes "
267 "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
268 "before installation. "
269 "This property is initialized by the value of the variable "
270 "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
273 ("COMPILE_FLAGS", cmProperty::TARGET,
274 "Additional flags to use when compiling this target's sources.",
275 "The COMPILE_FLAGS property sets additional compiler flags used "
276 "to build sources within the target. Use COMPILE_DEFINITIONS "
277 "to pass additional preprocessor definitions.");
280 ("COMPILE_DEFINITIONS", cmProperty::TARGET,
281 "Preprocessor definitions for compiling a target's sources.",
282 "The COMPILE_DEFINITIONS property may be set to a "
283 "semicolon-separated list of preprocessor "
284 "definitions using the syntax VAR or VAR=value. Function-style "
285 "definitions are not supported. CMake will automatically escape "
286 "the value correctly for the native build system (note that CMake "
287 "language syntax may require escapes to specify some values). "
288 "This property may be set on a per-configuration basis using the name "
289 "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
290 "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
291 "CMake will automatically drop some definitions that "
292 "are not supported by the native build tool. "
293 "The VS6 IDE does not support definition values with spaces "
294 "(but NMake does).\n"
295 "Contents of COMPILE_DEFINITIONS may use \"generator expressions\" with "
296 "the syntax \"$<...>\". "
297 CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS
298 CM_DOCUMENT_COMPILE_DEFINITIONS_DISCLAIMER);
301 ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
302 "Per-configuration preprocessor definitions on a target.",
303 "This is the configuration-specific version of COMPILE_DEFINITIONS.");
306 ("COMPILE_OPTIONS", cmProperty::TARGET,
307 "List of options to pass to the compiler.",
308 "This property specifies the list of options specified "
309 "so far for this property. "
310 "This property exists on directories and targets."
312 "The target property values are used by the generators to set "
313 "the options for the compiler.\n"
314 "Contents of COMPILE_OPTIONS may use \"generator expressions\" with "
315 "the syntax \"$<...>\". "
316 CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
319 ("INTERFACE_COMPILE_OPTIONS", cmProperty::TARGET,
320 "List of interface options to pass to the compiler.",
321 "Targets may populate this property to publish the compile options "
322 "required to compile against the headers for the target. Consuming "
323 "targets can add entries to their own COMPILE_OPTIONS property such "
324 "as $<TARGET_PROPERTY:foo,INTERFACE_COMPILE_OPTIONS> to use the "
325 "compile options specified in the interface of 'foo'."
327 CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
330 ("DEFINE_SYMBOL", cmProperty::TARGET,
331 "Define a symbol when compiling this target's sources.",
332 "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
333 "compiling sources in a shared library. "
334 "If not set here then it is set to target_EXPORTS by default "
335 "(with some substitutions if the target is not a valid C "
336 "identifier). This is useful for headers to know whether they are "
337 "being included from inside their library or outside to properly "
338 "setup dllexport/dllimport decorations. ");
341 ("DEBUG_POSTFIX", cmProperty::TARGET,
342 "See target property <CONFIG>_POSTFIX.",
343 "This property is a special case of the more-general <CONFIG>_POSTFIX "
344 "property for the DEBUG configuration.");
347 ("<CONFIG>_POSTFIX", cmProperty::TARGET,
348 "Postfix to append to the target file name for configuration <CONFIG>.",
349 "When building with configuration <CONFIG> the value of this property "
350 "is appended to the target file name built on disk. "
351 "For non-executable targets, this property is initialized by the value "
352 "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
354 "This property is ignored on the Mac for Frameworks and App Bundles.");
357 ("EchoString", cmProperty::TARGET,
358 "A message to be displayed when the target is built.",
359 "A message to display on some generators (such as makefiles) when "
360 "the target is built.");
363 ("BUNDLE", cmProperty::TARGET,
364 "This target is a CFBundle on the Mac.",
365 "If a module library target has this property set to true it will "
366 "be built as a CFBundle when built on the mac. It will have the "
367 "directory structure required for a CFBundle and will be suitable "
368 "to be used for creating Browser Plugins or other application "
372 ("BUNDLE_EXTENSION", cmProperty::TARGET,
373 "The file extension used to name a BUNDLE target on the Mac.",
374 "The default value is \"bundle\" - you can also use \"plugin\" or "
375 "whatever file extension is required by the host app for your "
379 ("EXCLUDE_FROM_DEFAULT_BUILD", cmProperty::TARGET,
380 "Exclude target from \"Build Solution\".",
381 "This property is only used by Visual Studio generators 7 and above. "
382 "When set to TRUE, the target will not be built when you press "
383 "\"Build Solution\".");
386 ("EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG>", cmProperty::TARGET,
387 "Per-configuration version of target exclusion from \"Build Solution\". ",
388 "This is the configuration-specific version of "
389 "EXCLUDE_FROM_DEFAULT_BUILD. If the generic EXCLUDE_FROM_DEFAULT_BUILD "
390 "is also set on a target, EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG> takes "
391 "precedence in configurations for which it has a value.");
394 ("FRAMEWORK", cmProperty::TARGET,
395 "This target is a framework on the Mac.",
396 "If a shared library target has this property set to true it will "
397 "be built as a framework when built on the mac. It will have the "
398 "directory structure required for a framework and will be suitable "
399 "to be used with the -framework option");
402 ("HAS_CXX", cmProperty::TARGET,
403 "Link the target using the C++ linker tool (obsolete).",
404 "This is equivalent to setting the LINKER_LANGUAGE property to CXX. "
405 "See that property's documentation for details.");
408 ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
409 "Specify #include line transforms for dependencies in a target.",
410 "This property specifies rules to transform macro-like #include lines "
411 "during implicit dependency scanning of C and C++ source files. "
412 "The list of rules must be semicolon-separated with each entry of "
413 "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
414 "During dependency scanning occurrences of A_MACRO(...) on #include "
415 "lines will be replaced by the value given with the macro argument "
416 "substituted for '%'. For example, the entry\n"
417 " MYDIR(%)=<mydir/%>\n"
418 "will convert lines of the form\n"
419 " #include MYDIR(myheader.h)\n"
421 " #include <mydir/myheader.h>\n"
422 "allowing the dependency to be followed.\n"
423 "This property applies to sources in the target on which it is set.");
426 ("IMPORT_PREFIX", cmProperty::TARGET,
427 "What comes before the import library name.",
428 "Similar to the target property PREFIX, but used for import libraries "
429 "(typically corresponding to a DLL) instead of regular libraries. "
430 "A target property that can be set to override the prefix "
431 "(such as \"lib\") on an import library name.");
434 ("IMPORT_SUFFIX", cmProperty::TARGET,
435 "What comes after the import library name.",
436 "Similar to the target property SUFFIX, but used for import libraries "
437 "(typically corresponding to a DLL) instead of regular libraries. "
438 "A target property that can be set to override the suffix "
439 "(such as \".lib\") on an import library name.");
442 ("IMPORTED", cmProperty::TARGET,
443 "Read-only indication of whether a target is IMPORTED.",
444 "The boolean value of this property is true for targets created with "
445 "the IMPORTED option to add_executable or add_library. "
446 "It is false for targets built within the project.");
449 ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
450 "Configurations provided for an IMPORTED target.",
451 "Set this to the list of configuration names available for an "
453 "The names correspond to configurations defined in the project from "
454 "which the target is imported. "
455 "If the importing project uses a different set of configurations "
456 "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
458 "Ignored for non-imported targets.");
461 ("IMPORTED_IMPLIB", cmProperty::TARGET,
462 "Full path to the import library for an IMPORTED target.",
463 "Set this to the location of the \".lib\" part of a windows DLL. "
464 "Ignored for non-imported targets.");
467 ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
468 "<CONFIG>-specific version of IMPORTED_IMPLIB property.",
469 "Configuration names correspond to those provided by the project "
470 "from which the target is imported.");
473 ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
474 "Dependent shared libraries of an imported shared library.",
475 "Shared libraries may be linked to other shared libraries as part "
476 "of their implementation. On some platforms the linker searches "
477 "for the dependent libraries of shared libraries they are including "
479 "Set this property to the list of dependent shared libraries of an "
482 "should be disjoint from the list of interface libraries in the "
483 "INTERFACE_LINK_LIBRARIES property. On platforms requiring "
484 "dependent shared libraries to be found at link time CMake uses this "
485 "list to add appropriate files or paths to the link command line. "
486 "Ignored for non-imported targets.");
489 ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
490 "<CONFIG>-specific version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
491 "Configuration names correspond to those provided by the project "
492 "from which the target is imported. "
493 "If set, this property completely overrides the generic property "
494 "for the named configuration.");
497 ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
498 "Transitive link interface of an IMPORTED target.",
499 "Set this to the list of libraries whose interface is included when "
500 "an IMPORTED library target is linked to another target. "
501 "The libraries will be included on the link line for the target. "
502 "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
503 "to all imported target types, including STATIC libraries. "
504 "This property is ignored for non-imported targets.\n"
505 "This property is ignored if the target also has a non-empty "
506 "INTERFACE_LINK_LIBRARIES property.\n"
507 "This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.");
510 ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
511 "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
512 "Configuration names correspond to those provided by the project "
513 "from which the target is imported. "
514 "If set, this property completely overrides the generic property "
515 "for the named configuration.\n"
516 "This property is ignored if the target also has a non-empty "
517 "INTERFACE_LINK_LIBRARIES property.\n"
518 "This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.");
521 ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET,
522 "Languages compiled into an IMPORTED static library.",
523 "Set this to the list of languages of source files compiled to "
524 "produce a STATIC IMPORTED library (such as \"C\" or \"CXX\"). "
525 "CMake accounts for these languages when computing how to link a "
526 "target to the imported library. "
527 "For example, when a C executable links to an imported C++ static "
528 "library CMake chooses the C++ linker to satisfy language runtime "
529 "dependencies of the static library. "
531 "This property is ignored for targets that are not STATIC libraries. "
532 "This property is ignored for non-imported targets.");
535 ("IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>", cmProperty::TARGET,
536 "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LANGUAGES.",
537 "Configuration names correspond to those provided by the project "
538 "from which the target is imported. "
539 "If set, this property completely overrides the generic property "
540 "for the named configuration.");
543 ("IMPORTED_LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
544 "Repetition count for cycles of IMPORTED static libraries.",
545 "This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.");
547 ("IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
548 "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_MULTIPLICITY.",
549 "If set, this property completely overrides the generic property "
550 "for the named configuration.");
553 ("IMPORTED_LOCATION", cmProperty::TARGET,
554 "Full path to the main file on disk for an IMPORTED target.",
555 "Set this to the location of an IMPORTED target file on disk. "
556 "For executables this is the location of the executable file. "
557 "For bundles on OS X this is the location of the executable file "
558 "inside Contents/MacOS under the application bundle folder. "
559 "For static libraries and modules this is the location of the "
560 "library or module. "
561 "For shared libraries on non-DLL platforms this is the location of "
562 "the shared library. "
563 "For frameworks on OS X this is the location of the library file "
564 "symlink just inside the framework folder. "
565 "For DLLs this is the location of the \".dll\" part of the library. "
566 "For UNKNOWN libraries this is the location of the file to be linked. "
567 "Ignored for non-imported targets."
569 "Projects may skip IMPORTED_LOCATION if the configuration-specific "
570 "property IMPORTED_LOCATION_<CONFIG> is set. "
571 "To get the location of an imported target read one of the "
572 "LOCATION or LOCATION_<CONFIG> properties.");
575 ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
576 "<CONFIG>-specific version of IMPORTED_LOCATION property.",
577 "Configuration names correspond to those provided by the project "
578 "from which the target is imported.");
581 ("IMPORTED_SONAME", cmProperty::TARGET,
582 "The \"soname\" of an IMPORTED target of shared library type.",
583 "Set this to the \"soname\" embedded in an imported shared library. "
584 "This is meaningful only on platforms supporting the feature. "
585 "Ignored for non-imported targets.");
588 ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
589 "<CONFIG>-specific version of IMPORTED_SONAME property.",
590 "Configuration names correspond to those provided by the project "
591 "from which the target is imported.");
594 ("IMPORTED_NO_SONAME", cmProperty::TARGET,
595 "Specifies that an IMPORTED shared library target has no \"soname\". ",
596 "Set this property to true for an imported shared library file that "
597 "has no \"soname\" field. "
598 "CMake may adjust generated link commands for some platforms to prevent "
599 "the linker from using the path to the library in place of its missing "
601 "Ignored for non-imported targets.");
604 ("IMPORTED_NO_SONAME_<CONFIG>", cmProperty::TARGET,
605 "<CONFIG>-specific version of IMPORTED_NO_SONAME property.",
606 "Configuration names correspond to those provided by the project "
607 "from which the target is imported.");
610 ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
611 "Exclude the target from the all target.",
612 "A property on a target that indicates if the target is excluded "
613 "from the default build target. If it is not, then with a Makefile "
614 "for example typing make will cause this target to be built. "
615 "The same concept applies to the default build of other generators. "
616 "Installing a target with EXCLUDE_FROM_ALL set to true has "
617 "undefined behavior.");
620 ("LINK_LIBRARIES", cmProperty::TARGET,
621 "List of direct link dependencies.",
622 "This property specifies the list of libraries or targets which will be "
624 "In addition to accepting values from the target_link_libraries "
625 "command, values may be set directly on any target using the "
626 "set_property command. "
628 "The target property values are used by the generators to set "
629 "the link libraries for the compiler. "
630 "See also the target_link_libraries command.\n"
631 "Contents of LINK_LIBRARIES may use \"generator expressions\" with "
632 "the syntax \"$<...>\". "
633 CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
636 ("INCLUDE_DIRECTORIES", cmProperty::TARGET,
637 "List of preprocessor include file search directories.",
638 "This property specifies the list of directories given "
639 "so far to the include_directories command. "
640 "This property exists on directories and targets. "
641 "In addition to accepting values from the include_directories "
642 "command, values may be set directly on any directory or any "
643 "target using the set_property command. "
644 "A target gets its initial value for this property from the value "
645 "of the directory property. "
646 "A directory gets its initial value from its parent directory if "
648 "Both directory and target property values are adjusted by calls "
649 "to the include_directories command."
651 "The target property values are used by the generators to set "
652 "the include paths for the compiler. "
653 "See also the include_directories command.\n"
654 "Contents of INCLUDE_DIRECTORIES may use \"generator expressions\" with "
655 "the syntax \"$<...>\". "
656 CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
659 ("INSTALL_NAME_DIR", cmProperty::TARGET,
660 "Mac OSX directory name for installed targets.",
661 "INSTALL_NAME_DIR is a string specifying the "
662 "directory portion of the \"install_name\" field of shared libraries "
663 "on Mac OSX to use in the installed targets. ");
666 ("INSTALL_RPATH", cmProperty::TARGET,
667 "The rpath to use for installed targets.",
668 "A semicolon-separated list specifying the rpath "
669 "to use in installed targets (for platforms that support it). "
670 "This property is initialized by the value of the variable "
671 "CMAKE_INSTALL_RPATH if it is set when a target is created.");
674 ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
675 "Add paths to linker search and installed rpath.",
676 "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
677 "append directories in the linker search path and outside the "
678 "project to the INSTALL_RPATH. "
679 "This property is initialized by the value of the variable "
680 "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
684 ("INTERPROCEDURAL_OPTIMIZATION", cmProperty::TARGET,
685 "Enable interprocedural optimization for a target.",
686 "If set to true, enables interprocedural optimizations "
687 "if they are known to be supported by the compiler.");
690 ("INTERPROCEDURAL_OPTIMIZATION_<CONFIG>", cmProperty::TARGET,
691 "Per-configuration interprocedural optimization for a target.",
692 "This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION. "
693 "If set, this property overrides the generic property "
694 "for the named configuration.");
697 ("LABELS", cmProperty::TARGET,
698 "Specify a list of text labels associated with a target.",
699 "Target label semantics are currently unspecified.");
702 ("LINK_FLAGS", cmProperty::TARGET,
703 "Additional flags to use when linking this target.",
704 "The LINK_FLAGS property can be used to add extra flags to the "
705 "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
706 "configuration <CONFIG>, "
707 "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
710 ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
711 "Per-configuration linker flags for a target.",
712 "This is the configuration-specific version of LINK_FLAGS.");
714 #define CM_LINK_SEARCH_SUMMARY \
715 "Some linkers support switches such as -Bstatic and -Bdynamic " \
716 "to determine whether to use static or shared libraries for -lXXX " \
717 "options. CMake uses these options to set the link type for " \
718 "libraries whose full paths are not known or (in some cases) are in " \
719 "implicit link directories for the platform. "
722 ("LINK_SEARCH_START_STATIC", cmProperty::TARGET,
723 "Assume the linker looks for static libraries by default.",
724 CM_LINK_SEARCH_SUMMARY
725 "By default the linker search type is assumed to be -Bdynamic at "
726 "the beginning of the library list. This property switches the "
727 "assumption to -Bstatic. It is intended for use when linking an "
728 "executable statically (e.g. with the GNU -static option). "
729 "See also LINK_SEARCH_END_STATIC.");
732 ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
733 "End a link line such that static system libraries are used.",
734 CM_LINK_SEARCH_SUMMARY
735 "By default CMake adds an option at the end of the library list (if "
736 "necessary) to set the linker search type back to its starting type. "
737 "This property switches the final linker search type to -Bstatic "
738 "regardless of how it started. "
739 "See also LINK_SEARCH_START_STATIC.");
742 ("LINKER_LANGUAGE", cmProperty::TARGET,
743 "Specifies language whose compiler will invoke the linker.",
744 "For executables, shared libraries, and modules, this sets the "
745 "language whose compiler is used to link the target "
746 "(such as \"C\" or \"CXX\"). "
747 "A typical value for an executable is the language of the source "
748 "file providing the program entry point (main). "
749 "If not set, the language with the highest linker preference "
750 "value is the default. "
751 "See documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables."
753 "If this property is not set by the user, it will be calculated at "
754 "generate-time by CMake."
758 ("LOCATION", cmProperty::TARGET,
759 "Read-only location of a target on disk.",
760 "For an imported target, this read-only property returns the value of "
761 "the LOCATION_<CONFIG> property for an unspecified configuration "
762 "<CONFIG> provided by the target.\n"
763 "For a non-imported target, this property is provided for compatibility "
764 "with CMake 2.4 and below. "
765 "It was meant to get the location of an executable target's output file "
766 "for use in add_custom_command. "
767 "The path may contain a build-system-specific portion that "
768 "is replaced at build time with the configuration getting built "
769 "(such as \"$(ConfigurationName)\" in VS). "
770 "In CMake 2.6 and above add_custom_command automatically recognizes a "
771 "target name in its COMMAND and DEPENDS options and computes the "
773 "In CMake 2.8.4 and above add_custom_command recognizes generator "
774 "expressions to refer to target locations anywhere in the command. "
775 "Therefore this property is not needed for creating custom commands."
776 CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
779 ("LOCATION_<CONFIG>", cmProperty::TARGET,
780 "Read-only property providing a target location on disk.",
781 "A read-only property that indicates where a target's main file is "
782 "located on disk for the configuration <CONFIG>. "
783 "The property is defined only for library and executable targets. "
784 "An imported target may provide a set of configurations different "
785 "from that of the importing project. "
786 "By default CMake looks for an exact-match but otherwise uses an "
787 "arbitrary available configuration. "
788 "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
789 "configurations explicitly."
790 CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
793 ("LINK_DEPENDS", cmProperty::TARGET,
794 "Additional files on which a target binary depends for linking.",
795 "Specifies a semicolon-separated list of full-paths to files on which "
796 "the link rule for this target depends. "
797 "The target binary will be linked if any of the named files is newer "
800 "This property is ignored by non-Makefile generators. "
801 "It is intended to specify dependencies on \"linker scripts\" for "
802 "custom Makefile link rules.");
805 ("LINK_DEPENDS_NO_SHARED", cmProperty::TARGET,
806 "Do not depend on linked shared library files.",
807 "Set this property to true to tell CMake generators not to add "
808 "file-level dependencies on the shared library files linked by "
810 "Modification to the shared libraries will not be sufficient to "
811 "re-link this target. "
812 "Logical target-level dependencies will not be affected so the "
813 "linked shared libraries will still be brought up to date before "
814 "this target is built."
816 "This property is initialized by the value of the variable "
817 "CMAKE_LINK_DEPENDS_NO_SHARED if it is set when a target is "
821 ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
822 "List public interface libraries for a shared library or executable.",
823 "By default linking to a shared library target transitively "
824 "links to targets with which the library itself was linked. "
825 "For an executable with exports (see the ENABLE_EXPORTS property) "
826 "no default transitive link dependencies are used. "
827 "This property replaces the default transitive link dependencies with "
829 "When the target is linked into another target the libraries "
830 "listed (and recursively their link interface libraries) will be "
831 "provided to the other target also. "
832 "If the list is empty then no transitive link dependencies will be "
833 "incorporated when this target is linked into another target even if "
834 "the default set is non-empty. "
835 "This property is initialized by the value of the variable "
836 "CMAKE_LINK_INTERFACE_LIBRARIES if it is set when a target is "
838 "This property is ignored for STATIC libraries.\n"
839 "This property is overridden by the INTERFACE_LINK_LIBRARIES property if "
840 "policy CMP0022 is NEW.\n"
841 "This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.");
844 ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
845 "Per-configuration list of public interface libraries for a target.",
846 "This is the configuration-specific version of "
847 "LINK_INTERFACE_LIBRARIES. "
848 "If set, this property completely overrides the generic property "
849 "for the named configuration.\n"
850 "This property is overridden by the INTERFACE_LINK_LIBRARIES property if "
851 "policy CMP0022 is NEW.\n"
852 "This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.");
855 ("INTERFACE_LINK_LIBRARIES", cmProperty::TARGET,
856 "List public interface libraries for a library.",
857 "This property contains the list of transitive link dependencies. "
858 "When the target is linked into another target the libraries "
859 "listed (and recursively their link interface libraries) will be "
860 "provided to the other target also. "
861 "This property is overridden by the LINK_INTERFACE_LIBRARIES or "
862 "LINK_INTERFACE_LIBRARIES_<CONFIG> property if "
863 "policy CMP0022 is OLD or unset.\n"
865 CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
868 ("INTERFACE_INCLUDE_DIRECTORIES", cmProperty::TARGET,
869 "List of public include directories for a library.",
870 "Targets may populate this property to publish the include directories "
871 "required to compile against the headers for the target. Consuming "
872 "targets can add entries to their own INCLUDE_DIRECTORIES property such "
873 "as $<TARGET_PROPERTY:foo,INTERFACE_INCLUDE_DIRECTORIES> to use the "
874 "include directories specified in the interface of 'foo'."
876 CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
879 ("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", cmProperty::TARGET,
880 "List of public system include directories for a library.",
881 "Targets may populate this property to publish the include directories "
882 "which contain system headers, and therefore should not result in "
883 "compiler warnings. Consuming targets will then mark the same include "
884 "directories as system headers."
886 CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
889 ("INTERFACE_COMPILE_DEFINITIONS", cmProperty::TARGET,
890 "List of public compile definitions for a library.",
891 "Targets may populate this property to publish the compile definitions "
892 "required to compile against the headers for the target. Consuming "
893 "targets can add entries to their own COMPILE_DEFINITIONS property such "
894 "as $<TARGET_PROPERTY:foo,INTERFACE_COMPILE_DEFINITIONS> to use the "
895 "compile definitions specified in the interface of 'foo'."
897 CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
900 ("LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
901 "Repetition count for STATIC libraries with cyclic dependencies.",
902 "When linking to a STATIC library target with cyclic dependencies the "
903 "linker may need to scan more than once through the archives in the "
904 "strongly connected component of the dependency graph. "
905 "CMake by default constructs the link line so that the linker will "
906 "scan through the component at least twice. "
907 "This property specifies the minimum number of scans if it is larger "
909 "CMake uses the largest value specified by any target in a component.");
911 ("LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
912 "Per-configuration repetition count for cycles of STATIC libraries.",
913 "This is the configuration-specific version of "
914 "LINK_INTERFACE_MULTIPLICITY. "
915 "If set, this property completely overrides the generic property "
916 "for the named configuration.");
919 ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
920 "Map from project configuration to IMPORTED target's configuration.",
921 "Set this to the list of configurations of an imported target that "
922 "may be used for the current project's <CONFIG> configuration. "
923 "Targets imported from another project may not provide the same set "
924 "of configuration names available in the current project. "
925 "Setting this property tells CMake what imported configurations are "
926 "suitable for use when building the <CONFIG> configuration. "
927 "The first configuration in the list found to be provided by the "
928 "imported target is selected. If this property is set and no matching "
929 "configurations are available, then the imported target is considered "
930 "to be not found. This property is ignored for non-imported targets.",
931 false /* TODO: make this chained */ );
934 ("OSX_ARCHITECTURES", cmProperty::TARGET,
935 "Target specific architectures for OS X.",
936 "The OSX_ARCHITECTURES property sets the target binary architecture "
937 "for targets on OS X. "
938 "This property is initialized by the value of the variable "
939 "CMAKE_OSX_ARCHITECTURES if it is set when a target is created. "
940 "Use OSX_ARCHITECTURES_<CONFIG> to set the binary architectures on a "
941 "per-configuration basis. "
942 "<CONFIG> is an upper-case name (ex: \"OSX_ARCHITECTURES_DEBUG\").");
945 ("OSX_ARCHITECTURES_<CONFIG>", cmProperty::TARGET,
946 "Per-configuration OS X binary architectures for a target.",
947 "This property is the configuration-specific version of "
948 "OSX_ARCHITECTURES.");
951 ("NAME", cmProperty::TARGET,
952 "Logical name for the target.",
953 "Read-only logical name for the target as used by CMake.");
956 ("EXPORT_NAME", cmProperty::TARGET,
957 "Exported name for target files.",
958 "This sets the name for the IMPORTED target generated when it this "
959 "target is is exported. "
960 "If not set, the logical target name is used by default.");
963 ("OUTPUT_NAME", cmProperty::TARGET,
964 "Output name for target files.",
965 "This sets the base name for output files created for an executable or "
967 "If not set, the logical target name is used by default.");
970 ("OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
971 "Per-configuration target file base name.",
972 "This is the configuration-specific version of OUTPUT_NAME.");
975 ("ALIASED_TARGET", cmProperty::TARGET,
976 "Name of target aliased by this target.",
977 "If this is an ALIAS target, this property contains the name of the "
981 ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET,
982 "Old per-configuration target file base name.",
983 "This is a configuration-specific version of OUTPUT_NAME. "
984 "Use OUTPUT_NAME_<CONFIG> instead.");
987 ("PDB_NAME", cmProperty::TARGET,
988 "Output name for MS debug symbols .pdb file from linker.",
989 "Set the base name for debug symbols file created for an "
990 "executable or shared library target. "
991 "If not set, the logical target name is used by default. "
993 "This property is not implemented by the Visual Studio 6 generator.");
996 ("PDB_NAME_<CONFIG>", cmProperty::TARGET,
997 "Per-configuration name for MS debug symbols .pdb file. ",
998 "This is the configuration-specific version of PDB_NAME. "
1000 "This property is not implemented by the Visual Studio 6 generator.");
1003 ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
1004 "Deprecated install support.",
1005 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
1006 "old way to specify CMake scripts to run before and after "
1007 "installing a target. They are used only when the old "
1008 "INSTALL_TARGETS command is used to install the target. Use the "
1009 "INSTALL command instead.");
1012 ("PREFIX", cmProperty::TARGET,
1013 "What comes before the library name.",
1014 "A target property that can be set to override the prefix "
1015 "(such as \"lib\") on a library name.");
1018 ("<LANG>_VISIBILITY_PRESET", cmProperty::TARGET,
1019 "Value for symbol visibility compile flags",
1020 "The <LANG>_VISIBILITY_PRESET property determines the value passed in "
1021 "a visibility related compile option, such as -fvisibility= for <LANG>. "
1022 "This property only has an affect for libraries and executables with "
1023 "exports. This property is initialized by the value of the variable "
1024 "CMAKE_<LANG>_VISIBILITY_PRESET if it is set when a target is created.");
1027 ("VISIBILITY_INLINES_HIDDEN", cmProperty::TARGET,
1028 "Whether to add a compile flag to hide symbols of inline functions",
1029 "The VISIBILITY_INLINES_HIDDEN property determines whether a flag for "
1030 "hiding symbols for inline functions. the value passed used in "
1031 "a visibility related compile option, such as -fvisibility=. This "
1032 "property only has an affect for libraries and executables with "
1033 "exports. This property is initialized by the value of the variable "
1034 "CMAKE_VISIBILITY_INLINES_HIDDEN if it is set when a target is "
1038 ("POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
1039 "Whether to create a position-independent target",
1040 "The POSITION_INDEPENDENT_CODE property determines whether position "
1041 "independent executables or shared libraries will be created. "
1042 "This property is true by default for SHARED and MODULE library "
1043 "targets and false otherwise. "
1044 "This property is initialized by the value of the variable "
1045 "CMAKE_POSITION_INDEPENDENT_CODE if it is set when a target is "
1049 ("INTERFACE_POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
1050 "Whether consumers need to create a position-independent target",
1051 "The INTERFACE_POSITION_INDEPENDENT_CODE property informs consumers of "
1052 "this target whether they must set their POSITION_INDEPENDENT_CODE "
1053 "property to ON. If this property is set to ON, then the "
1054 "POSITION_INDEPENDENT_CODE property on all consumers will be set to "
1055 "ON. Similarly, if this property is set to OFF, then the "
1056 "POSITION_INDEPENDENT_CODE property on all consumers will be set to "
1057 "OFF. If this property is undefined, then consumers will determine "
1058 "their POSITION_INDEPENDENT_CODE property by other means. Consumers "
1059 "must ensure that the targets that they link to have a consistent "
1060 "requirement for their INTERFACE_POSITION_INDEPENDENT_CODE property.");
1063 ("COMPATIBLE_INTERFACE_BOOL", cmProperty::TARGET,
1064 "Properties which must be compatible with their link interface",
1065 "The COMPATIBLE_INTERFACE_BOOL property may contain a list of properties"
1066 "for this target which must be consistent when evaluated as a boolean "
1067 "in the INTERFACE of all linked dependees. For example, if a "
1068 "property \"FOO\" appears in the list, then for each dependee, the "
1069 "\"INTERFACE_FOO\" property content in all of its dependencies must be "
1070 "consistent with each other, and with the \"FOO\" property in the "
1071 "dependee. Consistency in this sense has the meaning that if the "
1072 "property is set, then it must have the same boolean value as all "
1073 "others, and if the property is not set, then it is ignored. Note that "
1074 "for each dependee, the set of properties from this property must not "
1075 "intersect with the set of properties from the "
1076 "COMPATIBLE_INTERFACE_STRING property.");
1079 ("COMPATIBLE_INTERFACE_STRING", cmProperty::TARGET,
1080 "Properties which must be string-compatible with their link interface",
1081 "The COMPATIBLE_INTERFACE_STRING property may contain a list of "
1082 "properties for this target which must be the same when evaluated as "
1083 "a string in the INTERFACE of all linked dependees. For example, "
1084 "if a property \"FOO\" appears in the list, then for each dependee, the "
1085 "\"INTERFACE_FOO\" property content in all of its dependencies must be "
1086 "equal with each other, and with the \"FOO\" property in the dependee. "
1087 "If the property is not set, then it is ignored. Note that for each "
1088 "dependee, the set of properties from this property must not intersect "
1089 "with the set of properties from the COMPATIBLE_INTERFACE_BOOL "
1093 ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
1094 "Deprecated install support.",
1095 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
1096 "old way to specify CMake scripts to run before and after "
1097 "installing a target. They are used only when the old "
1098 "INSTALL_TARGETS command is used to install the target. Use the "
1099 "INSTALL command instead.");
1102 ("PRIVATE_HEADER", cmProperty::TARGET,
1103 "Specify private header files in a FRAMEWORK shared library target.",
1104 "Shared library targets marked with the FRAMEWORK property generate "
1105 "frameworks on OS X and normal shared libraries on other platforms. "
1106 "This property may be set to a list of header files to be placed "
1107 "in the PrivateHeaders directory inside the framework folder. "
1108 "On non-Apple platforms these headers may be installed using the "
1109 "PRIVATE_HEADER option to the install(TARGETS) command.");
1112 ("PUBLIC_HEADER", cmProperty::TARGET,
1113 "Specify public header files in a FRAMEWORK shared library target.",
1114 "Shared library targets marked with the FRAMEWORK property generate "
1115 "frameworks on OS X and normal shared libraries on other platforms. "
1116 "This property may be set to a list of header files to be placed "
1117 "in the Headers directory inside the framework folder. "
1118 "On non-Apple platforms these headers may be installed using the "
1119 "PUBLIC_HEADER option to the install(TARGETS) command.");
1122 ("RESOURCE", cmProperty::TARGET,
1123 "Specify resource files in a FRAMEWORK shared library target.",
1124 "Shared library targets marked with the FRAMEWORK property generate "
1125 "frameworks on OS X and normal shared libraries on other platforms. "
1126 "This property may be set to a list of files to be placed "
1127 "in the Resources directory inside the framework folder. "
1128 "On non-Apple platforms these files may be installed using the "
1129 "RESOURCE option to the install(TARGETS) command.");
1132 ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
1133 "Specify a launcher for compile rules.",
1134 "See the global property of the same name for details. "
1135 "This overrides the global and directory property for a target.",
1138 ("RULE_LAUNCH_LINK", cmProperty::TARGET,
1139 "Specify a launcher for link rules.",
1140 "See the global property of the same name for details. "
1141 "This overrides the global and directory property for a target.",
1144 ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
1145 "Specify a launcher for custom rules.",
1146 "See the global property of the same name for details. "
1147 "This overrides the global and directory property for a target.",
1151 ("SKIP_BUILD_RPATH", cmProperty::TARGET,
1152 "Should rpaths be used for the build tree.",
1153 "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
1154 "generation of an rpath allowing the target to run from the "
1156 "This property is initialized by the value of the variable "
1157 "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
1160 ("NO_SONAME", cmProperty::TARGET,
1161 "Whether to set \"soname\" when linking a shared library or module.",
1162 "Enable this boolean property if a generated shared library or module "
1163 "should not have \"soname\" set. Default is to set \"soname\" on all "
1164 "shared libraries and modules as long as the platform supports it. "
1165 "Generally, use this property only for leaf private libraries or "
1166 "plugins. If you use it on normal shared libraries which other targets "
1167 "link against, on some platforms a linker will insert a full path to "
1168 "the library (as specified at link time) into the dynamic section of "
1169 "the dependent binary. Therefore, once installed, dynamic loader may "
1170 "eventually fail to locate the library for the binary.");
1173 ("SOVERSION", cmProperty::TARGET,
1174 "What version number is this target.",
1175 "For shared libraries VERSION and SOVERSION can be used to specify "
1176 "the build version and API version respectively. When building or "
1177 "installing appropriate symlinks are created if the platform "
1178 "supports symlinks and the linker supports so-names. "
1179 "If only one of both is specified the missing is assumed to have "
1180 "the same version number. "
1181 "SOVERSION is ignored if NO_SONAME property is set. "
1182 "For shared libraries and executables on Windows the VERSION "
1183 "attribute is parsed to extract a \"major.minor\" version number. "
1184 "These numbers are used as the image version of the binary. ");
1187 ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
1188 "Extra flags to use when linking static libraries.",
1189 "Extra flags to use when linking a static library.");
1192 ("STATIC_LIBRARY_FLAGS_<CONFIG>", cmProperty::TARGET,
1193 "Per-configuration flags for creating a static library.",
1194 "This is the configuration-specific version of STATIC_LIBRARY_FLAGS.");
1197 ("SUFFIX", cmProperty::TARGET,
1198 "What comes after the target name.",
1199 "A target property that can be set to override the suffix "
1200 "(such as \".so\" or \".exe\") on the name of a library, module or "
1204 ("TYPE", cmProperty::TARGET,
1205 "The type of the target.",
1206 "This read-only property can be used to test the type of the given "
1207 "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
1208 "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
1211 ("VERSION", cmProperty::TARGET,
1212 "What version number is this target.",
1213 "For shared libraries VERSION and SOVERSION can be used to specify "
1214 "the build version and API version respectively. When building or "
1215 "installing appropriate symlinks are created if the platform "
1216 "supports symlinks and the linker supports so-names. "
1217 "If only one of both is specified the missing is assumed to have "
1218 "the same version number. "
1219 "For executables VERSION can be used to specify the build version. "
1220 "When building or installing appropriate symlinks are created if "
1221 "the platform supports symlinks. "
1222 "For shared libraries and executables on Windows the VERSION "
1223 "attribute is parsed to extract a \"major.minor\" version number. "
1224 "These numbers are used as the image version of the binary. ");
1228 ("WIN32_EXECUTABLE", cmProperty::TARGET,
1229 "Build an executable with a WinMain entry point on windows.",
1230 "When this property is set to true the executable when linked "
1231 "on Windows will be created with a WinMain() entry point instead "
1233 "This makes it a GUI executable instead of a console application. "
1234 "See the CMAKE_MFC_FLAG variable documentation to configure use "
1235 "of MFC for WinMain executables. "
1236 "This property is initialized by the value of the variable "
1237 "CMAKE_WIN32_EXECUTABLE if it is set when a target is created.");
1240 ("MACOSX_BUNDLE", cmProperty::TARGET,
1241 "Build an executable as an application bundle on Mac OS X.",
1242 "When this property is set to true the executable when built "
1243 "on Mac OS X will be created as an application bundle. "
1244 "This makes it a GUI executable that can be launched from "
1246 "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
1247 "about creation of the Info.plist file for the application bundle. "
1248 "This property is initialized by the value of the variable "
1249 "CMAKE_MACOSX_BUNDLE if it is set when a target is created.");
1252 ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
1253 "Specify a custom Info.plist template for a Mac OS X App Bundle.",
1254 "An executable target with MACOSX_BUNDLE enabled will be built as an "
1255 "application bundle on Mac OS X. "
1256 "By default its Info.plist file is created by configuring a template "
1257 "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
1258 "This property specifies an alternative template file name which "
1259 "may be a full path.\n"
1260 "The following target properties may be set to specify content to "
1261 "be configured into the file:\n"
1262 " MACOSX_BUNDLE_INFO_STRING\n"
1263 " MACOSX_BUNDLE_ICON_FILE\n"
1264 " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
1265 " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
1266 " MACOSX_BUNDLE_BUNDLE_NAME\n"
1267 " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
1268 " MACOSX_BUNDLE_BUNDLE_VERSION\n"
1269 " MACOSX_BUNDLE_COPYRIGHT\n"
1270 "CMake variables of the same name may be set to affect all targets "
1271 "in a directory that do not have each specific property set. "
1272 "If a custom Info.plist is specified by this property it may of course "
1273 "hard-code all the settings instead of using the target properties.");
1276 ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
1277 "Specify a custom Info.plist template for a Mac OS X Framework.",
1278 "A library target with FRAMEWORK enabled will be built as a "
1279 "framework on Mac OS X. "
1280 "By default its Info.plist file is created by configuring a template "
1281 "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
1282 "This property specifies an alternative template file name which "
1283 "may be a full path.\n"
1284 "The following target properties may be set to specify content to "
1285 "be configured into the file:\n"
1286 " MACOSX_FRAMEWORK_ICON_FILE\n"
1287 " MACOSX_FRAMEWORK_IDENTIFIER\n"
1288 " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
1289 " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
1290 "CMake variables of the same name may be set to affect all targets "
1291 "in a directory that do not have each specific property set. "
1292 "If a custom Info.plist is specified by this property it may of course "
1293 "hard-code all the settings instead of using the target properties.");
1296 ("MACOSX_RPATH", cmProperty::TARGET,
1297 "Whether to use rpaths on Mac OS X.",
1298 "When this property is set to true, the directory portion of the"
1299 "\"install_name\" field of shared libraries will default to \"@rpath\"."
1300 "Runtime paths will also be embedded in binaries using this target."
1301 "This property is initialized by the value of the variable "
1302 "CMAKE_MACOSX_RPATH if it is set when a target is created.");
1305 ("ENABLE_EXPORTS", cmProperty::TARGET,
1306 "Specify whether an executable exports symbols for loadable modules.",
1307 "Normally an executable does not export any symbols because it is "
1308 "the final program. It is possible for an executable to export "
1309 "symbols to be used by loadable modules. When this property is "
1310 "set to true CMake will allow other targets to \"link\" to the "
1311 "executable with the TARGET_LINK_LIBRARIES command. "
1312 "On all platforms a target-level dependency on the executable is "
1313 "created for targets that link to it. "
1314 "For DLL platforms an import library will be created for the "
1315 "exported symbols and then used for linking. "
1316 "All Windows-based systems including Cygwin are DLL platforms. "
1317 "For non-DLL platforms that require all symbols to be resolved at "
1318 "link time, such as Mac OS X, the module will \"link\" to the "
1319 "executable using a flag like \"-bundle_loader\". "
1320 "For other non-DLL platforms the link rule is simply ignored since "
1321 "the dynamic loader will automatically bind symbols when the "
1322 "module is loaded. "
1326 ("Fortran_FORMAT", cmProperty::TARGET,
1327 "Set to FIXED or FREE to indicate the Fortran source layout.",
1328 "This property tells CMake whether the Fortran source files "
1329 "in a target use fixed-format or free-format. "
1330 "CMake will pass the corresponding format flag to the compiler. "
1331 "Use the source-specific Fortran_FORMAT property to change the "
1332 "format of a specific source file. "
1333 "If the variable CMAKE_Fortran_FORMAT is set when a target "
1334 "is created its value is used to initialize this property.");
1337 ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
1338 "Specify output directory for Fortran modules provided by the target.",
1339 "If the target contains Fortran source files that provide modules "
1340 "and the compiler supports a module output directory this specifies "
1341 "the directory in which the modules will be placed. "
1342 "When this property is not set the modules will be placed in the "
1343 "build directory corresponding to the target's source directory. "
1344 "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
1345 "is created its value is used to initialize this property."
1347 "Note that some compilers will automatically search the module output "
1348 "directory for modules USEd during compilation but others will not. "
1349 "If your sources USE modules their location must be specified by "
1350 "INCLUDE_DIRECTORIES regardless of this property.");
1353 ("GNUtoMS", cmProperty::TARGET,
1354 "Convert GNU import library (.dll.a) to MS format (.lib).",
1355 "When linking a shared library or executable that exports symbols "
1356 "using GNU tools on Windows (MinGW/MSYS) with Visual Studio installed "
1357 "convert the import library (.dll.a) from GNU to MS format (.lib). "
1358 "Both import libraries will be installed by install(TARGETS) and "
1359 "exported by install(EXPORT) and export() to be linked by applications "
1360 "with either GNU- or MS-compatible tools."
1362 "If the variable CMAKE_GNUtoMS is set when a target "
1363 "is created its value is used to initialize this property. "
1364 "The variable must be set prior to the first command that enables "
1365 "a language such as project() or enable_language(). "
1366 "CMake provides the variable as an option to the user automatically "
1367 "when configuring on Windows with GNU tools.");
1370 ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
1371 "Set Xcode target attributes directly.",
1372 "Tell the Xcode generator to set '<an-attribute>' to a given value "
1373 "in the generated Xcode project. Ignored on other generators.");
1376 ("GENERATOR_FILE_NAME", cmProperty::TARGET,
1377 "Generator's file for this target.",
1378 "An internal property used by some generators to record the name of the "
1379 "project or dsp file associated with this target. Note that at configure "
1380 "time, this property is only set for targets created by "
1381 "include_external_msproject().");
1384 ("SOURCES", cmProperty::TARGET,
1385 "Source names specified for a target.",
1386 "Read-only list of sources specified for a target. "
1387 "The names returned are suitable for passing to the "
1388 "set_source_files_properties command.");
1391 ("FOLDER", cmProperty::TARGET,
1392 "Set the folder name. Use to organize targets in an IDE.",
1393 "Targets with no FOLDER property will appear as top level "
1394 "entities in IDEs like Visual Studio. Targets with the same "
1395 "FOLDER property value will appear next to each other in a "
1396 "folder of that name. To nest folders, use FOLDER values such "
1397 "as 'GUI/Dialogs' with '/' characters separating folder levels.");
1400 ("PROJECT_LABEL", cmProperty::TARGET,
1401 "Change the name of a target in an IDE.",
1402 "Can be used to change the name of the target in an IDE "
1403 "like Visual Studio. ");
1405 ("VS_KEYWORD", cmProperty::TARGET,
1406 "Visual Studio project keyword.",
1407 "Can be set to change the visual studio keyword, for example "
1408 "Qt integration works better if this is set to Qt4VSv1.0. ");
1410 ("VS_SCC_PROVIDER", cmProperty::TARGET,
1411 "Visual Studio Source Code Control Provider.",
1412 "Can be set to change the visual studio source code control "
1413 "provider property.");
1415 ("VS_SCC_LOCALPATH", cmProperty::TARGET,
1416 "Visual Studio Source Code Control Local Path.",
1417 "Can be set to change the visual studio source code control "
1418 "local path property.");
1420 ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
1421 "Visual Studio Source Code Control Project.",
1422 "Can be set to change the visual studio source code control "
1423 "project name property.");
1425 ("VS_SCC_AUXPATH", cmProperty::TARGET,
1426 "Visual Studio Source Code Control Aux Path.",
1427 "Can be set to change the visual studio source code control "
1428 "auxpath property.");
1430 ("VS_GLOBAL_PROJECT_TYPES", cmProperty::TARGET,
1431 "Visual Studio project type(s).",
1432 "Can be set to one or more UUIDs recognized by Visual Studio "
1433 "to indicate the type of project. This value is copied "
1434 "verbatim into the generated project file. Example for a "
1435 "managed C++ unit testing project:\n"
1436 " {3AC096D0-A1C2-E12C-1390-A8335801FDAB};"
1437 "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\n"
1438 "UUIDs are semicolon-delimited.");
1440 ("VS_GLOBAL_KEYWORD", cmProperty::TARGET,
1441 "Visual Studio project keyword.",
1442 "Sets the \"keyword\" attribute for a generated Visual Studio "
1443 "project. Defaults to \"Win32Proj\". You may wish to override "
1444 "this value with \"ManagedCProj\", for example, in a Visual "
1445 "Studio managed C++ unit test project.");
1447 ("VS_GLOBAL_ROOTNAMESPACE", cmProperty::TARGET,
1448 "Visual Studio project root namespace.",
1449 "Sets the \"RootNamespace\" attribute for a generated Visual Studio "
1450 "project. The attribute will be generated only if this is set.");
1452 ("VS_DOTNET_TARGET_FRAMEWORK_VERSION", cmProperty::TARGET,
1453 "Specify the .NET target framework version.",
1454 "Used to specify the .NET target framework version for C++/CLI. "
1455 "For example, \"v4.5\".");
1457 ("VS_DOTNET_REFERENCES", cmProperty::TARGET,
1458 "Visual Studio managed project .NET references",
1459 "Adds one or more semicolon-delimited .NET references to a "
1460 "generated Visual Studio project. For example, \"System;"
1461 "System.Windows.Forms\".");
1463 ("VS_WINRT_EXTENSIONS", cmProperty::TARGET,
1464 "Visual Studio project C++/CX language extensions for Windows Runtime",
1465 "Can be set to enable C++/CX language extensions.");
1467 ("VS_WINRT_REFERENCES", cmProperty::TARGET,
1468 "Visual Studio project Windows Runtime Metadata references",
1469 "Adds one or more semicolon-delimited WinRT references to a "
1470 "generated Visual Studio project. For example, \"Windows;"
1471 "Windows.UI.Core\".");
1473 ("VS_GLOBAL_<variable>", cmProperty::TARGET,
1474 "Visual Studio project-specific global variable.",
1475 "Tell the Visual Studio generator to set the global variable "
1476 "'<variable>' to a given value in the generated Visual Studio "
1477 "project. Ignored on other generators. Qt integration works "
1478 "better if VS_GLOBAL_QtVersion is set to the version "
1479 "FindQt4.cmake found. For example, \"4.7.3\"");
1481 #define CM_TARGET_FILE_TYPES_DOC \
1482 "There are three kinds of target files that may be built: " \
1483 "archive, library, and runtime. " \
1484 "Executables are always treated as runtime targets. " \
1485 "Static libraries are always treated as archive targets. " \
1486 "Module libraries are always treated as library targets. " \
1487 "For non-DLL platforms shared libraries are treated as library " \
1489 "For DLL platforms the DLL part of a shared library is treated as " \
1490 "a runtime target and the corresponding import library is treated as " \
1491 "an archive target. " \
1492 "All Windows-based systems including Cygwin are DLL platforms."
1494 #define CM_TARGET_OUTDIR_DOC(TYPE, type) \
1495 "This property specifies the directory into which " #type " target " \
1496 "files should be built. " \
1497 "Multi-configuration generators (VS, Xcode) append " \
1498 "a per-configuration subdirectory to the specified directory. " \
1499 CM_TARGET_FILE_TYPES_DOC " " \
1500 "This property is initialized by the value of the variable " \
1501 "CMAKE_" #TYPE "_OUTPUT_DIRECTORY if it is set when a target is created."
1503 #define CM_TARGET_OUTDIR_CONFIG_DOC(TYPE) \
1504 "This is a per-configuration version of " #TYPE "_OUTPUT_DIRECTORY, " \
1505 "but multi-configuration generators (VS, Xcode) do NOT append " \
1506 "a per-configuration subdirectory to the specified directory. " \
1507 "This property is initialized by the value of the variable " \
1508 "CMAKE_" #TYPE "_OUTPUT_DIRECTORY_<CONFIG> " \
1509 "if it is set when a target is created."
1512 ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
1513 "Output directory in which to build ARCHIVE target files.",
1514 CM_TARGET_OUTDIR_DOC(ARCHIVE, archive));
1516 ("ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1517 "Per-configuration output directory for ARCHIVE target files.",
1518 CM_TARGET_OUTDIR_CONFIG_DOC(ARCHIVE));
1520 ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
1521 "Output directory in which to build LIBRARY target files.",
1522 CM_TARGET_OUTDIR_DOC(LIBRARY, library));
1524 ("LIBRARY_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1525 "Per-configuration output directory for LIBRARY target files.",
1526 CM_TARGET_OUTDIR_CONFIG_DOC(LIBRARY));
1528 ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
1529 "Output directory in which to build RUNTIME target files.",
1530 CM_TARGET_OUTDIR_DOC(RUNTIME, runtime));
1532 ("RUNTIME_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1533 "Per-configuration output directory for RUNTIME target files.",
1534 CM_TARGET_OUTDIR_CONFIG_DOC(RUNTIME));
1537 ("PDB_OUTPUT_DIRECTORY", cmProperty::TARGET,
1538 "Output directory for MS debug symbols .pdb file from linker.",
1539 "This property specifies the directory into which the MS debug symbols "
1540 "will be placed by the linker. "
1541 "This property is initialized by the value of the variable "
1542 "CMAKE_PDB_OUTPUT_DIRECTORY if it is set when a target is created."
1544 "This property is not implemented by the Visual Studio 6 generator.");
1546 ("PDB_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
1547 "Per-configuration output directory for MS debug symbols .pdb files.",
1548 "This is a per-configuration version of PDB_OUTPUT_DIRECTORY, "
1549 "but multi-configuration generators (VS, Xcode) do NOT append "
1550 "a per-configuration subdirectory to the specified directory. "
1551 "This property is initialized by the value of the variable "
1552 "CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG> "
1553 "if it is set when a target is created."
1555 "This property is not implemented by the Visual Studio 6 generator.");
1558 ("ARCHIVE_OUTPUT_NAME", cmProperty::TARGET,
1559 "Output name for ARCHIVE target files.",
1560 "This property specifies the base name for archive target files. "
1561 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
1562 CM_TARGET_FILE_TYPES_DOC);
1564 ("ARCHIVE_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1565 "Per-configuration output name for ARCHIVE target files.",
1566 "This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.");
1568 ("LIBRARY_OUTPUT_NAME", cmProperty::TARGET,
1569 "Output name for LIBRARY target files.",
1570 "This property specifies the base name for library target files. "
1571 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
1572 CM_TARGET_FILE_TYPES_DOC);
1574 ("LIBRARY_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1575 "Per-configuration output name for LIBRARY target files.",
1576 "This is the configuration-specific version of LIBRARY_OUTPUT_NAME.");
1578 ("RUNTIME_OUTPUT_NAME", cmProperty::TARGET,
1579 "Output name for RUNTIME target files.",
1580 "This property specifies the base name for runtime target files. "
1581 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
1582 CM_TARGET_FILE_TYPES_DOC);
1584 ("RUNTIME_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
1585 "Per-configuration output name for RUNTIME target files.",
1586 "This is the configuration-specific version of RUNTIME_OUTPUT_NAME.");
1589 void cmTarget::SetType(TargetType type, const char* name)
1592 // only add dependency information for library targets
1593 this->TargetTypeValue = type;
1594 if(this->TargetTypeValue >= STATIC_LIBRARY
1595 && this->TargetTypeValue <= MODULE_LIBRARY)
1597 this->RecordDependencies = true;
1601 this->RecordDependencies = false;
1605 //----------------------------------------------------------------------------
1606 void cmTarget::SetMakefile(cmMakefile* mf)
1608 // Set our makefile.
1609 this->Makefile = mf;
1611 // set the cmake instance of the properties
1612 this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
1614 // Check whether this is a DLL platform.
1615 this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
1616 this->Makefile->IsOn("CYGWIN") ||
1617 this->Makefile->IsOn("MINGW"));
1619 // Check whether we are targeting an Apple platform.
1620 this->IsApple = this->Makefile->IsOn("APPLE");
1622 // Setup default property values.
1623 this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
1624 this->SetPropertyDefault("INSTALL_RPATH", "");
1625 this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
1626 this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
1627 this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
1628 this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
1629 this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
1630 this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
1631 this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
1632 this->SetPropertyDefault("Fortran_FORMAT", 0);
1633 this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
1634 this->SetPropertyDefault("GNUtoMS", 0);
1635 this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
1636 this->SetPropertyDefault("AUTOMOC", 0);
1637 this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
1638 this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
1639 this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
1640 this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
1641 this->SetPropertyDefault("MACOSX_BUNDLE", 0);
1642 this->SetPropertyDefault("MACOSX_RPATH", 0);
1645 // Collect the set of configuration types.
1646 std::vector<std::string> configNames;
1647 mf->GetConfigurations(configNames);
1649 // Setup per-configuration property default values.
1650 const char* configProps[] = {
1651 "ARCHIVE_OUTPUT_DIRECTORY_",
1652 "LIBRARY_OUTPUT_DIRECTORY_",
1653 "RUNTIME_OUTPUT_DIRECTORY_",
1654 "PDB_OUTPUT_DIRECTORY_",
1656 for(std::vector<std::string>::iterator ci = configNames.begin();
1657 ci != configNames.end(); ++ci)
1659 std::string configUpper = cmSystemTools::UpperCase(*ci);
1660 for(const char** p = configProps; *p; ++p)
1662 std::string property = *p;
1663 property += configUpper;
1664 this->SetPropertyDefault(property.c_str(), 0);
1667 // Initialize per-configuration name postfix property from the
1668 // variable only for non-executable targets. This preserves
1669 // compatibility with previous CMake versions in which executables
1670 // did not support this variable. Projects may still specify the
1671 // property directly. TODO: Make this depend on backwards
1672 // compatibility setting.
1673 if(this->TargetTypeValue != cmTarget::EXECUTABLE)
1675 std::string property = cmSystemTools::UpperCase(*ci);
1676 property += "_POSTFIX";
1677 this->SetPropertyDefault(property.c_str(), 0);
1681 // Save the backtrace of target construction.
1682 this->Makefile->GetBacktrace(this->Internal->Backtrace);
1684 // Initialize the INCLUDE_DIRECTORIES property based on the current value
1685 // of the same directory property:
1686 const std::vector<cmValueWithOrigin> parentIncludes =
1687 this->Makefile->GetIncludeDirectoriesEntries();
1689 for (std::vector<cmValueWithOrigin>::const_iterator it
1690 = parentIncludes.begin(); it != parentIncludes.end(); ++it)
1692 this->InsertInclude(*it);
1695 const std::set<cmStdString> parentSystemIncludes =
1696 this->Makefile->GetSystemIncludeDirectories();
1698 for (std::set<cmStdString>::const_iterator it
1699 = parentSystemIncludes.begin();
1700 it != parentSystemIncludes.end(); ++it)
1702 this->SystemIncludeDirectories.insert(*it);
1705 const std::vector<cmValueWithOrigin> parentOptions =
1706 this->Makefile->GetCompileOptionsEntries();
1708 for (std::vector<cmValueWithOrigin>::const_iterator it
1709 = parentOptions.begin(); it != parentOptions.end(); ++it)
1711 this->InsertCompileOption(*it);
1714 this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
1715 this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
1716 this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
1718 if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
1719 || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
1721 this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
1723 this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
1725 // Record current policies for later use.
1726 #define CAPTURE_TARGET_POLICY(POLICY) \
1727 this->PolicyStatus ## POLICY = \
1728 this->Makefile->GetPolicyStatus(cmPolicies::POLICY);
1730 CM_FOR_EACH_TARGET_POLICY(CAPTURE_TARGET_POLICY)
1732 #undef CAPTURE_TARGET_POLICY
1735 //----------------------------------------------------------------------------
1736 void cmTarget::FinishConfigure()
1738 // Erase any cached link information that might have been comptued
1739 // on-demand during the configuration. This ensures that build
1740 // system generation uses up-to-date information even if other cache
1741 // invalidation code in this source file is buggy.
1742 this->ClearLinkMaps();
1744 // Do old-style link dependency analysis.
1745 this->AnalyzeLibDependencies(*this->Makefile);
1748 //----------------------------------------------------------------------------
1749 void cmTarget::ClearLinkMaps()
1751 this->Internal->LinkImplMap.clear();
1752 this->Internal->LinkInterfaceMap.clear();
1753 this->Internal->LinkClosureMap.clear();
1754 for (cmTargetLinkInformationMap::const_iterator it
1755 = this->LinkInformation.begin();
1756 it != this->LinkInformation.end(); ++it)
1760 this->LinkInformation.clear();
1763 //----------------------------------------------------------------------------
1764 cmListFileBacktrace const& cmTarget::GetBacktrace() const
1766 return this->Internal->Backtrace;
1769 //----------------------------------------------------------------------------
1770 std::string cmTarget::GetSupportDirectory() const
1772 std::string dir = this->Makefile->GetCurrentOutputDirectory();
1773 dir += cmake::GetCMakeFilesDirectory();
1784 //----------------------------------------------------------------------------
1785 bool cmTarget::IsExecutableWithExports()
1787 return (this->GetType() == cmTarget::EXECUTABLE &&
1788 this->GetPropertyAsBool("ENABLE_EXPORTS"));
1791 //----------------------------------------------------------------------------
1792 bool cmTarget::IsLinkable()
1794 return (this->GetType() == cmTarget::STATIC_LIBRARY ||
1795 this->GetType() == cmTarget::SHARED_LIBRARY ||
1796 this->GetType() == cmTarget::MODULE_LIBRARY ||
1797 this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
1798 this->IsExecutableWithExports());
1801 //----------------------------------------------------------------------------
1802 bool cmTarget::HasImportLibrary()
1804 return (this->DLLPlatform &&
1805 (this->GetType() == cmTarget::SHARED_LIBRARY ||
1806 this->IsExecutableWithExports()));
1809 //----------------------------------------------------------------------------
1810 bool cmTarget::IsFrameworkOnApple()
1812 return (this->GetType() == cmTarget::SHARED_LIBRARY &&
1813 this->Makefile->IsOn("APPLE") &&
1814 this->GetPropertyAsBool("FRAMEWORK"));
1817 //----------------------------------------------------------------------------
1818 bool cmTarget::IsAppBundleOnApple()
1820 return (this->GetType() == cmTarget::EXECUTABLE &&
1821 this->Makefile->IsOn("APPLE") &&
1822 this->GetPropertyAsBool("MACOSX_BUNDLE"));
1825 //----------------------------------------------------------------------------
1826 bool cmTarget::IsCFBundleOnApple()
1828 return (this->GetType() == cmTarget::MODULE_LIBRARY &&
1829 this->Makefile->IsOn("APPLE") &&
1830 this->GetPropertyAsBool("BUNDLE"));
1833 //----------------------------------------------------------------------------
1834 bool cmTarget::IsBundleOnApple()
1836 return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
1837 this->IsCFBundleOnApple();
1840 //----------------------------------------------------------------------------
1841 class cmTargetTraceDependencies
1844 cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal);
1848 cmTargetInternals* Internal;
1849 cmMakefile* Makefile;
1850 cmGlobalGenerator* GlobalGenerator;
1851 typedef cmTargetInternals::SourceEntry SourceEntry;
1852 SourceEntry* CurrentEntry;
1853 std::queue<cmSourceFile*> SourceQueue;
1854 std::set<cmSourceFile*> SourcesQueued;
1855 typedef std::map<cmStdString, cmSourceFile*> NameMapType;
1856 NameMapType NameMap;
1858 void QueueSource(cmSourceFile* sf);
1859 void FollowName(std::string const& name);
1860 void FollowNames(std::vector<std::string> const& names);
1861 bool IsUtility(std::string const& dep);
1862 void CheckCustomCommand(cmCustomCommand const& cc);
1863 void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
1866 //----------------------------------------------------------------------------
1867 cmTargetTraceDependencies
1868 ::cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal):
1869 Target(target), Internal(internal)
1872 this->Makefile = this->Target->GetMakefile();
1873 this->GlobalGenerator =
1874 this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
1875 this->CurrentEntry = 0;
1877 // Queue all the source files already specified for the target.
1878 std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
1879 for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
1880 si != sources.end(); ++si)
1882 this->QueueSource(*si);
1885 // Queue pre-build, pre-link, and post-build rule dependencies.
1886 this->CheckCustomCommands(this->Target->GetPreBuildCommands());
1887 this->CheckCustomCommands(this->Target->GetPreLinkCommands());
1888 this->CheckCustomCommands(this->Target->GetPostBuildCommands());
1891 //----------------------------------------------------------------------------
1892 void cmTargetTraceDependencies::Trace()
1894 // Process one dependency at a time until the queue is empty.
1895 while(!this->SourceQueue.empty())
1897 // Get the next source from the queue.
1898 cmSourceFile* sf = this->SourceQueue.front();
1899 this->SourceQueue.pop();
1900 this->CurrentEntry = &this->Internal->SourceEntries[sf];
1902 // Queue dependencies added explicitly by the user.
1903 if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
1905 std::vector<std::string> objDeps;
1906 cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
1907 this->FollowNames(objDeps);
1910 // Queue the source needed to generate this file, if any.
1911 this->FollowName(sf->GetFullPath());
1913 // Queue dependencies added programatically by commands.
1914 this->FollowNames(sf->GetDepends());
1916 // Queue custom command dependencies.
1917 if(cmCustomCommand const* cc = sf->GetCustomCommand())
1919 this->CheckCustomCommand(*cc);
1922 this->CurrentEntry = 0;
1925 //----------------------------------------------------------------------------
1926 void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
1928 if(this->SourcesQueued.insert(sf).second)
1930 this->SourceQueue.push(sf);
1932 // Make sure this file is in the target.
1933 this->Target->AddSourceFile(sf);
1937 //----------------------------------------------------------------------------
1938 void cmTargetTraceDependencies::FollowName(std::string const& name)
1940 NameMapType::iterator i = this->NameMap.find(name);
1941 if(i == this->NameMap.end())
1943 // Check if we know how to generate this file.
1944 cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
1945 NameMapType::value_type entry(name, sf);
1946 i = this->NameMap.insert(entry).first;
1948 if(cmSourceFile* sf = i->second)
1950 // Record the dependency we just followed.
1951 if(this->CurrentEntry)
1953 this->CurrentEntry->Depends.push_back(sf);
1956 this->QueueSource(sf);
1960 //----------------------------------------------------------------------------
1962 cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
1964 for(std::vector<std::string>::const_iterator i = names.begin();
1965 i != names.end(); ++i)
1967 this->FollowName(*i);
1971 //----------------------------------------------------------------------------
1972 bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
1974 // Dependencies on targets (utilities) are supposed to be named by
1975 // just the target name. However for compatibility we support
1976 // naming the output file generated by the target (assuming there is
1977 // no output-name property which old code would not have set). In
1978 // that case the target name will be the file basename of the
1980 std::string util = cmSystemTools::GetFilenameName(dep);
1981 if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
1983 util = cmSystemTools::GetFilenameWithoutLastExtension(util);
1986 // Check for a target with this name.
1987 if(cmTarget* t = this->Makefile->FindTargetToUse(util.c_str()))
1989 // If we find the target and the dep was given as a full path,
1990 // then make sure it was not a full path to something else, and
1991 // the fact that the name matched a target was just a coincidence.
1992 if(cmSystemTools::FileIsFullPath(dep.c_str()))
1994 if(t->GetType() >= cmTarget::EXECUTABLE &&
1995 t->GetType() <= cmTarget::MODULE_LIBRARY)
1997 // This is really only for compatibility so we do not need to
1998 // worry about configuration names and output names.
1999 std::string tLocation = t->GetLocation(0);
2000 tLocation = cmSystemTools::GetFilenamePath(tLocation);
2001 std::string depLocation = cmSystemTools::GetFilenamePath(dep);
2002 depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
2003 tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
2004 if(depLocation == tLocation)
2006 this->Target->AddUtility(util.c_str());
2013 // The original name of the dependency was not a full path. It
2014 // must name a target, so add the target-level dependency.
2015 this->Target->AddUtility(util.c_str());
2020 // The dependency does not name a target built in this project.
2024 //----------------------------------------------------------------------------
2026 cmTargetTraceDependencies
2027 ::CheckCustomCommand(cmCustomCommand const& cc)
2029 // Transform command names that reference targets built in this
2030 // project to corresponding target-level dependencies.
2031 cmGeneratorExpression ge(cc.GetBacktrace());
2033 // Add target-level dependencies referenced by generator expressions.
2034 std::set<cmTarget*> targets;
2036 for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
2037 cit != cc.GetCommandLines().end(); ++cit)
2039 std::string const& command = *cit->begin();
2040 // Check for a target with this name.
2041 if(cmTarget* t = this->Makefile->FindTargetToUse(command.c_str()))
2043 if(t->GetType() == cmTarget::EXECUTABLE)
2045 // The command refers to an executable target built in
2046 // this project. Add the target-level dependency to make
2047 // sure the executable is up to date before this custom
2048 // command possibly runs.
2049 this->Target->AddUtility(command.c_str());
2053 // Check for target references in generator expressions.
2054 for(cmCustomCommandLine::const_iterator cli = cit->begin();
2055 cli != cit->end(); ++cli)
2057 const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
2059 cge->Evaluate(this->Makefile, 0, true);
2060 std::set<cmTarget*> geTargets = cge->GetTargets();
2061 for(std::set<cmTarget*>::const_iterator it = geTargets.begin();
2062 it != geTargets.end(); ++it)
2064 targets.insert(*it);
2069 for(std::set<cmTarget*>::iterator ti = targets.begin();
2070 ti != targets.end(); ++ti)
2072 this->Target->AddUtility((*ti)->GetName());
2075 // Queue the custom command dependencies.
2076 std::vector<std::string> const& depends = cc.GetDepends();
2077 for(std::vector<std::string>::const_iterator di = depends.begin();
2078 di != depends.end(); ++di)
2080 std::string const& dep = *di;
2081 if(!this->IsUtility(dep))
2083 // The dependency does not name a target and may be a file we
2084 // know how to generate. Queue it.
2085 this->FollowName(dep);
2090 //----------------------------------------------------------------------------
2092 cmTargetTraceDependencies
2093 ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
2095 for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
2096 cli != commands.end(); ++cli)
2098 this->CheckCustomCommand(*cli);
2102 //----------------------------------------------------------------------------
2103 void cmTarget::TraceDependencies()
2105 // CMake-generated targets have no dependencies to trace. Normally tracing
2106 // would find nothing anyway, but when building CMake itself the "install"
2107 // target command ends up referencing the "cmake" target but we do not
2108 // really want the dependency because "install" depend on "all" anyway.
2109 if(this->GetType() == cmTarget::GLOBAL_TARGET)
2114 // Use a helper object to trace the dependencies.
2115 cmTargetTraceDependencies tracer(this, this->Internal.Get());
2119 //----------------------------------------------------------------------------
2120 bool cmTarget::FindSourceFiles()
2122 for(std::vector<cmSourceFile*>::const_iterator
2123 si = this->SourceFiles.begin();
2124 si != this->SourceFiles.end(); ++si)
2127 if((*si)->GetFullPath(&e).empty())
2131 cmake* cm = this->Makefile->GetCMakeInstance();
2132 cm->IssueMessage(cmake::FATAL_ERROR, e,
2133 this->GetBacktrace());
2141 //----------------------------------------------------------------------------
2142 std::vector<cmSourceFile*> const& cmTarget::GetSourceFiles()
2144 return this->SourceFiles;
2147 //----------------------------------------------------------------------------
2148 void cmTarget::AddSourceFile(cmSourceFile* sf)
2150 typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
2151 SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
2152 if(i == this->Internal->SourceEntries.end())
2154 typedef cmTargetInternals::SourceEntry SourceEntry;
2155 SourceEntriesType::value_type entry(sf, SourceEntry());
2156 i = this->Internal->SourceEntries.insert(entry).first;
2157 this->SourceFiles.push_back(sf);
2161 //----------------------------------------------------------------------------
2162 std::vector<cmSourceFile*> const*
2163 cmTarget::GetSourceDepends(cmSourceFile* sf)
2165 typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
2166 SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
2167 if(i != this->Internal->SourceEntries.end())
2169 return &i->second.Depends;
2174 //----------------------------------------------------------------------------
2175 void cmTarget::AddSources(std::vector<std::string> const& srcs)
2177 for(std::vector<std::string>::const_iterator i = srcs.begin();
2178 i != srcs.end(); ++i)
2180 const char* src = i->c_str();
2181 if(src[0] == '$' && src[1] == '<')
2183 this->ProcessSourceExpression(*i);
2187 this->AddSource(src);
2192 //----------------------------------------------------------------------------
2193 cmSourceFile* cmTarget::AddSource(const char* s)
2195 std::string src = s;
2197 // For backwards compatibility replace varibles in source names.
2198 // This should eventually be removed.
2199 this->Makefile->ExpandVariablesInString(src);
2201 cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
2202 this->AddSourceFile(sf);
2206 //----------------------------------------------------------------------------
2207 void cmTarget::ProcessSourceExpression(std::string const& expr)
2209 if(strncmp(expr.c_str(), "$<TARGET_OBJECTS:", 17) == 0 &&
2210 expr[expr.size()-1] == '>')
2212 std::string objLibName = expr.substr(17, expr.size()-18);
2213 this->ObjectLibraries.push_back(objLibName);
2218 e << "Unrecognized generator expression:\n"
2220 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
2224 //----------------------------------------------------------------------------
2225 struct cmTarget::SourceFileFlags
2226 cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
2228 struct SourceFileFlags flags;
2229 this->ConstructSourceFileFlags();
2230 std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
2231 this->Internal->SourceFlagsMap.find(sf);
2232 if(si != this->Internal->SourceFlagsMap.end())
2239 //----------------------------------------------------------------------------
2240 void cmTarget::ConstructSourceFileFlags()
2242 if(this->Internal->SourceFileFlagsConstructed)
2246 this->Internal->SourceFileFlagsConstructed = true;
2248 // Process public headers to mark the source files.
2249 if(const char* files = this->GetProperty("PUBLIC_HEADER"))
2251 std::vector<std::string> relFiles;
2252 cmSystemTools::ExpandListArgument(files, relFiles);
2253 for(std::vector<std::string>::iterator it = relFiles.begin();
2254 it != relFiles.end(); ++it)
2256 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
2258 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
2259 flags.MacFolder = "Headers";
2260 flags.Type = cmTarget::SourceFileTypePublicHeader;
2265 // Process private headers after public headers so that they take
2266 // precedence if a file is listed in both.
2267 if(const char* files = this->GetProperty("PRIVATE_HEADER"))
2269 std::vector<std::string> relFiles;
2270 cmSystemTools::ExpandListArgument(files, relFiles);
2271 for(std::vector<std::string>::iterator it = relFiles.begin();
2272 it != relFiles.end(); ++it)
2274 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
2276 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
2277 flags.MacFolder = "PrivateHeaders";
2278 flags.Type = cmTarget::SourceFileTypePrivateHeader;
2283 // Mark sources listed as resources.
2284 if(const char* files = this->GetProperty("RESOURCE"))
2286 std::vector<std::string> relFiles;
2287 cmSystemTools::ExpandListArgument(files, relFiles);
2288 for(std::vector<std::string>::iterator it = relFiles.begin();
2289 it != relFiles.end(); ++it)
2291 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
2293 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
2294 flags.MacFolder = "Resources";
2295 flags.Type = cmTarget::SourceFileTypeResource;
2300 // Handle the MACOSX_PACKAGE_LOCATION property on source files that
2301 // were not listed in one of the other lists.
2302 std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
2303 for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
2304 si != sources.end(); ++si)
2306 cmSourceFile* sf = *si;
2307 if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
2309 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
2310 if(flags.Type == cmTarget::SourceFileTypeNormal)
2312 flags.MacFolder = location;
2313 if(strcmp(location, "Resources") == 0)
2315 flags.Type = cmTarget::SourceFileTypeResource;
2319 flags.Type = cmTarget::SourceFileTypeMacContent;
2326 //----------------------------------------------------------------------------
2327 void cmTarget::MergeLinkLibraries( cmMakefile& mf,
2328 const char *selfname,
2329 const LinkLibraryVectorType& libs )
2331 // Only add on libraries we haven't added on before.
2332 // Assumption: the global link libraries could only grow, never shrink
2333 LinkLibraryVectorType::const_iterator i = libs.begin();
2334 i += this->PrevLinkedLibraries.size();
2335 for( ; i != libs.end(); ++i )
2337 // This is equivalent to the target_link_libraries plain signature.
2338 this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
2339 this->AppendProperty("INTERFACE_LINK_LIBRARIES",
2340 this->GetDebugGeneratorExpressions(i->first.c_str(), i->second).c_str());
2342 this->PrevLinkedLibraries = libs;
2345 //----------------------------------------------------------------------------
2346 void cmTarget::AddLinkDirectory(const char* d)
2348 // Make sure we don't add unnecessary search directories.
2349 if(this->LinkDirectoriesEmmitted.insert(d).second)
2351 this->LinkDirectories.push_back(d);
2355 //----------------------------------------------------------------------------
2356 const std::vector<std::string>& cmTarget::GetLinkDirectories()
2358 return this->LinkDirectories;
2361 //----------------------------------------------------------------------------
2362 cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
2364 // No configuration is always optimized.
2365 if(!(config && *config))
2367 return cmTarget::OPTIMIZED;
2370 // Get the list of configurations considered to be DEBUG.
2371 std::vector<std::string> const& debugConfigs =
2372 this->Makefile->GetCMakeInstance()->GetDebugConfigs();
2374 // Check if any entry in the list matches this configuration.
2375 std::string configUpper = cmSystemTools::UpperCase(config);
2376 for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
2377 i != debugConfigs.end(); ++i)
2379 if(*i == configUpper)
2381 return cmTarget::DEBUG;
2385 // The current configuration is not a debug configuration.
2386 return cmTarget::OPTIMIZED;
2389 //----------------------------------------------------------------------------
2390 void cmTarget::ClearDependencyInformation( cmMakefile& mf,
2391 const char* target )
2393 // Clear the dependencies. The cache variable must exist iff we are
2394 // recording dependency information for this target.
2395 std::string depname = target;
2396 depname += "_LIB_DEPENDS";
2397 if (this->RecordDependencies)
2399 mf.AddCacheDefinition(depname.c_str(), "",
2400 "Dependencies for target", cmCacheManager::STATIC);
2404 if (mf.GetDefinition( depname.c_str() ))
2406 std::string message = "Target ";
2408 message += " has dependency information when it shouldn't.\n";
2409 message += "Your cache is probably stale. Please remove the entry\n ";
2411 message += "\nfrom the cache.";
2412 cmSystemTools::Error( message.c_str() );
2417 //----------------------------------------------------------------------------
2418 bool cmTarget::NameResolvesToFramework(const std::string& libname)
2420 return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
2421 NameResolvesToFramework(libname);
2424 //----------------------------------------------------------------------------
2425 void cmTarget::GetDirectLinkLibraries(const char *config,
2426 std::vector<std::string> &libs, cmTarget *head)
2428 const char *prop = this->GetProperty("LINK_LIBRARIES");
2431 cmListFileBacktrace lfbt;
2432 cmGeneratorExpression ge(lfbt);
2433 const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
2435 cmGeneratorExpressionDAGChecker dagChecker(lfbt,
2437 "LINK_LIBRARIES", 0, 0);
2438 cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile,
2445 std::set<cmStdString> seenProps = cge->GetSeenTargetProperties();
2446 for (std::set<cmStdString>::const_iterator it = seenProps.begin();
2447 it != seenProps.end(); ++it)
2449 if (!this->GetProperty(it->c_str()))
2451 this->LinkImplicitNullProperties.insert(*it);
2457 //----------------------------------------------------------------------------
2458 std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
2459 cmTarget::LinkLibraryType llt)
2466 // Get the list of configurations considered to be DEBUG.
2467 std::vector<std::string> const& debugConfigs =
2468 this->Makefile->GetCMakeInstance()->GetDebugConfigs();
2470 std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
2472 if (debugConfigs.size() > 1)
2474 for(std::vector<std::string>::const_iterator
2475 li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
2477 configString += ",$<CONFIG:" + *li + ">";
2479 configString = "$<OR:" + configString + ">";
2482 if (llt == OPTIMIZED)
2484 configString = "$<NOT:" + configString + ">";
2486 return "$<" + configString + ":" + value + ">";
2489 //----------------------------------------------------------------------------
2490 static std::string targetNameGenex(const char *lib)
2492 return std::string("$<TARGET_NAME:") + lib + ">";
2495 //----------------------------------------------------------------------------
2496 bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
2499 if (!this->TLLCommands.empty())
2501 if (this->TLLCommands.back().first != signature)
2506 cmListFileBacktrace lfbt;
2507 this->Makefile->GetBacktrace(lfbt);
2508 this->TLLCommands.push_back(std::make_pair(signature, lfbt));
2512 //----------------------------------------------------------------------------
2513 void cmTarget::GetTllSignatureTraces(cmOStringStream &s,
2514 TLLSignature sig) const
2516 std::vector<cmListFileBacktrace> sigs;
2517 typedef std::vector<std::pair<TLLSignature, cmListFileBacktrace> > Container;
2518 for(Container::const_iterator it = this->TLLCommands.begin();
2519 it != this->TLLCommands.end(); ++it)
2521 if (it->first == sig)
2523 sigs.push_back(it->second);
2528 const char *sigString
2529 = (sig == cmTarget::KeywordTLLSignature ? "keyword"
2531 s << "The uses of the " << sigString << " signature are here:\n";
2532 std::set<cmStdString> emitted;
2533 for(std::vector<cmListFileBacktrace>::const_iterator it = sigs.begin();
2534 it != sigs.end(); ++it)
2536 cmListFileBacktrace::const_iterator i = it->begin();
2539 cmListFileContext const& lfc = *i;
2540 cmOStringStream line;
2541 line << " * " << (lfc.Line? "": " in ") << lfc << std::endl;
2542 if (emitted.insert(line.str()).second)
2552 //----------------------------------------------------------------------------
2553 void cmTarget::AddLinkLibrary(cmMakefile& mf,
2554 const char *target, const char* lib,
2555 LinkLibraryType llt)
2557 // Never add a self dependency, even if the user asks for it.
2558 if(strcmp( target, lib ) == 0)
2564 cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
2565 const bool isNonImportedTarget = tgt && !tgt->IsImported();
2567 const std::string libName = (isNonImportedTarget && llt != GENERAL)
2568 ? targetNameGenex(lib)
2570 this->AppendProperty("LINK_LIBRARIES",
2571 this->GetDebugGeneratorExpressions(libName,
2575 if (cmGeneratorExpression::Find(lib) != std::string::npos)
2580 cmTarget::LibraryID tmp;
2583 this->LinkLibraries.push_back( tmp );
2584 this->OriginalLinkLibraries.push_back(tmp);
2585 this->ClearLinkMaps();
2587 // Add the explicit dependency information for this target. This is
2588 // simply a set of libraries separated by ";". There should always
2589 // be a trailing ";". These library names are not canonical, in that
2590 // they may be "-framework x", "-ly", "/path/libz.a", etc.
2591 // We shouldn't remove duplicates here because external libraries
2592 // may be purposefully duplicated to handle recursive dependencies,
2593 // and we removing one instance will break the link line. Duplicates
2594 // will be appropriately eliminated at emit time.
2595 if(this->RecordDependencies)
2597 std::string targetEntry = target;
2598 targetEntry += "_LIB_DEPENDS";
2599 std::string dependencies;
2600 const char* old_val = mf.GetDefinition( targetEntry.c_str() );
2603 dependencies += old_val;
2607 case cmTarget::GENERAL:
2608 dependencies += "general";
2610 case cmTarget::DEBUG:
2611 dependencies += "debug";
2613 case cmTarget::OPTIMIZED:
2614 dependencies += "optimized";
2617 dependencies += ";";
2618 dependencies += lib;
2619 dependencies += ";";
2620 mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
2621 "Dependencies for the target",
2622 cmCacheManager::STATIC );
2627 //----------------------------------------------------------------------------
2629 cmTarget::AddSystemIncludeDirectories(const std::set<cmStdString> &incs)
2631 for(std::set<cmStdString>::const_iterator li = incs.begin();
2632 li != incs.end(); ++li)
2634 this->SystemIncludeDirectories.insert(*li);
2638 //----------------------------------------------------------------------------
2640 cmTarget::AddSystemIncludeDirectories(const std::vector<std::string> &incs)
2642 for(std::vector<std::string>::const_iterator li = incs.begin();
2643 li != incs.end(); ++li)
2645 this->SystemIncludeDirectories.insert(*li);
2649 //----------------------------------------------------------------------------
2650 void cmTarget::FinalizeSystemIncludeDirectories()
2652 for (std::vector<cmValueWithOrigin>::const_iterator
2653 it = this->Internal->LinkInterfacePropertyEntries.begin(),
2654 end = this->Internal->LinkInterfacePropertyEntries.end();
2658 cmListFileBacktrace lfbt;
2659 cmGeneratorExpression ge(lfbt);
2660 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
2661 ge.Parse(it->Value);
2662 std::string targetName = cge->Evaluate(this->Makefile, 0,
2664 if (!this->Makefile->FindTargetToUse(targetName.c_str()))
2669 std::string includeGenex = "$<TARGET_PROPERTY:" +
2670 it->Value + ",INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>";
2671 if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
2673 // Because it->Value is a generator expression, ensure that it
2674 // evaluates to the non-empty string before being used in the
2675 // TARGET_PROPERTY expression.
2676 includeGenex = "$<$<BOOL:" + it->Value + ">:" + includeGenex + ">";
2678 this->SystemIncludeDirectories.insert(includeGenex);
2682 //----------------------------------------------------------------------------
2684 cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
2686 // There are two key parts of the dependency analysis: (1)
2687 // determining the libraries in the link line, and (2) constructing
2688 // the dependency graph for those libraries.
2690 // The latter is done using the cache entries that record the
2691 // dependencies of each library.
2693 // The former is a more thorny issue, since it is not clear how to
2694 // determine if two libraries listed on the link line refer to the a
2695 // single library or not. For example, consider the link "libraries"
2696 // /usr/lib/libtiff.so -ltiff
2697 // Is this one library or two? The solution implemented here is the
2698 // simplest (and probably the only practical) one: two libraries are
2699 // the same if their "link strings" are identical. Thus, the two
2700 // libraries above are considered distinct. This also means that for
2701 // dependency analysis to be effective, the CMake user must specify
2702 // libraries build by his project without using any linker flags or
2703 // file extensions. That is,
2704 // LINK_LIBRARIES( One Two )
2706 // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
2707 // The former is probably what most users would do, but it never
2708 // hurts to document the assumptions. :-) Therefore, in the analysis
2709 // code, the "canonical name" of a library is simply its name as
2710 // given to a LINK_LIBRARIES command.
2712 // Also, we will leave the original link line intact; we will just add any
2713 // dependencies that were missing.
2715 // There is a problem with recursive external libraries
2716 // (i.e. libraries with no dependency information that are
2717 // recursively dependent). We must make sure that the we emit one of
2718 // the libraries twice to satisfy the recursion, but we shouldn't
2719 // emit it more times than necessary. In particular, we must make
2720 // sure that handling this improbable case doesn't cost us when
2721 // dealing with the common case of non-recursive libraries. The
2722 // solution is to assume that the recursion is satisfied at one node
2723 // of the dependency tree. To illustrate, assume libA and libB are
2724 // extrenal and mutually dependent. Suppose libX depends on
2725 // libA, and libY on libA and libX. Then
2726 // TARGET_LINK_LIBRARIES( Y X A B A )
2727 // TARGET_LINK_LIBRARIES( X A B A )
2728 // TARGET_LINK_LIBRARIES( Exec Y )
2729 // would result in "-lY -lX -lA -lB -lA". This is the correct way to
2730 // specify the dependencies, since the mutual dependency of A and B
2731 // is resolved *every time libA is specified*.
2734 // TARGET_LINK_LIBRARIES( Y X A B A )
2735 // TARGET_LINK_LIBRARIES( X A B )
2736 // TARGET_LINK_LIBRARIES( Exec Y )
2737 // would result in "-lY -lX -lA -lB", and the mutual dependency
2738 // information is lost. This is because in some case (Y), the mutual
2739 // dependency of A and B is listed, while in another other case (X),
2740 // it is not. Depending on which line actually emits A, the mutual
2741 // dependency may or may not be on the final link line. We can't
2742 // handle this pathalogical case cleanly without emitting extra
2743 // libraries for the normal cases. Besides, the dependency
2744 // information for X is wrong anyway: if we build an executable
2745 // depending on X alone, we would not have the mutual dependency on
2746 // A and B resolved.
2749 // -- The current algorithm will not always pick the "optimal" link line
2750 // when recursive dependencies are present. It will instead break the
2751 // cycles at an aribtrary point. The majority of projects won't have
2752 // cyclic dependencies, so this is probably not a big deal. Note that
2753 // the link line is always correct, just not necessary optimal.
2756 // Expand variables in link library names. This is for backwards
2757 // compatibility with very early CMake versions and should
2758 // eventually be removed. This code was moved here from the end of
2759 // old source list processing code which was called just before this
2761 for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
2762 p != this->LinkLibraries.end(); ++p)
2764 this->Makefile->ExpandVariablesInString(p->first, true, true);
2768 // The dependency map.
2769 DependencyMap dep_map;
2771 // 1. Build the dependency graph
2773 for(LinkLibraryVectorType::reverse_iterator lib
2774 = this->LinkLibraries.rbegin();
2775 lib != this->LinkLibraries.rend(); ++lib)
2777 this->GatherDependencies( mf, *lib, dep_map);
2780 // 2. Remove any dependencies that are already satisfied in the original
2783 for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
2784 lib != this->LinkLibraries.end(); ++lib)
2786 for( LinkLibraryVectorType::iterator lib2 = lib;
2787 lib2 != this->LinkLibraries.end(); ++lib2)
2789 this->DeleteDependency( dep_map, *lib, *lib2);
2794 // 3. Create the new link line by simply emitting any dependencies that are
2795 // missing. Start from the back and keep adding.
2797 std::set<DependencyMap::key_type> done, visited;
2798 std::vector<DependencyMap::key_type> newLinkLibraries;
2799 for(LinkLibraryVectorType::reverse_iterator lib =
2800 this->LinkLibraries.rbegin();
2801 lib != this->LinkLibraries.rend(); ++lib)
2803 // skip zero size library entries, this may happen
2804 // if a variable expands to nothing.
2805 if (lib->first.size() != 0)
2807 this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
2811 // 4. Add the new libraries to the link line.
2813 for( std::vector<DependencyMap::key_type>::reverse_iterator k =
2814 newLinkLibraries.rbegin();
2815 k != newLinkLibraries.rend(); ++k )
2817 // get the llt from the dep_map
2818 this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
2820 this->LinkLibrariesAnalyzed = true;
2823 //----------------------------------------------------------------------------
2824 void cmTarget::InsertDependency( DependencyMap& depMap,
2825 const LibraryID& lib,
2826 const LibraryID& dep)
2828 depMap[lib].push_back(dep);
2831 //----------------------------------------------------------------------------
2832 void cmTarget::DeleteDependency( DependencyMap& depMap,
2833 const LibraryID& lib,
2834 const LibraryID& dep)
2836 // Make sure there is an entry in the map for lib. If so, delete all
2837 // dependencies to dep. There may be repeated entries because of
2838 // external libraries that are specified multiple times.
2839 DependencyMap::iterator map_itr = depMap.find( lib );
2840 if( map_itr != depMap.end() )
2842 DependencyList& depList = map_itr->second;
2843 DependencyList::iterator itr;
2844 while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
2847 depList.erase( itr );
2852 //----------------------------------------------------------------------------
2853 void cmTarget::Emit(const LibraryID lib,
2854 const DependencyMap& dep_map,
2855 std::set<LibraryID>& emitted,
2856 std::set<LibraryID>& visited,
2857 DependencyList& link_line )
2859 // It's already been emitted
2860 if( emitted.find(lib) != emitted.end() )
2865 // Emit the dependencies only if this library node hasn't been
2866 // visited before. If it has, then we have a cycle. The recursion
2867 // that got us here should take care of everything.
2869 if( visited.insert(lib).second )
2871 if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
2873 const DependencyList& dep_on = dep_map.find( lib )->second;
2874 DependencyList::const_reverse_iterator i;
2876 // To cater for recursive external libraries, we must emit
2877 // duplicates on this link line *unless* they were emitted by
2878 // some other node, in which case we assume that the recursion
2879 // was resolved then. We making the simplifying assumption that
2880 // any duplicates on a single link line are on purpose, and must
2883 // This variable will keep track of the libraries that were
2884 // emitted directly from the current node, and not from a
2885 // recursive call. This way, if we come across a library that
2886 // has already been emitted, we repeat it iff it has been
2888 std::set<DependencyMap::key_type> emitted_here;
2889 for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
2891 if( emitted_here.find(*i) != emitted_here.end() )
2893 // a repeat. Must emit.
2895 link_line.push_back( *i );
2899 // Emit only if no-one else has
2900 if( emitted.find(*i) == emitted.end() )
2902 // emit dependencies
2903 Emit( *i, dep_map, emitted, visited, link_line );
2906 emitted_here.insert(*i);
2907 link_line.push_back( *i );
2915 //----------------------------------------------------------------------------
2916 void cmTarget::GatherDependencies( const cmMakefile& mf,
2917 const LibraryID& lib,
2918 DependencyMap& dep_map)
2920 // If the library is already in the dependency map, then it has
2921 // already been fully processed.
2922 if( dep_map.find(lib) != dep_map.end() )
2927 const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
2928 if( deps && strcmp(deps,"") != 0 )
2930 // Make sure this library is in the map, even if it has an empty
2931 // set of dependencies. This distinguishes the case of explicitly
2932 // no dependencies with that of unspecified dependencies.
2935 // Parse the dependency information, which is a set of
2936 // type, library pairs separated by ";". There is always a trailing ";".
2937 cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
2938 std::string depline = deps;
2939 std::string::size_type start = 0;
2940 std::string::size_type end;
2941 end = depline.find( ";", start );
2942 while( end != std::string::npos )
2944 std::string l = depline.substr( start, end-start );
2949 llt = cmTarget::DEBUG;
2951 else if (l == "optimized")
2953 llt = cmTarget::OPTIMIZED;
2955 else if (l == "general")
2957 llt = cmTarget::GENERAL;
2961 LibraryID lib2(l,llt);
2962 this->InsertDependency( dep_map, lib, lib2);
2963 this->GatherDependencies( mf, lib2, dep_map);
2964 llt = cmTarget::GENERAL;
2967 start = end+1; // skip the ;
2968 end = depline.find( ";", start );
2970 // cannot depend on itself
2971 this->DeleteDependency( dep_map, lib, lib);
2975 //----------------------------------------------------------------------------
2976 void cmTarget::SetProperty(const char* prop, const char* value)
2982 if (strcmp(prop, "NAME") == 0)
2985 e << "NAME property is read-only\n";
2986 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
2989 if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
2991 cmListFileBacktrace lfbt;
2992 this->Makefile->GetBacktrace(lfbt);
2993 cmGeneratorExpression ge(lfbt);
2994 deleteAndClear(this->Internal->IncludeDirectoriesEntries);
2995 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
2996 this->Internal->IncludeDirectoriesEntries.push_back(
2997 new cmTargetInternals::TargetPropertyEntry(cge));
3000 if(strcmp(prop,"COMPILE_OPTIONS") == 0)
3002 cmListFileBacktrace lfbt;
3003 this->Makefile->GetBacktrace(lfbt);
3004 cmGeneratorExpression ge(lfbt);
3005 deleteAndClear(this->Internal->CompileOptionsEntries);
3006 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
3007 this->Internal->CompileOptionsEntries.push_back(
3008 new cmTargetInternals::TargetPropertyEntry(cge));
3011 if(strcmp(prop,"COMPILE_DEFINITIONS") == 0)
3013 cmListFileBacktrace lfbt;
3014 this->Makefile->GetBacktrace(lfbt);
3015 cmGeneratorExpression ge(lfbt);
3016 deleteAndClear(this->Internal->CompileDefinitionsEntries);
3017 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
3018 this->Internal->CompileDefinitionsEntries.push_back(
3019 new cmTargetInternals::TargetPropertyEntry(cge));
3022 if(strcmp(prop,"EXPORT_NAME") == 0 && this->IsImported())
3025 e << "EXPORT_NAME property can't be set on imported targets (\""
3026 << this->Name << "\")\n";
3027 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
3030 if (strcmp(prop, "LINK_LIBRARIES") == 0)
3032 this->Internal->LinkInterfacePropertyEntries.clear();
3033 if (cmGeneratorExpression::IsValidTargetName(value)
3034 || cmGeneratorExpression::Find(value) != std::string::npos)
3036 cmListFileBacktrace lfbt;
3037 this->Makefile->GetBacktrace(lfbt);
3038 cmValueWithOrigin entry(value, lfbt);
3039 this->Internal->LinkInterfacePropertyEntries.push_back(entry);
3043 this->Properties.SetProperty(prop, value, cmProperty::TARGET);
3044 this->MaybeInvalidatePropertyCache(prop);
3047 //----------------------------------------------------------------------------
3048 void cmTarget::AppendProperty(const char* prop, const char* value,
3055 if (strcmp(prop, "NAME") == 0)
3058 e << "NAME property is read-only\n";
3059 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
3062 if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
3064 cmListFileBacktrace lfbt;
3065 this->Makefile->GetBacktrace(lfbt);
3066 cmGeneratorExpression ge(lfbt);
3067 this->Internal->IncludeDirectoriesEntries.push_back(
3068 new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
3071 if(strcmp(prop,"COMPILE_OPTIONS") == 0)
3073 cmListFileBacktrace lfbt;
3074 this->Makefile->GetBacktrace(lfbt);
3075 cmGeneratorExpression ge(lfbt);
3076 this->Internal->CompileOptionsEntries.push_back(
3077 new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
3080 if(strcmp(prop,"COMPILE_DEFINITIONS") == 0)
3082 cmListFileBacktrace lfbt;
3083 this->Makefile->GetBacktrace(lfbt);
3084 cmGeneratorExpression ge(lfbt);
3085 this->Internal->CompileDefinitionsEntries.push_back(
3086 new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
3089 if(strcmp(prop,"EXPORT_NAME") == 0 && this->IsImported())
3092 e << "EXPORT_NAME property can't be set on imported targets (\""
3093 << this->Name << "\")\n";
3094 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
3097 if (strcmp(prop, "LINK_LIBRARIES") == 0)
3099 if (cmGeneratorExpression::IsValidTargetName(value)
3100 || cmGeneratorExpression::Find(value) != std::string::npos)
3102 cmListFileBacktrace lfbt;
3103 this->Makefile->GetBacktrace(lfbt);
3104 cmValueWithOrigin entry(value, lfbt);
3105 this->Internal->LinkInterfacePropertyEntries.push_back(entry);
3109 this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
3110 this->MaybeInvalidatePropertyCache(prop);
3113 //----------------------------------------------------------------------------
3114 const char* cmTarget::GetExportName()
3116 const char *exportName = this->GetProperty("EXPORT_NAME");
3118 if (exportName && *exportName)
3120 if (!cmGeneratorExpression::IsValidTargetName(exportName))
3123 e << "EXPORT_NAME property \"" << exportName << "\" for \""
3124 << this->GetName() << "\": is not valid.";
3125 cmSystemTools::Error(e.str().c_str());
3130 return this->GetName();
3133 //----------------------------------------------------------------------------
3134 void cmTarget::AppendBuildInterfaceIncludes()
3136 if(this->GetType() != cmTarget::SHARED_LIBRARY &&
3137 this->GetType() != cmTarget::STATIC_LIBRARY &&
3138 this->GetType() != cmTarget::MODULE_LIBRARY &&
3139 !this->IsExecutableWithExports())
3143 if (this->BuildInterfaceIncludesAppended)
3147 this->BuildInterfaceIncludesAppended = true;
3149 if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
3151 const char *binDir = this->Makefile->GetStartOutputDirectory();
3152 const char *srcDir = this->Makefile->GetStartDirectory();
3153 const std::string dirs = std::string(binDir ? binDir : "")
3154 + std::string(binDir ? ";" : "")
3155 + std::string(srcDir ? srcDir : "");
3158 this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
3159 ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
3164 //----------------------------------------------------------------------------
3165 void cmTarget::InsertInclude(const cmValueWithOrigin &entry,
3168 cmGeneratorExpression ge(entry.Backtrace);
3170 std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
3171 = before ? this->Internal->IncludeDirectoriesEntries.begin()
3172 : this->Internal->IncludeDirectoriesEntries.end();
3174 this->Internal->IncludeDirectoriesEntries.insert(position,
3175 new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
3178 //----------------------------------------------------------------------------
3179 void cmTarget::InsertCompileOption(const cmValueWithOrigin &entry,
3182 cmGeneratorExpression ge(entry.Backtrace);
3184 std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
3185 = before ? this->Internal->CompileOptionsEntries.begin()
3186 : this->Internal->CompileOptionsEntries.end();
3188 this->Internal->CompileOptionsEntries.insert(position,
3189 new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
3192 //----------------------------------------------------------------------------
3193 void cmTarget::InsertCompileDefinition(const cmValueWithOrigin &entry,
3196 cmGeneratorExpression ge(entry.Backtrace);
3198 std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
3199 = before ? this->Internal->CompileDefinitionsEntries.begin()
3200 : this->Internal->CompileDefinitionsEntries.end();
3202 this->Internal->CompileDefinitionsEntries.insert(position,
3203 new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
3206 //----------------------------------------------------------------------------
3207 static void processIncludeDirectories(cmTarget *tgt,
3208 const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
3209 std::vector<std::string> &includes,
3210 std::set<std::string> &uniqueIncludes,
3211 cmGeneratorExpressionDAGChecker *dagChecker,
3212 const char *config, bool debugIncludes)
3214 cmMakefile *mf = tgt->GetMakefile();
3216 for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
3217 it = entries.begin(), end = entries.end(); it != end; ++it)
3219 bool testIsOff = true;
3220 bool cacheIncludes = false;
3221 std::vector<std::string> entryIncludes = (*it)->CachedEntries;
3222 if(!entryIncludes.empty())
3228 cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
3234 if (mf->IsGeneratingBuildSystem()
3235 && !(*it)->ge->GetHadContextSensitiveCondition())
3237 cacheIncludes = true;
3240 std::string usedIncludes;
3241 for(std::vector<std::string>::iterator
3242 li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
3244 cmTarget *dependentTarget =
3245 mf->FindTargetToUse((*it)->TargetName.c_str());
3247 const bool fromImported = dependentTarget
3248 && dependentTarget->IsImported();
3250 if (fromImported && !cmSystemTools::FileExists(li->c_str()))
3253 e << "Imported target \"" << (*it)->TargetName << "\" includes "
3254 "non-existent path\n \"" << *li << "\"\nin its "
3255 "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
3256 "* The path was deleted, renamed, or moved to another "
3258 "* An install or uninstall procedure did not complete "
3260 "* The installation package was faulty and references files it "
3261 "does not provide.\n";
3262 tgt->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
3266 if (!cmSystemTools::FileIsFullPath(li->c_str()))
3269 bool noMessage = false;
3270 cmake::MessageType messageType = cmake::FATAL_ERROR;
3271 if (!(*it)->TargetName.empty())
3273 e << "Target \"" << (*it)->TargetName << "\" contains relative "
3274 "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
3275 " \"" << *li << "\"";
3279 switch(tgt->GetPolicyStatusCMP0021())
3281 case cmPolicies::WARN:
3284 e << (mf->GetPolicies()
3285 ->GetPolicyWarning(cmPolicies::CMP0021)) << "\n";
3286 messageType = cmake::AUTHOR_WARNING;
3289 case cmPolicies::OLD:
3291 case cmPolicies::REQUIRED_IF_USED:
3292 case cmPolicies::REQUIRED_ALWAYS:
3293 case cmPolicies::NEW:
3294 // Issue the fatal message.
3297 e << "Found relative path while evaluating include directories of "
3298 "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
3302 tgt->GetMakefile()->IssueMessage(messageType, e.str().c_str());
3303 if (messageType == cmake::FATAL_ERROR)
3310 if (testIsOff && !cmSystemTools::IsOff(li->c_str()))
3312 cmSystemTools::ConvertToUnixSlashes(*li);
3314 std::string inc = *li;
3316 if(uniqueIncludes.insert(inc).second)
3318 includes.push_back(inc);
3321 usedIncludes += " * " + inc + "\n";
3327 (*it)->CachedEntries = entryIncludes;
3329 if (!usedIncludes.empty())
3331 mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
3332 std::string("Used includes for target ")
3333 + tgt->GetName() + ":\n"
3334 + usedIncludes, (*it)->ge->GetBacktrace());
3339 //----------------------------------------------------------------------------
3340 std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
3342 std::vector<std::string> includes;
3343 std::set<std::string> uniqueIncludes;
3344 cmListFileBacktrace lfbt;
3346 cmGeneratorExpressionDAGChecker dagChecker(lfbt,
3348 "INCLUDE_DIRECTORIES", 0, 0);
3350 this->AppendBuildInterfaceIncludes();
3352 std::vector<std::string> debugProperties;
3353 const char *debugProp =
3354 this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
3357 cmSystemTools::ExpandListArgument(debugProp, debugProperties);
3360 bool debugIncludes = !this->DebugIncludesDone
3361 && std::find(debugProperties.begin(),
3362 debugProperties.end(),
3363 "INCLUDE_DIRECTORIES")
3364 != debugProperties.end();
3366 if (this->Makefile->IsGeneratingBuildSystem())
3368 this->DebugIncludesDone = true;
3371 processIncludeDirectories(this,
3372 this->Internal->IncludeDirectoriesEntries,
3379 std::string configString = config ? config : "";
3380 if (!this->Internal->CacheLinkInterfaceIncludeDirectoriesDone[configString])
3382 for (std::vector<cmValueWithOrigin>::const_iterator
3383 it = this->Internal->LinkInterfacePropertyEntries.begin(),
3384 end = this->Internal->LinkInterfacePropertyEntries.end();
3388 cmGeneratorExpression ge(lfbt);
3389 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
3390 ge.Parse(it->Value);
3391 std::string result = cge->Evaluate(this->Makefile, config,
3393 if (!this->Makefile->FindTargetToUse(result.c_str()))
3398 std::string includeGenex = "$<TARGET_PROPERTY:" +
3399 it->Value + ",INTERFACE_INCLUDE_DIRECTORIES>";
3400 if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
3402 // Because it->Value is a generator expression, ensure that it
3403 // evaluates to the non-empty string before being used in the
3404 // TARGET_PROPERTY expression.
3405 includeGenex = "$<$<BOOL:" + it->Value + ">:" + includeGenex + ">";
3407 cmGeneratorExpression ge(it->Backtrace);
3408 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
3412 ->CachedLinkInterfaceIncludeDirectoriesEntries[configString].push_back(
3413 new cmTargetInternals::TargetPropertyEntry(cge,
3417 if(this->Makefile->IsOn("APPLE"))
3419 LinkImplementation const* impl = this->GetLinkImplementation(config,
3421 for(std::vector<std::string>::const_iterator
3422 it = impl->Libraries.begin();
3423 it != impl->Libraries.end(); ++it)
3425 std::string libDir = cmSystemTools::CollapseFullPath(it->c_str());
3427 static cmsys::RegularExpression
3428 frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
3429 if(!frameworkCheck.find(libDir))
3434 libDir = frameworkCheck.match(1);
3436 cmGeneratorExpression ge(lfbt);
3437 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
3438 ge.Parse(libDir.c_str());
3440 ->CachedLinkInterfaceIncludeDirectoriesEntries[configString]
3441 .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
3446 processIncludeDirectories(this,
3447 this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries[configString],
3454 if (!this->Makefile->IsGeneratingBuildSystem())
3457 this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries);
3461 this->Internal->CacheLinkInterfaceIncludeDirectoriesDone[configString]
3468 //----------------------------------------------------------------------------
3469 static void processCompileOptionsInternal(cmTarget *tgt,
3470 const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
3471 std::vector<std::string> &options,
3472 std::set<std::string> &uniqueOptions,
3473 cmGeneratorExpressionDAGChecker *dagChecker,
3474 const char *config, bool debugOptions, const char *logName)
3476 cmMakefile *mf = tgt->GetMakefile();
3478 for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
3479 it = entries.begin(), end = entries.end(); it != end; ++it)
3481 bool cacheOptions = false;
3482 std::vector<std::string> entryOptions = (*it)->CachedEntries;
3483 if(entryOptions.empty())
3485 cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
3491 if (mf->IsGeneratingBuildSystem()
3492 && !(*it)->ge->GetHadContextSensitiveCondition())
3494 cacheOptions = true;
3497 std::string usedOptions;
3498 for(std::vector<std::string>::iterator
3499 li = entryOptions.begin(); li != entryOptions.end(); ++li)
3501 std::string opt = *li;
3503 if(uniqueOptions.insert(opt).second)
3505 options.push_back(opt);
3508 usedOptions += " * " + opt + "\n";
3514 (*it)->CachedEntries = entryOptions;
3516 if (!usedOptions.empty())
3518 mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
3519 std::string("Used compile ") + logName
3520 + std::string(" for target ")
3521 + tgt->GetName() + ":\n"
3522 + usedOptions, (*it)->ge->GetBacktrace());
3527 //----------------------------------------------------------------------------
3528 static void processCompileOptions(cmTarget *tgt,
3529 const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
3530 std::vector<std::string> &options,
3531 std::set<std::string> &uniqueOptions,
3532 cmGeneratorExpressionDAGChecker *dagChecker,
3533 const char *config, bool debugOptions)
3535 processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
3536 dagChecker, config, debugOptions, "options");
3539 //----------------------------------------------------------------------------
3540 void cmTarget::GetCompileOptions(std::vector<std::string> &result,
3543 std::set<std::string> uniqueOptions;
3544 cmListFileBacktrace lfbt;
3546 cmGeneratorExpressionDAGChecker dagChecker(lfbt,
3548 "COMPILE_OPTIONS", 0, 0);
3550 std::vector<std::string> debugProperties;
3551 const char *debugProp =
3552 this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
3555 cmSystemTools::ExpandListArgument(debugProp, debugProperties);
3558 bool debugOptions = !this->DebugCompileOptionsDone
3559 && std::find(debugProperties.begin(),
3560 debugProperties.end(),
3562 != debugProperties.end();
3564 if (this->Makefile->IsGeneratingBuildSystem())
3566 this->DebugCompileOptionsDone = true;
3569 processCompileOptions(this,
3570 this->Internal->CompileOptionsEntries,
3577 std::string configString = config ? config : "";
3578 if (!this->Internal->CacheLinkInterfaceCompileOptionsDone[configString])
3580 for (std::vector<cmValueWithOrigin>::const_iterator
3581 it = this->Internal->LinkInterfacePropertyEntries.begin(),
3582 end = this->Internal->LinkInterfacePropertyEntries.end();
3586 cmGeneratorExpression ge(lfbt);
3587 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
3588 ge.Parse(it->Value);
3589 std::string targetResult = cge->Evaluate(this->Makefile, config,
3591 if (!this->Makefile->FindTargetToUse(targetResult.c_str()))
3596 std::string optionGenex = "$<TARGET_PROPERTY:" +
3597 it->Value + ",INTERFACE_COMPILE_OPTIONS>";
3598 if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
3600 // Because it->Value is a generator expression, ensure that it
3601 // evaluates to the non-empty string before being used in the
3602 // TARGET_PROPERTY expression.
3603 optionGenex = "$<$<BOOL:" + it->Value + ">:" + optionGenex + ">";
3605 cmGeneratorExpression ge(it->Backtrace);
3606 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
3610 ->CachedLinkInterfaceCompileOptionsEntries[configString].push_back(
3611 new cmTargetInternals::TargetPropertyEntry(cge,
3616 processCompileOptions(this,
3617 this->Internal->CachedLinkInterfaceCompileOptionsEntries[configString],
3624 if (!this->Makefile->IsGeneratingBuildSystem())
3626 deleteAndClear(this->Internal->CachedLinkInterfaceCompileOptionsEntries);
3630 this->Internal->CacheLinkInterfaceCompileOptionsDone[configString] = true;
3634 //----------------------------------------------------------------------------
3635 static void processCompileDefinitions(cmTarget *tgt,
3636 const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
3637 std::vector<std::string> &options,
3638 std::set<std::string> &uniqueOptions,
3639 cmGeneratorExpressionDAGChecker *dagChecker,
3640 const char *config, bool debugOptions)
3642 processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
3643 dagChecker, config, debugOptions,
3647 //----------------------------------------------------------------------------
3648 void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
3651 std::set<std::string> uniqueOptions;
3652 cmListFileBacktrace lfbt;
3654 cmGeneratorExpressionDAGChecker dagChecker(lfbt,
3656 "COMPILE_DEFINITIONS", 0, 0);
3658 std::vector<std::string> debugProperties;
3659 const char *debugProp =
3660 this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
3663 cmSystemTools::ExpandListArgument(debugProp, debugProperties);
3666 bool debugDefines = !this->DebugCompileDefinitionsDone
3667 && std::find(debugProperties.begin(),
3668 debugProperties.end(),
3669 "COMPILE_DEFINITIONS")
3670 != debugProperties.end();
3672 if (this->Makefile->IsGeneratingBuildSystem())
3674 this->DebugCompileDefinitionsDone = true;
3677 processCompileDefinitions(this,
3678 this->Internal->CompileDefinitionsEntries,
3685 std::string configString = config ? config : "";
3686 if (!this->Internal->CacheLinkInterfaceCompileDefinitionsDone[configString])
3688 for (std::vector<cmValueWithOrigin>::const_iterator
3689 it = this->Internal->LinkInterfacePropertyEntries.begin(),
3690 end = this->Internal->LinkInterfacePropertyEntries.end();
3694 cmGeneratorExpression ge(lfbt);
3695 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
3696 ge.Parse(it->Value);
3697 std::string targetResult = cge->Evaluate(this->Makefile, config,
3699 if (!this->Makefile->FindTargetToUse(targetResult.c_str()))
3704 std::string defsGenex = "$<TARGET_PROPERTY:" +
3705 it->Value + ",INTERFACE_COMPILE_DEFINITIONS>";
3706 if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
3708 // Because it->Value is a generator expression, ensure that it
3709 // evaluates to the non-empty string before being used in the
3710 // TARGET_PROPERTY expression.
3711 defsGenex = "$<$<BOOL:" + it->Value + ">:" + defsGenex + ">";
3713 cmGeneratorExpression ge(it->Backtrace);
3714 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
3718 ->CachedLinkInterfaceCompileDefinitionsEntries[configString].push_back(
3719 new cmTargetInternals::TargetPropertyEntry(cge,
3724 std::string configPropName = "COMPILE_DEFINITIONS_"
3725 + cmSystemTools::UpperCase(config);
3726 const char *configProp = this->GetProperty(configPropName.c_str());
3727 std::string defsString = (configProp ? configProp : "");
3729 cmGeneratorExpression ge(lfbt);
3730 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
3731 ge.Parse(defsString);
3733 ->CachedLinkInterfaceCompileDefinitionsEntries[configString].push_back(
3734 new cmTargetInternals::TargetPropertyEntry(cge));
3739 processCompileDefinitions(this,
3740 this->Internal->CachedLinkInterfaceCompileDefinitionsEntries[configString],
3747 if (!this->Makefile->IsGeneratingBuildSystem())
3749 deleteAndClear(this->Internal
3750 ->CachedLinkInterfaceCompileDefinitionsEntries);
3754 this->Internal->CacheLinkInterfaceCompileDefinitionsDone[configString]
3759 //----------------------------------------------------------------------------
3760 void cmTarget::MaybeInvalidatePropertyCache(const char* prop)
3762 // Wipe out maps caching information affected by this property.
3763 if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
3765 this->Internal->ImportInfoMap.clear();
3767 if(!this->IsImported() && strncmp(prop, "LINK_INTERFACE_", 15) == 0)
3769 this->ClearLinkMaps();
3773 //----------------------------------------------------------------------------
3774 static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
3775 const char* prop, const char* value, cmMakefile* context, bool imported
3778 // Look for link-type keywords in the value.
3779 static cmsys::RegularExpression
3780 keys("(^|;)(debug|optimized|general)(;|$)");
3781 if(!keys.find(value))
3786 // Support imported and non-imported versions of the property.
3787 const char* base = (imported?
3788 "IMPORTED_LINK_INTERFACE_LIBRARIES" :
3789 "LINK_INTERFACE_LIBRARIES");
3793 e << "Property " << prop << " may not contain link-type keyword \""
3794 << keys.match(2) << "\". "
3795 << "The " << base << " property has a per-configuration "
3796 << "version called " << base << "_<CONFIG> which may be "
3797 << "used to specify per-configuration rules.";
3801 << "Alternatively, an IMPORTED library may be created, configured "
3802 << "with a per-configuration location, and then named in the "
3803 << "property value. "
3804 << "See the add_library command's IMPORTED mode for details."
3806 << "If you have a list of libraries that already contains the "
3807 << "keyword, use the target_link_libraries command with its "
3808 << "LINK_INTERFACE_LIBRARIES mode to set the property. "
3809 << "The command automatically recognizes link-type keywords and sets "
3810 << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
3811 << "properties accordingly.";
3813 context->IssueMessage(cmake::FATAL_ERROR, e.str());
3816 //----------------------------------------------------------------------------
3817 static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
3818 cmMakefile* context)
3820 // Look for link-type keywords in the value.
3821 static cmsys::RegularExpression
3822 keys("(^|;)(debug|optimized|general)(;|$)");
3823 if(!keys.find(value))
3831 e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
3832 "keyword \"" << keys.match(2) << "\". The INTERFACE_LINK_LIBRARIES "
3833 "property may contain configuration-sensitive generator-expressions "
3834 "which may be used to specify per-configuration rules.";
3836 context->IssueMessage(cmake::FATAL_ERROR, e.str());
3839 //----------------------------------------------------------------------------
3840 void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
3842 // Certain properties need checking.
3843 if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
3845 if(const char* value = this->GetProperty(prop))
3847 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
3850 if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
3852 if(const char* value = this->GetProperty(prop))
3854 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
3857 if(strncmp(prop, "INTERFACE_LINK_LIBRARIES", 24) == 0)
3859 if(const char* value = this->GetProperty(prop))
3861 cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
3866 //----------------------------------------------------------------------------
3867 void cmTarget::MarkAsImported()
3869 this->IsImportedTarget = true;
3872 //----------------------------------------------------------------------------
3873 bool cmTarget::HaveWellDefinedOutputFiles()
3876 this->GetType() == cmTarget::STATIC_LIBRARY ||
3877 this->GetType() == cmTarget::SHARED_LIBRARY ||
3878 this->GetType() == cmTarget::MODULE_LIBRARY ||
3879 this->GetType() == cmTarget::EXECUTABLE;
3882 //----------------------------------------------------------------------------
3883 cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
3885 // There is no output information for imported targets.
3886 if(this->IsImported())
3891 // Only libraries and executables have well-defined output files.
3892 if(!this->HaveWellDefinedOutputFiles())
3894 std::string msg = "cmTarget::GetOutputInfo called for ";
3895 msg += this->GetName();
3896 msg += " which has type ";
3897 msg += cmTarget::GetTargetTypeName(this->GetType());
3898 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
3903 // Lookup/compute/cache the output information for this configuration.
3904 std::string config_upper;
3905 if(config && *config)
3907 config_upper = cmSystemTools::UpperCase(config);
3909 typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
3910 OutputInfoMapType::const_iterator i =
3911 this->Internal->OutputInfoMap.find(config_upper);
3912 if(i == this->Internal->OutputInfoMap.end())
3915 this->ComputeOutputDir(config, false, info.OutDir);
3916 this->ComputeOutputDir(config, true, info.ImpDir);
3917 if(!this->ComputePDBOutputDir(config, info.PdbDir))
3919 info.PdbDir = info.OutDir;
3921 OutputInfoMapType::value_type entry(config_upper, info);
3922 i = this->Internal->OutputInfoMap.insert(entry).first;
3927 //----------------------------------------------------------------------------
3928 std::string cmTarget::GetDirectory(const char* config, bool implib)
3930 if (this->IsImported())
3932 // Return the directory from which the target is imported.
3934 cmSystemTools::GetFilenamePath(
3935 this->ImportedGetFullPath(config, implib));
3937 else if(OutputInfo const* info = this->GetOutputInfo(config))
3939 // Return the directory in which the target will be built.
3940 return implib? info->ImpDir : info->OutDir;
3945 //----------------------------------------------------------------------------
3946 std::string cmTarget::GetPDBDirectory(const char* config)
3948 if(OutputInfo const* info = this->GetOutputInfo(config))
3950 // Return the directory in which the target will be built.
3951 return info->PdbDir;
3956 //----------------------------------------------------------------------------
3957 const char* cmTarget::GetLocation(const char* config)
3959 if (this->IsImported())
3961 return this->ImportedGetLocation(config);
3965 return this->NormalGetLocation(config);
3969 //----------------------------------------------------------------------------
3970 const char* cmTarget::ImportedGetLocation(const char* config)
3972 this->Location = this->ImportedGetFullPath(config, false);
3973 return this->Location.c_str();
3976 //----------------------------------------------------------------------------
3977 const char* cmTarget::NormalGetLocation(const char* config)
3979 // Handle the configuration-specific case first.
3982 this->Location = this->GetFullPath(config, false);
3983 return this->Location.c_str();
3986 // Now handle the deprecated build-time configuration location.
3987 this->Location = this->GetDirectory();
3988 const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
3989 if(cfgid && strcmp(cfgid, ".") != 0)
3991 this->Location += "/";
3992 this->Location += cfgid;
3995 if(this->IsAppBundleOnApple())
3997 std::string macdir = this->BuildMacContentDirectory("", config, false);
4000 this->Location += "/";
4001 this->Location += macdir;
4004 this->Location += "/";
4005 this->Location += this->GetFullName(config, false);
4006 return this->Location.c_str();
4009 //----------------------------------------------------------------------------
4010 void cmTarget::GetTargetVersion(int& major, int& minor)
4013 this->GetTargetVersion(false, major, minor, patch);
4016 //----------------------------------------------------------------------------
4017 void cmTarget::GetTargetVersion(bool soversion,
4018 int& major, int& minor, int& patch)
4020 // Set the default values.
4025 // Look for a VERSION or SOVERSION property.
4026 const char* prop = soversion? "SOVERSION" : "VERSION";
4027 if(const char* version = this->GetProperty(prop))
4029 // Try to parse the version number and store the results that were
4030 // successfully parsed.
4034 switch(sscanf(version, "%d.%d.%d",
4035 &parsed_major, &parsed_minor, &parsed_patch))
4037 case 3: patch = parsed_patch; // no break!
4038 case 2: minor = parsed_minor; // no break!
4039 case 1: major = parsed_major; // no break!
4045 //----------------------------------------------------------------------------
4046 const char* cmTarget::GetFeature(const char* feature, const char* config)
4048 if(config && *config)
4050 std::string featureConfig = feature;
4051 featureConfig += "_";
4052 featureConfig += cmSystemTools::UpperCase(config);
4053 if(const char* value = this->GetProperty(featureConfig.c_str()))
4058 if(const char* value = this->GetProperty(feature))
4062 return this->Makefile->GetFeature(feature, config);
4065 //----------------------------------------------------------------------------
4066 const char *cmTarget::GetProperty(const char* prop)
4068 return this->GetProperty(prop, cmProperty::TARGET);
4071 //----------------------------------------------------------------------------
4072 const char *cmTarget::GetProperty(const char* prop,
4073 cmProperty::ScopeType scope)
4080 if (strcmp(prop, "NAME") == 0)
4082 return this->GetName();
4085 // Watch for special "computed" properties that are dependent on
4086 // other properties or variables. Always recompute them.
4087 if(this->GetType() == cmTarget::EXECUTABLE ||
4088 this->GetType() == cmTarget::STATIC_LIBRARY ||
4089 this->GetType() == cmTarget::SHARED_LIBRARY ||
4090 this->GetType() == cmTarget::MODULE_LIBRARY ||
4091 this->GetType() == cmTarget::UNKNOWN_LIBRARY)
4093 if(strcmp(prop,"LOCATION") == 0)
4095 // Set the LOCATION property of the target.
4097 // For an imported target this is the location of an arbitrary
4098 // available configuration.
4100 // For a non-imported target this is deprecated because it
4101 // cannot take into account the per-configuration name of the
4102 // target because the configuration type may not be known at
4104 this->SetProperty("LOCATION", this->GetLocation(0));
4107 // Support "LOCATION_<CONFIG>".
4108 if(strncmp(prop, "LOCATION_", 9) == 0)
4110 std::string configName = prop+9;
4111 this->SetProperty(prop, this->GetLocation(configName.c_str()));
4115 // Support "<CONFIG>_LOCATION" for compatiblity.
4116 int len = static_cast<int>(strlen(prop));
4117 if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
4119 std::string configName(prop, len-9);
4120 if(configName != "IMPORTED")
4122 this->SetProperty(prop, this->GetLocation(configName.c_str()));
4127 if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
4129 static std::string output;
4132 typedef cmTargetInternals::TargetPropertyEntry
4133 TargetPropertyEntry;
4134 for (std::vector<TargetPropertyEntry*>::const_iterator
4135 it = this->Internal->IncludeDirectoriesEntries.begin(),
4136 end = this->Internal->IncludeDirectoriesEntries.end();
4140 output += (*it)->ge->GetInput();
4143 return output.c_str();
4145 if(strcmp(prop,"COMPILE_OPTIONS") == 0)
4147 static std::string output;
4150 typedef cmTargetInternals::TargetPropertyEntry
4151 TargetPropertyEntry;
4152 for (std::vector<TargetPropertyEntry*>::const_iterator
4153 it = this->Internal->CompileOptionsEntries.begin(),
4154 end = this->Internal->CompileOptionsEntries.end();
4158 output += (*it)->ge->GetInput();
4161 return output.c_str();
4163 if(strcmp(prop,"COMPILE_DEFINITIONS") == 0)
4165 static std::string output;
4168 typedef cmTargetInternals::TargetPropertyEntry
4169 TargetPropertyEntry;
4170 for (std::vector<TargetPropertyEntry*>::const_iterator
4171 it = this->Internal->CompileDefinitionsEntries.begin(),
4172 end = this->Internal->CompileDefinitionsEntries.end();
4176 output += (*it)->ge->GetInput();
4179 return output.c_str();
4182 if (strcmp(prop,"IMPORTED") == 0)
4184 return this->IsImported()?"TRUE":"FALSE";
4187 if(!strcmp(prop,"SOURCES"))
4190 const char* sep = "";
4191 for(std::vector<cmSourceFile*>::const_iterator
4192 i = this->SourceFiles.begin();
4193 i != this->SourceFiles.end(); ++i)
4195 // Separate from the previous list entries.
4199 // Construct what is known about this source file location.
4200 cmSourceFileLocation const& location = (*i)->GetLocation();
4201 std::string sname = location.GetDirectory();
4206 sname += location.GetName();
4208 // Append this list entry.
4211 this->SetProperty("SOURCES", ss.str().c_str());
4214 // the type property returns what type the target is
4215 if (!strcmp(prop,"TYPE"))
4217 return cmTarget::GetTargetTypeName(this->GetType());
4220 const char *retVal =
4221 this->Properties.GetPropertyValue(prop, scope, chain);
4224 return this->Makefile->GetProperty(prop,scope);
4229 //----------------------------------------------------------------------------
4230 bool cmTarget::GetPropertyAsBool(const char* prop)
4232 return cmSystemTools::IsOn(this->GetProperty(prop));
4235 //----------------------------------------------------------------------------
4236 class cmTargetCollectLinkLanguages
4239 cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
4240 std::set<cmStdString>& languages,
4242 Config(config), Languages(languages), HeadTarget(head)
4243 { this->Visited.insert(target); }
4245 void Visit(cmTarget* target)
4247 if(!target || !this->Visited.insert(target).second)
4252 cmTarget::LinkInterface const* iface =
4253 target->GetLinkInterface(this->Config, this->HeadTarget);
4254 if(!iface) { return; }
4256 for(std::vector<std::string>::const_iterator
4257 li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
4259 this->Languages.insert(*li);
4262 cmMakefile* mf = target->GetMakefile();
4263 for(std::vector<std::string>::const_iterator
4264 li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
4266 this->Visit(mf->FindTargetToUse(li->c_str()));
4271 std::set<cmStdString>& Languages;
4272 cmTarget* HeadTarget;
4273 std::set<cmTarget*> Visited;
4276 //----------------------------------------------------------------------------
4277 const char* cmTarget::GetLinkerLanguage(const char* config, cmTarget *head)
4279 cmTarget *headTarget = head ? head : this;
4280 const char* lang = this->GetLinkClosure(config, headTarget)
4281 ->LinkerLanguage.c_str();
4282 return *lang? lang : 0;
4285 //----------------------------------------------------------------------------
4286 cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config,
4289 TargetConfigPair key(head, cmSystemTools::UpperCase(config ? config : ""));
4290 cmTargetInternals::LinkClosureMapType::iterator
4291 i = this->Internal->LinkClosureMap.find(key);
4292 if(i == this->Internal->LinkClosureMap.end())
4295 this->ComputeLinkClosure(config, lc, head);
4296 cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
4297 i = this->Internal->LinkClosureMap.insert(entry).first;
4302 //----------------------------------------------------------------------------
4303 class cmTargetSelectLinker
4307 cmMakefile* Makefile;
4308 cmGlobalGenerator* GG;
4309 std::set<cmStdString> Preferred;
4311 cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
4313 this->Makefile = this->Target->GetMakefile();
4314 this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
4316 void Consider(const char* lang)
4318 int preference = this->GG->GetLinkerPreference(lang);
4319 if(preference > this->Preference)
4321 this->Preference = preference;
4322 this->Preferred.clear();
4324 if(preference == this->Preference)
4326 this->Preferred.insert(lang);
4329 std::string Choose()
4331 if(this->Preferred.empty())
4335 else if(this->Preferred.size() > 1)
4338 e << "Target " << this->Target->GetName()
4339 << " contains multiple languages with the highest linker preference"
4340 << " (" << this->Preference << "):\n";
4341 for(std::set<cmStdString>::const_iterator
4342 li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
4344 e << " " << *li << "\n";
4346 e << "Set the LINKER_LANGUAGE property for this target.";
4347 cmake* cm = this->Makefile->GetCMakeInstance();
4348 cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
4349 this->Target->GetBacktrace());
4351 return *this->Preferred.begin();
4355 //----------------------------------------------------------------------------
4356 void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc,
4359 // Get languages built in this target.
4360 std::set<cmStdString> languages;
4361 LinkImplementation const* impl = this->GetLinkImplementation(config, head);
4362 for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
4363 li != impl->Languages.end(); ++li)
4365 languages.insert(*li);
4368 // Add interface languages from linked targets.
4369 cmTargetCollectLinkLanguages cll(this, config, languages, head);
4370 for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
4371 li != impl->Libraries.end(); ++li)
4373 cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
4376 // Store the transitive closure of languages.
4377 for(std::set<cmStdString>::const_iterator li = languages.begin();
4378 li != languages.end(); ++li)
4380 lc.Languages.push_back(*li);
4383 // Choose the language whose linker should be used.
4384 if(this->GetProperty("HAS_CXX"))
4386 lc.LinkerLanguage = "CXX";
4388 else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
4390 lc.LinkerLanguage = linkerLang;
4394 // Find the language with the highest preference value.
4395 cmTargetSelectLinker tsl(this);
4397 // First select from the languages compiled directly in this target.
4398 for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
4399 li != impl->Languages.end(); ++li)
4401 tsl.Consider(li->c_str());
4404 // Now consider languages that propagate from linked targets.
4405 for(std::set<cmStdString>::const_iterator sit = languages.begin();
4406 sit != languages.end(); ++sit)
4408 std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
4409 if(this->Makefile->IsOn(propagates.c_str()))
4411 tsl.Consider(sit->c_str());
4415 lc.LinkerLanguage = tsl.Choose();
4419 //----------------------------------------------------------------------------
4420 const char* cmTarget::GetSuffixVariableInternal(bool implib)
4422 switch(this->GetType())
4424 case cmTarget::STATIC_LIBRARY:
4425 return "CMAKE_STATIC_LIBRARY_SUFFIX";
4426 case cmTarget::SHARED_LIBRARY:
4428 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
4429 : "CMAKE_SHARED_LIBRARY_SUFFIX");
4430 case cmTarget::MODULE_LIBRARY:
4432 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
4433 : "CMAKE_SHARED_MODULE_SUFFIX");
4434 case cmTarget::EXECUTABLE:
4436 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
4437 : "CMAKE_EXECUTABLE_SUFFIX");
4445 //----------------------------------------------------------------------------
4446 const char* cmTarget::GetPrefixVariableInternal(bool implib)
4448 switch(this->GetType())
4450 case cmTarget::STATIC_LIBRARY:
4451 return "CMAKE_STATIC_LIBRARY_PREFIX";
4452 case cmTarget::SHARED_LIBRARY:
4454 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
4455 : "CMAKE_SHARED_LIBRARY_PREFIX");
4456 case cmTarget::MODULE_LIBRARY:
4458 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
4459 : "CMAKE_SHARED_MODULE_PREFIX");
4460 case cmTarget::EXECUTABLE:
4461 return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
4468 //----------------------------------------------------------------------------
4469 std::string cmTarget::GetPDBName(const char* config)
4474 this->GetFullNameInternal(config, false, prefix, base, suffix);
4476 std::vector<std::string> props;
4477 std::string configUpper =
4478 cmSystemTools::UpperCase(config? config : "");
4479 if(!configUpper.empty())
4481 // PDB_NAME_<CONFIG>
4482 props.push_back("PDB_NAME_" + configUpper);
4486 props.push_back("PDB_NAME");
4488 for(std::vector<std::string>::const_iterator i = props.begin();
4489 i != props.end(); ++i)
4491 if(const char* outName = this->GetProperty(i->c_str()))
4497 return prefix+base+".pdb";
4500 //----------------------------------------------------------------------------
4501 bool cmTarget::HasSOName(const char* config)
4503 // soname is supported only for shared libraries and modules,
4504 // and then only when the platform supports an soname flag.
4505 return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
4506 this->GetType() == cmTarget::MODULE_LIBRARY) &&
4507 !this->GetPropertyAsBool("NO_SONAME") &&
4508 this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config,
4512 //----------------------------------------------------------------------------
4513 std::string cmTarget::GetSOName(const char* config)
4515 if(this->IsImported())
4517 // Lookup the imported soname.
4518 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
4522 // The imported library has no builtin soname so the name
4523 // searched at runtime will be just the filename.
4524 return cmSystemTools::GetFilenameName(info->Location);
4528 // Use the soname given if any.
4529 if(info->SOName.find("@rpath/") == 0)
4531 return info->SOName.substr(6);
4533 return info->SOName;
4543 // Compute the soname that will be built.
4546 std::string realName;
4547 std::string impName;
4548 std::string pdbName;
4549 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
4554 //----------------------------------------------------------------------------
4555 bool cmTarget::HasMacOSXRpath(const char* config)
4557 bool install_name_is_rpath = false;
4558 bool macosx_rpath = this->GetPropertyAsBool("MACOSX_RPATH");
4560 if(!this->IsImportedTarget)
4562 const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
4563 bool use_install_name =
4564 this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
4565 if(install_name && use_install_name &&
4566 std::string(install_name) == "@rpath")
4568 install_name_is_rpath = true;
4570 else if(install_name && use_install_name)
4577 // Lookup the imported soname.
4578 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
4580 if(!info->NoSOName && !info->SOName.empty())
4582 if(info->SOName.find("@rpath/") == 0)
4584 install_name_is_rpath = true;
4589 std::string install_name;
4590 cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
4591 if(install_name.find("@rpath") != std::string::npos)
4593 install_name_is_rpath = true;
4599 if(!install_name_is_rpath && !macosx_rpath)
4604 if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
4607 w << "Attempting to use";
4610 w << " MACOSX_RPATH";
4616 w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
4617 w << " This could be because you are using a Mac OS X version";
4618 w << " less than 10.5 or because CMake's platform configuration is";
4620 cmake* cm = this->Makefile->GetCMakeInstance();
4621 cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
4627 //----------------------------------------------------------------------------
4628 bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
4630 if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
4632 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
4634 return info->NoSOName;
4640 //----------------------------------------------------------------------------
4641 std::string cmTarget::NormalGetRealName(const char* config)
4643 // This should not be called for imported targets.
4644 // TODO: Split cmTarget into a class hierarchy to get compile-time
4645 // enforcement of the limited imported target API.
4646 if(this->IsImported())
4648 std::string msg = "NormalGetRealName called on imported target: ";
4649 msg += this->GetName();
4650 this->GetMakefile()->
4651 IssueMessage(cmake::INTERNAL_ERROR,
4655 if(this->GetType() == cmTarget::EXECUTABLE)
4657 // Compute the real name that will be built.
4659 std::string realName;
4660 std::string impName;
4661 std::string pdbName;
4662 this->GetExecutableNames(name, realName, impName, pdbName, config);
4667 // Compute the real name that will be built.
4670 std::string realName;
4671 std::string impName;
4672 std::string pdbName;
4673 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
4678 //----------------------------------------------------------------------------
4679 std::string cmTarget::GetFullName(const char* config, bool implib)
4681 if(this->IsImported())
4683 return this->GetFullNameImported(config, implib);
4687 return this->GetFullNameInternal(config, implib);
4691 //----------------------------------------------------------------------------
4692 std::string cmTarget::GetFullNameImported(const char* config, bool implib)
4694 return cmSystemTools::GetFilenameName(
4695 this->ImportedGetFullPath(config, implib));
4698 //----------------------------------------------------------------------------
4699 void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
4700 std::string& suffix, const char* config,
4703 this->GetFullNameInternal(config, implib, prefix, base, suffix);
4706 //----------------------------------------------------------------------------
4707 std::string cmTarget::GetFullPath(const char* config, bool implib,
4710 if(this->IsImported())
4712 return this->ImportedGetFullPath(config, implib);
4716 return this->NormalGetFullPath(config, implib, realname);
4720 //----------------------------------------------------------------------------
4721 std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
4724 std::string fpath = this->GetDirectory(config, implib);
4726 if(this->IsAppBundleOnApple())
4728 fpath = this->BuildMacContentDirectory(fpath, config, false);
4732 // Add the full name of the target.
4735 fpath += this->GetFullName(config, true);
4739 fpath += this->NormalGetRealName(config);
4743 fpath += this->GetFullName(config, false);
4748 //----------------------------------------------------------------------------
4749 std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
4752 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
4754 result = implib? info->ImportLibrary : info->Location;
4758 result = this->GetName();
4759 result += "-NOTFOUND";
4764 //----------------------------------------------------------------------------
4765 std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
4770 this->GetFullNameInternal(config, implib, prefix, base, suffix);
4771 return prefix+base+suffix;
4774 //----------------------------------------------------------------------------
4775 void cmTarget::GetFullNameInternal(const char* config,
4777 std::string& outPrefix,
4778 std::string& outBase,
4779 std::string& outSuffix)
4781 // Use just the target name for non-main target types.
4782 if(this->GetType() != cmTarget::STATIC_LIBRARY &&
4783 this->GetType() != cmTarget::SHARED_LIBRARY &&
4784 this->GetType() != cmTarget::MODULE_LIBRARY &&
4785 this->GetType() != cmTarget::EXECUTABLE)
4788 outBase = this->GetName();
4793 // Return an empty name for the import library if this platform
4794 // does not support import libraries.
4796 !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
4804 // The implib option is only allowed for shared libraries, module
4805 // libraries, and executables.
4806 if(this->GetType() != cmTarget::SHARED_LIBRARY &&
4807 this->GetType() != cmTarget::MODULE_LIBRARY &&
4808 this->GetType() != cmTarget::EXECUTABLE)
4813 // Compute the full name for main target types.
4814 const char* targetPrefix = (implib
4815 ? this->GetProperty("IMPORT_PREFIX")
4816 : this->GetProperty("PREFIX"));
4817 const char* targetSuffix = (implib
4818 ? this->GetProperty("IMPORT_SUFFIX")
4819 : this->GetProperty("SUFFIX"));
4820 const char* configPostfix = 0;
4821 if(config && *config)
4823 std::string configProp = cmSystemTools::UpperCase(config);
4824 configProp += "_POSTFIX";
4825 configPostfix = this->GetProperty(configProp.c_str());
4826 // Mac application bundles and frameworks have no postfix.
4828 (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
4833 const char* prefixVar = this->GetPrefixVariableInternal(implib);
4834 const char* suffixVar = this->GetSuffixVariableInternal(implib);
4836 // Check for language-specific default prefix and suffix.
4837 if(const char* ll = this->GetLinkerLanguage(config, this))
4839 if(!targetSuffix && suffixVar && *suffixVar)
4841 std::string langSuff = suffixVar + std::string("_") + ll;
4842 targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
4844 if(!targetPrefix && prefixVar && *prefixVar)
4846 std::string langPrefix = prefixVar + std::string("_") + ll;
4847 targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
4851 // if there is no prefix on the target use the cmake definition
4852 if(!targetPrefix && prefixVar)
4854 targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
4856 // if there is no suffix on the target use the cmake definition
4857 if(!targetSuffix && suffixVar)
4859 targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
4862 // frameworks have directory prefix but no suffix
4863 std::string fw_prefix;
4864 if(this->IsFrameworkOnApple())
4866 fw_prefix = this->GetOutputName(config, false);
4867 fw_prefix += ".framework/";
4868 targetPrefix = fw_prefix.c_str();
4872 if(this->IsCFBundleOnApple())
4874 fw_prefix = this->GetOutputName(config, false);
4876 const char *ext = this->GetProperty("BUNDLE_EXTENSION");
4882 fw_prefix += "/Contents/MacOS/";
4883 targetPrefix = fw_prefix.c_str();
4887 // Begin the final name with the prefix.
4888 outPrefix = targetPrefix?targetPrefix:"";
4890 // Append the target name or property-specified name.
4891 outBase += this->GetOutputName(config, implib);
4893 // Append the per-configuration postfix.
4894 outBase += configPostfix?configPostfix:"";
4896 // Name shared libraries with their version number on some platforms.
4897 if(const char* soversion = this->GetProperty("SOVERSION"))
4899 if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
4900 this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
4903 outBase += soversion;
4907 // Append the suffix.
4908 outSuffix = targetSuffix?targetSuffix:"";
4911 //----------------------------------------------------------------------------
4912 void cmTarget::GetLibraryNames(std::string& name,
4913 std::string& soName,
4914 std::string& realName,
4915 std::string& impName,
4916 std::string& pdbName,
4919 // This should not be called for imported targets.
4920 // TODO: Split cmTarget into a class hierarchy to get compile-time
4921 // enforcement of the limited imported target API.
4922 if(this->IsImported())
4924 std::string msg = "GetLibraryNames called on imported target: ";
4925 msg += this->GetName();
4926 this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
4931 // Check for library version properties.
4932 const char* version = this->GetProperty("VERSION");
4933 const char* soversion = this->GetProperty("SOVERSION");
4934 if(!this->HasSOName(config) ||
4935 this->IsFrameworkOnApple())
4937 // Versioning is supported only for shared libraries and modules,
4938 // and then only when the platform supports an soname flag.
4942 if(version && !soversion)
4944 // The soversion must be set if the library version is set. Use
4945 // the library version as the soversion.
4946 soversion = version;
4948 if(!version && soversion)
4950 // Use the soversion as the library version.
4951 version = soversion;
4954 // Get the components of the library name.
4958 this->GetFullNameInternal(config, false, prefix, base, suffix);
4960 // The library name.
4961 name = prefix+base+suffix;
4963 if(this->IsFrameworkOnApple())
4966 realName += "Versions/";
4967 realName += this->GetFrameworkVersion();
4974 // The library's soname.
4975 this->ComputeVersionedName(soName, prefix, base, suffix,
4977 // The library's real name on disk.
4978 this->ComputeVersionedName(realName, prefix, base, suffix,
4982 // The import library name.
4983 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
4984 this->GetType() == cmTarget::MODULE_LIBRARY)
4986 impName = this->GetFullNameInternal(config, true);
4993 // The program database file name.
4994 pdbName = this->GetPDBName(config);
4997 //----------------------------------------------------------------------------
4998 void cmTarget::ComputeVersionedName(std::string& vName,
4999 std::string const& prefix,
5000 std::string const& base,
5001 std::string const& suffix,
5002 std::string const& name,
5003 const char* version)
5005 vName = this->IsApple? (prefix+base) : name;
5011 vName += this->IsApple? suffix : std::string();
5014 //----------------------------------------------------------------------------
5015 void cmTarget::GetExecutableNames(std::string& name,
5016 std::string& realName,
5017 std::string& impName,
5018 std::string& pdbName,
5021 // This should not be called for imported targets.
5022 // TODO: Split cmTarget into a class hierarchy to get compile-time
5023 // enforcement of the limited imported target API.
5024 if(this->IsImported())
5027 "GetExecutableNames called on imported target: ";
5028 msg += this->GetName();
5029 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
5032 // This versioning is supported only for executables and then only
5033 // when the platform supports symbolic links.
5034 #if defined(_WIN32) && !defined(__CYGWIN__)
5035 const char* version = 0;
5037 // Check for executable version properties.
5038 const char* version = this->GetProperty("VERSION");
5039 if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
5045 // Get the components of the executable name.
5049 this->GetFullNameInternal(config, false, prefix, base, suffix);
5051 // The executable name.
5052 name = prefix+base+suffix;
5054 // The executable's real name on disk.
5055 #if defined(__CYGWIN__)
5056 realName = prefix+base;
5063 realName += version;
5065 #if defined(__CYGWIN__)
5069 // The import library name.
5070 impName = this->GetFullNameInternal(config, true);
5072 // The program database file name.
5073 pdbName = this->GetPDBName(config);
5076 //----------------------------------------------------------------------------
5077 bool cmTarget::HasImplibGNUtoMS()
5079 return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
5082 //----------------------------------------------------------------------------
5083 bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
5084 std::string& out, const char* newExt)
5086 if(this->HasImplibGNUtoMS() &&
5087 gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
5089 out = gnuName.substr(0, gnuName.size()-6);
5090 out += newExt? newExt : ".lib";
5096 //----------------------------------------------------------------------------
5097 void cmTarget::GenerateTargetManifest(const char* config)
5099 cmMakefile* mf = this->Makefile;
5100 cmLocalGenerator* lg = mf->GetLocalGenerator();
5101 cmGlobalGenerator* gg = lg->GetGlobalGenerator();
5106 std::string realName;
5107 std::string impName;
5108 std::string pdbName;
5109 if(this->GetType() == cmTarget::EXECUTABLE)
5111 this->GetExecutableNames(name, realName, impName, pdbName, config);
5113 else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
5114 this->GetType() == cmTarget::SHARED_LIBRARY ||
5115 this->GetType() == cmTarget::MODULE_LIBRARY)
5117 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
5124 // Get the directory.
5125 std::string dir = this->GetDirectory(config, false);
5134 gg->AddToManifest(config? config:"", f);
5141 gg->AddToManifest(config? config:"", f);
5143 if(!realName.empty())
5148 gg->AddToManifest(config? config:"", f);
5150 if(!pdbName.empty())
5152 f = this->GetPDBDirectory(config);
5155 gg->AddToManifest(config? config:"", f);
5157 if(!impName.empty())
5159 f = this->GetDirectory(config, true);
5162 gg->AddToManifest(config? config:"", f);
5166 //----------------------------------------------------------------------------
5167 void cmTarget::SetPropertyDefault(const char* property,
5168 const char* default_value)
5170 // Compute the name of the variable holding the default value.
5171 std::string var = "CMAKE_";
5174 if(const char* value = this->Makefile->GetDefinition(var.c_str()))
5176 this->SetProperty(property, value);
5178 else if(default_value)
5180 this->SetProperty(property, default_value);
5184 //----------------------------------------------------------------------------
5185 bool cmTarget::HaveBuildTreeRPATH(const char *config)
5187 if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
5191 std::vector<std::string> libs;
5192 this->GetDirectLinkLibraries(config, libs, this);
5193 return !libs.empty();
5196 //----------------------------------------------------------------------------
5197 bool cmTarget::HaveInstallTreeRPATH()
5199 const char* install_rpath = this->GetProperty("INSTALL_RPATH");
5200 return (install_rpath && *install_rpath) &&
5201 !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
5204 //----------------------------------------------------------------------------
5205 bool cmTarget::NeedRelinkBeforeInstall(const char* config)
5207 // Only executables and shared libraries can have an rpath and may
5209 if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
5210 this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
5211 this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
5216 // If there is no install location this target will not be installed
5217 // and therefore does not need relinking.
5218 if(!this->GetHaveInstallRule())
5223 // If skipping all rpaths completely then no relinking is needed.
5224 if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
5229 // If building with the install-tree rpath no relinking is needed.
5230 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
5235 // If chrpath is going to be used no relinking is needed.
5236 if(this->IsChrpathUsed(config))
5241 // Check for rpath support on this platform.
5242 if(const char* ll = this->GetLinkerLanguage(config, this))
5244 std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
5247 if(!this->Makefile->IsSet(flagVar.c_str()))
5249 // There is no rpath support on this platform so nothing needs
5256 // No linker language is known. This error will be reported by
5261 // If either a build or install tree rpath is set then the rpath
5262 // will likely change between the build tree and install tree and
5263 // this target must be relinked.
5264 return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
5267 //----------------------------------------------------------------------------
5268 std::string cmTarget::GetInstallNameDirForBuildTree(const char* config)
5270 // If building directly for installation then the build tree install_name
5271 // is the same as the install tree.
5272 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
5274 return GetInstallNameDirForInstallTree();
5277 // Use the build tree directory for the target.
5278 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
5279 !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
5280 !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
5283 if(this->GetPropertyAsBool("MACOSX_RPATH"))
5289 dir = this->GetDirectory(config);
5300 //----------------------------------------------------------------------------
5301 std::string cmTarget::GetInstallNameDirForInstallTree()
5303 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
5306 const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
5308 if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
5309 !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
5311 if(install_name_dir && *install_name_dir)
5313 dir = install_name_dir;
5317 if(!install_name_dir && this->GetPropertyAsBool("MACOSX_RPATH"))
5329 //----------------------------------------------------------------------------
5330 const char* cmTarget::GetOutputTargetType(bool implib)
5332 switch(this->GetType())
5334 case cmTarget::SHARED_LIBRARY:
5335 if(this->DLLPlatform)
5339 // A DLL import library is treated as an archive target.
5344 // A DLL shared library is treated as a runtime target.
5350 // For non-DLL platforms shared libraries are treated as
5354 case cmTarget::STATIC_LIBRARY:
5355 // Static libraries are always treated as archive targets.
5357 case cmTarget::MODULE_LIBRARY:
5360 // Module libraries are always treated as library targets.
5365 // Module import libraries are treated as archive targets.
5368 case cmTarget::EXECUTABLE:
5371 // Executable import libraries are treated as archive targets.
5376 // Executables are always treated as runtime targets.
5385 //----------------------------------------------------------------------------
5386 bool cmTarget::ComputeOutputDir(const char* config,
5387 bool implib, std::string& out)
5389 bool usesDefaultOutputDir = false;
5391 // Look for a target property defining the target output directory
5392 // based on the target type.
5393 std::string targetTypeName = this->GetOutputTargetType(implib);
5394 const char* propertyName = 0;
5395 std::string propertyNameStr = targetTypeName;
5396 if(!propertyNameStr.empty())
5398 propertyNameStr += "_OUTPUT_DIRECTORY";
5399 propertyName = propertyNameStr.c_str();
5402 // Check for a per-configuration output directory target property.
5403 std::string configUpper = cmSystemTools::UpperCase(config? config : "");
5404 const char* configProp = 0;
5405 std::string configPropStr = targetTypeName;
5406 if(!configPropStr.empty())
5408 configPropStr += "_OUTPUT_DIRECTORY_";
5409 configPropStr += configUpper;
5410 configProp = configPropStr.c_str();
5413 // Select an output directory.
5414 if(const char* config_outdir = this->GetProperty(configProp))
5416 // Use the user-specified per-configuration output directory.
5417 out = config_outdir;
5419 // Skip per-configuration subdirectory.
5422 else if(const char* outdir = this->GetProperty(propertyName))
5424 // Use the user-specified output directory.
5427 else if(this->GetType() == cmTarget::EXECUTABLE)
5429 // Lookup the output path for executables.
5430 out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
5432 else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
5433 this->GetType() == cmTarget::SHARED_LIBRARY ||
5434 this->GetType() == cmTarget::MODULE_LIBRARY)
5436 // Lookup the output path for libraries.
5437 out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
5441 // Default to the current output directory.
5442 usesDefaultOutputDir = true;
5446 // Convert the output path to a full path in case it is
5447 // specified as a relative path. Treat a relative path as
5448 // relative to the current output directory for this makefile.
5449 out = (cmSystemTools::CollapseFullPath
5450 (out.c_str(), this->Makefile->GetStartOutputDirectory()));
5452 // The generator may add the configuration's subdirectory.
5453 if(config && *config)
5455 const char *platforms = this->Makefile->GetDefinition(
5456 "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
5457 std::string suffix =
5458 usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
5459 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
5460 AppendDirectoryForConfig("/", config, suffix.c_str(), out);
5463 return usesDefaultOutputDir;
5466 //----------------------------------------------------------------------------
5467 bool cmTarget::ComputePDBOutputDir(const char* config, std::string& out)
5469 // Look for a target property defining the target output directory
5470 // based on the target type.
5471 std::string targetTypeName = "PDB";
5472 const char* propertyName = 0;
5473 std::string propertyNameStr = targetTypeName;
5474 if(!propertyNameStr.empty())
5476 propertyNameStr += "_OUTPUT_DIRECTORY";
5477 propertyName = propertyNameStr.c_str();
5480 // Check for a per-configuration output directory target property.
5481 std::string configUpper = cmSystemTools::UpperCase(config? config : "");
5482 const char* configProp = 0;
5483 std::string configPropStr = targetTypeName;
5484 if(!configPropStr.empty())
5486 configPropStr += "_OUTPUT_DIRECTORY_";
5487 configPropStr += configUpper;
5488 configProp = configPropStr.c_str();
5491 // Select an output directory.
5492 if(const char* config_outdir = this->GetProperty(configProp))
5494 // Use the user-specified per-configuration output directory.
5495 out = config_outdir;
5497 // Skip per-configuration subdirectory.
5500 else if(const char* outdir = this->GetProperty(propertyName))
5502 // Use the user-specified output directory.
5510 // Convert the output path to a full path in case it is
5511 // specified as a relative path. Treat a relative path as
5512 // relative to the current output directory for this makefile.
5513 out = (cmSystemTools::CollapseFullPath
5514 (out.c_str(), this->Makefile->GetStartOutputDirectory()));
5516 // The generator may add the configuration's subdirectory.
5517 if(config && *config)
5519 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
5520 AppendDirectoryForConfig("/", config, "", out);
5525 //----------------------------------------------------------------------------
5526 bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib)
5529 return this->ComputeOutputDir(config, implib, dir);
5532 //----------------------------------------------------------------------------
5533 std::string cmTarget::GetOutputName(const char* config, bool implib)
5535 std::vector<std::string> props;
5536 std::string type = this->GetOutputTargetType(implib);
5537 std::string configUpper = cmSystemTools::UpperCase(config? config : "");
5538 if(!type.empty() && !configUpper.empty())
5540 // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
5541 props.push_back(type + "_OUTPUT_NAME_" + configUpper);
5545 // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
5546 props.push_back(type + "_OUTPUT_NAME");
5548 if(!configUpper.empty())
5550 // OUTPUT_NAME_<CONFIG>
5551 props.push_back("OUTPUT_NAME_" + configUpper);
5552 // <CONFIG>_OUTPUT_NAME
5553 props.push_back(configUpper + "_OUTPUT_NAME");
5556 props.push_back("OUTPUT_NAME");
5558 for(std::vector<std::string>::const_iterator i = props.begin();
5559 i != props.end(); ++i)
5561 if(const char* outName = this->GetProperty(i->c_str()))
5566 return this->GetName();
5569 //----------------------------------------------------------------------------
5570 std::string cmTarget::GetFrameworkVersion()
5572 if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
5576 else if(const char* tversion = this->GetProperty("VERSION"))
5586 //----------------------------------------------------------------------------
5587 const char* cmTarget::GetExportMacro()
5589 // Define the symbol for targets that export symbols.
5590 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
5591 this->GetType() == cmTarget::MODULE_LIBRARY ||
5592 this->IsExecutableWithExports())
5594 if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
5596 this->ExportMacro = custom_export_name;
5600 std::string in = this->GetName();
5602 this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
5604 return this->ExportMacro.c_str();
5612 //----------------------------------------------------------------------------
5613 bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p)
5615 return this->LinkImplicitNullProperties.find(p)
5616 != this->LinkImplicitNullProperties.end();
5619 //----------------------------------------------------------------------------
5620 template<typename PropertyType>
5621 PropertyType getTypedProperty(cmTarget *tgt, const char *prop,
5624 //----------------------------------------------------------------------------
5626 bool getTypedProperty<bool>(cmTarget *tgt, const char *prop, bool *)
5628 return tgt->GetPropertyAsBool(prop);
5631 //----------------------------------------------------------------------------
5633 const char *getTypedProperty<const char *>(cmTarget *tgt, const char *prop,
5636 return tgt->GetProperty(prop);
5639 //----------------------------------------------------------------------------
5640 template<typename PropertyType>
5641 bool consistentProperty(PropertyType lhs, PropertyType rhs);
5643 //----------------------------------------------------------------------------
5645 bool consistentProperty(bool lhs, bool rhs)
5650 //----------------------------------------------------------------------------
5652 bool consistentProperty(const char *lhs, const char *rhs)
5658 return strcmp(lhs, rhs) == 0;
5661 //----------------------------------------------------------------------------
5662 template<typename PropertyType>
5663 PropertyType checkInterfacePropertyCompatibility(cmTarget *tgt,
5664 const std::string &p,
5666 const char *defaultValue,
5669 PropertyType propContent = getTypedProperty<PropertyType>(tgt, p.c_str(),
5671 const bool explicitlySet = tgt->GetProperties()
5673 != tgt->GetProperties().end();
5674 const bool impliedByUse =
5675 tgt->IsNullImpliedByLinkLibraries(p);
5676 assert((impliedByUse ^ explicitlySet)
5677 || (!impliedByUse && !explicitlySet));
5679 cmComputeLinkInformation *info = tgt->GetLinkInformation(config);
5684 const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
5685 bool propInitialized = explicitlySet;
5687 for(cmComputeLinkInformation::ItemVector::const_iterator li =
5689 li != deps.end(); ++li)
5691 // An error should be reported if one dependency
5692 // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
5693 // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
5694 // target itself has a POSITION_INDEPENDENT_CODE which disagrees
5695 // with a dependency.
5702 const bool ifaceIsSet = li->Target->GetProperties()
5703 .find("INTERFACE_" + p)
5704 != li->Target->GetProperties().end();
5705 PropertyType ifacePropContent =
5706 getTypedProperty<PropertyType>(li->Target,
5707 ("INTERFACE_" + p).c_str(), 0);
5712 if (!consistentProperty(propContent, ifacePropContent))
5715 e << "Property " << p << " on target \""
5716 << tgt->GetName() << "\" does\nnot match the "
5717 "INTERFACE_" << p << " property requirement\nof "
5718 "dependency \"" << li->Target->GetName() << "\".\n";
5719 cmSystemTools::Error(e.str().c_str());
5730 // Explicitly set on target and not set in iface. Can't disagree.
5734 else if (impliedByUse)
5738 if (!consistentProperty(propContent, ifacePropContent))
5741 e << "Property " << p << " on target \""
5742 << tgt->GetName() << "\" is\nimplied to be " << defaultValue
5743 << " because it was used to determine the link libraries\n"
5744 "already. The INTERFACE_" << p << " property on\ndependency \""
5745 << li->Target->GetName() << "\" is in conflict.\n";
5746 cmSystemTools::Error(e.str().c_str());
5757 // Implicitly set on target and not set in iface. Can't disagree.
5765 if (propInitialized)
5767 if (!consistentProperty(propContent, ifacePropContent))
5770 e << "The INTERFACE_" << p << " property of \""
5771 << li->Target->GetName() << "\" does\nnot agree with the value "
5772 "of " << p << " already determined\nfor \""
5773 << tgt->GetName() << "\".\n";
5774 cmSystemTools::Error(e.str().c_str());
5785 propContent = ifacePropContent;
5786 propInitialized = true;
5791 // Not set. Nothing to agree on.
5799 //----------------------------------------------------------------------------
5800 bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
5803 return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
5807 //----------------------------------------------------------------------------
5808 const char * cmTarget::GetLinkInterfaceDependentStringProperty(
5809 const std::string &p,
5812 return checkInterfacePropertyCompatibility<const char *>(this,
5818 //----------------------------------------------------------------------------
5819 bool isLinkDependentProperty(cmTarget *tgt, const std::string &p,
5820 const char *interfaceProperty,
5823 cmComputeLinkInformation *info = tgt->GetLinkInformation(config);
5829 const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
5831 for(cmComputeLinkInformation::ItemVector::const_iterator li =
5833 li != deps.end(); ++li)
5839 const char *prop = li->Target->GetProperty(interfaceProperty);
5845 std::vector<std::string> props;
5846 cmSystemTools::ExpandListArgument(prop, props);
5848 for(std::vector<std::string>::iterator pi = props.begin();
5849 pi != props.end(); ++pi)
5861 //----------------------------------------------------------------------------
5862 bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
5865 if (this->TargetTypeValue == OBJECT_LIBRARY)
5869 return (p == "POSITION_INDEPENDENT_CODE") ||
5870 isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_BOOL",
5874 //----------------------------------------------------------------------------
5875 bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
5878 if (this->TargetTypeValue == OBJECT_LIBRARY)
5882 return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_STRING",
5886 //----------------------------------------------------------------------------
5887 void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
5889 for(std::vector<cmSourceFile*>::const_iterator
5890 i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
5892 if(const char* lang = (*i)->GetLanguage())
5894 languages.insert(lang);
5899 //----------------------------------------------------------------------------
5900 bool cmTarget::IsChrpathUsed(const char* config)
5902 // Only certain target types have an rpath.
5903 if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
5904 this->GetType() == cmTarget::MODULE_LIBRARY ||
5905 this->GetType() == cmTarget::EXECUTABLE))
5910 // If the target will not be installed we do not need to change its
5912 if(!this->GetHaveInstallRule())
5917 // Skip chrpath if skipping rpath altogether.
5918 if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
5923 // Skip chrpath if it does not need to be changed at install time.
5924 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
5929 // Allow the user to disable builtin chrpath explicitly.
5930 if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
5935 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
5940 #if defined(CMAKE_USE_ELF_PARSER)
5941 // Enable if the rpath flag uses a separator and the target uses ELF
5943 if(const char* ll = this->GetLinkerLanguage(config, this))
5945 std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
5947 sepVar += "_FLAG_SEP";
5948 const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
5951 // TODO: Add ELF check to ABI detection and get rid of
5952 // CMAKE_EXECUTABLE_FORMAT.
5953 if(const char* fmt =
5954 this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
5956 return strcmp(fmt, "ELF") == 0;
5961 static_cast<void>(config);
5965 //----------------------------------------------------------------------------
5966 cmTarget::ImportInfo const*
5967 cmTarget::GetImportInfo(const char* config, cmTarget *headTarget)
5969 // There is no imported information for non-imported targets.
5970 if(!this->IsImported())
5975 // Lookup/compute/cache the import information for this
5977 std::string config_upper;
5978 if(config && *config)
5980 config_upper = cmSystemTools::UpperCase(config);
5984 config_upper = "NOCONFIG";
5986 TargetConfigPair key(headTarget, config_upper);
5987 typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
5989 ImportInfoMapType::const_iterator i =
5990 this->Internal->ImportInfoMap.find(key);
5991 if(i == this->Internal->ImportInfoMap.end())
5994 this->ComputeImportInfo(config_upper, info, headTarget);
5995 ImportInfoMapType::value_type entry(key, info);
5996 i = this->Internal->ImportInfoMap.insert(entry).first;
5999 // If the location is empty then the target is not available for
6000 // this configuration.
6001 if(i->second.Location.empty() && i->second.ImportLibrary.empty())
6006 // Return the import information.
6010 bool cmTarget::GetMappedConfig(std::string const& desired_config,
6013 std::string& suffix)
6015 // Track the configuration-specific property suffix.
6017 suffix += desired_config;
6019 std::vector<std::string> mappedConfigs;
6021 std::string mapProp = "MAP_IMPORTED_CONFIG_";
6022 mapProp += desired_config;
6023 if(const char* mapValue = this->GetProperty(mapProp.c_str()))
6025 cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
6029 // If we needed to find one of the mapped configurations but did not
6030 // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
6031 // library or an executable with exports.
6032 bool allowImp = this->HasImportLibrary();
6034 // If a mapping was found, check its configurations.
6035 for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
6036 !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
6038 // Look for this configuration.
6039 std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
6040 std::string locProp = "IMPORTED_LOCATION_";
6042 *loc = this->GetProperty(locProp.c_str());
6045 std::string impProp = "IMPORTED_IMPLIB_";
6047 *imp = this->GetProperty(impProp.c_str());
6050 // If it was found, use it for all properties below.
6058 // If we needed to find one of the mapped configurations but did not
6059 // then the target is not found. The project does not want any
6060 // other configuration.
6061 if(!mappedConfigs.empty() && !*loc && !*imp)
6066 // If we have not yet found it then there are no mapped
6067 // configurations. Look for an exact-match.
6070 std::string locProp = "IMPORTED_LOCATION";
6072 *loc = this->GetProperty(locProp.c_str());
6075 std::string impProp = "IMPORTED_IMPLIB";
6077 *imp = this->GetProperty(impProp.c_str());
6081 // If we have not yet found it then there are no mapped
6082 // configurations and no exact match.
6085 // The suffix computed above is not useful.
6088 // Look for a configuration-less location. This may be set by
6089 // manually-written code.
6090 *loc = this->GetProperty("IMPORTED_LOCATION");
6093 *imp = this->GetProperty("IMPORTED_IMPLIB");
6097 // If we have not yet found it then the project is willing to try
6098 // any available configuration.
6101 std::vector<std::string> availableConfigs;
6102 if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
6104 cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
6106 for(std::vector<std::string>::const_iterator
6107 aci = availableConfigs.begin();
6108 !*loc && !*imp && aci != availableConfigs.end(); ++aci)
6111 suffix += cmSystemTools::UpperCase(*aci);
6112 std::string locProp = "IMPORTED_LOCATION";
6114 *loc = this->GetProperty(locProp.c_str());
6117 std::string impProp = "IMPORTED_IMPLIB";
6119 *imp = this->GetProperty(impProp.c_str());
6123 // If we have not yet found it then the target is not available.
6132 //----------------------------------------------------------------------------
6133 void cmTarget::ComputeImportInfo(std::string const& desired_config,
6135 cmTarget *headTarget)
6137 // This method finds information about an imported target from its
6138 // properties. The "IMPORTED_" namespace is reserved for properties
6139 // defined by the project exporting the target.
6141 // Initialize members.
6142 info.NoSOName = false;
6144 const char* loc = 0;
6145 const char* imp = 0;
6147 if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
6152 // A provided configuration has been chosen. Load the
6153 // configuration's properties.
6155 // Get the location.
6158 info.Location = loc;
6162 std::string impProp = "IMPORTED_LOCATION";
6164 if(const char* config_location = this->GetProperty(impProp.c_str()))
6166 info.Location = config_location;
6168 else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
6170 info.Location = location;
6175 if(this->GetType() == cmTarget::SHARED_LIBRARY)
6177 std::string soProp = "IMPORTED_SONAME";
6179 if(const char* config_soname = this->GetProperty(soProp.c_str()))
6181 info.SOName = config_soname;
6183 else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
6185 info.SOName = soname;
6189 // Get the "no-soname" mark.
6190 if(this->GetType() == cmTarget::SHARED_LIBRARY)
6192 std::string soProp = "IMPORTED_NO_SONAME";
6194 if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
6196 info.NoSOName = cmSystemTools::IsOn(config_no_soname);
6198 else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
6200 info.NoSOName = cmSystemTools::IsOn(no_soname);
6204 // Get the import library.
6207 info.ImportLibrary = imp;
6209 else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
6210 this->IsExecutableWithExports())
6212 std::string impProp = "IMPORTED_IMPLIB";
6214 if(const char* config_implib = this->GetProperty(impProp.c_str()))
6216 info.ImportLibrary = config_implib;
6218 else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
6220 info.ImportLibrary = implib;
6224 // Get the link interface.
6226 std::string linkProp = "INTERFACE_LINK_LIBRARIES";
6227 const char *propertyLibs = this->GetProperty(linkProp.c_str());
6231 linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
6233 propertyLibs = this->GetProperty(linkProp.c_str());
6238 linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
6239 propertyLibs = this->GetProperty(linkProp.c_str());
6243 cmListFileBacktrace lfbt;
6244 cmGeneratorExpression ge(lfbt);
6246 cmGeneratorExpressionDAGChecker dagChecker(lfbt,
6249 cmSystemTools::ExpandListArgument(ge.Parse(propertyLibs)
6250 ->Evaluate(this->Makefile,
6251 desired_config.c_str(),
6256 info.LinkInterface.Libraries);
6260 // Get the link dependencies.
6262 std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
6264 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
6266 cmSystemTools::ExpandListArgument(config_libs,
6267 info.LinkInterface.SharedDeps);
6269 else if(const char* libs =
6270 this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
6272 cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
6276 // Get the link languages.
6277 if(this->LinkLanguagePropagatesToDependents())
6279 std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
6281 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
6283 cmSystemTools::ExpandListArgument(config_libs,
6284 info.LinkInterface.Languages);
6286 else if(const char* libs =
6287 this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
6289 cmSystemTools::ExpandListArgument(libs,
6290 info.LinkInterface.Languages);
6294 // Get the cyclic repetition count.
6295 if(this->GetType() == cmTarget::STATIC_LIBRARY)
6297 std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
6299 if(const char* config_reps = this->GetProperty(linkProp.c_str()))
6301 sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
6303 else if(const char* reps =
6304 this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
6306 sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
6311 //----------------------------------------------------------------------------
6312 cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config,
6315 // Imported targets have their own link interface.
6316 if(this->IsImported())
6318 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head))
6320 return &info->LinkInterface;
6325 // Link interfaces are not supported for executables that do not
6327 if(this->GetType() == cmTarget::EXECUTABLE &&
6328 !this->IsExecutableWithExports())
6333 // Lookup any existing link interface for this configuration.
6334 TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
6336 cmTargetInternals::LinkInterfaceMapType::iterator
6337 i = this->Internal->LinkInterfaceMap.find(key);
6338 if(i == this->Internal->LinkInterfaceMap.end())
6340 // Compute the link interface for this configuration.
6341 cmTargetInternals::OptionalLinkInterface iface;
6342 iface.Exists = this->ComputeLinkInterface(config, iface, head);
6344 // Store the information for this configuration.
6345 cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
6346 i = this->Internal->LinkInterfaceMap.insert(entry).first;
6349 return i->second.Exists? &i->second : 0;
6352 //----------------------------------------------------------------------------
6353 void cmTarget::GetTransitivePropertyLinkLibraries(
6355 cmTarget *headTarget,
6356 std::vector<std::string> &libs)
6358 cmTarget::LinkInterface const* iface = this->GetLinkInterface(config,
6364 if(this->GetType() != STATIC_LIBRARY
6365 || this->GetPolicyStatusCMP0022() == cmPolicies::WARN
6366 || this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
6368 libs = iface->Libraries;
6372 const char* linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
6373 const char* interfaceLibs = this->GetProperty(linkIfaceProp);
6380 // The interface libraries have been explicitly set.
6381 cmListFileBacktrace lfbt;
6382 cmGeneratorExpression ge(lfbt);
6383 cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
6384 linkIfaceProp, 0, 0);
6385 dagChecker.SetTransitivePropertiesOnly();
6386 cmSystemTools::ExpandListArgument(ge.Parse(interfaceLibs)->Evaluate(
6391 this, &dagChecker), libs);
6394 //----------------------------------------------------------------------------
6395 bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface,
6396 cmTarget *headTarget)
6398 // Construct the property name suffix for this configuration.
6399 std::string suffix = "_";
6400 if(config && *config)
6402 suffix += cmSystemTools::UpperCase(config);
6406 suffix += "NOCONFIG";
6409 // An explicit list of interface libraries may be set for shared
6410 // libraries and executables that export symbols.
6411 const char* explicitLibraries = 0;
6412 std::string linkIfaceProp;
6413 if(this->PolicyStatusCMP0022 != cmPolicies::OLD &&
6414 this->PolicyStatusCMP0022 != cmPolicies::WARN)
6416 // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
6417 linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
6418 explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
6420 else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
6421 this->IsExecutableWithExports())
6423 // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
6424 // shared lib or executable.
6426 // Lookup the per-configuration property.
6427 linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
6428 linkIfaceProp += suffix;
6429 explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
6431 // If not set, try the generic property.
6432 if(!explicitLibraries)
6434 linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
6435 explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
6439 if(explicitLibraries && this->PolicyStatusCMP0022 == cmPolicies::WARN &&
6440 !this->Internal->PolicyWarnedCMP0022)
6442 // Compare the explicitly set old link interface properties to the
6443 // preferred new link interface property one and warn if different.
6444 const char* newExplicitLibraries =
6445 this->GetProperty("INTERFACE_LINK_LIBRARIES");
6446 if (newExplicitLibraries
6447 && strcmp(newExplicitLibraries, explicitLibraries) != 0)
6451 (this->Makefile->GetPolicies()
6452 ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
6453 "Target \"" << this->GetName() << "\" has an "
6454 "INTERFACE_LINK_LIBRARIES property which differs from its " <<
6455 linkIfaceProp << " properties."
6457 "INTERFACE_LINK_LIBRARIES:\n"
6458 " " << newExplicitLibraries << "\n" <<
6459 linkIfaceProp << ":\n"
6460 " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
6461 this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
6462 this->Internal->PolicyWarnedCMP0022 = true;
6466 // There is no implicit link interface for executables or modules
6467 // so if none was explicitly set then there is no link interface.
6468 // Note that CMake versions 2.2 and below allowed linking to modules.
6469 bool canLinkModules = this->Makefile->NeedBackwardsCompatibility(2,2);
6470 if(!explicitLibraries &&
6471 (this->GetType() == cmTarget::EXECUTABLE ||
6472 (this->GetType() == cmTarget::MODULE_LIBRARY && !canLinkModules)))
6477 if(explicitLibraries)
6479 // The interface libraries have been explicitly set.
6480 cmListFileBacktrace lfbt;
6481 cmGeneratorExpression ge(lfbt);
6482 cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
6483 linkIfaceProp, 0, 0);
6484 cmSystemTools::ExpandListArgument(ge.Parse(explicitLibraries)->Evaluate(
6489 this, &dagChecker), iface.Libraries);
6491 if(this->GetType() == cmTarget::SHARED_LIBRARY
6492 || this->GetType() == cmTarget::STATIC_LIBRARY)
6494 // Shared libraries may have runtime implementation dependencies
6495 // on other shared libraries that are not in the interface.
6496 std::set<cmStdString> emitted;
6497 for(std::vector<std::string>::const_iterator
6498 li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
6500 emitted.insert(*li);
6502 LinkImplementation const* impl = this->GetLinkImplementation(config,
6504 for(std::vector<std::string>::const_iterator
6505 li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
6507 if(emitted.insert(*li).second)
6509 if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
6511 // This is a runtime dependency on another shared library.
6512 if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
6514 iface.SharedDeps.push_back(*li);
6519 // TODO: Recognize shared library file names. Perhaps this
6520 // should be moved to cmComputeLinkInformation, but that creates
6521 // a chicken-and-egg problem since this list is needed for its
6526 if(this->LinkLanguagePropagatesToDependents())
6528 // Targets using this archive need its language runtime libraries.
6529 iface.Languages = impl->Languages;
6533 else if (this->PolicyStatusCMP0022 == cmPolicies::WARN
6534 || this->PolicyStatusCMP0022 == cmPolicies::OLD)
6535 // If CMP0022 is NEW then the plain tll signature sets the
6536 // INTERFACE_LINK_LIBRARIES, so if we get here then the project
6537 // cleared the property explicitly and we should not fall back
6538 // to the link implementation.
6540 // The link implementation is the default link interface.
6541 LinkImplementation const* impl = this->GetLinkImplementation(config,
6543 iface.ImplementationIsInterface = true;
6544 iface.Libraries = impl->Libraries;
6545 iface.WrongConfigLibraries = impl->WrongConfigLibraries;
6546 if(this->LinkLanguagePropagatesToDependents())
6548 // Targets using this archive need its language runtime libraries.
6549 iface.Languages = impl->Languages;
6552 if(this->PolicyStatusCMP0022 == cmPolicies::WARN &&
6553 !this->Internal->PolicyWarnedCMP0022)
6555 // Compare the link implementation fallback link interface to the
6556 // preferred new link interface property and warn if different.
6557 cmListFileBacktrace lfbt;
6558 cmGeneratorExpression ge(lfbt);
6559 cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
6560 "INTERFACE_LINK_LIBRARIES", 0, 0);
6561 std::vector<std::string> ifaceLibs;
6562 const char* newExplicitLibraries =
6563 this->GetProperty("INTERFACE_LINK_LIBRARIES");
6564 cmSystemTools::ExpandListArgument(
6565 ge.Parse(newExplicitLibraries)->Evaluate(this->Makefile,
6571 if (ifaceLibs != impl->Libraries)
6573 std::string oldLibraries;
6574 std::string newLibraries;
6575 const char *sep = "";
6576 for(std::vector<std::string>::const_iterator it
6577 = impl->Libraries.begin(); it != impl->Libraries.end(); ++it)
6579 oldLibraries += sep;
6580 oldLibraries += *it;
6584 for(std::vector<std::string>::const_iterator it
6585 = ifaceLibs.begin(); it != ifaceLibs.end(); ++it)
6587 newLibraries += sep;
6588 newLibraries += *it;
6591 if(oldLibraries.empty())
6592 { oldLibraries = "(empty)"; }
6593 if(newLibraries.empty())
6594 { newLibraries = "(empty)"; }
6598 (this->Makefile->GetPolicies()
6599 ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
6600 "Target \"" << this->GetName() << "\" has an "
6601 "INTERFACE_LINK_LIBRARIES property. "
6602 "This should be preferred as the source of the link interface "
6603 "for this library but because CMP0022 is not set CMake is "
6604 "ignoring the property and using the link implementation "
6605 "as the link interface instead."
6607 "INTERFACE_LINK_LIBRARIES:\n"
6608 " " << newLibraries << "\n"
6609 "Link implementation:\n"
6610 " " << oldLibraries << "\n";
6611 this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
6612 this->Internal->PolicyWarnedCMP0022 = true;
6617 if(this->GetType() == cmTarget::STATIC_LIBRARY)
6619 // How many repetitions are needed if this library has cyclic
6621 std::string propName = "LINK_INTERFACE_MULTIPLICITY";
6623 if(const char* config_reps = this->GetProperty(propName.c_str()))
6625 sscanf(config_reps, "%u", &iface.Multiplicity);
6627 else if(const char* reps =
6628 this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
6630 sscanf(reps, "%u", &iface.Multiplicity);
6637 //----------------------------------------------------------------------------
6638 cmTarget::LinkImplementation const*
6639 cmTarget::GetLinkImplementation(const char* config, cmTarget *head)
6641 // There is no link implementation for imported targets.
6642 if(this->IsImported())
6647 // Lookup any existing link implementation for this configuration.
6648 TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
6650 cmTargetInternals::LinkImplMapType::iterator
6651 i = this->Internal->LinkImplMap.find(key);
6652 if(i == this->Internal->LinkImplMap.end())
6654 // Compute the link implementation for this configuration.
6655 LinkImplementation impl;
6656 this->ComputeLinkImplementation(config, impl, head);
6658 // Store the information for this configuration.
6659 cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
6660 i = this->Internal->LinkImplMap.insert(entry).first;
6666 //----------------------------------------------------------------------------
6667 void cmTarget::ComputeLinkImplementation(const char* config,
6668 LinkImplementation& impl,
6671 // Compute which library configuration to link.
6672 cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
6674 // Collect libraries directly linked in this configuration.
6675 std::vector<std::string> llibs;
6676 this->GetDirectLinkLibraries(config, llibs, head);
6677 for(std::vector<std::string>::const_iterator li = llibs.begin();
6678 li != llibs.end(); ++li)
6680 // Skip entries that resolve to the target itself or are empty.
6681 std::string item = this->CheckCMP0004(*li);
6682 if(item == this->GetName() || item.empty())
6686 // The entry is meant for this configuration.
6687 impl.Libraries.push_back(item);
6690 LinkLibraryVectorType const& oldllibs = this->GetOriginalLinkLibraries();
6691 for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
6692 li != oldllibs.end(); ++li)
6694 if(li->second != cmTarget::GENERAL && li->second != linkType)
6696 std::string item = this->CheckCMP0004(li->first);
6697 if(item == this->GetName() || item.empty())
6701 // Support OLD behavior for CMP0003.
6702 impl.WrongConfigLibraries.push_back(item);
6706 // This target needs runtime libraries for its source languages.
6707 std::set<cmStdString> languages;
6708 // Get languages used in our source files.
6709 this->GetLanguages(languages);
6710 // Get languages used in object library sources.
6711 for(std::vector<std::string>::iterator i = this->ObjectLibraries.begin();
6712 i != this->ObjectLibraries.end(); ++i)
6714 if(cmTarget* objLib = this->Makefile->FindTargetToUse(i->c_str()))
6716 if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
6718 objLib->GetLanguages(languages);
6722 // Copy the set of langauges to the link implementation.
6723 for(std::set<cmStdString>::iterator li = languages.begin();
6724 li != languages.end(); ++li)
6726 impl.Languages.push_back(*li);
6730 //----------------------------------------------------------------------------
6731 std::string cmTarget::CheckCMP0004(std::string const& item)
6733 // Strip whitespace off the library names because we used to do this
6734 // in case variables were expanded at generate time. We no longer
6735 // do the expansion but users link to libraries like " ${VAR} ".
6736 std::string lib = item;
6737 std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
6740 lib = lib.substr(pos, lib.npos);
6742 pos = lib.find_last_not_of(" \t\r\n");
6745 lib = lib.substr(0, pos+1);
6749 cmake* cm = this->Makefile->GetCMakeInstance();
6750 switch(this->PolicyStatusCMP0004)
6752 case cmPolicies::WARN:
6755 w << (this->Makefile->GetPolicies()
6756 ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
6757 << "Target \"" << this->GetName() << "\" links to item \""
6758 << item << "\" which has leading or trailing whitespace.";
6759 cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
6760 this->GetBacktrace());
6762 case cmPolicies::OLD:
6764 case cmPolicies::NEW:
6767 e << "Target \"" << this->GetName() << "\" links to item \""
6768 << item << "\" which has leading or trailing whitespace. "
6769 << "This is now an error according to policy CMP0004.";
6770 cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
6773 case cmPolicies::REQUIRED_IF_USED:
6774 case cmPolicies::REQUIRED_ALWAYS:
6777 e << (this->Makefile->GetPolicies()
6778 ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
6779 << "Target \"" << this->GetName() << "\" links to item \""
6780 << item << "\" which has leading or trailing whitespace.";
6781 cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
6789 template<typename PropertyType>
6790 PropertyType getLinkInterfaceDependentProperty(cmTarget *tgt,
6791 const std::string prop,
6796 bool getLinkInterfaceDependentProperty(cmTarget *tgt,
6797 const std::string prop,
6798 const char *config, bool *)
6800 return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
6804 const char * getLinkInterfaceDependentProperty(cmTarget *tgt,
6805 const std::string prop,
6809 return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
6812 //----------------------------------------------------------------------------
6813 template<typename PropertyType>
6814 void checkPropertyConsistency(cmTarget *depender, cmTarget *dependee,
6815 const char *propName,
6816 std::set<cmStdString> &emitted,
6820 const char *prop = dependee->GetProperty(propName);
6826 std::vector<std::string> props;
6827 cmSystemTools::ExpandListArgument(prop, props);
6829 for(std::vector<std::string>::iterator pi = props.begin();
6830 pi != props.end(); ++pi)
6832 if (depender->GetMakefile()->GetCMakeInstance()
6833 ->GetIsPropertyDefined(pi->c_str(),
6834 cmProperty::TARGET))
6837 e << "Target \"" << dependee->GetName() << "\" has property \""
6838 << *pi << "\" listed in its " << propName << " property. "
6839 "This is not allowed. Only user-defined properties may appear "
6840 "listed in the " << propName << " property.";
6841 depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
6844 if(emitted.insert(*pi).second)
6846 getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
6848 if (cmSystemTools::GetErrorOccuredFlag())
6856 //----------------------------------------------------------------------------
6857 void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
6860 const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
6862 std::set<cmStdString> emittedBools;
6863 std::set<cmStdString> emittedStrings;
6865 for(cmComputeLinkInformation::ItemVector::const_iterator li =
6867 li != deps.end(); ++li)
6874 checkPropertyConsistency<bool>(this, li->Target,
6875 "COMPATIBLE_INTERFACE_BOOL",
6876 emittedBools, config, 0);
6877 if (cmSystemTools::GetErrorOccuredFlag())
6881 checkPropertyConsistency<const char *>(this, li->Target,
6882 "COMPATIBLE_INTERFACE_STRING",
6883 emittedStrings, config, 0);
6884 if (cmSystemTools::GetErrorOccuredFlag())
6890 for(std::set<cmStdString>::const_iterator li = emittedBools.begin();
6891 li != emittedBools.end(); ++li)
6893 const std::set<cmStdString>::const_iterator si = emittedStrings.find(*li);
6894 if (si != emittedStrings.end())
6897 e << "Property \"" << *li << "\" appears in both the "
6898 "COMPATIBLE_INTERFACE_BOOL and the COMPATIBLE_INTERFACE_STRING "
6899 "property in the dependencies of target \"" << this->GetName() <<
6900 "\". This is not allowed. A property may only require compatibility "
6901 "in a boolean interpretation or a string interpretation, but not both.";
6902 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
6908 //----------------------------------------------------------------------------
6909 cmComputeLinkInformation*
6910 cmTarget::GetLinkInformation(const char* config, cmTarget *head)
6912 cmTarget *headTarget = head ? head : this;
6913 // Lookup any existing information for this configuration.
6914 TargetConfigPair key(headTarget,
6915 cmSystemTools::UpperCase(config?config:""));
6916 cmTargetLinkInformationMap::iterator
6917 i = this->LinkInformation.find(key);
6918 if(i == this->LinkInformation.end())
6920 // Compute information for this configuration.
6921 cmComputeLinkInformation* info =
6922 new cmComputeLinkInformation(this, config, headTarget);
6923 if(!info || !info->Compute())
6929 // Store the information for this configuration.
6930 cmTargetLinkInformationMap::value_type entry(key, info);
6931 i = this->LinkInformation.insert(entry).first;
6935 this->CheckPropertyCompatibility(info, config);
6941 //----------------------------------------------------------------------------
6942 std::string cmTarget::GetFrameworkDirectory(const char* config,
6946 fpath += this->GetOutputName(config, false);
6947 fpath += ".framework";
6950 fpath += "/Versions/";
6951 fpath += this->GetFrameworkVersion();
6956 //----------------------------------------------------------------------------
6957 std::string cmTarget::GetCFBundleDirectory(const char* config,
6961 fpath += this->GetOutputName(config, false);
6963 const char *ext = this->GetProperty("BUNDLE_EXTENSION");
6969 fpath += "/Contents";
6975 //----------------------------------------------------------------------------
6976 std::string cmTarget::GetAppBundleDirectory(const char* config,
6979 std::string fpath = this->GetFullName(config, false);
6980 fpath += ".app/Contents";
6986 //----------------------------------------------------------------------------
6987 std::string cmTarget::BuildMacContentDirectory(const std::string& base,
6991 std::string fpath = base;
6992 if(this->IsAppBundleOnApple())
6994 fpath += this->GetAppBundleDirectory(config, contentOnly);
6996 if(this->IsFrameworkOnApple())
6998 fpath += this->GetFrameworkDirectory(config, contentOnly);
7000 if(this->IsCFBundleOnApple())
7002 fpath += this->GetCFBundleDirectory(config, contentOnly);
7007 //----------------------------------------------------------------------------
7008 std::string cmTarget::GetMacContentDirectory(const char* config,
7011 // Start with the output directory for the target.
7012 std::string fpath = this->GetDirectory(config, implib);
7014 bool contentOnly = true;
7015 if(this->IsFrameworkOnApple())
7017 // additional files with a framework go into the version specific
7019 contentOnly = false;
7021 fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
7025 //----------------------------------------------------------------------------
7026 cmTargetLinkInformationMap
7027 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
7029 // Ideally cmTarget instances should never be copied. However until
7030 // we can make a sweep to remove that, this copy constructor avoids
7031 // allowing the resources (LinkInformation) from getting copied. In
7032 // the worst case this will lead to extra cmComputeLinkInformation
7033 // instances. We also enforce in debug mode that the map be emptied
7035 static_cast<void>(r);
7039 //----------------------------------------------------------------------------
7040 cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
7042 for(derived::iterator i = this->begin(); i != this->end(); ++i)
7048 //----------------------------------------------------------------------------
7049 cmTargetInternalPointer::cmTargetInternalPointer()
7051 this->Pointer = new cmTargetInternals;
7054 //----------------------------------------------------------------------------
7055 cmTargetInternalPointer
7056 ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
7058 // Ideally cmTarget instances should never be copied. However until
7059 // we can make a sweep to remove that, this copy constructor avoids
7060 // allowing the resources (Internals) to be copied.
7061 this->Pointer = new cmTargetInternals(*r.Pointer);
7064 //----------------------------------------------------------------------------
7065 cmTargetInternalPointer::~cmTargetInternalPointer()
7067 deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
7068 deleteAndClear(this->Pointer->CompileOptionsEntries);
7069 deleteAndClear(this->Pointer->CompileDefinitionsEntries);
7070 delete this->Pointer;
7073 //----------------------------------------------------------------------------
7074 cmTargetInternalPointer&
7075 cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
7077 if(this == &r) { return *this; } // avoid warning on HP about self check
7078 // Ideally cmTarget instances should never be copied. However until
7079 // we can make a sweep to remove that, this copy constructor avoids
7080 // allowing the resources (Internals) to be copied.
7081 cmTargetInternals* oldPointer = this->Pointer;
7082 this->Pointer = new cmTargetInternals(*r.Pointer);