1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmTarget.cxx,v $
6 Date: $Date: 2009-03-23 18:48:09 $
7 Version: $Revision: 1.237 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
19 #include "cmMakefile.h"
20 #include "cmSourceFile.h"
21 #include "cmLocalGenerator.h"
22 #include "cmGlobalGenerator.h"
23 #include "cmComputeLinkInformation.h"
24 #include "cmListFileCache.h"
25 #include <cmsys/RegularExpression.hxx>
29 #include <stdlib.h> // required for atof
31 const char* cmTarget::TargetTypeNames
[] = {
32 "EXECUTABLE", "STATIC_LIBRARY",
33 "SHARED_LIBRARY", "MODULE_LIBRARY", "UTILITY", "GLOBAL_TARGET",
34 "INSTALL_FILES", "INSTALL_PROGRAMS", "INSTALL_DIRECTORY",
38 //----------------------------------------------------------------------------
39 class cmTargetInternals
44 this->SourceFileFlagsConstructed
= false;
46 typedef cmTarget::SourceFileFlags SourceFileFlags
;
47 std::map
<cmSourceFile
const*, SourceFileFlags
> SourceFlagsMap
;
48 bool SourceFileFlagsConstructed
;
50 // The backtrace when the target was created.
51 cmListFileBacktrace Backtrace
;
54 //----------------------------------------------------------------------------
58 this->PolicyStatusCMP0003
= cmPolicies::WARN
;
59 this->PolicyStatusCMP0004
= cmPolicies::WARN
;
60 this->PolicyStatusCMP0008
= cmPolicies::WARN
;
61 this->LinkLibrariesAnalyzed
= false;
62 this->HaveInstallRule
= false;
63 this->DLLPlatform
= false;
64 this->IsImportedTarget
= false;
67 //----------------------------------------------------------------------------
68 void cmTarget::DefineProperties(cmake
*cm
)
71 ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET
,
72 "Should build tree targets have install tree rpaths.",
73 "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
74 "the target in the build tree with the INSTALL_RPATH. This takes "
75 "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
76 "before installation. "
77 "This property is initialized by the value of the variable "
78 "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
81 ("CLEAN_DIRECT_OUTPUT", cmProperty::TARGET
,
82 "Do not delete other variants of this target.",
83 "When a library is built CMake by default generates code to remove "
84 "any existing library using all possible names. This is needed "
85 "to support libraries that switch between STATIC and SHARED by "
86 "a user option. However when using OUTPUT_NAME to build a static "
87 "and shared library of the same name using different logical target "
88 "names the two targets will remove each other's files. This can be "
89 "prevented by setting the CLEAN_DIRECT_OUTPUT property to 1.");
92 ("COMPILE_FLAGS", cmProperty::TARGET
,
93 "Additional flags to use when compiling this target's sources.",
94 "The COMPILE_FLAGS property sets additional compiler flags used "
95 "to build sources within the target. Use COMPILE_DEFINITIONS "
96 "to pass additional preprocessor definitions.");
99 ("COMPILE_DEFINITIONS", cmProperty::TARGET
,
100 "Preprocessor definitions for compiling a target's sources.",
101 "The COMPILE_DEFINITIONS property may be set to a list of preprocessor "
102 "definitions using the syntax VAR or VAR=value. Function-style "
103 "definitions are not supported. CMake will automatically escape "
104 "the value correctly for the native build system (note that CMake "
105 "language syntax may require escapes to specify some values). "
106 "This property may be set on a per-configuration basis using the name "
107 "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
108 "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
109 "CMake will automatically drop some definitions that "
110 "are not supported by the native build tool. "
111 "The VS6 IDE does not support definition values with spaces "
112 "(but NMake does).\n"
113 "Dislaimer: Most native build tools have poor support for escaping "
114 "certain values. CMake has work-arounds for many cases but some "
115 "values may just not be possible to pass correctly. If a value "
116 "does not seem to be escaped correctly, do not attempt to "
117 "work-around the problem by adding escape sequences to the value. "
118 "Your work-around may break in a future version of CMake that "
119 "has improved escape support. Instead consider defining the macro "
120 "in a (configured) header file. Then report the limitation.");
123 ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET
,
124 "Per-configuration preprocessor definitions on a target.",
125 "This is the configuration-specific version of COMPILE_DEFINITIONS.");
128 ("DEFINE_SYMBOL", cmProperty::TARGET
,
129 "Define a symbol when compiling this target's sources.",
130 "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
131 "compiling sources in a shared library. "
132 "If not set here then it is set to target_EXPORTS by default "
133 "(with some substitutions if the target is not a valid C "
134 "identifier). This is useful for headers to know whether they are "
135 "being included from inside their library our outside to properly "
136 "setup dllexport/dllimport decorations. ");
139 ("DEBUG_POSTFIX", cmProperty::TARGET
,
140 "See target property <CONFIG>_POSTFIX.",
141 "This property is a special case of the more-general <CONFIG>_POSTFIX "
142 "property for the DEBUG configuration.");
145 ("<CONFIG>_POSTFIX", cmProperty::TARGET
,
146 "Postfix to append to the target file name for configuration <CONFIG>.",
147 "When building with configuration <CONFIG> the value of this property "
148 "is appended to the target file name built on disk. "
149 "For non-executable targets, this property is initialized by the value "
150 "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
152 "This property is ignored on the Mac for Frameworks and App Bundles.");
155 ("EchoString", cmProperty::TARGET
,
156 "A message to be displayed when the target is built.",
157 "A message to display on some generators (such as makefiles) when "
158 "the target is built.");
161 ("FRAMEWORK", cmProperty::TARGET
,
162 "This target is a framework on the Mac.",
163 "If a shared library target has this property set to true it will "
164 "be built as a framework when built on the mac. It will have the "
165 "directory structure required for a framework and will be suitable "
166 "to be used with the -framework option");
169 ("HAS_CXX", cmProperty::TARGET
,
170 "Force a target to use the CXX linker.",
171 "Setting HAS_CXX on a target will force the target to use the "
172 "C++ linker (and C++ runtime libraries) for linking even if the "
173 "target has no C++ code in it.");
176 ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET
,
177 "Specify #include line transforms for dependencies in a target.",
178 "This property specifies rules to transform macro-like #include lines "
179 "during implicit dependency scanning of C and C++ source files. "
180 "The list of rules must be semicolon-separated with each entry of "
181 "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
182 "During dependency scanning occurrences of A_MACRO(...) on #include "
183 "lines will be replaced by the value given with the macro argument "
184 "substituted for '%'. For example, the entry\n"
185 " MYDIR(%)=<mydir/%>\n"
186 "will convert lines of the form\n"
187 " #include MYDIR(myheader.h)\n"
189 " #include <mydir/myheader.h>\n"
190 "allowing the dependency to be followed.\n"
191 "This property applies to sources in the target on which it is set.");
194 ("IMPORT_PREFIX", cmProperty::TARGET
,
195 "What comes before the import library name.",
196 "Similar to the target property PREFIX, but used for import libraries "
197 "(typically corresponding to a DLL) instead of regular libraries. "
198 "A target property that can be set to override the prefix "
199 "(such as \"lib\") on an import library name.");
202 ("IMPORT_SUFFIX", cmProperty::TARGET
,
203 "What comes after the import library name.",
204 "Similar to the target property SUFFIX, but used for import libraries "
205 "(typically corresponding to a DLL) instead of regular libraries. "
206 "A target property that can be set to override the suffix "
207 "(such as \".lib\") on an import library name.");
210 ("IMPORTED", cmProperty::TARGET
,
211 "Read-only indication of whether a target is IMPORTED.",
212 "The boolean value of this property is true for targets created with "
213 "the IMPORTED option to add_executable or add_library. "
214 "It is false for targets built within the project.");
217 ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET
,
218 "Configurations provided for an IMPORTED target.",
219 "Lists configuration names available for an IMPORTED target. "
220 "The names correspond to configurations defined in the project from "
221 "which the target is imported. "
222 "If the importing project uses a different set of configurations "
223 "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
225 "Ignored for non-imported targets.");
228 ("IMPORTED_IMPLIB", cmProperty::TARGET
,
229 "Full path to the import library for an IMPORTED target.",
230 "Specifies the location of the \".lib\" part of a windows DLL. "
231 "Ignored for non-imported targets.");
234 ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET
,
235 "Per-configuration version of IMPORTED_IMPLIB property.",
236 "This property is used when loading settings for the <CONFIG> "
237 "configuration of an imported target. "
238 "Configuration names correspond to those provided by the project "
239 "from which the target is imported.");
242 ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET
,
243 "Dependent shared libraries of an imported shared library.",
244 "Shared libraries may be linked to other shared libraries as part "
245 "of their implementation. On some platforms the linker searches "
246 "for the dependent libraries of shared libraries they are including "
247 "in the link. This property lists "
248 "the dependent shared libraries of an imported library. The list "
249 "should be disjoint from the list of interface libraries in the "
250 "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring "
251 "dependent shared libraries to be found at link time CMake uses this "
252 "list to add appropriate files or paths to the link command line. "
253 "Ignored for non-imported targets.");
256 ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET
,
257 "Per-configuration version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
258 "This property is used when loading settings for the <CONFIG> "
259 "configuration of an imported target. "
260 "Configuration names correspond to those provided by the project "
261 "from which the target is imported. "
262 "If set, this property completely overrides the generic property "
263 "for the named configuration.");
266 ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET
,
267 "Transitive link interface of an IMPORTED target.",
268 "Lists libraries whose interface is included when an IMPORTED library "
269 "target is linked to another target. "
270 "The libraries will be included on the link line for the target. "
271 "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
272 "to all imported target types, including STATIC libraries. "
273 "This property is ignored for non-imported targets.");
276 ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET
,
277 "Per-configuration version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
278 "This property is used when loading settings for the <CONFIG> "
279 "configuration of an imported target. "
280 "Configuration names correspond to those provided by the project "
281 "from which the target is imported. "
282 "If set, this property completely overrides the generic property "
283 "for the named configuration.");
286 ("IMPORTED_LOCATION", cmProperty::TARGET
,
287 "Full path to the main file on disk for an IMPORTED target.",
288 "Specifies the location of an IMPORTED target file on disk. "
289 "For executables this is the location of the executable file. "
290 "For bundles on OS X this is the location of the executable file "
291 "inside Contents/MacOS under the application bundle folder. "
292 "For static libraries and modules this is the location of the "
293 "library or module. "
294 "For shared libraries on non-DLL platforms this is the location of "
295 "the shared library. "
296 "For frameworks on OS X this is the location of the library file "
297 "symlink just inside the framework folder. "
298 "For DLLs this is the location of the \".dll\" part of the library. "
299 "For UNKNOWN libraries this is the location of the file to be linked. "
300 "Ignored for non-imported targets.");
303 ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET
,
304 "Per-configuration version of IMPORTED_LOCATION property.",
305 "This property is used when loading settings for the <CONFIG> "
306 "configuration of an imported target. "
307 "Configuration names correspond to those provided by the project "
308 "from which the target is imported.");
311 ("IMPORTED_SONAME", cmProperty::TARGET
,
312 "The \"soname\" of an IMPORTED target of shared library type.",
313 "Specifies the \"soname\" embedded in an imported shared library. "
314 "This is meaningful only on platforms supporting the feature. "
315 "Ignored for non-imported targets.");
318 ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET
,
319 "Per-configuration version of IMPORTED_SONAME property.",
320 "This property is used when loading settings for the <CONFIG> "
321 "configuration of an imported target. "
322 "Configuration names correspond to those provided by the project "
323 "from which the target is imported.");
326 ("EXCLUDE_FROM_ALL", cmProperty::TARGET
,
327 "Exclude the target from the all target.",
328 "A property on a target that indicates if the target is excluded "
329 "from the default build target. If it is not, then with a Makefile "
330 "for example typing make will cause this target to be built. "
331 "The same concept applies to the default build of other generators. "
332 "Installing a target with EXCLUDE_FROM_ALL set to true has "
333 "undefined behavior.");
336 ("INSTALL_NAME_DIR", cmProperty::TARGET
,
337 "Mac OSX directory name for installed targets.",
338 "INSTALL_NAME_DIR is a string specifying the "
339 "directory portion of the \"install_name\" field of shared libraries "
340 "on Mac OSX to use in the installed targets. ");
343 ("INSTALL_RPATH", cmProperty::TARGET
,
344 "The rpath to use for installed targets.",
345 "A semicolon-separated list specifying the rpath "
346 "to use in installed targets (for platforms that support it). "
347 "This property is initialized by the value of the variable "
348 "CMAKE_INSTALL_RPATH if it is set when a target is created.");
351 ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET
,
352 "Add paths to linker search and installed rpath.",
353 "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
354 "append directories in the linker search path and outside the "
355 "project to the INSTALL_RPATH. "
356 "This property is initialized by the value of the variable "
357 "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
361 ("LABELS", cmProperty::TARGET
,
362 "Specify a list of text labels associated with a target.",
363 "Target label semantics are currently unspecified.");
366 ("LINK_FLAGS", cmProperty::TARGET
,
367 "Additional flags to use when linking this target.",
368 "The LINK_FLAGS property can be used to add extra flags to the "
369 "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
370 "configuration <CONFIG>, "
371 "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
374 ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET
,
375 "Per-configuration linker flags for a target.",
376 "This is the configuration-specific version of LINK_FLAGS.");
379 ("LINK_SEARCH_END_STATIC", cmProperty::TARGET
,
380 "End a link line such that static system libraries are used.",
381 "Some linkers support switches such as -Bstatic and -Bdynamic "
382 "to determine whether to use static or shared libraries for -lXXX "
383 "options. CMake uses these options to set the link type for "
384 "libraries whose full paths are not known or (in some cases) are in "
385 "implicit link directories for the platform. By default the "
386 "linker search type is left at -Bdynamic by the end of the library "
387 "list. This property switches the final linker search type to "
391 ("LINKER_LANGUAGE", cmProperty::TARGET
,
392 "What tool to use for linking, based on language.",
393 "The LINKER_LANGUAGE property is used to change the tool "
394 "used to link an executable or shared library. The default is "
395 "set the language to match the files in the library. CXX and C "
396 "are common values for this property.");
399 ("LOCATION", cmProperty::TARGET
,
400 "Read-only location of a target on disk.",
401 "For an imported target, this read-only property returns the value of "
402 "the LOCATION_<CONFIG> property for an unspecified configuration "
403 "<CONFIG> provided by the target.\n"
404 "For a non-imported target, this property is provided for compatibility "
405 "with CMake 2.4 and below. "
406 "It was meant to get the location of an executable target's output file "
407 "for use in add_custom_command. "
408 "The path may contain a build-system-specific portion that "
409 "is replaced at build time with the configuration getting built "
410 "(such as \"$(ConfigurationName)\" in VS). "
411 "In CMake 2.6 and above add_custom_command automatically recognizes a "
412 "target name in its COMMAND and DEPENDS options and computes the "
414 "Therefore this property is not needed for creating custom commands.");
417 ("LOCATION_<CONFIG>", cmProperty::TARGET
,
418 "Read-only property providing a target location on disk.",
419 "A read-only property that indicates where a target's main file is "
420 "located on disk for the configuration <CONFIG>. "
421 "The property is defined only for library and executable targets. "
422 "An imported target may provide a set of configurations different "
423 "from that of the importing project. "
424 "By default CMake looks for an exact-match but otherwise uses an "
425 "arbitrary available configuration. "
426 "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
427 "configurations explicitly.");
430 ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET
,
431 "List public interface libraries for a shared library or executable.",
432 "By default linking to a shared library target transitively "
433 "links to targets with which the library itself was linked. "
434 "For an executable with exports (see the ENABLE_EXPORTS property) "
435 "no default transitive link dependencies are used. "
436 "This property replaces the default transitive link dependencies with "
438 "When the target is linked into another target the libraries "
439 "listed (and recursively their link interface libraries) will be "
440 "provided to the other target also. "
441 "If the list is empty then no transitive link dependencies will be "
442 "incorporated when this target is linked into another target even if "
443 "the default set is non-empty. "
444 "This property is ignored for STATIC libraries.");
447 ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET
,
448 "Per-configuration list of public interface libraries for a target.",
449 "This is the configuration-specific version of "
450 "LINK_INTERFACE_LIBRARIES. "
451 "If set, this property completely overrides the generic property "
452 "for the named configuration.");
455 ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET
,
456 "Map from project configuration to IMPORTED target's configuration.",
457 "List configurations of an imported target that may be used for "
458 "the current project's <CONFIG> configuration. "
459 "Targets imported from another project may not provide the same set "
460 "of configuration names available in the current project. "
461 "Setting this property tells CMake what imported configurations are "
462 "suitable for use when building the <CONFIG> configuration. "
463 "The first configuration in the list found to be provided by the "
464 "imported target is selected. If no matching configurations are "
465 "available the imported target is considered to be not found. "
466 "This property is ignored for non-imported targets.",
467 false /* TODO: make this chained */ );
470 ("OUTPUT_NAME", cmProperty::TARGET
,
471 "Sets the real name of a target when it is built.",
472 "Sets the real name of a target when it is built and "
473 "can be used to help create two targets of the same name even though "
474 "CMake requires unique logical target names. There is also a "
475 "<CONFIG>_OUTPUT_NAME that can set the output name on a "
476 "per-configuration basis.");
479 ("PRE_INSTALL_SCRIPT", cmProperty::TARGET
,
480 "Deprecated install support.",
481 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
482 "old way to specify CMake scripts to run before and after "
483 "installing a target. They are used only when the old "
484 "INSTALL_TARGETS command is used to install the target. Use the "
485 "INSTALL command instead.");
488 ("PREFIX", cmProperty::TARGET
,
489 "What comes before the library name.",
490 "A target property that can be set to override the prefix "
491 "(such as \"lib\") on a library name.");
494 ("POST_INSTALL_SCRIPT", cmProperty::TARGET
,
495 "Deprecated install support.",
496 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
497 "old way to specify CMake scripts to run before and after "
498 "installing a target. They are used only when the old "
499 "INSTALL_TARGETS command is used to install the target. Use the "
500 "INSTALL command instead.");
503 ("PRIVATE_HEADER", cmProperty::TARGET
,
504 "Specify private header files in a FRAMEWORK shared library target.",
505 "Shared library targets marked with the FRAMEWORK property generate "
506 "frameworks on OS X and normal shared libraries on other platforms. "
507 "This property may be set to a list of header files to be placed "
508 "in the PrivateHeaders directory inside the framework folder. "
509 "On non-Apple platforms these headers may be installed using the "
510 "PRIVATE_HEADER option to the install(TARGETS) command.");
513 ("PUBLIC_HEADER", cmProperty::TARGET
,
514 "Specify public header files in a FRAMEWORK shared library target.",
515 "Shared library targets marked with the FRAMEWORK property generate "
516 "frameworks on OS X and normal shared libraries on other platforms. "
517 "This property may be set to a list of header files to be placed "
518 "in the Headers directory inside the framework folder. "
519 "On non-Apple platforms these headers may be installed using the "
520 "PUBLIC_HEADER option to the install(TARGETS) command.");
523 ("RESOURCE", cmProperty::TARGET
,
524 "Specify resource files in a FRAMEWORK shared library target.",
525 "Shared library targets marked with the FRAMEWORK property generate "
526 "frameworks on OS X and normal shared libraries on other platforms. "
527 "This property may be set to a list of files to be placed "
528 "in the Resources directory inside the framework folder. "
529 "On non-Apple platforms these files may be installed using the "
530 "RESOURCE option to the install(TARGETS) command.");
533 ("RULE_LAUNCH_COMPILE", cmProperty::TARGET
,
534 "Specify a launcher for compile rules.",
535 "See the global property of the same name for details. "
536 "This overrides the global and directory property for a target.",
539 ("RULE_LAUNCH_LINK", cmProperty::TARGET
,
540 "Specify a launcher for link rules.",
541 "See the global property of the same name for details. "
542 "This overrides the global and directory property for a target.",
545 ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET
,
546 "Specify a launcher for custom rules.",
547 "See the global property of the same name for details. "
548 "This overrides the global and directory property for a target.",
552 ("SKIP_BUILD_RPATH", cmProperty::TARGET
,
553 "Should rpaths be used for the build tree.",
554 "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
555 "generation of an rpath allowing the target to run from the "
557 "This property is initialized by the value of the variable "
558 "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
561 ("SOVERSION", cmProperty::TARGET
,
562 "What version number is this target.",
563 "For shared libraries VERSION and SOVERSION can be used to specify "
564 "the build version and api version respectively. When building or "
565 "installing appropriate symlinks are created if the platform "
566 "supports symlinks and the linker supports so-names. "
567 "If only one of both is specified the missing is assumed to have "
568 "the same version number. "
569 "For shared libraries and executables on Windows the VERSION "
570 "attribute is parsed to extract a \"major.minor\" version number. "
571 "These numbers are used as the image version of the binary. ");
574 ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET
,
575 "Extra flags to use when linking static libraries.",
576 "Extra flags to use when linking a static library.");
579 ("SUFFIX", cmProperty::TARGET
,
580 "What comes after the library name.",
581 "A target property that can be set to override the suffix "
582 "(such as \".so\") on a library name.");
585 ("TYPE", cmProperty::TARGET
,
586 "The type of the target.",
587 "This read-only property can be used to test the type of the given "
588 "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
589 "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
592 ("VERSION", cmProperty::TARGET
,
593 "What version number is this target.",
594 "For shared libraries VERSION and SOVERSION can be used to specify "
595 "the build version and api version respectively. When building or "
596 "installing appropriate symlinks are created if the platform "
597 "supports symlinks and the linker supports so-names. "
598 "If only one of both is specified the missing is assumed to have "
599 "the same version number. "
600 "For executables VERSION can be used to specify the build version. "
601 "When building or installing appropriate symlinks are created if "
602 "the platform supports symlinks. "
603 "For shared libraries and executables on Windows the VERSION "
604 "attribute is parsed to extract a \"major.minor\" version number. "
605 "These numbers are used as the image version of the binary. ");
609 ("WIN32_EXECUTABLE", cmProperty::TARGET
,
610 "Build an executable with a WinMain entry point on windows.",
611 "When this property is set to true the executable when linked "
612 "on Windows will be created with a WinMain() entry point instead "
614 "This makes it a GUI executable instead of a console application. "
615 "See the CMAKE_MFC_FLAG variable documentation to configure use "
616 "of MFC for WinMain executables.");
619 ("MACOSX_BUNDLE", cmProperty::TARGET
,
620 "Build an executable as an application bundle on Mac OS X.",
621 "When this property is set to true the executable when built "
622 "on Mac OS X will be created as an application bundle. "
623 "This makes it a GUI executable that can be launched from "
625 "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
626 "about creation of the Info.plist file for the application bundle.");
629 ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET
,
630 "Specify a custom Info.plist template for a Mac OS X App Bundle.",
631 "An executable target with MACOSX_BUNDLE enabled will be built as an "
632 "application bundle on Mac OS X. "
633 "By default its Info.plist file is created by configuring a template "
634 "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
635 "This property specifies an alternative template file name which "
636 "may be a full path.\n"
637 "The following target properties may be set to specify content to "
638 "be configured into the file:\n"
639 " MACOSX_BUNDLE_INFO_STRING\n"
640 " MACOSX_BUNDLE_ICON_FILE\n"
641 " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
642 " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
643 " MACOSX_BUNDLE_BUNDLE_NAME\n"
644 " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
645 " MACOSX_BUNDLE_BUNDLE_VERSION\n"
646 " MACOSX_BUNDLE_COPYRIGHT\n"
647 "CMake variables of the same name may be set to affect all targets "
648 "in a directory that do not have each specific property set. "
649 "If a custom Info.plist is specified by this property it may of course "
650 "hard-code all the settings instead of using the target properties.");
653 ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET
,
654 "Specify a custom Info.plist template for a Mac OS X Framework.",
655 "An library target with FRAMEWORK enabled will be built as a "
656 "framework on Mac OS X. "
657 "By default its Info.plist file is created by configuring a template "
658 "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
659 "This property specifies an alternative template file name which "
660 "may be a full path.\n"
661 "The following target properties may be set to specify content to "
662 "be configured into the file:\n"
663 " MACOSX_FRAMEWORK_ICON_FILE\n"
664 " MACOSX_FRAMEWORK_IDENTIFIER\n"
665 " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
666 " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
667 "CMake variables of the same name may be set to affect all targets "
668 "in a directory that do not have each specific property set. "
669 "If a custom Info.plist is specified by this property it may of course "
670 "hard-code all the settings instead of using the target properties.");
673 ("ENABLE_EXPORTS", cmProperty::TARGET
,
674 "Specify whether an executable exports symbols for loadable modules.",
675 "Normally an executable does not export any symbols because it is "
676 "the final program. It is possible for an executable to export "
677 "symbols to be used by loadable modules. When this property is "
678 "set to true CMake will allow other targets to \"link\" to the "
679 "executable with the TARGET_LINK_LIBRARIES command. "
680 "On all platforms a target-level dependency on the executable is "
681 "created for targets that link to it. "
682 "For non-DLL platforms the link rule is simply ignored since "
683 "the dynamic loader will automatically bind symbols when the "
685 "For DLL platforms an import library will be created for the "
686 "exported symbols and then used for linking. "
687 "All Windows-based systems including Cygwin are DLL platforms.");
690 ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET
,
691 "Specify output directory for Fortran modules provided by the target.",
692 "If the target contains Fortran source files that provide modules "
693 "and the compiler supports a module output directory this specifies "
694 "the directory in which the modules will be placed. "
695 "When this property is not set the modules will be placed in the "
696 "build directory corresponding to the target's source directory. "
697 "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
698 "is created its value is used to initialize this property.");
701 ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET
,
702 "Set Xcode target attributes directly.",
703 "Tell the Xcode generator to set '<an-attribute>' to a given value "
704 "in the generated Xcode project. Ignored on other generators.");
707 ("GENERATOR_FILE_NAME", cmProperty::TARGET
,
708 "Generator's file for this target.",
709 "An internal property used by some generators to record the name of "
710 "project or dsp file associated with this target.");
713 ("SOURCES", cmProperty::TARGET
,
714 "Source names specified for a target.",
715 "Read-only list of sources specified for a target. "
716 "The names returned are suitable for passing to the "
717 "set_source_files_properties command.");
720 ("PROJECT_LABEL", cmProperty::TARGET
,
721 "Change the name of a target in an IDE.",
722 "Can be used to change the name of the target in an IDE "
723 "like visual stuido. ");
725 ("VS_KEYWORD", cmProperty::TARGET
,
726 "Visual Studio project keyword.",
727 "Can be set to change the visual studio keyword, for example "
728 "QT integration works better if this is set to Qt4VSv1.0. ");
730 ("VS_SCC_PROVIDER", cmProperty::TARGET
,
731 "Visual Studio Source Code Control Provider.",
732 "Can be set to change the visual studio source code control "
733 "provider property.");
735 ("VS_SCC_LOCALPATH", cmProperty::TARGET
,
736 "Visual Studio Source Code Control Provider.",
737 "Can be set to change the visual studio source code control "
738 "local path property.");
740 ("VS_SCC_PROJECTNAME", cmProperty::TARGET
,
741 "Visual Studio Source Code Control Project.",
742 "Can be set to change the visual studio source code control "
743 "project name property.");
747 ("OBJECT_FILES", cmProperty::TARGET
,
748 "Used to get the resulting list of object files that make up a "
750 "This can be used to put object files from one library "
751 "into another library. It is a read only property. It "
752 "converts the source list for the target into a list of full "
753 "paths to object names that will be produced by the target.");
756 #define CM_TARGET_FILE_TYPES_DOC \
757 "There are three kinds of target files that may be built: " \
758 "archive, library, and runtime. " \
759 "Executables are always treated as runtime targets. " \
760 "Static libraries are always treated as archive targets. " \
761 "Module libraries are always treated as library targets. " \
762 "For non-DLL platforms shared libraries are treated as library " \
764 "For DLL platforms the DLL part of a shared library is treated as " \
765 "a runtime target and the corresponding import library is treated as " \
766 "an archive target. " \
767 "All Windows-based systems including Cygwin are DLL platforms."
770 ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET
,
771 "Output directory in which to build ARCHIVE target files.",
772 "This property specifies the directory into which archive target files "
774 CM_TARGET_FILE_TYPES_DOC
" "
775 "This property is initialized by the value of the variable "
776 "CMAKE_ARCHIVE_OUTPUT_DIRECTORY if it is set when a target is created.");
778 ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET
,
779 "Output directory in which to build LIBRARY target files.",
780 "This property specifies the directory into which library target files "
782 CM_TARGET_FILE_TYPES_DOC
" "
783 "This property is initialized by the value of the variable "
784 "CMAKE_LIBRARY_OUTPUT_DIRECTORY if it is set when a target is created.");
786 ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET
,
787 "Output directory in which to build RUNTIME target files.",
788 "This property specifies the directory into which runtime target files "
790 CM_TARGET_FILE_TYPES_DOC
" "
791 "This property is initialized by the value of the variable "
792 "CMAKE_RUNTIME_OUTPUT_DIRECTORY if it is set when a target is created.");
794 // define some properties without documentation
795 cm
->DefineProperty("DEBUG_OUTPUT_NAME", cmProperty::TARGET
,0,0);
796 cm
->DefineProperty("RELEASE_OUTPUT_NAME", cmProperty::TARGET
,0,0);
799 void cmTarget::SetType(TargetType type
, const char* name
)
802 if(type
== cmTarget::INSTALL_FILES
||
803 type
== cmTarget::INSTALL_PROGRAMS
||
804 type
== cmTarget::INSTALL_DIRECTORY
)
807 IssueMessage(cmake::INTERNAL_ERROR
,
808 "SetType called on cmTarget for INSTALL_FILES, "
809 "INSTALL_PROGRAMS, or INSTALL_DIRECTORY ");
812 // only add dependency information for library targets
813 this->TargetTypeValue
= type
;
814 if(this->TargetTypeValue
>= STATIC_LIBRARY
815 && this->TargetTypeValue
<= MODULE_LIBRARY
)
817 this->RecordDependencies
= true;
821 this->RecordDependencies
= false;
825 //----------------------------------------------------------------------------
826 void cmTarget::SetMakefile(cmMakefile
* mf
)
831 // set the cmake instance of the properties
832 this->Properties
.SetCMakeInstance(mf
->GetCMakeInstance());
834 // Check whether this is a DLL platform.
835 this->DLLPlatform
= (this->Makefile
->IsOn("WIN32") ||
836 this->Makefile
->IsOn("CYGWIN") ||
837 this->Makefile
->IsOn("MINGW"));
839 // Setup default property values.
840 this->SetPropertyDefault("INSTALL_NAME_DIR", "");
841 this->SetPropertyDefault("INSTALL_RPATH", "");
842 this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
843 this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
844 this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
845 this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
846 this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
847 this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
848 this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
850 // Collect the set of configuration types.
851 std::vector
<std::string
> configNames
;
852 if(const char* configurationTypes
=
853 mf
->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
855 cmSystemTools::ExpandListArgument(configurationTypes
, configNames
);
857 else if(const char* buildType
= mf
->GetDefinition("CMAKE_BUILD_TYPE"))
861 configNames
.push_back(buildType
);
865 // Setup per-configuration property default values.
866 for(std::vector
<std::string
>::iterator ci
= configNames
.begin();
867 ci
!= configNames
.end(); ++ci
)
869 // Initialize per-configuration name postfix property from the
870 // variable only for non-executable targets. This preserves
871 // compatibility with previous CMake versions in which executables
872 // did not support this variable. Projects may still specify the
873 // property directly. TODO: Make this depend on backwards
874 // compatibility setting.
875 if(this->TargetTypeValue
!= cmTarget::EXECUTABLE
)
877 std::string property
= cmSystemTools::UpperCase(*ci
);
878 property
+= "_POSTFIX";
879 this->SetPropertyDefault(property
.c_str(), 0);
883 // Save the backtrace of target construction.
884 this->Makefile
->GetBacktrace(this->Internal
->Backtrace
);
886 // Record current policies for later use.
887 this->PolicyStatusCMP0003
=
888 this->Makefile
->GetPolicyStatus(cmPolicies::CMP0003
);
889 this->PolicyStatusCMP0004
=
890 this->Makefile
->GetPolicyStatus(cmPolicies::CMP0004
);
891 this->PolicyStatusCMP0008
=
892 this->Makefile
->GetPolicyStatus(cmPolicies::CMP0008
);
895 //----------------------------------------------------------------------------
896 cmListFileBacktrace
const& cmTarget::GetBacktrace() const
898 return this->Internal
->Backtrace
;
901 //----------------------------------------------------------------------------
902 std::string
cmTarget::GetSupportDirectory() const
904 std::string dir
= this->Makefile
->GetCurrentOutputDirectory();
905 dir
+= cmake::GetCMakeFilesDirectory();
912 //----------------------------------------------------------------------------
913 bool cmTarget::IsExecutableWithExports()
915 return (this->GetType() == cmTarget::EXECUTABLE
&&
916 this->GetPropertyAsBool("ENABLE_EXPORTS"));
919 //----------------------------------------------------------------------------
920 bool cmTarget::IsLinkable()
922 return (this->GetType() == cmTarget::STATIC_LIBRARY
||
923 this->GetType() == cmTarget::SHARED_LIBRARY
||
924 this->GetType() == cmTarget::MODULE_LIBRARY
||
925 this->GetType() == cmTarget::UNKNOWN_LIBRARY
||
926 this->IsExecutableWithExports());
929 //----------------------------------------------------------------------------
930 bool cmTarget::IsFrameworkOnApple()
932 return (this->GetType() == cmTarget::SHARED_LIBRARY
&&
933 this->Makefile
->IsOn("APPLE") &&
934 this->GetPropertyAsBool("FRAMEWORK"));
937 //----------------------------------------------------------------------------
938 bool cmTarget::IsAppBundleOnApple()
940 return (this->GetType() == cmTarget::EXECUTABLE
&&
941 this->Makefile
->IsOn("APPLE") &&
942 this->GetPropertyAsBool("MACOSX_BUNDLE"));
945 //----------------------------------------------------------------------------
946 class cmTargetTraceDependencies
949 cmTargetTraceDependencies(cmTarget
* target
, const char* vsProjectFile
);
953 cmMakefile
* Makefile
;
954 cmGlobalGenerator
* GlobalGenerator
;
955 std::queue
<cmStdString
> DependencyQueue
;
956 std::set
<cmStdString
> DependenciesQueued
;
957 std::set
<cmSourceFile
*> TargetSources
;
959 void QueueOnce(std::string
const& name
);
960 void QueueOnce(std::vector
<std::string
> const& names
);
961 void QueueDependencies(cmSourceFile
* sf
);
962 bool IsUtility(std::string
const& dep
);
963 void CheckCustomCommand(cmCustomCommand
const& cc
);
964 void CheckCustomCommands(const std::vector
<cmCustomCommand
>& commands
);
967 //----------------------------------------------------------------------------
968 cmTargetTraceDependencies
969 ::cmTargetTraceDependencies(cmTarget
* target
, const char* vsProjectFile
):
973 this->Makefile
= this->Target
->GetMakefile();
974 this->GlobalGenerator
=
975 this->Makefile
->GetLocalGenerator()->GetGlobalGenerator();
977 // Queue all the source files already specified for the target.
978 std::vector
<cmSourceFile
*> const& sources
= this->Target
->GetSourceFiles();
979 for(std::vector
<cmSourceFile
*>::const_iterator si
= sources
.begin();
980 si
!= sources
.end(); ++si
)
982 // Queue the source file itself in case it is generated.
983 this->QueueOnce((*si
)->GetFullPath());
985 // Queue the dependencies of the source file in case they are
987 this->QueueDependencies(*si
);
989 // Track the sources already known to the target.
990 this->TargetSources
.insert(*si
);
993 // Queue the VS project file to check dependencies on the rule to
997 this->QueueOnce(vsProjectFile
);
1000 // Queue pre-build, pre-link, and post-build rule dependencies.
1001 this->CheckCustomCommands(this->Target
->GetPreBuildCommands());
1002 this->CheckCustomCommands(this->Target
->GetPreLinkCommands());
1003 this->CheckCustomCommands(this->Target
->GetPostBuildCommands());
1006 //----------------------------------------------------------------------------
1007 void cmTargetTraceDependencies::Trace()
1009 // Process one dependency at a time until the queue is empty.
1010 while(!this->DependencyQueue
.empty())
1012 // Get the next dependency in from queue.
1013 std::string dep
= this->DependencyQueue
.front();
1014 this->DependencyQueue
.pop();
1016 // Check if we know how to generate this dependency.
1017 if(cmSourceFile
* sf
=
1018 this->Makefile
->GetSourceFileWithOutput(dep
.c_str()))
1020 // Queue dependencies needed to generate this file.
1021 this->QueueDependencies(sf
);
1023 // Make sure this file is in the target.
1024 if(this->TargetSources
.insert(sf
).second
)
1026 this->Target
->AddSourceFile(sf
);
1032 //----------------------------------------------------------------------------
1033 void cmTargetTraceDependencies::QueueOnce(std::string
const& name
)
1035 if(this->DependenciesQueued
.insert(name
).second
)
1037 this->DependencyQueue
.push(name
);
1041 //----------------------------------------------------------------------------
1043 cmTargetTraceDependencies::QueueOnce(std::vector
<std::string
> const& names
)
1045 for(std::vector
<std::string
>::const_iterator i
= names
.begin();
1046 i
!= names
.end(); ++i
)
1048 this->QueueOnce(*i
);
1052 //----------------------------------------------------------------------------
1053 bool cmTargetTraceDependencies::IsUtility(std::string
const& dep
)
1055 // Dependencies on targets (utilities) are supposed to be named by
1056 // just the target name. However for compatibility we support
1057 // naming the output file generated by the target (assuming there is
1058 // no output-name property which old code would not have set). In
1059 // that case the target name will be the file basename of the
1061 std::string util
= cmSystemTools::GetFilenameName(dep
);
1062 if(cmSystemTools::GetFilenameLastExtension(util
) == ".exe")
1064 util
= cmSystemTools::GetFilenameWithoutLastExtension(util
);
1067 // Check for a non-imported target with this name.
1068 if(cmTarget
* t
= this->GlobalGenerator
->FindTarget(0, util
.c_str()))
1070 // If we find the target and the dep was given as a full path,
1071 // then make sure it was not a full path to something else, and
1072 // the fact that the name matched a target was just a coincidence.
1073 if(cmSystemTools::FileIsFullPath(dep
.c_str()))
1075 // This is really only for compatibility so we do not need to
1076 // worry about configuration names and output names.
1077 std::string tLocation
= t
->GetLocation(0);
1078 tLocation
= cmSystemTools::GetFilenamePath(tLocation
);
1079 std::string depLocation
= cmSystemTools::GetFilenamePath(dep
);
1080 depLocation
= cmSystemTools::CollapseFullPath(depLocation
.c_str());
1081 tLocation
= cmSystemTools::CollapseFullPath(tLocation
.c_str());
1082 if(depLocation
== tLocation
)
1084 this->Target
->AddUtility(util
.c_str());
1090 // The original name of the dependency was not a full path. It
1091 // must name a target, so add the target-level dependency.
1092 this->Target
->AddUtility(util
.c_str());
1097 // The dependency does not name a target built in this project.
1101 //----------------------------------------------------------------------------
1102 void cmTargetTraceDependencies::QueueDependencies(cmSourceFile
* sf
)
1104 // Queue dependency added explicitly by the user.
1105 if(const char* additionalDeps
= sf
->GetProperty("OBJECT_DEPENDS"))
1107 std::vector
<std::string
> objDeps
;
1108 cmSystemTools::ExpandListArgument(additionalDeps
, objDeps
);
1109 this->QueueOnce(objDeps
);
1112 // Queue dependencies added programatically by commands.
1113 this->QueueOnce(sf
->GetDepends());
1115 // Queue custom command dependencies.
1116 if(cmCustomCommand
const* cc
= sf
->GetCustomCommand())
1118 this->CheckCustomCommand(*cc
);
1123 //----------------------------------------------------------------------------
1125 cmTargetTraceDependencies
1126 ::CheckCustomCommand(cmCustomCommand
const& cc
)
1128 // Transform command names that reference targets built in this
1129 // project to corresponding target-level dependencies.
1130 for(cmCustomCommandLines::const_iterator cit
= cc
.GetCommandLines().begin();
1131 cit
!= cc
.GetCommandLines().end(); ++cit
)
1133 std::string
const& command
= *cit
->begin();
1134 // Look for a non-imported target with this name.
1135 if(cmTarget
* t
= this->GlobalGenerator
->FindTarget(0, command
.c_str()))
1137 if(t
->GetType() == cmTarget::EXECUTABLE
)
1139 // The command refers to an executable target built in
1140 // this project. Add the target-level dependency to make
1141 // sure the executable is up to date before this custom
1142 // command possibly runs.
1143 this->Target
->AddUtility(command
.c_str());
1148 // Queue the custom command dependencies.
1149 std::vector
<std::string
> const& depends
= cc
.GetDepends();
1150 for(std::vector
<std::string
>::const_iterator di
= depends
.begin();
1151 di
!= depends
.end(); ++di
)
1153 std::string
const& dep
= *di
;
1154 if(!this->IsUtility(dep
))
1156 // The dependency does not name a target and may be a file we
1157 // know how to generate. Queue it.
1158 this->QueueOnce(dep
);
1163 //----------------------------------------------------------------------------
1165 cmTargetTraceDependencies
1166 ::CheckCustomCommands(const std::vector
<cmCustomCommand
>& commands
)
1168 for(std::vector
<cmCustomCommand
>::const_iterator cli
= commands
.begin();
1169 cli
!= commands
.end(); ++cli
)
1171 this->CheckCustomCommand(*cli
);
1175 //----------------------------------------------------------------------------
1176 void cmTarget::TraceDependencies(const char* vsProjectFile
)
1178 // Use a helper object to trace the dependencies.
1179 cmTargetTraceDependencies
tracer(this, vsProjectFile
);
1183 //----------------------------------------------------------------------------
1184 bool cmTarget::FindSourceFiles()
1186 for(std::vector
<cmSourceFile
*>::const_iterator
1187 si
= this->SourceFiles
.begin();
1188 si
!= this->SourceFiles
.end(); ++si
)
1190 if((*si
)->GetFullPath().empty())
1198 //----------------------------------------------------------------------------
1199 void cmTarget::AddSources(std::vector
<std::string
> const& srcs
)
1201 for(std::vector
<std::string
>::const_iterator i
= srcs
.begin();
1202 i
!= srcs
.end(); ++i
)
1204 this->AddSource(i
->c_str());
1208 //----------------------------------------------------------------------------
1209 cmSourceFile
* cmTarget::AddSource(const char* s
)
1211 std::string src
= s
;
1213 // For backwards compatibility replace varibles in source names.
1214 // This should eventually be removed.
1215 this->Makefile
->ExpandVariablesInString(src
);
1217 cmSourceFile
* sf
= this->Makefile
->GetOrCreateSource(src
.c_str());
1218 this->AddSourceFile(sf
);
1222 //----------------------------------------------------------------------------
1223 struct cmTarget::SourceFileFlags
1224 cmTarget::GetTargetSourceFileFlags(const cmSourceFile
* sf
)
1226 struct SourceFileFlags flags
;
1227 this->ConstructSourceFileFlags();
1228 std::map
<cmSourceFile
const*, SourceFileFlags
>::iterator si
=
1229 this->Internal
->SourceFlagsMap
.find(sf
);
1230 if(si
!= this->Internal
->SourceFlagsMap
.end())
1237 //----------------------------------------------------------------------------
1238 void cmTarget::ConstructSourceFileFlags()
1240 if(this->Internal
->SourceFileFlagsConstructed
)
1244 this->Internal
->SourceFileFlagsConstructed
= true;
1246 // Process public headers to mark the source files.
1247 if(const char* files
= this->GetProperty("PUBLIC_HEADER"))
1249 std::vector
<std::string
> relFiles
;
1250 cmSystemTools::ExpandListArgument(files
, relFiles
);
1251 for(std::vector
<std::string
>::iterator it
= relFiles
.begin();
1252 it
!= relFiles
.end(); ++it
)
1254 if(cmSourceFile
* sf
= this->Makefile
->GetSource(it
->c_str()))
1256 SourceFileFlags
& flags
= this->Internal
->SourceFlagsMap
[sf
];
1257 flags
.MacFolder
= "Headers";
1258 flags
.Type
= cmTarget::SourceFileTypePublicHeader
;
1263 // Process private headers after public headers so that they take
1264 // precedence if a file is listed in both.
1265 if(const char* files
= this->GetProperty("PRIVATE_HEADER"))
1267 std::vector
<std::string
> relFiles
;
1268 cmSystemTools::ExpandListArgument(files
, relFiles
);
1269 for(std::vector
<std::string
>::iterator it
= relFiles
.begin();
1270 it
!= relFiles
.end(); ++it
)
1272 if(cmSourceFile
* sf
= this->Makefile
->GetSource(it
->c_str()))
1274 SourceFileFlags
& flags
= this->Internal
->SourceFlagsMap
[sf
];
1275 flags
.MacFolder
= "PrivateHeaders";
1276 flags
.Type
= cmTarget::SourceFileTypePrivateHeader
;
1281 // Mark sources listed as resources.
1282 if(const char* files
= this->GetProperty("RESOURCE"))
1284 std::vector
<std::string
> relFiles
;
1285 cmSystemTools::ExpandListArgument(files
, relFiles
);
1286 for(std::vector
<std::string
>::iterator it
= relFiles
.begin();
1287 it
!= relFiles
.end(); ++it
)
1289 if(cmSourceFile
* sf
= this->Makefile
->GetSource(it
->c_str()))
1291 SourceFileFlags
& flags
= this->Internal
->SourceFlagsMap
[sf
];
1292 flags
.MacFolder
= "Resources";
1293 flags
.Type
= cmTarget::SourceFileTypeResource
;
1298 // Handle the MACOSX_PACKAGE_LOCATION property on source files that
1299 // were not listed in one of the other lists.
1300 std::vector
<cmSourceFile
*> const& sources
= this->GetSourceFiles();
1301 for(std::vector
<cmSourceFile
*>::const_iterator si
= sources
.begin();
1302 si
!= sources
.end(); ++si
)
1304 cmSourceFile
* sf
= *si
;
1305 if(const char* location
= sf
->GetProperty("MACOSX_PACKAGE_LOCATION"))
1307 SourceFileFlags
& flags
= this->Internal
->SourceFlagsMap
[sf
];
1308 if(flags
.Type
== cmTarget::SourceFileTypeNormal
)
1310 flags
.MacFolder
= location
;
1311 if(strcmp(location
, "Resources") == 0)
1313 flags
.Type
= cmTarget::SourceFileTypeResource
;
1317 flags
.Type
= cmTarget::SourceFileTypeMacContent
;
1324 //----------------------------------------------------------------------------
1325 void cmTarget::MergeLinkLibraries( cmMakefile
& mf
,
1326 const char *selfname
,
1327 const LinkLibraryVectorType
& libs
)
1329 // Only add on libraries we haven't added on before.
1330 // Assumption: the global link libraries could only grow, never shrink
1331 LinkLibraryVectorType::const_iterator i
= libs
.begin();
1332 i
+= this->PrevLinkedLibraries
.size();
1333 for( ; i
!= libs
.end(); ++i
)
1335 // We call this so that the dependencies get written to the cache
1336 this->AddLinkLibrary( mf
, selfname
, i
->first
.c_str(), i
->second
);
1338 this->PrevLinkedLibraries
= libs
;
1341 //----------------------------------------------------------------------------
1342 void cmTarget::AddLinkDirectory(const char* d
)
1344 // Make sure we don't add unnecessary search directories.
1345 if(this->LinkDirectoriesEmmitted
.insert(d
).second
)
1347 this->LinkDirectories
.push_back(d
);
1351 //----------------------------------------------------------------------------
1352 const std::vector
<std::string
>& cmTarget::GetLinkDirectories()
1354 return this->LinkDirectories
;
1357 //----------------------------------------------------------------------------
1358 cmTarget::LinkLibraryType
cmTarget::ComputeLinkType(const char* config
)
1360 // No configuration is always optimized.
1361 if(!(config
&& *config
))
1363 return cmTarget::OPTIMIZED
;
1366 // Get the list of configurations considered to be DEBUG.
1367 std::vector
<std::string
> const& debugConfigs
=
1368 this->Makefile
->GetCMakeInstance()->GetDebugConfigs();
1370 // Check if any entry in the list matches this configuration.
1371 std::string configUpper
= cmSystemTools::UpperCase(config
);
1372 for(std::vector
<std::string
>::const_iterator i
= debugConfigs
.begin();
1373 i
!= debugConfigs
.end(); ++i
)
1375 if(*i
== configUpper
)
1377 return cmTarget::DEBUG
;
1381 // The current configuration is not a debug configuration.
1382 return cmTarget::OPTIMIZED
;
1385 //----------------------------------------------------------------------------
1386 void cmTarget::ClearDependencyInformation( cmMakefile
& mf
,
1387 const char* target
)
1389 // Clear the dependencies. The cache variable must exist iff we are
1390 // recording dependency information for this target.
1391 std::string depname
= target
;
1392 depname
+= "_LIB_DEPENDS";
1393 if (this->RecordDependencies
)
1395 mf
.AddCacheDefinition(depname
.c_str(), "",
1396 "Dependencies for target", cmCacheManager::STATIC
);
1400 if (mf
.GetDefinition( depname
.c_str() ))
1402 std::string message
= "Target ";
1404 message
+= " has dependency information when it shouldn't.\n";
1405 message
+= "Your cache is probably stale. Please remove the entry\n ";
1407 message
+= "\nfrom the cache.";
1408 cmSystemTools::Error( message
.c_str() );
1413 //----------------------------------------------------------------------------
1414 void cmTarget::AddLinkLibrary(const std::string
& lib
,
1415 LinkLibraryType llt
)
1417 this->AddFramework(lib
.c_str(), llt
);
1418 cmTarget::LibraryID tmp
;
1421 this->LinkLibraries
.push_back(tmp
);
1422 this->OriginalLinkLibraries
.push_back(tmp
);
1425 //----------------------------------------------------------------------------
1426 bool cmTarget::NameResolvesToFramework(const std::string
& libname
)
1428 return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
1429 NameResolvesToFramework(libname
);
1432 //----------------------------------------------------------------------------
1433 bool cmTarget::AddFramework(const std::string
& libname
, LinkLibraryType llt
)
1435 (void)llt
; // TODO: What is this?
1436 if(this->NameResolvesToFramework(libname
.c_str()))
1438 std::string frameworkDir
= libname
;
1439 frameworkDir
+= "/../";
1440 frameworkDir
= cmSystemTools::CollapseFullPath(frameworkDir
.c_str());
1441 std::vector
<std::string
>::iterator i
=
1442 std::find(this->Frameworks
.begin(),
1443 this->Frameworks
.end(), frameworkDir
);
1444 if(i
== this->Frameworks
.end())
1446 this->Frameworks
.push_back(frameworkDir
);
1453 //----------------------------------------------------------------------------
1454 void cmTarget::AddLinkLibrary(cmMakefile
& mf
,
1455 const char *target
, const char* lib
,
1456 LinkLibraryType llt
)
1458 // Never add a self dependency, even if the user asks for it.
1459 if(strcmp( target
, lib
) == 0)
1463 this->AddFramework(lib
, llt
);
1464 cmTarget::LibraryID tmp
;
1467 this->LinkLibraries
.push_back( tmp
);
1468 this->OriginalLinkLibraries
.push_back(tmp
);
1470 // Add the explicit dependency information for this target. This is
1471 // simply a set of libraries separated by ";". There should always
1472 // be a trailing ";". These library names are not canonical, in that
1473 // they may be "-framework x", "-ly", "/path/libz.a", etc.
1474 // We shouldn't remove duplicates here because external libraries
1475 // may be purposefully duplicated to handle recursive dependencies,
1476 // and we removing one instance will break the link line. Duplicates
1477 // will be appropriately eliminated at emit time.
1478 if(this->RecordDependencies
)
1480 std::string targetEntry
= target
;
1481 targetEntry
+= "_LIB_DEPENDS";
1482 std::string dependencies
;
1483 const char* old_val
= mf
.GetDefinition( targetEntry
.c_str() );
1486 dependencies
+= old_val
;
1490 case cmTarget::GENERAL
:
1491 dependencies
+= "general";
1493 case cmTarget::DEBUG
:
1494 dependencies
+= "debug";
1496 case cmTarget::OPTIMIZED
:
1497 dependencies
+= "optimized";
1500 dependencies
+= ";";
1501 dependencies
+= lib
;
1502 dependencies
+= ";";
1503 mf
.AddCacheDefinition( targetEntry
.c_str(), dependencies
.c_str(),
1504 "Dependencies for the target",
1505 cmCacheManager::STATIC
);
1510 //----------------------------------------------------------------------------
1512 cmTarget::AnalyzeLibDependencies( const cmMakefile
& mf
)
1514 // There are two key parts of the dependency analysis: (1)
1515 // determining the libraries in the link line, and (2) constructing
1516 // the dependency graph for those libraries.
1518 // The latter is done using the cache entries that record the
1519 // dependencies of each library.
1521 // The former is a more thorny issue, since it is not clear how to
1522 // determine if two libraries listed on the link line refer to the a
1523 // single library or not. For example, consider the link "libraries"
1524 // /usr/lib/libtiff.so -ltiff
1525 // Is this one library or two? The solution implemented here is the
1526 // simplest (and probably the only practical) one: two libraries are
1527 // the same if their "link strings" are identical. Thus, the two
1528 // libraries above are considered distinct. This also means that for
1529 // dependency analysis to be effective, the CMake user must specify
1530 // libraries build by his project without using any linker flags or
1531 // file extensions. That is,
1532 // LINK_LIBRARIES( One Two )
1534 // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
1535 // The former is probably what most users would do, but it never
1536 // hurts to document the assumptions. :-) Therefore, in the analysis
1537 // code, the "canonical name" of a library is simply its name as
1538 // given to a LINK_LIBRARIES command.
1540 // Also, we will leave the original link line intact; we will just add any
1541 // dependencies that were missing.
1543 // There is a problem with recursive external libraries
1544 // (i.e. libraries with no dependency information that are
1545 // recursively dependent). We must make sure that the we emit one of
1546 // the libraries twice to satisfy the recursion, but we shouldn't
1547 // emit it more times than necessary. In particular, we must make
1548 // sure that handling this improbable case doesn't cost us when
1549 // dealing with the common case of non-recursive libraries. The
1550 // solution is to assume that the recursion is satisfied at one node
1551 // of the dependency tree. To illustrate, assume libA and libB are
1552 // extrenal and mutually dependent. Suppose libX depends on
1553 // libA, and libY on libA and libX. Then
1554 // TARGET_LINK_LIBRARIES( Y X A B A )
1555 // TARGET_LINK_LIBRARIES( X A B A )
1556 // TARGET_LINK_LIBRARIES( Exec Y )
1557 // would result in "-lY -lX -lA -lB -lA". This is the correct way to
1558 // specify the dependencies, since the mutual dependency of A and B
1559 // is resolved *every time libA is specified*.
1562 // TARGET_LINK_LIBRARIES( Y X A B A )
1563 // TARGET_LINK_LIBRARIES( X A B )
1564 // TARGET_LINK_LIBRARIES( Exec Y )
1565 // would result in "-lY -lX -lA -lB", and the mutual dependency
1566 // information is lost. This is because in some case (Y), the mutual
1567 // dependency of A and B is listed, while in another other case (X),
1568 // it is not. Depending on which line actually emits A, the mutual
1569 // dependency may or may not be on the final link line. We can't
1570 // handle this pathalogical case cleanly without emitting extra
1571 // libraries for the normal cases. Besides, the dependency
1572 // information for X is wrong anyway: if we build an executable
1573 // depending on X alone, we would not have the mutual dependency on
1574 // A and B resolved.
1577 // -- The current algorithm will not always pick the "optimal" link line
1578 // when recursive dependencies are present. It will instead break the
1579 // cycles at an aribtrary point. The majority of projects won't have
1580 // cyclic dependencies, so this is probably not a big deal. Note that
1581 // the link line is always correct, just not necessary optimal.
1584 // Expand variables in link library names. This is for backwards
1585 // compatibility with very early CMake versions and should
1586 // eventually be removed. This code was moved here from the end of
1587 // old source list processing code which was called just before this
1589 for(LinkLibraryVectorType::iterator p
= this->LinkLibraries
.begin();
1590 p
!= this->LinkLibraries
.end(); ++p
)
1592 this->Makefile
->ExpandVariablesInString(p
->first
, true, true);
1596 typedef std::vector
< std::string
> LinkLine
;
1598 // The dependency map.
1599 DependencyMap dep_map
;
1601 // 1. Build the dependency graph
1603 for(LinkLibraryVectorType::reverse_iterator lib
1604 = this->LinkLibraries
.rbegin();
1605 lib
!= this->LinkLibraries
.rend(); ++lib
)
1607 this->GatherDependencies( mf
, *lib
, dep_map
);
1610 // 2. Remove any dependencies that are already satisfied in the original
1613 for(LinkLibraryVectorType::iterator lib
= this->LinkLibraries
.begin();
1614 lib
!= this->LinkLibraries
.end(); ++lib
)
1616 for( LinkLibraryVectorType::iterator lib2
= lib
;
1617 lib2
!= this->LinkLibraries
.end(); ++lib2
)
1619 this->DeleteDependency( dep_map
, *lib
, *lib2
);
1624 // 3. Create the new link line by simply emitting any dependencies that are
1625 // missing. Start from the back and keep adding.
1627 std::set
<DependencyMap::key_type
> done
, visited
;
1628 std::vector
<DependencyMap::key_type
> newLinkLibraries
;
1629 for(LinkLibraryVectorType::reverse_iterator lib
=
1630 this->LinkLibraries
.rbegin();
1631 lib
!= this->LinkLibraries
.rend(); ++lib
)
1633 // skip zero size library entries, this may happen
1634 // if a variable expands to nothing.
1635 if (lib
->first
.size() != 0)
1637 this->Emit( *lib
, dep_map
, done
, visited
, newLinkLibraries
);
1641 // 4. Add the new libraries to the link line.
1643 for( std::vector
<DependencyMap::key_type
>::reverse_iterator k
=
1644 newLinkLibraries
.rbegin();
1645 k
!= newLinkLibraries
.rend(); ++k
)
1647 // get the llt from the dep_map
1648 this->LinkLibraries
.push_back( std::make_pair(k
->first
,k
->second
) );
1650 this->LinkLibrariesAnalyzed
= true;
1653 //----------------------------------------------------------------------------
1654 void cmTarget::InsertDependency( DependencyMap
& depMap
,
1655 const LibraryID
& lib
,
1656 const LibraryID
& dep
)
1658 depMap
[lib
].push_back(dep
);
1661 //----------------------------------------------------------------------------
1662 void cmTarget::DeleteDependency( DependencyMap
& depMap
,
1663 const LibraryID
& lib
,
1664 const LibraryID
& dep
)
1666 // Make sure there is an entry in the map for lib. If so, delete all
1667 // dependencies to dep. There may be repeated entries because of
1668 // external libraries that are specified multiple times.
1669 DependencyMap::iterator map_itr
= depMap
.find( lib
);
1670 if( map_itr
!= depMap
.end() )
1672 DependencyList
& depList
= map_itr
->second
;
1673 DependencyList::iterator itr
;
1674 while( (itr
= std::find(depList
.begin(), depList
.end(), dep
)) !=
1677 depList
.erase( itr
);
1682 //----------------------------------------------------------------------------
1683 void cmTarget::Emit(const LibraryID lib
,
1684 const DependencyMap
& dep_map
,
1685 std::set
<LibraryID
>& emitted
,
1686 std::set
<LibraryID
>& visited
,
1687 DependencyList
& link_line
)
1689 // It's already been emitted
1690 if( emitted
.find(lib
) != emitted
.end() )
1695 // Emit the dependencies only if this library node hasn't been
1696 // visited before. If it has, then we have a cycle. The recursion
1697 // that got us here should take care of everything.
1699 if( visited
.insert(lib
).second
)
1701 if( dep_map
.find(lib
) != dep_map
.end() ) // does it have dependencies?
1703 const DependencyList
& dep_on
= dep_map
.find( lib
)->second
;
1704 DependencyList::const_reverse_iterator i
;
1706 // To cater for recursive external libraries, we must emit
1707 // duplicates on this link line *unless* they were emitted by
1708 // some other node, in which case we assume that the recursion
1709 // was resolved then. We making the simplifying assumption that
1710 // any duplicates on a single link line are on purpose, and must
1713 // This variable will keep track of the libraries that were
1714 // emitted directory from the current node, and not from a
1715 // recursive call. This way, if we come across a library that
1716 // has already been emitted, we repeat it iff it has been
1718 std::set
<DependencyMap::key_type
> emitted_here
;
1719 for( i
= dep_on
.rbegin(); i
!= dep_on
.rend(); ++i
)
1721 if( emitted_here
.find(*i
) != emitted_here
.end() )
1723 // a repeat. Must emit.
1725 link_line
.push_back( *i
);
1729 // Emit only if no-one else has
1730 if( emitted
.find(*i
) == emitted
.end() )
1732 // emit dependencies
1733 Emit( *i
, dep_map
, emitted
, visited
, link_line
);
1736 emitted_here
.insert(*i
);
1737 link_line
.push_back( *i
);
1745 //----------------------------------------------------------------------------
1746 void cmTarget::GatherDependencies( const cmMakefile
& mf
,
1747 const LibraryID
& lib
,
1748 DependencyMap
& dep_map
)
1750 // If the library is already in the dependency map, then it has
1751 // already been fully processed.
1752 if( dep_map
.find(lib
) != dep_map
.end() )
1757 const char* deps
= mf
.GetDefinition( (lib
.first
+"_LIB_DEPENDS").c_str() );
1758 if( deps
&& strcmp(deps
,"") != 0 )
1760 // Make sure this library is in the map, even if it has an empty
1761 // set of dependencies. This distinguishes the case of explicitly
1762 // no dependencies with that of unspecified dependencies.
1765 // Parse the dependency information, which is a set of
1766 // type, library pairs separated by ";". There is always a trailing ";".
1767 cmTarget::LinkLibraryType llt
= cmTarget::GENERAL
;
1768 std::string depline
= deps
;
1769 std::string::size_type start
= 0;
1770 std::string::size_type end
;
1771 end
= depline
.find( ";", start
);
1772 while( end
!= std::string::npos
)
1774 std::string l
= depline
.substr( start
, end
-start
);
1779 llt
= cmTarget::DEBUG
;
1781 else if (l
== "optimized")
1783 llt
= cmTarget::OPTIMIZED
;
1785 else if (l
== "general")
1787 llt
= cmTarget::GENERAL
;
1791 LibraryID
lib2(l
,llt
);
1792 this->InsertDependency( dep_map
, lib
, lib2
);
1793 this->GatherDependencies( mf
, lib2
, dep_map
);
1794 llt
= cmTarget::GENERAL
;
1797 start
= end
+1; // skip the ;
1798 end
= depline
.find( ";", start
);
1800 // cannot depend on itself
1801 this->DeleteDependency( dep_map
, lib
, lib
);
1805 //----------------------------------------------------------------------------
1806 void cmTarget::SetProperty(const char* prop
, const char* value
)
1813 this->Properties
.SetProperty(prop
, value
, cmProperty::TARGET
);
1815 // If imported information is being set, wipe out cached
1817 if(this->IsImported() && strncmp(prop
, "IMPORTED", 8) == 0)
1819 this->ImportInfoMap
.clear();
1823 //----------------------------------------------------------------------------
1824 void cmTarget::AppendProperty(const char* prop
, const char* value
)
1830 this->Properties
.AppendProperty(prop
, value
, cmProperty::TARGET
);
1832 // If imported information is being set, wipe out cached
1834 if(this->IsImported() && strncmp(prop
, "IMPORTED", 8) == 0)
1836 this->ImportInfoMap
.clear();
1840 //----------------------------------------------------------------------------
1841 static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
1842 const char* prop
, const char* value
, cmMakefile
* context
, bool imported
1845 // Look for link-type keywords in the value.
1846 static cmsys::RegularExpression
1847 keys("(^|;)(debug|optimized|general)(;|$)");
1848 if(!keys
.find(value
))
1853 // Support imported and non-imported versions of the property.
1854 const char* base
= (imported
?
1855 "IMPORTED_LINK_INTERFACE_LIBRARIES" :
1856 "LINK_INTERFACE_LIBRARIES");
1860 e
<< "Property " << prop
<< " may not contain link-type keyword \""
1861 << keys
.match(2) << "\". "
1862 << "The " << base
<< " property has a per-configuration "
1863 << "version called " << base
<< "_<CONFIG> which may be "
1864 << "used to specify per-configuration rules.";
1868 << "Alternatively, an IMPORTED library may be created, configured "
1869 << "with a per-configuration location, and then named in the "
1870 << "property value. "
1871 << "See the add_library command's IMPORTED mode for details."
1873 << "If you have a list of libraries that already contains the "
1874 << "keyword, use the target_link_libraries command with its "
1875 << "LINK_INTERFACE_LIBRARIES mode to set the property. "
1876 << "The command automatically recognizes link-type keywords and sets "
1877 << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
1878 << "properties accordingly.";
1880 context
->IssueMessage(cmake::FATAL_ERROR
, e
.str());
1883 //----------------------------------------------------------------------------
1884 void cmTarget::CheckProperty(const char* prop
, cmMakefile
* context
)
1886 // Certain properties need checking.
1887 if(strncmp(prop
, "LINK_INTERFACE_LIBRARIES", 24) == 0)
1889 if(const char* value
= this->GetProperty(prop
))
1891 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop
, value
, context
, false);
1894 if(strncmp(prop
, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
1896 if(const char* value
= this->GetProperty(prop
))
1898 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop
, value
, context
, true);
1903 //----------------------------------------------------------------------------
1904 void cmTarget::MarkAsImported()
1906 this->IsImportedTarget
= true;
1909 //----------------------------------------------------------------------------
1910 std::string
cmTarget::GetDirectory(const char* config
, bool implib
)
1912 if (this->IsImported())
1914 // Return the directory from which the target is imported.
1916 cmSystemTools::GetFilenamePath(
1917 this->ImportedGetFullPath(config
, implib
));
1921 // Return the directory in which the target will be built.
1922 if(config
&& *config
)
1924 // Add the configuration's subdirectory.
1925 std::string dir
= this->GetOutputDir(implib
);
1926 this->Makefile
->GetLocalGenerator()->GetGlobalGenerator()->
1927 AppendDirectoryForConfig("/", config
, "", dir
);
1932 return this->GetOutputDir(implib
);
1937 //----------------------------------------------------------------------------
1938 const char* cmTarget::GetLocation(const char* config
)
1940 if (this->IsImported())
1942 return this->ImportedGetLocation(config
);
1946 return this->NormalGetLocation(config
);
1950 //----------------------------------------------------------------------------
1951 const char* cmTarget::ImportedGetLocation(const char* config
)
1953 this->Location
= this->ImportedGetFullPath(config
, false);
1954 return this->Location
.c_str();
1957 //----------------------------------------------------------------------------
1958 const char* cmTarget::NormalGetLocation(const char* config
)
1960 // Handle the configuration-specific case first.
1963 this->Location
= this->GetFullPath(config
, false);
1964 return this->Location
.c_str();
1967 // Now handle the deprecated build-time configuration location.
1968 this->Location
= this->GetDirectory();
1969 if(!this->Location
.empty())
1971 this->Location
+= "/";
1973 const char* cfgid
= this->Makefile
->GetDefinition("CMAKE_CFG_INTDIR");
1974 if(cfgid
&& strcmp(cfgid
, ".") != 0)
1976 this->Location
+= cfgid
;
1977 this->Location
+= "/";
1979 if(this->IsAppBundleOnApple())
1981 this->Location
+= this->GetFullName(config
, false);
1982 this->Location
+= ".app/Contents/MacOS/";
1984 if(this->IsFrameworkOnApple())
1986 this->Location
+= this->GetFullName(config
, false);
1987 this->Location
+= ".framework/Versions/";
1988 this->Location
+= this->GetFrameworkVersion();
1989 this->Location
+= "/";
1991 this->Location
+= this->GetFullName(config
, false);
1992 return this->Location
.c_str();
1995 //----------------------------------------------------------------------------
1996 void cmTarget::GetTargetVersion(int& major
, int& minor
)
1999 this->GetTargetVersion(false, major
, minor
, patch
);
2002 //----------------------------------------------------------------------------
2003 void cmTarget::GetTargetVersion(bool soversion
,
2004 int& major
, int& minor
, int& patch
)
2006 // Set the default values.
2011 // Look for a VERSION or SOVERSION property.
2012 const char* prop
= soversion
? "SOVERSION" : "VERSION";
2013 if(const char* version
= this->GetProperty(prop
))
2015 // Try to parse the version number and store the results that were
2016 // successfully parsed.
2020 switch(sscanf(version
, "%d.%d.%d",
2021 &parsed_major
, &parsed_minor
, &parsed_patch
))
2023 case 3: patch
= parsed_patch
; // no break!
2024 case 2: minor
= parsed_minor
; // no break!
2025 case 1: major
= parsed_major
; // no break!
2031 //----------------------------------------------------------------------------
2032 const char *cmTarget::GetProperty(const char* prop
)
2034 return this->GetProperty(prop
, cmProperty::TARGET
);
2037 //----------------------------------------------------------------------------
2038 void cmTarget::ComputeObjectFiles()
2040 if (this->IsImported())
2045 std::vector
<std::string
> dirs
;
2046 this->Makefile
->GetLocalGenerator()->
2047 GetTargetObjectFileDirectories(this,
2049 std::string objectFiles
;
2050 std::string objExtensionLookup1
= "CMAKE_";
2051 std::string objExtensionLookup2
= "_OUTPUT_EXTENSION";
2053 for(std::vector
<std::string
>::iterator d
= dirs
.begin();
2054 d
!= dirs
.end(); ++d
)
2056 for(std::vector
<cmSourceFile
*>::iterator s
= this->SourceFiles
.begin();
2057 s
!= this->SourceFiles
.end(); ++s
)
2059 cmSourceFile
* sf
= *s
;
2060 if(const char* lang
= sf
->GetLanguage())
2062 std::string lookupObj
= objExtensionLookup1
+ lang
;
2063 lookupObj
+= objExtensionLookup2
;
2064 const char* obj
= this->Makefile
->GetDefinition(lookupObj
.c_str());
2067 if(objectFiles
.size())
2071 std::string objFile
= *d
;
2073 objFile
+= this->Makefile
->GetLocalGenerator()->
2074 GetSourceObjectName(*sf
);
2076 objectFiles
+= objFile
;
2081 this->SetProperty("OBJECT_FILES", objectFiles
.c_str());
2085 //----------------------------------------------------------------------------
2086 const char *cmTarget::GetProperty(const char* prop
,
2087 cmProperty::ScopeType scope
)
2094 // Watch for special "computed" properties that are dependent on
2095 // other properties or variables. Always recompute them.
2096 if(this->GetType() == cmTarget::EXECUTABLE
||
2097 this->GetType() == cmTarget::STATIC_LIBRARY
||
2098 this->GetType() == cmTarget::SHARED_LIBRARY
||
2099 this->GetType() == cmTarget::MODULE_LIBRARY
||
2100 this->GetType() == cmTarget::UNKNOWN_LIBRARY
)
2102 if(strcmp(prop
,"LOCATION") == 0)
2104 // Set the LOCATION property of the target.
2106 // For an imported target this is the location of an arbitrary
2107 // available configuration.
2109 // For a non-imported target this is deprecated because it
2110 // cannot take into account the per-configuration name of the
2111 // target because the configuration type may not be known at
2113 this->SetProperty("LOCATION", this->GetLocation(0));
2116 // Support "LOCATION_<CONFIG>".
2117 if(strncmp(prop
, "LOCATION_", 9) == 0)
2119 std::string configName
= prop
+9;
2120 this->SetProperty(prop
, this->GetLocation(configName
.c_str()));
2124 // Support "<CONFIG>_LOCATION" for compatiblity.
2125 int len
= static_cast<int>(strlen(prop
));
2126 if(len
> 9 && strcmp(prop
+len
-9, "_LOCATION") == 0)
2128 std::string
configName(prop
, len
-9);
2129 if(configName
!= "IMPORTED")
2131 this->SetProperty(prop
, this->GetLocation(configName
.c_str()));
2137 if (strcmp(prop
,"IMPORTED") == 0)
2139 return this->IsImported()?"TRUE":"FALSE";
2142 if(!strcmp(prop
,"SOURCES"))
2145 const char* sep
= "";
2146 for(std::vector
<cmSourceFile
*>::const_iterator
2147 i
= this->SourceFiles
.begin();
2148 i
!= this->SourceFiles
.end(); ++i
)
2150 // Separate from the previous list entries.
2154 // Construct what is known about this source file location.
2155 cmSourceFileLocation
const& location
= (*i
)->GetLocation();
2156 std::string sname
= location
.GetDirectory();
2161 sname
+= location
.GetName();
2163 // Append this list entry.
2166 this->SetProperty("SOURCES", ss
.str().c_str());
2169 // the type property returns what type the target is
2170 if (!strcmp(prop
,"TYPE"))
2172 switch( this->GetType() )
2174 case cmTarget::STATIC_LIBRARY
:
2175 return "STATIC_LIBRARY";
2176 // break; /* unreachable */
2177 case cmTarget::MODULE_LIBRARY
:
2178 return "MODULE_LIBRARY";
2179 // break; /* unreachable */
2180 case cmTarget::SHARED_LIBRARY
:
2181 return "SHARED_LIBRARY";
2182 // break; /* unreachable */
2183 case cmTarget::EXECUTABLE
:
2184 return "EXECUTABLE";
2185 // break; /* unreachable */
2186 case cmTarget::UTILITY
:
2188 // break; /* unreachable */
2189 case cmTarget::GLOBAL_TARGET
:
2190 return "GLOBAL_TARGET";
2191 // break; /* unreachable */
2192 case cmTarget::INSTALL_FILES
:
2193 return "INSTALL_FILES";
2194 // break; /* unreachable */
2195 case cmTarget::INSTALL_PROGRAMS
:
2196 return "INSTALL_PROGRAMS";
2197 // break; /* unreachable */
2198 case cmTarget::INSTALL_DIRECTORY
:
2199 return "INSTALL_DIRECTORY";
2200 // break; /* unreachable */
2201 case cmTarget::UNKNOWN_LIBRARY
:
2202 return "UNKNOWN_LIBRARY";
2203 // break; /* unreachable */
2208 const char *retVal
=
2209 this->Properties
.GetPropertyValue(prop
, scope
, chain
);
2212 return this->Makefile
->GetProperty(prop
,scope
);
2217 //----------------------------------------------------------------------------
2218 bool cmTarget::GetPropertyAsBool(const char* prop
)
2220 return cmSystemTools::IsOn(this->GetProperty(prop
));
2223 //----------------------------------------------------------------------------
2224 const char* cmTarget::GetLinkerLanguage(cmGlobalGenerator
* gg
)
2226 if(this->GetProperty("HAS_CXX"))
2228 const_cast<cmTarget
*>(this)->SetProperty("LINKER_LANGUAGE", "CXX");
2230 const char* linkerLang
= this->GetProperty("LINKER_LANGUAGE");
2233 // if the property has not yet been set, collect all languages in the
2234 // target and then find the language with the highest preference value
2235 std::set
<cmStdString
> languages
;
2236 this->GetLanguages(languages
);
2238 std::string linkerLangList
; // only used for the error message
2239 int maxLinkerPref
= 0;
2240 bool multiplePreferedLanguages
= false;
2241 for(std::set
<cmStdString
>::const_iterator sit
= languages
.begin();
2242 sit
!= languages
.end(); ++sit
)
2244 int linkerPref
= gg
->GetLinkerPreference(sit
->c_str());
2245 if ((linkerPref
> maxLinkerPref
) || (linkerLang
==0))
2247 maxLinkerPref
= linkerPref
;
2248 linkerLang
= sit
->c_str();
2249 linkerLangList
= *sit
;
2250 multiplePreferedLanguages
= false;
2252 else if (linkerPref
== maxLinkerPref
)
2254 linkerLangList
+= "; ";
2255 linkerLangList
+= *sit
;
2256 multiplePreferedLanguages
= true;
2262 const_cast<cmTarget
*>(this)->SetProperty("LINKER_LANGUAGE", linkerLang
);
2264 if (multiplePreferedLanguages
)
2266 cmOStringStream err
;
2267 err
<< "Error: Target " << this->Name
<< " contains multiple languages "
2268 << "with the highest linker preference (" << maxLinkerPref
<< "): "
2269 << linkerLangList
<< "\n"
2270 << "You must set the LINKER_LANGUAGE property for this target.";
2271 cmSystemTools::Error(err
.str().c_str());
2274 return this->GetProperty("LINKER_LANGUAGE");
2277 //----------------------------------------------------------------------------
2278 const char* cmTarget::GetCreateRuleVariable()
2280 switch(this->GetType())
2282 case cmTarget::STATIC_LIBRARY
:
2283 return "_CREATE_STATIC_LIBRARY";
2284 case cmTarget::SHARED_LIBRARY
:
2285 return "_CREATE_SHARED_LIBRARY";
2286 case cmTarget::MODULE_LIBRARY
:
2287 return "_CREATE_SHARED_MODULE";
2288 case cmTarget::EXECUTABLE
:
2289 return "_LINK_EXECUTABLE";
2296 //----------------------------------------------------------------------------
2297 const char* cmTarget::GetSuffixVariableInternal(TargetType type
,
2302 case cmTarget::STATIC_LIBRARY
:
2303 return "CMAKE_STATIC_LIBRARY_SUFFIX";
2304 case cmTarget::SHARED_LIBRARY
:
2306 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2307 : "CMAKE_SHARED_LIBRARY_SUFFIX");
2308 case cmTarget::MODULE_LIBRARY
:
2310 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2311 : "CMAKE_SHARED_MODULE_SUFFIX");
2312 case cmTarget::EXECUTABLE
:
2314 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2315 : "CMAKE_EXECUTABLE_SUFFIX");
2323 //----------------------------------------------------------------------------
2324 const char* cmTarget::GetPrefixVariableInternal(TargetType type
,
2329 case cmTarget::STATIC_LIBRARY
:
2330 return "CMAKE_STATIC_LIBRARY_PREFIX";
2331 case cmTarget::SHARED_LIBRARY
:
2333 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2334 : "CMAKE_SHARED_LIBRARY_PREFIX");
2335 case cmTarget::MODULE_LIBRARY
:
2337 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2338 : "CMAKE_SHARED_MODULE_PREFIX");
2339 case cmTarget::EXECUTABLE
:
2340 return (implib
? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
2347 //----------------------------------------------------------------------------
2348 std::string
cmTarget::GetPDBName(const char* config
)
2353 this->GetFullNameInternal(this->GetType(), config
, false,
2354 prefix
, base
, suffix
);
2355 return prefix
+base
+".pdb";
2358 //----------------------------------------------------------------------------
2359 std::string
cmTarget::GetSOName(const char* config
)
2361 if(this->IsImported())
2363 // Lookup the imported soname.
2364 if(cmTarget::ImportInfo
const* info
= this->GetImportInfo(config
))
2368 // The imported library has no builtin soname so the name
2369 // searched at runtime will be just the filename.
2370 return cmSystemTools::GetFilenameName(info
->Location
);
2374 // Use the soname given if any.
2375 return info
->SOName
;
2385 // Compute the soname that will be built.
2388 std::string realName
;
2389 std::string impName
;
2390 std::string pdbName
;
2391 this->GetLibraryNames(name
, soName
, realName
, impName
, pdbName
, config
);
2396 //----------------------------------------------------------------------------
2397 bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config
)
2399 if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY
)
2401 if(cmTarget::ImportInfo
const* info
= this->GetImportInfo(config
))
2403 return info
->NoSOName
;
2409 //----------------------------------------------------------------------------
2410 std::string
cmTarget::NormalGetRealName(const char* config
)
2412 // This should not be called for imported targets.
2413 // TODO: Split cmTarget into a class hierarchy to get compile-time
2414 // enforcement of the limited imported target API.
2415 if(this->IsImported())
2417 std::string msg
= "NormalGetRealName called on imported target: ";
2418 msg
+= this->GetName();
2419 this->GetMakefile()->
2420 IssueMessage(cmake::INTERNAL_ERROR
,
2424 if(this->GetType() == cmTarget::EXECUTABLE
)
2426 // Compute the real name that will be built.
2428 std::string realName
;
2429 std::string impName
;
2430 std::string pdbName
;
2431 this->GetExecutableNames(name
, realName
, impName
, pdbName
, config
);
2436 // Compute the real name that will be built.
2439 std::string realName
;
2440 std::string impName
;
2441 std::string pdbName
;
2442 this->GetLibraryNames(name
, soName
, realName
, impName
, pdbName
, config
);
2447 //----------------------------------------------------------------------------
2448 std::string
cmTarget::GetFullName(const char* config
, bool implib
)
2450 if(this->IsImported())
2452 return this->GetFullNameImported(config
, implib
);
2456 return this->GetFullNameInternal(this->GetType(), config
, implib
);
2460 //----------------------------------------------------------------------------
2461 std::string
cmTarget::GetFullNameImported(const char* config
, bool implib
)
2463 return cmSystemTools::GetFilenameName(
2464 this->ImportedGetFullPath(config
, implib
));
2467 //----------------------------------------------------------------------------
2468 void cmTarget::GetFullNameComponents(std::string
& prefix
, std::string
& base
,
2469 std::string
& suffix
, const char* config
,
2472 this->GetFullNameInternal(this->GetType(), config
, implib
,
2473 prefix
, base
, suffix
);
2476 //----------------------------------------------------------------------------
2477 std::string
cmTarget::GetFullPath(const char* config
, bool implib
,
2480 if(this->IsImported())
2482 return this->ImportedGetFullPath(config
, implib
);
2486 return this->NormalGetFullPath(config
, implib
, realname
);
2490 //----------------------------------------------------------------------------
2491 std::string
cmTarget::NormalGetFullPath(const char* config
, bool implib
,
2494 // Start with the output directory for the target.
2495 std::string fpath
= this->GetDirectory(config
, implib
);
2498 if(this->IsAppBundleOnApple())
2500 fpath
+= this->GetFullName(config
, false);
2501 fpath
+= ".app/Contents/MacOS/";
2503 if(this->IsFrameworkOnApple())
2505 fpath
+= this->GetFullName(config
, false);
2506 fpath
+= ".framework/Versions/";
2507 fpath
+= this->GetFrameworkVersion();
2511 // Add the full name of the target.
2514 fpath
+= this->GetFullName(config
, true);
2518 fpath
+= this->NormalGetRealName(config
);
2522 fpath
+= this->GetFullName(config
, false);
2527 //----------------------------------------------------------------------------
2528 std::string
cmTarget::ImportedGetFullPath(const char* config
, bool implib
)
2530 if(cmTarget::ImportInfo
const* info
= this->GetImportInfo(config
))
2534 return info
->ImportLibrary
;
2538 return info
->Location
;
2543 std::string result
= this->GetName();
2544 result
+= "-NOTFOUND";
2549 //----------------------------------------------------------------------------
2551 cmTarget::GetFullNameInternal(TargetType type
, const char* config
,
2557 this->GetFullNameInternal(type
, config
, implib
, prefix
, base
, suffix
);
2558 return prefix
+base
+suffix
;
2561 //----------------------------------------------------------------------------
2562 void cmTarget::GetFullNameInternal(TargetType type
,
2565 std::string
& outPrefix
,
2566 std::string
& outBase
,
2567 std::string
& outSuffix
)
2569 // Use just the target name for non-main target types.
2570 if(type
!= cmTarget::STATIC_LIBRARY
&&
2571 type
!= cmTarget::SHARED_LIBRARY
&&
2572 type
!= cmTarget::MODULE_LIBRARY
&&
2573 type
!= cmTarget::EXECUTABLE
)
2576 outBase
= this->GetName();
2581 // Return an empty name for the import library if this platform
2582 // does not support import libraries.
2584 !this->Makefile
->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
2592 // The implib option is only allowed for shared libraries, module
2593 // libraries, and executables.
2594 if(type
!= cmTarget::SHARED_LIBRARY
&&
2595 type
!= cmTarget::MODULE_LIBRARY
&&
2596 type
!= cmTarget::EXECUTABLE
)
2601 // Compute the full name for main target types.
2602 const char* targetPrefix
= (implib
2603 ? this->GetProperty("IMPORT_PREFIX")
2604 : this->GetProperty("PREFIX"));
2605 const char* targetSuffix
= (implib
2606 ? this->GetProperty("IMPORT_SUFFIX")
2607 : this->GetProperty("SUFFIX"));
2608 const char* configPostfix
= 0;
2609 if(config
&& *config
)
2611 std::string configProp
= cmSystemTools::UpperCase(config
);
2612 configProp
+= "_POSTFIX";
2613 configPostfix
= this->GetProperty(configProp
.c_str());
2614 // Mac application bundles and frameworks have no postfix.
2616 (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
2621 const char* prefixVar
= this->GetPrefixVariableInternal(type
, implib
);
2622 const char* suffixVar
= this->GetSuffixVariableInternal(type
, implib
);
2624 this->GetLinkerLanguage(
2625 this->Makefile
->GetLocalGenerator()->GetGlobalGenerator());
2626 // first try language specific suffix
2629 if(!targetSuffix
&& suffixVar
&& *suffixVar
)
2631 std::string langSuff
= suffixVar
+ std::string("_") + ll
;
2632 targetSuffix
= this->Makefile
->GetDefinition(langSuff
.c_str());
2634 if(!targetPrefix
&& prefixVar
&& *prefixVar
)
2636 std::string langPrefix
= prefixVar
+ std::string("_") + ll
;
2637 targetPrefix
= this->Makefile
->GetDefinition(langPrefix
.c_str());
2641 // if there is no prefix on the target use the cmake definition
2642 if(!targetPrefix
&& prefixVar
)
2644 targetPrefix
= this->Makefile
->GetSafeDefinition(prefixVar
);
2646 // if there is no suffix on the target use the cmake definition
2647 if(!targetSuffix
&& suffixVar
)
2649 targetSuffix
= this->Makefile
->GetSafeDefinition(suffixVar
);
2652 // frameworks do not have a prefix or a suffix
2653 if(this->IsFrameworkOnApple())
2659 // Begin the final name with the prefix.
2660 outPrefix
= targetPrefix
?targetPrefix
:"";
2662 // Append the target name or property-specified name.
2663 const char* outName
= 0;
2664 if(config
&& *config
)
2666 std::string configProp
= cmSystemTools::UpperCase(config
);
2667 configProp
+= "_OUTPUT_NAME";
2668 outName
= this->GetProperty(configProp
.c_str());
2672 outName
= this->GetProperty("OUTPUT_NAME");
2680 outBase
= this->GetName();
2683 // Append the per-configuration postfix.
2684 outBase
+= configPostfix
?configPostfix
:"";
2686 // Name shared libraries with their version number on some platforms.
2687 if(const char* version
= this->GetProperty("VERSION"))
2689 if(type
== cmTarget::SHARED_LIBRARY
&& !implib
&&
2690 this->Makefile
->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
2697 // Append the suffix.
2698 outSuffix
= targetSuffix
?targetSuffix
:"";
2701 //----------------------------------------------------------------------------
2702 void cmTarget::GetLibraryNames(std::string
& name
,
2703 std::string
& soName
,
2704 std::string
& realName
,
2705 std::string
& impName
,
2706 std::string
& pdbName
,
2709 // Get the names based on the real type of the library.
2710 this->GetLibraryNamesInternal(name
, soName
, realName
, impName
, pdbName
,
2711 this->GetType(), config
);
2714 //----------------------------------------------------------------------------
2715 void cmTarget::GetLibraryCleanNames(std::string
& staticName
,
2716 std::string
& sharedName
,
2717 std::string
& sharedSOName
,
2718 std::string
& sharedRealName
,
2719 std::string
& importName
,
2720 std::string
& pdbName
,
2723 // Get the name as if this were a static library.
2725 std::string realName
;
2726 std::string impName
;
2727 this->GetLibraryNamesInternal(staticName
, soName
, realName
, impName
,
2728 pdbName
, cmTarget::STATIC_LIBRARY
, config
);
2730 // Get the names as if this were a shared library.
2731 if(this->GetType() == cmTarget::STATIC_LIBRARY
)
2733 // Since the real type is static then the user either specified
2734 // STATIC or did not specify a type. In the former case the
2735 // shared library will never be present. In the latter case the
2736 // type will never be MODULE. Either way the only names that
2737 // might have to be cleaned are the shared library names.
2738 this->GetLibraryNamesInternal(sharedName
, sharedSOName
, sharedRealName
,
2739 importName
, pdbName
,
2740 cmTarget::SHARED_LIBRARY
, config
);
2744 // Use the name of the real type of the library (shared or module).
2745 this->GetLibraryNamesInternal(sharedName
, sharedSOName
, sharedRealName
,
2746 importName
, pdbName
, this->GetType(),
2751 //----------------------------------------------------------------------------
2752 void cmTarget::GetLibraryNamesInternal(std::string
& name
,
2753 std::string
& soName
,
2754 std::string
& realName
,
2755 std::string
& impName
,
2756 std::string
& pdbName
,
2760 // This should not be called for imported targets.
2761 // TODO: Split cmTarget into a class hierarchy to get compile-time
2762 // enforcement of the limited imported target API.
2763 if(this->IsImported())
2765 std::string msg
= "GetLibraryNamesInternal called on imported target: ";
2766 msg
+= this->GetName();
2767 this->Makefile
->IssueMessage(cmake::INTERNAL_ERROR
,
2772 // Construct the name of the soname flag variable for this language.
2774 this->GetLinkerLanguage(
2775 this->Makefile
->GetLocalGenerator()->GetGlobalGenerator());
2776 std::string sonameFlag
= "CMAKE_SHARED_LIBRARY_SONAME";
2782 sonameFlag
+= "_FLAG";
2784 // Check for library version properties.
2785 const char* version
= this->GetProperty("VERSION");
2786 const char* soversion
= this->GetProperty("SOVERSION");
2787 if((type
!= cmTarget::SHARED_LIBRARY
&& type
!= cmTarget::MODULE_LIBRARY
) ||
2788 !this->Makefile
->GetDefinition(sonameFlag
.c_str()) ||
2789 this->IsFrameworkOnApple())
2791 // Versioning is supported only for shared libraries and modules,
2792 // and then only when the platform supports an soname flag.
2796 if(version
&& !soversion
)
2798 // The soversion must be set if the library version is set. Use
2799 // the library version as the soversion.
2800 soversion
= version
;
2803 // Get the components of the library name.
2807 this->GetFullNameInternal(type
, config
, false, prefix
, base
, suffix
);
2809 // The library name.
2810 name
= prefix
+base
+suffix
;
2812 // The library's soname.
2813 #if defined(__APPLE__)
2814 soName
= prefix
+base
;
2821 soName
+= soversion
;
2823 #if defined(__APPLE__)
2827 // The library's real name on disk.
2828 #if defined(__APPLE__)
2829 realName
= prefix
+base
;
2836 realName
+= version
;
2841 realName
+= soversion
;
2843 #if defined(__APPLE__)
2847 // The import library name.
2848 if(type
== cmTarget::SHARED_LIBRARY
||
2849 type
== cmTarget::MODULE_LIBRARY
)
2851 impName
= this->GetFullNameInternal(type
, config
, true);
2858 // The program database file name.
2859 pdbName
= prefix
+base
+".pdb";
2862 //----------------------------------------------------------------------------
2863 void cmTarget::GetExecutableNames(std::string
& name
,
2864 std::string
& realName
,
2865 std::string
& impName
,
2866 std::string
& pdbName
,
2869 // Get the names based on the real type of the executable.
2870 this->GetExecutableNamesInternal(name
, realName
, impName
, pdbName
,
2871 this->GetType(), config
);
2874 //----------------------------------------------------------------------------
2875 void cmTarget::GetExecutableCleanNames(std::string
& name
,
2876 std::string
& realName
,
2877 std::string
& impName
,
2878 std::string
& pdbName
,
2881 // Get the name and versioned name of this executable.
2882 this->GetExecutableNamesInternal(name
, realName
, impName
, pdbName
,
2883 cmTarget::EXECUTABLE
, config
);
2886 //----------------------------------------------------------------------------
2887 void cmTarget::GetExecutableNamesInternal(std::string
& name
,
2888 std::string
& realName
,
2889 std::string
& impName
,
2890 std::string
& pdbName
,
2894 // This should not be called for imported targets.
2895 // TODO: Split cmTarget into a class hierarchy to get compile-time
2896 // enforcement of the limited imported target API.
2897 if(this->IsImported())
2900 "GetExecutableNamesInternal called on imported target: ";
2901 msg
+= this->GetName();
2902 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR
, msg
.c_str());
2905 // This versioning is supported only for executables and then only
2906 // when the platform supports symbolic links.
2907 #if defined(_WIN32) && !defined(__CYGWIN__)
2908 const char* version
= 0;
2910 // Check for executable version properties.
2911 const char* version
= this->GetProperty("VERSION");
2912 if(type
!= cmTarget::EXECUTABLE
|| this->Makefile
->IsOn("XCODE"))
2918 // Get the components of the executable name.
2922 this->GetFullNameInternal(type
, config
, false, prefix
, base
, suffix
);
2924 // The executable name.
2925 name
= prefix
+base
+suffix
;
2927 // The executable's real name on disk.
2928 #if defined(__CYGWIN__)
2929 realName
= prefix
+base
;
2936 realName
+= version
;
2938 #if defined(__CYGWIN__)
2942 // The import library name.
2943 impName
= this->GetFullNameInternal(type
, config
, true);
2945 // The program database file name.
2946 pdbName
= prefix
+base
+".pdb";
2949 //----------------------------------------------------------------------------
2950 void cmTarget::GenerateTargetManifest(const char* config
)
2952 cmMakefile
* mf
= this->Makefile
;
2953 cmLocalGenerator
* lg
= mf
->GetLocalGenerator();
2954 cmGlobalGenerator
* gg
= lg
->GetGlobalGenerator();
2959 std::string realName
;
2960 std::string impName
;
2961 std::string pdbName
;
2962 if(this->GetType() == cmTarget::EXECUTABLE
)
2964 this->GetExecutableNames(name
, realName
, impName
, pdbName
, config
);
2966 else if(this->GetType() == cmTarget::STATIC_LIBRARY
||
2967 this->GetType() == cmTarget::SHARED_LIBRARY
||
2968 this->GetType() == cmTarget::MODULE_LIBRARY
)
2970 this->GetLibraryNames(name
, soName
, realName
, impName
, pdbName
, config
);
2977 // Get the directory.
2978 std::string dir
= this->GetDirectory(config
, false);
2987 gg
->AddToManifest(config
? config
:"", f
);
2994 gg
->AddToManifest(config
? config
:"", f
);
2996 if(!realName
.empty())
3001 gg
->AddToManifest(config
? config
:"", f
);
3003 if(!pdbName
.empty())
3008 gg
->AddToManifest(config
? config
:"", f
);
3010 if(!impName
.empty())
3012 f
= this->GetDirectory(config
, true);
3015 gg
->AddToManifest(config
? config
:"", f
);
3019 //----------------------------------------------------------------------------
3020 void cmTarget::SetPropertyDefault(const char* property
,
3021 const char* default_value
)
3023 // Compute the name of the variable holding the default value.
3024 std::string var
= "CMAKE_";
3027 if(const char* value
= this->Makefile
->GetDefinition(var
.c_str()))
3029 this->SetProperty(property
, value
);
3031 else if(default_value
)
3033 this->SetProperty(property
, default_value
);
3037 //----------------------------------------------------------------------------
3038 bool cmTarget::HaveBuildTreeRPATH()
3040 return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
3041 !this->LinkLibraries
.empty());
3044 //----------------------------------------------------------------------------
3045 bool cmTarget::HaveInstallTreeRPATH()
3047 const char* install_rpath
= this->GetProperty("INSTALL_RPATH");
3048 return install_rpath
&& *install_rpath
;
3051 //----------------------------------------------------------------------------
3052 bool cmTarget::NeedRelinkBeforeInstall()
3054 // Only executables and shared libraries can have an rpath and may
3056 if(this->TargetTypeValue
!= cmTarget::EXECUTABLE
&&
3057 this->TargetTypeValue
!= cmTarget::SHARED_LIBRARY
&&
3058 this->TargetTypeValue
!= cmTarget::MODULE_LIBRARY
)
3063 // If there is no install location this target will not be installed
3064 // and therefore does not need relinking.
3065 if(!this->GetHaveInstallRule())
3070 // If skipping all rpaths completely then no relinking is needed.
3071 if(this->Makefile
->IsOn("CMAKE_SKIP_RPATH"))
3076 // If building with the install-tree rpath no relinking is needed.
3077 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3082 // If chrpath is going to be used no relinking is needed.
3083 if(this->IsChrpathUsed())
3088 // Check for rpath support on this platform.
3089 if(const char* ll
= this->GetLinkerLanguage(
3090 this->Makefile
->GetLocalGenerator()->GetGlobalGenerator()))
3092 std::string flagVar
= "CMAKE_SHARED_LIBRARY_RUNTIME_";
3095 if(!this->Makefile
->IsSet(flagVar
.c_str()))
3097 // There is no rpath support on this platform so nothing needs
3104 // No linker language is known. This error will be reported by
3109 // If either a build or install tree rpath is set then the rpath
3110 // will likely change between the build tree and install tree and
3111 // this target must be relinked.
3112 return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
3115 //----------------------------------------------------------------------------
3116 std::string
cmTarget::GetInstallNameDirForBuildTree(const char* config
,
3119 // If building directly for installation then the build tree install_name
3120 // is the same as the install tree.
3121 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3123 return GetInstallNameDirForInstallTree(config
, for_xcode
);
3126 // Use the build tree directory for the target.
3127 if(this->Makefile
->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3128 !this->Makefile
->IsOn("CMAKE_SKIP_RPATH") &&
3129 !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
3131 std::string dir
= this->GetDirectory(config
);
3133 if(this->IsFrameworkOnApple() && !for_xcode
)
3135 dir
+= this->GetFullName(config
, false);
3136 dir
+= ".framework/Versions/";
3137 dir
+= this->GetFrameworkVersion();
3148 //----------------------------------------------------------------------------
3149 std::string
cmTarget::GetInstallNameDirForInstallTree(const char* config
,
3152 // Lookup the target property.
3153 const char* install_name_dir
= this->GetProperty("INSTALL_NAME_DIR");
3154 if(this->Makefile
->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3155 !this->Makefile
->IsOn("CMAKE_SKIP_RPATH") &&
3156 install_name_dir
&& *install_name_dir
)
3158 std::string dir
= install_name_dir
;
3160 if(this->IsFrameworkOnApple() && !for_xcode
)
3162 dir
+= this->GetFullName(config
, false);
3163 dir
+= ".framework/Versions/";
3164 dir
+= this->GetFrameworkVersion();
3175 //----------------------------------------------------------------------------
3176 std::string
cmTarget::GetOutputDir(bool implib
)
3178 // The implib option is only allowed for shared libraries, module
3179 // libraries, and executables.
3180 if(this->GetType() != cmTarget::SHARED_LIBRARY
&&
3181 this->GetType() != cmTarget::MODULE_LIBRARY
&&
3182 this->GetType() != cmTarget::EXECUTABLE
)
3187 // Sanity check. Only generators on platforms supporting import
3188 // libraries should be asking for the import library output
3191 !this->Makefile
->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
3193 std::string msg
= "GetOutputDir, imlib set but there is no "
3194 "CMAKE_IMPORT_LIBRARY_SUFFIX for target: ";
3195 msg
+= this->GetName();
3196 this->GetMakefile()->
3197 IssueMessage(cmake::INTERNAL_ERROR
,
3200 if(implib
&& !this->DLLPlatform
)
3202 std::string msg
= "implib set for platform that does not "
3203 " support DLL's for target: ";
3204 msg
+= this->GetName();
3205 this->GetMakefile()->
3206 IssueMessage(cmake::INTERNAL_ERROR
,
3210 return this->ComputeBaseOutputDir(implib
);
3213 //----------------------------------------------------------------------------
3214 std::string
const& cmTarget::ComputeBaseOutputDir(bool implib
)
3216 // Select whether we are constructing the directory for the main
3217 // target or the import library.
3218 std::string
& out
= implib
? this->BaseOutputDirImplib
: this->BaseOutputDir
;
3220 // Return immediately if the directory has already been computed.
3226 // Look for a target property defining the target output directory
3227 // based on the target type.
3228 const char* propertyName
= 0;
3229 switch(this->GetType())
3231 case cmTarget::SHARED_LIBRARY
:
3233 // For non-DLL platforms shared libraries are treated as
3234 // library targets. For DLL platforms the DLL part of a
3235 // shared library is treated as a runtime target and the
3236 // corresponding import library is treated as an archive
3238 if(this->DLLPlatform
)
3242 propertyName
= "ARCHIVE_OUTPUT_DIRECTORY";
3246 propertyName
= "RUNTIME_OUTPUT_DIRECTORY";
3251 propertyName
= "LIBRARY_OUTPUT_DIRECTORY";
3254 case cmTarget::STATIC_LIBRARY
:
3256 // Static libraries are always treated as archive targets.
3257 propertyName
= "ARCHIVE_OUTPUT_DIRECTORY";
3259 case cmTarget::MODULE_LIBRARY
:
3261 // Module libraries are always treated as library targets.
3262 // Module import libraries are treated as archive targets.
3265 propertyName
= "ARCHIVE_OUTPUT_DIRECTORY";
3269 propertyName
= "LIBRARY_OUTPUT_DIRECTORY";
3272 case cmTarget::EXECUTABLE
:
3274 // Executables are always treated as runtime targets.
3275 // Executable import libraries are treated as archive targets.
3278 propertyName
= "ARCHIVE_OUTPUT_DIRECTORY";
3282 propertyName
= "RUNTIME_OUTPUT_DIRECTORY";
3288 // Select an output directory.
3289 if(const char* outdir
= this->GetProperty(propertyName
))
3291 // Use the user-specified output directory.
3294 else if(this->GetType() == cmTarget::EXECUTABLE
)
3296 // Lookup the output path for executables.
3297 out
= this->Makefile
->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
3299 else if(this->GetType() == cmTarget::STATIC_LIBRARY
||
3300 this->GetType() == cmTarget::SHARED_LIBRARY
||
3301 this->GetType() == cmTarget::MODULE_LIBRARY
)
3303 // Lookup the output path for libraries.
3304 out
= this->Makefile
->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
3308 // Default to the current output directory.
3312 // Convert the output path to a full path in case it is
3313 // specified as a relative path. Treat a relative path as
3314 // relative to the current output directory for this makefile.
3315 out
= (cmSystemTools::CollapseFullPath
3316 (out
.c_str(), this->Makefile
->GetStartOutputDirectory()));
3320 //----------------------------------------------------------------------------
3321 std::string
cmTarget::GetFrameworkVersion()
3323 if(const char* fversion
= this->GetProperty("FRAMEWORK_VERSION"))
3327 else if(const char* tversion
= this->GetProperty("VERSION"))
3337 //----------------------------------------------------------------------------
3338 const char* cmTarget::GetExportMacro()
3340 // Define the symbol for targets that export symbols.
3341 if(this->GetType() == cmTarget::SHARED_LIBRARY
||
3342 this->GetType() == cmTarget::MODULE_LIBRARY
||
3343 this->IsExecutableWithExports())
3345 if(const char* custom_export_name
= this->GetProperty("DEFINE_SYMBOL"))
3347 this->ExportMacro
= custom_export_name
;
3351 std::string in
= this->GetName();
3353 this->ExportMacro
= cmSystemTools::MakeCindentifier(in
.c_str());
3355 return this->ExportMacro
.c_str();
3363 //----------------------------------------------------------------------------
3364 void cmTarget::GetLanguages(std::set
<cmStdString
>& languages
) const
3366 for(std::vector
<cmSourceFile
*>::const_iterator
3367 i
= this->SourceFiles
.begin(); i
!= this->SourceFiles
.end(); ++i
)
3369 if(const char* lang
= (*i
)->GetLanguage())
3371 languages
.insert(lang
);
3376 //----------------------------------------------------------------------------
3377 bool cmTarget::IsChrpathUsed()
3379 #if defined(CMAKE_USE_ELF_PARSER)
3380 // Only certain target types have an rpath.
3381 if(!(this->GetType() == cmTarget::SHARED_LIBRARY
||
3382 this->GetType() == cmTarget::MODULE_LIBRARY
||
3383 this->GetType() == cmTarget::EXECUTABLE
))
3388 // If the target will not be installed we do not need to change its
3390 if(!this->GetHaveInstallRule())
3395 // Skip chrpath if skipping rpath altogether.
3396 if(this->Makefile
->IsOn("CMAKE_SKIP_RPATH"))
3401 // Skip chrpath if it does not need to be changed at install time.
3402 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3407 // Allow the user to disable builtin chrpath explicitly.
3408 if(this->Makefile
->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
3413 // Enable if the rpath flag uses a separator and the target uses ELF
3415 if(const char* ll
= this->GetLinkerLanguage(
3416 this->Makefile
->GetLocalGenerator()->GetGlobalGenerator()))
3418 std::string sepVar
= "CMAKE_SHARED_LIBRARY_RUNTIME_";
3420 sepVar
+= "_FLAG_SEP";
3421 const char* sep
= this->Makefile
->GetDefinition(sepVar
.c_str());
3424 // TODO: Add ELF check to ABI detection and get rid of
3425 // CMAKE_EXECUTABLE_FORMAT.
3426 if(const char* fmt
=
3427 this->Makefile
->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
3429 return strcmp(fmt
, "ELF") == 0;
3437 //----------------------------------------------------------------------------
3438 cmTarget::ImportInfo
const*
3439 cmTarget::GetImportInfo(const char* config
)
3441 // There is no imported information for non-imported targets.
3442 if(!this->IsImported())
3447 // Lookup/compute/cache the import information for this
3449 std::string config_upper
;
3450 if(config
&& *config
)
3452 config_upper
= cmSystemTools::UpperCase(config
);
3456 config_upper
= "NOCONFIG";
3458 ImportInfoMapType::const_iterator i
=
3459 this->ImportInfoMap
.find(config_upper
);
3460 if(i
== this->ImportInfoMap
.end())
3463 this->ComputeImportInfo(config_upper
, info
);
3464 ImportInfoMapType::value_type
entry(config_upper
, info
);
3465 i
= this->ImportInfoMap
.insert(entry
).first
;
3468 // If the location is empty then the target is not available for
3469 // this configuration.
3470 if(i
->second
.Location
.empty())
3475 // Return the import information.
3479 //----------------------------------------------------------------------------
3480 void cmTarget::ComputeImportInfo(std::string
const& desired_config
,
3483 // This method finds information about an imported target from its
3484 // properties. The "IMPORTED_" namespace is reserved for properties
3485 // defined by the project exporting the target.
3487 // Initialize members.
3488 info
.NoSOName
= false;
3490 // Track the configuration-specific property suffix.
3491 std::string suffix
= "_";
3492 suffix
+= desired_config
;
3494 // Look for a mapping from the current project's configuration to
3495 // the imported project's configuration.
3496 std::vector
<std::string
> mappedConfigs
;
3498 std::string mapProp
= "MAP_IMPORTED_CONFIG_";
3499 mapProp
+= desired_config
;
3500 if(const char* mapValue
= this->GetProperty(mapProp
.c_str()))
3502 cmSystemTools::ExpandListArgument(mapValue
, mappedConfigs
);
3506 // If a mapping was found, check its configurations.
3507 const char* loc
= 0;
3508 for(std::vector
<std::string
>::const_iterator mci
= mappedConfigs
.begin();
3509 !loc
&& mci
!= mappedConfigs
.end(); ++mci
)
3511 // Look for this configuration.
3512 std::string mcUpper
= cmSystemTools::UpperCase(mci
->c_str());
3513 std::string locProp
= "IMPORTED_LOCATION_";
3515 loc
= this->GetProperty(locProp
.c_str());
3517 // If it was found, use it for all properties below.
3525 // If we needed to find one of the mapped configurations but did not
3526 // then the target is not found. The project does not want any
3527 // other configuration.
3528 if(!mappedConfigs
.empty() && !loc
)
3533 // If we have not yet found it then there are no mapped
3534 // configurations. Look for an exact-match.
3537 std::string locProp
= "IMPORTED_LOCATION";
3539 loc
= this->GetProperty(locProp
.c_str());
3542 // If we have not yet found it then there are no mapped
3543 // configurations and no exact match.
3546 // The suffix computed above is not useful.
3549 // Look for a configuration-less location. This may be set by
3550 // manually-written code.
3551 loc
= this->GetProperty("IMPORTED_LOCATION");
3554 // If we have not yet found it then the project is willing to try
3555 // any available configuration.
3558 std::vector
<std::string
> availableConfigs
;
3559 if(const char* iconfigs
= this->GetProperty("IMPORTED_CONFIGURATIONS"))
3561 cmSystemTools::ExpandListArgument(iconfigs
, availableConfigs
);
3563 for(std::vector
<std::string
>::const_iterator
3564 aci
= availableConfigs
.begin();
3565 !loc
&& aci
!= availableConfigs
.end(); ++aci
)
3568 suffix
+= cmSystemTools::UpperCase(availableConfigs
[0]);
3569 std::string locProp
= "IMPORTED_LOCATION";
3571 loc
= this->GetProperty(locProp
.c_str());
3575 // If we have not yet found it then the target is not available.
3581 // A provided configuration has been chosen. Load the
3582 // configuration's properties.
3583 info
.Location
= loc
;
3586 if(this->GetType() == cmTarget::SHARED_LIBRARY
)
3588 std::string soProp
= "IMPORTED_SONAME";
3590 if(const char* config_soname
= this->GetProperty(soProp
.c_str()))
3592 info
.SOName
= config_soname
;
3594 else if(const char* soname
= this->GetProperty("IMPORTED_SONAME"))
3596 info
.SOName
= soname
;
3600 // Get the "no-soname" mark.
3601 if(this->GetType() == cmTarget::SHARED_LIBRARY
)
3603 std::string soProp
= "IMPORTED_NO_SONAME";
3605 if(const char* config_no_soname
= this->GetProperty(soProp
.c_str()))
3607 info
.NoSOName
= cmSystemTools::IsOn(config_no_soname
);
3609 else if(const char* no_soname
= this->GetProperty("IMPORTED_NO_SONAME"))
3611 info
.NoSOName
= cmSystemTools::IsOn(no_soname
);
3615 // Get the import library.
3616 if(this->GetType() == cmTarget::SHARED_LIBRARY
||
3617 this->IsExecutableWithExports())
3619 std::string impProp
= "IMPORTED_IMPLIB";
3621 if(const char* config_implib
= this->GetProperty(impProp
.c_str()))
3623 info
.ImportLibrary
= config_implib
;
3625 else if(const char* implib
= this->GetProperty("IMPORTED_IMPLIB"))
3627 info
.ImportLibrary
= implib
;
3631 // Get the link interface.
3633 std::string linkProp
= "IMPORTED_LINK_INTERFACE_LIBRARIES";
3635 if(const char* config_libs
= this->GetProperty(linkProp
.c_str()))
3637 cmSystemTools::ExpandListArgument(config_libs
,
3638 info
.LinkInterface
.Libraries
);
3640 else if(const char* libs
=
3641 this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
3643 cmSystemTools::ExpandListArgument(libs
,
3644 info
.LinkInterface
.Libraries
);
3648 // Get the link dependencies.
3650 std::string linkProp
= "IMPORTED_LINK_DEPENDENT_LIBRARIES";
3652 if(const char* config_libs
= this->GetProperty(linkProp
.c_str()))
3654 cmSystemTools::ExpandListArgument(config_libs
,
3655 info
.LinkInterface
.SharedDeps
);
3657 else if(const char* libs
=
3658 this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
3660 cmSystemTools::ExpandListArgument(libs
, info
.LinkInterface
.SharedDeps
);
3665 //----------------------------------------------------------------------------
3666 cmTargetLinkInterface
const* cmTarget::GetLinkInterface(const char* config
)
3668 // Imported targets have their own link interface.
3669 if(this->IsImported())
3671 if(cmTarget::ImportInfo
const* info
= this->GetImportInfo(config
))
3673 return &info
->LinkInterface
;
3678 // Link interfaces are supported only for shared libraries and
3679 // executables that export symbols.
3680 if((this->GetType() != cmTarget::SHARED_LIBRARY
&&
3681 !this->IsExecutableWithExports()))
3686 // Lookup any existing link interface for this configuration.
3687 std::map
<cmStdString
, cmTargetLinkInterface
*>::iterator
3688 i
= this->LinkInterface
.find(config
?config
:"");
3689 if(i
== this->LinkInterface
.end())
3691 // Compute the link interface for this configuration.
3692 cmTargetLinkInterface
* iface
= this->ComputeLinkInterface(config
);
3694 // Store the information for this configuration.
3695 std::map
<cmStdString
, cmTargetLinkInterface
*>::value_type
3696 entry(config
?config
:"", iface
);
3697 i
= this->LinkInterface
.insert(entry
).first
;
3703 //----------------------------------------------------------------------------
3704 cmTargetLinkInterface
* cmTarget::ComputeLinkInterface(const char* config
)
3706 // Construct the property name suffix for this configuration.
3707 std::string suffix
= "_";
3708 if(config
&& *config
)
3710 suffix
+= cmSystemTools::UpperCase(config
);
3714 suffix
+= "NOCONFIG";
3717 // Lookup the link interface libraries.
3718 const char* libs
= 0;
3720 // Lookup the per-configuration property.
3721 std::string propName
= "LINK_INTERFACE_LIBRARIES";
3723 libs
= this->GetProperty(propName
.c_str());
3725 // If not set, try the generic property.
3728 libs
= this->GetProperty("LINK_INTERFACE_LIBRARIES");
3732 // If still not set, there is no link interface.
3738 // Allocate the interface.
3739 cmTargetLinkInterface
* iface
= new cmTargetLinkInterface
;
3745 // Expand the list of libraries in the interface.
3746 cmSystemTools::ExpandListArgument(libs
, iface
->Libraries
);
3748 // Now we need to construct a list of shared library dependencies
3749 // not included in the interface.
3750 if(this->GetType() == cmTarget::SHARED_LIBRARY
)
3752 // Use a set to keep track of what libraries have been emitted to
3754 std::set
<cmStdString
> emitted
;
3755 for(std::vector
<std::string
>::const_iterator
3756 li
= iface
->Libraries
.begin();
3757 li
!= iface
->Libraries
.end(); ++li
)
3759 emitted
.insert(*li
);
3762 // Compute which library configuration to link.
3763 cmTarget::LinkLibraryType linkType
= this->ComputeLinkType(config
);
3765 // Construct the list of libs linked for this configuration.
3766 cmTarget::LinkLibraryVectorType
const& llibs
=
3767 this->GetOriginalLinkLibraries();
3768 for(cmTarget::LinkLibraryVectorType::const_iterator li
= llibs
.begin();
3769 li
!= llibs
.end(); ++li
)
3771 // Skip entries that will resolve to the target itself, are empty,
3772 // or are not meant for this configuration.
3773 if(li
->first
== this->GetName() || li
->first
.empty() ||
3774 !(li
->second
== cmTarget::GENERAL
|| li
->second
== linkType
))
3779 // Skip entries that have already been emitted into either list.
3780 if(!emitted
.insert(li
->first
).second
)
3785 // Add this entry if it is a shared library.
3786 if(cmTarget
* tgt
= this->Makefile
->FindTargetToUse(li
->first
.c_str()))
3788 if(tgt
->GetType() == cmTarget::SHARED_LIBRARY
)
3790 iface
->SharedDeps
.push_back(li
->first
);
3795 // TODO: Recognize shared library file names. Perhaps this
3796 // should be moved to cmComputeLinkInformation, but that creates
3797 // a chicken-and-egg problem since this list is needed for its
3803 // Return the completed interface.
3807 //----------------------------------------------------------------------------
3808 cmComputeLinkInformation
*
3809 cmTarget::GetLinkInformation(const char* config
)
3811 // Lookup any existing information for this configuration.
3812 std::map
<cmStdString
, cmComputeLinkInformation
*>::iterator
3813 i
= this->LinkInformation
.find(config
?config
:"");
3814 if(i
== this->LinkInformation
.end())
3816 // Compute information for this configuration.
3817 cmComputeLinkInformation
* info
=
3818 new cmComputeLinkInformation(this, config
);
3819 if(!info
|| !info
->Compute())
3825 // Store the information for this configuration.
3826 std::map
<cmStdString
, cmComputeLinkInformation
*>::value_type
3827 entry(config
?config
:"", info
);
3828 i
= this->LinkInformation
.insert(entry
).first
;
3833 //----------------------------------------------------------------------------
3834 cmTargetLinkInformationMap
3835 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap
const& r
): derived()
3837 // Ideally cmTarget instances should never be copied. However until
3838 // we can make a sweep to remove that, this copy constructor avoids
3839 // allowing the resources (LinkInformation) from getting copied. In
3840 // the worst case this will lead to extra cmComputeLinkInformation
3841 // instances. We also enforce in debug mode that the map be emptied
3843 static_cast<void>(r
);
3847 //----------------------------------------------------------------------------
3848 cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
3850 for(derived::iterator i
= this->begin(); i
!= this->end(); ++i
)
3856 //----------------------------------------------------------------------------
3857 cmTargetLinkInterfaceMap
3858 ::cmTargetLinkInterfaceMap(cmTargetLinkInterfaceMap
const& r
): derived()
3860 // Ideally cmTarget instances should never be copied. However until
3861 // we can make a sweep to remove that, this copy constructor avoids
3862 // allowing the resources (LinkInterface) from getting copied. In
3863 // the worst case this will lead to extra cmTargetLinkInterface
3864 // instances. We also enforce in debug mode that the map be emptied
3866 static_cast<void>(r
);
3870 //----------------------------------------------------------------------------
3871 cmTargetLinkInterfaceMap::~cmTargetLinkInterfaceMap()
3873 for(derived::iterator i
= this->begin(); i
!= this->end(); ++i
)
3879 //----------------------------------------------------------------------------
3880 cmTargetInternalPointer::cmTargetInternalPointer()
3882 this->Pointer
= new cmTargetInternals
;
3885 //----------------------------------------------------------------------------
3886 cmTargetInternalPointer
3887 ::cmTargetInternalPointer(cmTargetInternalPointer
const&)
3889 // Ideally cmTarget instances should never be copied. However until
3890 // we can make a sweep to remove that, this copy constructor avoids
3891 // allowing the resources (Internals) to be copied.
3892 this->Pointer
= new cmTargetInternals
;
3895 //----------------------------------------------------------------------------
3896 cmTargetInternalPointer::~cmTargetInternalPointer()
3898 delete this->Pointer
;
3901 //----------------------------------------------------------------------------
3902 cmTargetInternalPointer
&
3903 cmTargetInternalPointer::operator=(cmTargetInternalPointer
const& r
)
3905 if(this == &r
) { return *this; } // avoid warning on HP about self check
3906 // Ideally cmTarget instances should never be copied. However until
3907 // we can make a sweep to remove that, this copy constructor avoids
3908 // allowing the resources (Internals) to be copied.
3909 cmTargetInternals
* oldPointer
= this->Pointer
;
3910 this->Pointer
= new cmTargetInternals
;