STYLE: Nightly Date Stamp
[cmake.git] / Source / cmTarget.cxx
blobdc0f79ca97bcb938b7369dc4e8bdc467dd3b91dd
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmTarget.cxx,v $
5 Language: C++
6 Date: $Date: 2008-09-15 17:30:11 $
7 Version: $Revision: 1.227 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmTarget.h"
18 #include "cmake.h"
19 #include "cmMakefile.h"
20 #include "cmSourceFile.h"
21 #include "cmLocalGenerator.h"
22 #include "cmGlobalGenerator.h"
23 #include "cmComputeLinkInformation.h"
24 #include "cmListFileCache.h"
25 #include <cmsys/RegularExpression.hxx>
26 #include <map>
27 #include <set>
28 #include <queue>
29 #include <stdlib.h> // required for atof
30 #include <assert.h>
31 const char* cmTarget::TargetTypeNames[] = {
32 "EXECUTABLE", "STATIC_LIBRARY",
33 "SHARED_LIBRARY", "MODULE_LIBRARY", "UTILITY", "GLOBAL_TARGET",
34 "INSTALL_FILES", "INSTALL_PROGRAMS", "INSTALL_DIRECTORY",
35 "UNKNOWN_LIBRARY"
38 //----------------------------------------------------------------------------
39 class cmTargetInternals
41 public:
42 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 //----------------------------------------------------------------------------
55 cmTarget::cmTarget()
57 this->Makefile = 0;
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)
70 cm->DefineProperty
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.");
78 cm->DefineProperty
79 ("CLEAN_DIRECT_OUTPUT", cmProperty::TARGET,
80 "Do not delete other variants of this target.",
81 "When a library is built CMake by default generates code to remove "
82 "any existing library using all possible names. This is needed "
83 "to support libraries that switch between STATIC and SHARED by "
84 "a user option. However when using OUTPUT_NAME to build a static "
85 "and shared library of the same name using different logical target "
86 "names the two targets will remove each other's files. This can be "
87 "prevented by setting the CLEAN_DIRECT_OUTPUT property to 1.");
89 cm->DefineProperty
90 ("COMPILE_FLAGS", cmProperty::TARGET,
91 "Additional flags to use when compiling this target's sources.",
92 "The COMPILE_FLAGS property sets additional compiler flags used "
93 "to build sources within the target. Use COMPILE_DEFINITIONS "
94 "to pass additional preprocessor definitions.");
96 cm->DefineProperty
97 ("COMPILE_DEFINITIONS", cmProperty::TARGET,
98 "Preprocessor definitions for compiling a target's sources.",
99 "The COMPILE_DEFINITIONS property may be set to a list of preprocessor "
100 "definitions using the syntax VAR or VAR=value. Function-style "
101 "definitions are not supported. CMake will automatically escape "
102 "the value correctly for the native build system (note that CMake "
103 "language syntax may require escapes to specify some values). "
104 "This property may be set on a per-configuration basis using the name "
105 "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
106 "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
107 "CMake will automatically drop some definitions that "
108 "are not supported by the native build tool. "
109 "The VS6 IDE does not support definitions with values "
110 "(but NMake does).\n"
111 "Dislaimer: Most native build tools have poor support for escaping "
112 "certain values. CMake has work-arounds for many cases but some "
113 "values may just not be possible to pass correctly. If a value "
114 "does not seem to be escaped correctly, do not attempt to "
115 "work-around the problem by adding escape sequences to the value. "
116 "Your work-around may break in a future version of CMake that "
117 "has improved escape support. Instead consider defining the macro "
118 "in a (configured) header file. Then report the limitation.");
120 cm->DefineProperty
121 ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
122 "Per-configuration preprocessor definitions on a target.",
123 "This is the configuration-specific version of COMPILE_DEFINITIONS.");
125 cm->DefineProperty
126 ("DEFINE_SYMBOL", cmProperty::TARGET,
127 "Define a symbol when compiling this target's sources.",
128 "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
129 "compiling sources in a shared library. "
130 "If not set here then it is set to target_EXPORTS by default "
131 "(with some substitutions if the target is not a valid C "
132 "identifier). This is useful for headers to know whether they are "
133 "being included from inside their library our outside to properly "
134 "setup dllexport/dllimport decorations. ");
136 cm->DefineProperty
137 ("DEBUG_POSTFIX", cmProperty::TARGET,
138 "A postfix that will be applied to this target when build debug.",
139 "A property on a target that specifies a postfix to add to the "
140 "target name when built in debug mode. For example \"foo.dll\" "
141 "versus \"fooD.dll\". Ignored for Mac Frameworks and App Bundles.");
143 cm->DefineProperty
144 ("EchoString", cmProperty::TARGET,
145 "A message to be displayed when the target is built.",
146 "A message to display on some generators (such as makefiles) when "
147 "the target is built.");
149 cm->DefineProperty
150 ("FRAMEWORK", cmProperty::TARGET,
151 "This target is a framework on the Mac.",
152 "If a shared library target has this property set to true it will "
153 "be built as a framework when built on the mac. It will have the "
154 "directory structure required for a framework and will be suitable "
155 "to be used with the -framework option");
157 cm->DefineProperty
158 ("HAS_CXX", cmProperty::TARGET,
159 "Force a target to use the CXX linker.",
160 "Setting HAS_CXX on a target will force the target to use the "
161 "C++ linker (and C++ runtime libraries) for linking even if the "
162 "target has no C++ code in it.");
164 cm->DefineProperty
165 ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
166 "Specify #include line transforms for dependencies in a target.",
167 "This property specifies rules to transform macro-like #include lines "
168 "during implicit dependency scanning of C and C++ source files. "
169 "The list of rules must be semicolon-separated with each entry of "
170 "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
171 "During dependency scanning occurrences of A_MACRO(...) on #include "
172 "lines will be replaced by the value given with the macro argument "
173 "substituted for '%'. For example, the entry\n"
174 " MYDIR(%)=<mydir/%>\n"
175 "will convert lines of the form\n"
176 " #include MYDIR(myheader.h)\n"
177 "to\n"
178 " #include <mydir/myheader.h>\n"
179 "allowing the dependency to be followed.\n"
180 "This property applies to sources in the target on which it is set.");
182 cm->DefineProperty
183 ("IMPORT_PREFIX", cmProperty::TARGET,
184 "What comes before the import library name.",
185 "Similar to the target property PREFIX, but used for import libraries "
186 "(typically corresponding to a DLL) instead of regular libraries. "
187 "A target property that can be set to override the prefix "
188 "(such as \"lib\") on an import library name.");
190 cm->DefineProperty
191 ("IMPORT_SUFFIX", cmProperty::TARGET,
192 "What comes after the import library name.",
193 "Similar to the target property SUFFIX, but used for import libraries "
194 "(typically corresponding to a DLL) instead of regular libraries. "
195 "A target property that can be set to override the suffix "
196 "(such as \".lib\") on an import library name.");
198 cm->DefineProperty
199 ("IMPORTED", cmProperty::TARGET,
200 "Read-only indication of whether a target is IMPORTED.",
201 "The boolean value of this property is true for targets created with "
202 "the IMPORTED option to add_executable or add_library. "
203 "It is false for targets built within the project.");
205 cm->DefineProperty
206 ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
207 "Configurations provided for an IMPORTED target.",
208 "Lists configuration names available for an IMPORTED target. "
209 "The names correspond to configurations defined in the project from "
210 "which the target is imported. "
211 "If the importing project uses a different set of configurations "
212 "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
213 "property. "
214 "Ignored for non-imported targets.");
216 cm->DefineProperty
217 ("IMPORTED_IMPLIB", cmProperty::TARGET,
218 "Full path to the import library for an IMPORTED target.",
219 "Specifies the location of the \".lib\" part of a windows DLL. "
220 "Ignored for non-imported targets.");
222 cm->DefineProperty
223 ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
224 "Per-configuration version of IMPORTED_IMPLIB property.",
225 "This property is used when loading settings for the <CONFIG> "
226 "configuration of an imported target. "
227 "Configuration names correspond to those provided by the project "
228 "from which the target is imported.");
230 cm->DefineProperty
231 ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
232 "Dependent shared libraries of an imported shared library.",
233 "Shared libraries may be linked to other shared libraries as part "
234 "of their implementation. On some platforms the linker searches "
235 "for the dependent libraries of shared libraries they are including "
236 "in the link. This property lists "
237 "the dependent shared libraries of an imported library. The list "
238 "should be disjoint from the list of interface libraries in the "
239 "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring "
240 "dependent shared libraries to be found at link time CMake uses this "
241 "list to add appropriate files or paths to the link command line. "
242 "Ignored for non-imported targets.");
244 cm->DefineProperty
245 ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
246 "Per-configuration version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
247 "This property is used when loading settings for the <CONFIG> "
248 "configuration of an imported target. "
249 "Configuration names correspond to those provided by the project "
250 "from which the target is imported. "
251 "If set, this property completely overrides the generic property "
252 "for the named configuration.");
254 cm->DefineProperty
255 ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
256 "Transitive link interface of an IMPORTED target.",
257 "Lists libraries whose interface is included when an IMPORTED library "
258 "target is linked to another target. "
259 "The libraries will be included on the link line for the target. "
260 "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
261 "to all imported target types, including STATIC libraries. "
262 "This property is ignored for non-imported targets.");
264 cm->DefineProperty
265 ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
266 "Per-configuration version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
267 "This property is used when loading settings for the <CONFIG> "
268 "configuration of an imported target. "
269 "Configuration names correspond to those provided by the project "
270 "from which the target is imported. "
271 "If set, this property completely overrides the generic property "
272 "for the named configuration.");
274 cm->DefineProperty
275 ("IMPORTED_LOCATION", cmProperty::TARGET,
276 "Full path to the main file on disk for an IMPORTED target.",
277 "Specifies the location of an IMPORTED target file on disk. "
278 "For executables this is the location of the executable file. "
279 "For bundles on OS X this is the location of the executable file "
280 "inside Contents/MacOS under the application bundle folder. "
281 "For static libraries and modules this is the location of the "
282 "library or module. "
283 "For shared libraries on non-DLL platforms this is the location of "
284 "the shared library. "
285 "For frameworks on OS X this is the location of the library file "
286 "symlink just inside the framework folder. "
287 "For DLLs this is the location of the \".dll\" part of the library. "
288 "For UNKNOWN libraries this is the location of the file to be linked. "
289 "Ignored for non-imported targets.");
291 cm->DefineProperty
292 ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
293 "Per-configuration version of IMPORTED_LOCATION property.",
294 "This property is used when loading settings for the <CONFIG> "
295 "configuration of an imported target. "
296 "Configuration names correspond to those provided by the project "
297 "from which the target is imported.");
299 cm->DefineProperty
300 ("IMPORTED_SONAME", cmProperty::TARGET,
301 "The \"soname\" of an IMPORTED target of shared library type.",
302 "Specifies the \"soname\" embedded in an imported shared library. "
303 "This is meaningful only on platforms supporting the feature. "
304 "Ignored for non-imported targets.");
306 cm->DefineProperty
307 ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
308 "Per-configuration version of IMPORTED_SONAME property.",
309 "This property is used when loading settings for the <CONFIG> "
310 "configuration of an imported target. "
311 "Configuration names correspond to those provided by the project "
312 "from which the target is imported.");
314 cm->DefineProperty
315 ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
316 "Exclude the target from the all target.",
317 "A property on a target that indicates if the target is excluded "
318 "from the default build target. If it is not, then with a Makefile "
319 "for example typing make will cause this target to be built. "
320 "The same concept applies to the default build of other generators. "
321 "Installing a target with EXCLUDE_FROM_ALL set to true has "
322 "undefined behavior.");
324 cm->DefineProperty
325 ("INSTALL_NAME_DIR", cmProperty::TARGET,
326 "Mac OSX directory name for installed targets.",
327 "INSTALL_NAME_DIR is a string specifying the "
328 "directory portion of the \"install_name\" field of shared libraries "
329 "on Mac OSX to use in the installed targets. ");
331 cm->DefineProperty
332 ("INSTALL_RPATH", cmProperty::TARGET,
333 "The rpath to use for installed targets.",
334 "A semicolon-separated list specifying the rpath "
335 "to use in installed targets (for platforms that support it).");
337 cm->DefineProperty
338 ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
339 "Add paths to linker search and installed rpath.",
340 "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
341 "append directories in the linker search path and outside the "
342 "project to the INSTALL_RPATH. ");
344 cm->DefineProperty
345 ("LINK_FLAGS", cmProperty::TARGET,
346 "Additional flags to use when linking this target.",
347 "The LINK_FLAGS property can be used to add extra flags to the "
348 "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
349 "configuration <CONFIG>, "
350 "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
352 cm->DefineProperty
353 ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
354 "Per-configuration linker flags for a target.",
355 "This is the configuration-specific version of LINK_FLAGS.");
357 cm->DefineProperty
358 ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
359 "End a link line such that static system libraries are used.",
360 "Some linkers support switches such as -Bstatic and -Bdynamic "
361 "to determine whether to use static or shared libraries for -lXXX "
362 "options. CMake uses these options to set the link type for "
363 "libraries whose full paths are not known or (in some cases) are in "
364 "implicit link directories for the platform. By default the "
365 "linker search type is left at -Bdynamic by the end of the library "
366 "list. This property switches the final linker search type to "
367 "-Bstatic.");
369 cm->DefineProperty
370 ("LINKER_LANGUAGE", cmProperty::TARGET,
371 "What tool to use for linking, based on language.",
372 "The LINKER_LANGUAGE property is used to change the tool "
373 "used to link an executable or shared library. The default is "
374 "set the language to match the files in the library. CXX and C "
375 "are common values for this property.");
377 cm->DefineProperty
378 ("LOCATION", cmProperty::TARGET,
379 "Deprecated. Use LOCATION_<CONFIG> or avoid altogether.",
380 "This property is provided for compatibility with CMake 2.4 and below. "
381 "It was meant to get the location of an executable target's output file "
382 "for use in add_custom_command. "
383 "In CMake 2.6 and above add_custom_command automatically recognizes a "
384 "target name in its COMMAND and DEPENDS options and computes the "
385 "target location. Therefore this property need not be used. "
386 "This property is not defined for IMPORTED targets because they "
387 "were not available in CMake 2.4 or below anyway.");
389 cm->DefineProperty
390 ("LOCATION_<CONFIG>", cmProperty::TARGET,
391 "Read-only property providing a target location on disk.",
392 "A read-only property that indicates where a target's main file is "
393 "located on disk for the configuration <CONFIG>. "
394 "The property is defined only for library and executable targets.");
396 cm->DefineProperty
397 ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
398 "List public interface libraries for a shared library or executable.",
399 "By default linking to a shared library target transitively "
400 "links to targets with which the library itself was linked. "
401 "For an executable with exports (see the ENABLE_EXPORTS property) "
402 "no default transitive link dependencies are used. "
403 "This property replaces the default transitive link dependencies with "
404 "an explict list. "
405 "When the target is linked into another target the libraries "
406 "listed (and recursively their link interface libraries) will be "
407 "provided to the other target also. "
408 "If the list is empty then no transitive link dependencies will be "
409 "incorporated when this target is linked into another target even if "
410 "the default set is non-empty. "
411 "This property is ignored for STATIC libraries.");
413 cm->DefineProperty
414 ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
415 "Per-configuration list of public interface libraries for a target.",
416 "This is the configuration-specific version of "
417 "LINK_INTERFACE_LIBRARIES. "
418 "If set, this property completely overrides the generic property "
419 "for the named configuration.");
421 cm->DefineProperty
422 ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
423 "Map from project configuration to IMPORTED target's configuration.",
424 "List configurations of an imported target that may be used for "
425 "the current project's <CONFIG> configuration. "
426 "Targets imported from another project may not provide the same set "
427 "of configuration names available in the current project. "
428 "Setting this property tells CMake what imported configurations are "
429 "suitable for use when building the <CONFIG> configuration. "
430 "The first configuration in the list found to be provided by the "
431 "imported target is selected. If no matching configurations are "
432 "available the imported target is considered to be not found. "
433 "This property is ignored for non-imported targets.",
434 false /* TODO: make this chained */ );
436 cm->DefineProperty
437 ("OUTPUT_NAME", cmProperty::TARGET,
438 "Sets the real name of a target when it is built.",
439 "Sets the real name of a target when it is built and "
440 "can be used to help create two targets of the same name even though "
441 "CMake requires unique logical target names. There is also a "
442 "<CONFIG>_OUTPUT_NAME that can set the output name on a "
443 "per-configuration basis.");
445 cm->DefineProperty
446 ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
447 "Deprecated install support.",
448 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
449 "old way to specify CMake scripts to run before and after "
450 "installing a target. They are used only when the old "
451 "INSTALL_TARGETS command is used to install the target. Use the "
452 "INSTALL command instead.");
454 cm->DefineProperty
455 ("PREFIX", cmProperty::TARGET,
456 "What comes before the library name.",
457 "A target property that can be set to override the prefix "
458 "(such as \"lib\") on a library name.");
460 cm->DefineProperty
461 ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
462 "Deprecated install support.",
463 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
464 "old way to specify CMake scripts to run before and after "
465 "installing a target. They are used only when the old "
466 "INSTALL_TARGETS command is used to install the target. Use the "
467 "INSTALL command instead.");
469 cm->DefineProperty
470 ("PRIVATE_HEADER", cmProperty::TARGET,
471 "Specify private header files in a FRAMEWORK shared library target.",
472 "Shared library targets marked with the FRAMEWORK property generate "
473 "frameworks on OS X and normal shared libraries on other platforms. "
474 "This property may be set to a list of header files to be placed "
475 "in the PrivateHeaders directory inside the framework folder. "
476 "On non-Apple platforms these headers may be installed using the "
477 "PRIVATE_HEADER option to the install(TARGETS) command.");
479 cm->DefineProperty
480 ("PUBLIC_HEADER", cmProperty::TARGET,
481 "Specify public header files in a FRAMEWORK shared library target.",
482 "Shared library targets marked with the FRAMEWORK property generate "
483 "frameworks on OS X and normal shared libraries on other platforms. "
484 "This property may be set to a list of header files to be placed "
485 "in the Headers directory inside the framework folder. "
486 "On non-Apple platforms these headers may be installed using the "
487 "PUBLIC_HEADER option to the install(TARGETS) command.");
489 cm->DefineProperty
490 ("RESOURCE", cmProperty::TARGET,
491 "Specify resource files in a FRAMEWORK shared library target.",
492 "Shared library targets marked with the FRAMEWORK property generate "
493 "frameworks on OS X and normal shared libraries on other platforms. "
494 "This property may be set to a list of files to be placed "
495 "in the Resources directory inside the framework folder. "
496 "On non-Apple platforms these files may be installed using the "
497 "RESOURCE option to the install(TARGETS) command.");
499 cm->DefineProperty
500 ("SKIP_BUILD_RPATH", cmProperty::TARGET,
501 "Should rpaths be used for the build tree.",
502 "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
503 "generation of an rpath allowing the target to run from the "
504 "build tree. ");
506 cm->DefineProperty
507 ("SOVERSION", cmProperty::TARGET,
508 "What version number is this target.",
509 "For shared libraries VERSION and SOVERSION can be used to specify "
510 "the build version and api version respectively. When building or "
511 "installing appropriate symlinks are created if the platform "
512 "supports symlinks and the linker supports so-names. "
513 "If only one of both is specified the missing is assumed to have "
514 "the same version number. "
515 "For shared libraries and executables on Windows the VERSION "
516 "attribute is parsed to extract a \"major.minor\" version number. "
517 "These numbers are used as the image version of the binary. ");
519 cm->DefineProperty
520 ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
521 "Extra flags to use when linking static libraries.",
522 "Extra flags to use when linking a static library.");
524 cm->DefineProperty
525 ("SUFFIX", cmProperty::TARGET,
526 "What comes after the library name.",
527 "A target property that can be set to override the suffix "
528 "(such as \".so\") on a library name.");
530 cm->DefineProperty
531 ("VERSION", cmProperty::TARGET,
532 "What version number is this target.",
533 "For shared libraries VERSION and SOVERSION can be used to specify "
534 "the build version and api version respectively. When building or "
535 "installing appropriate symlinks are created if the platform "
536 "supports symlinks and the linker supports so-names. "
537 "If only one of both is specified the missing is assumed to have "
538 "the same version number. "
539 "For executables VERSION can be used to specify the build version. "
540 "When building or installing appropriate symlinks are created if "
541 "the platform supports symlinks. "
542 "For shared libraries and executables on Windows the VERSION "
543 "attribute is parsed to extract a \"major.minor\" version number. "
544 "These numbers are used as the image version of the binary. ");
547 cm->DefineProperty
548 ("WIN32_EXECUTABLE", cmProperty::TARGET,
549 "Build an executable with a WinMain entry point on windows.",
550 "When this property is set to true the executable when linked "
551 "on Windows will be created with a WinMain() entry point instead "
552 "of of just main()."
553 "This makes it a GUI executable instead of a console application. "
554 "See the CMAKE_MFC_FLAG variable documentation to configure use "
555 "of MFC for WinMain executables.");
557 cm->DefineProperty
558 ("MACOSX_BUNDLE", cmProperty::TARGET,
559 "Build an executable as an application bundle on Mac OS X.",
560 "When this property is set to true the executable when built "
561 "on Mac OS X will be created as an application bundle. "
562 "This makes it a GUI executable that can be launched from "
563 "the Finder. "
564 "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
565 "about creation of the Info.plist file for the application bundle.");
567 cm->DefineProperty
568 ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
569 "Specify a custom Info.plist template for a Mac OS X App Bundle.",
570 "An executable target with MACOSX_BUNDLE enabled will be built as an "
571 "application bundle on Mac OS X. "
572 "By default its Info.plist file is created by configuring a template "
573 "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
574 "This property specifies an alternative template file name which "
575 "may be a full path.\n"
576 "The following target properties may be set to specify content to "
577 "be configured into the file:\n"
578 " MACOSX_BUNDLE_INFO_STRING\n"
579 " MACOSX_BUNDLE_ICON_FILE\n"
580 " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
581 " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
582 " MACOSX_BUNDLE_BUNDLE_NAME\n"
583 " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
584 " MACOSX_BUNDLE_BUNDLE_VERSION\n"
585 " MACOSX_BUNDLE_COPYRIGHT\n"
586 "CMake variables of the same name may be set to affect all targets "
587 "in a directory that do not have each specific property set. "
588 "If a custom Info.plist is specified by this property it may of course "
589 "hard-code all the settings instead of using the target properties.");
591 cm->DefineProperty
592 ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
593 "Specify a custom Info.plist template for a Mac OS X Framework.",
594 "An library target with FRAMEWORK enabled will be built as a "
595 "framework on Mac OS X. "
596 "By default its Info.plist file is created by configuring a template "
597 "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
598 "This property specifies an alternative template file name which "
599 "may be a full path.\n"
600 "The following target properties may be set to specify content to "
601 "be configured into the file:\n"
602 " MACOSX_FRAMEWORK_ICON_FILE\n"
603 " MACOSX_FRAMEWORK_IDENTIFIER\n"
604 " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
605 " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
606 "CMake variables of the same name may be set to affect all targets "
607 "in a directory that do not have each specific property set. "
608 "If a custom Info.plist is specified by this property it may of course "
609 "hard-code all the settings instead of using the target properties.");
611 cm->DefineProperty
612 ("ENABLE_EXPORTS", cmProperty::TARGET,
613 "Specify whether an executable exports symbols for loadable modules.",
614 "Normally an executable does not export any symbols because it is "
615 "the final program. It is possible for an executable to export "
616 "symbols to be used by loadable modules. When this property is "
617 "set to true CMake will allow other targets to \"link\" to the "
618 "executable with the TARGET_LINK_LIBRARIES command. "
619 "On all platforms a target-level dependency on the executable is "
620 "created for targets that link to it. "
621 "For non-DLL platforms the link rule is simply ignored since "
622 "the dynamic loader will automatically bind symbols when the "
623 "module is loaded. "
624 "For DLL platforms an import library will be created for the "
625 "exported symbols and then used for linking. "
626 "All Windows-based systems including Cygwin are DLL platforms.");
628 cm->DefineProperty
629 ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
630 "Specify output directory for Fortran modules provided by the target.",
631 "If the target contains Fortran source files that provide modules "
632 "and the compiler supports a module output directory this specifies "
633 "the directory in which the modules will be placed. "
634 "When this property is not set the modules will be placed in the "
635 "build directory corresponding to the target's source directory. "
636 "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
637 "is created its value is used to initialize this property.");
639 cm->DefineProperty
640 ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
641 "Set Xcode target attributes directly.",
642 "Tell the Xcode generator to set '<an-attribute>' to a given value "
643 "in the generated Xcode project. Ignored on other generators.");
645 cm->DefineProperty
646 ("GENERATOR_FILE_NAME", cmProperty::TARGET,
647 "Generator's file for this target.",
648 "An internal property used by some generators to record the name of "
649 "project or dsp file associated with this target.");
651 cm->DefineProperty
652 ("SOURCES", cmProperty::TARGET,
653 "Source names specified for a target.",
654 "Read-only list of sources specified for a target. "
655 "The names returned are suitable for passing to the "
656 "set_source_files_properties command.");
658 #if 0
659 cm->DefineProperty
660 ("OBJECT_FILES", cmProperty::TARGET,
661 "Used to get the resulting list of object files that make up a "
662 "target.",
663 "This can be used to put object files from one library "
664 "into another library. It is a read only property. It "
665 "converts the source list for the target into a list of full "
666 "paths to object names that will be produced by the target.");
667 #endif
669 #define CM_TARGET_FILE_TYPES_DOC \
670 "There are three kinds of target files that may be built: " \
671 "archive, library, and runtime. " \
672 "Executables are always treated as runtime targets. " \
673 "Static libraries are always treated as archive targets. " \
674 "Module libraries are always treated as library targets. " \
675 "For non-DLL platforms shared libraries are treated as library " \
676 "targets. " \
677 "For DLL platforms the DLL part of a shared library is treated as " \
678 "a runtime target and the corresponding import library is treated as " \
679 "an archive target. " \
680 "All Windows-based systems including Cygwin are DLL platforms."
682 cm->DefineProperty
683 ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
684 "Output directory in which to build ARCHIVE target files.",
685 "This property specifies the directory into which archive target files "
686 "should be built. "
687 CM_TARGET_FILE_TYPES_DOC " "
688 "This property is initialized by the value of the variable "
689 "CMAKE_ARCHIVE_OUTPUT_DIRECTORY if it is set when a target is created.");
690 cm->DefineProperty
691 ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
692 "Output directory in which to build LIBRARY target files.",
693 "This property specifies the directory into which library target files "
694 "should be built. "
695 CM_TARGET_FILE_TYPES_DOC " "
696 "This property is initialized by the value of the variable "
697 "CMAKE_LIBRARY_OUTPUT_DIRECTORY if it is set when a target is created.");
698 cm->DefineProperty
699 ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
700 "Output directory in which to build RUNTIME target files.",
701 "This property specifies the directory into which runtime target files "
702 "should be built. "
703 CM_TARGET_FILE_TYPES_DOC " "
704 "This property is initialized by the value of the variable "
705 "CMAKE_RUNTIME_OUTPUT_DIRECTORY if it is set when a target is created.");
707 // define some properties without documentation
708 cm->DefineProperty("DEBUG_OUTPUT_NAME", cmProperty::TARGET,0,0);
709 cm->DefineProperty("RELEASE_OUTPUT_NAME", cmProperty::TARGET,0,0);
712 void cmTarget::SetType(TargetType type, const char* name)
714 this->Name = name;
715 if(type == cmTarget::INSTALL_FILES ||
716 type == cmTarget::INSTALL_PROGRAMS ||
717 type == cmTarget::INSTALL_DIRECTORY)
719 this->Makefile->
720 IssueMessage(cmake::INTERNAL_ERROR,
721 "SetType called on cmTarget for INSTALL_FILES, "
722 "INSTALL_PROGRAMS, or INSTALL_DIRECTORY ");
723 return;
725 // only add dependency information for library targets
726 this->TargetTypeValue = type;
727 if(this->TargetTypeValue >= STATIC_LIBRARY
728 && this->TargetTypeValue <= MODULE_LIBRARY)
730 this->RecordDependencies = true;
732 else
734 this->RecordDependencies = false;
738 //----------------------------------------------------------------------------
739 void cmTarget::SetMakefile(cmMakefile* mf)
741 // Set our makefile.
742 this->Makefile = mf;
744 // set the cmake instance of the properties
745 this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
747 // Check whether this is a DLL platform.
748 this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
749 this->Makefile->IsOn("CYGWIN") ||
750 this->Makefile->IsOn("MINGW"));
752 // Setup default property values.
753 this->SetPropertyDefault("INSTALL_NAME_DIR", "");
754 this->SetPropertyDefault("INSTALL_RPATH", "");
755 this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
756 this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
757 this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
758 this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
759 this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
760 this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
761 this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
763 // Collect the set of configuration types.
764 std::vector<std::string> configNames;
765 if(const char* configurationTypes =
766 mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
768 cmSystemTools::ExpandListArgument(configurationTypes, configNames);
770 else if(const char* buildType = mf->GetDefinition("CMAKE_BUILD_TYPE"))
772 if(*buildType)
774 configNames.push_back(buildType);
778 // Setup per-configuration property default values.
779 for(std::vector<std::string>::iterator ci = configNames.begin();
780 ci != configNames.end(); ++ci)
782 // Initialize per-configuration name postfix property from the
783 // variable only for non-executable targets. This preserves
784 // compatibility with previous CMake versions in which executables
785 // did not support this variable. Projects may still specify the
786 // property directly. TODO: Make this depend on backwards
787 // compatibility setting.
788 if(this->TargetTypeValue != cmTarget::EXECUTABLE)
790 std::string property = cmSystemTools::UpperCase(*ci);
791 property += "_POSTFIX";
792 this->SetPropertyDefault(property.c_str(), 0);
796 // Save the backtrace of target construction.
797 this->Makefile->GetBacktrace(this->Internal->Backtrace);
799 // Record current policies for later use.
800 this->PolicyStatusCMP0003 =
801 this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
802 this->PolicyStatusCMP0004 =
803 this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
804 this->PolicyStatusCMP0008 =
805 this->Makefile->GetPolicyStatus(cmPolicies::CMP0008);
808 //----------------------------------------------------------------------------
809 cmListFileBacktrace const& cmTarget::GetBacktrace() const
811 return this->Internal->Backtrace;
814 //----------------------------------------------------------------------------
815 bool cmTarget::IsExecutableWithExports()
817 return (this->GetType() == cmTarget::EXECUTABLE &&
818 this->GetPropertyAsBool("ENABLE_EXPORTS"));
821 //----------------------------------------------------------------------------
822 bool cmTarget::IsLinkable()
824 return (this->GetType() == cmTarget::STATIC_LIBRARY ||
825 this->GetType() == cmTarget::SHARED_LIBRARY ||
826 this->GetType() == cmTarget::MODULE_LIBRARY ||
827 this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
828 this->IsExecutableWithExports());
831 //----------------------------------------------------------------------------
832 bool cmTarget::IsFrameworkOnApple()
834 return (this->GetType() == cmTarget::SHARED_LIBRARY &&
835 this->Makefile->IsOn("APPLE") &&
836 this->GetPropertyAsBool("FRAMEWORK"));
839 //----------------------------------------------------------------------------
840 bool cmTarget::IsAppBundleOnApple()
842 return (this->GetType() == cmTarget::EXECUTABLE &&
843 this->Makefile->IsOn("APPLE") &&
844 this->GetPropertyAsBool("MACOSX_BUNDLE"));
847 //----------------------------------------------------------------------------
848 class cmTargetTraceDependencies
850 public:
851 cmTargetTraceDependencies(cmTarget* target, const char* vsProjectFile);
852 void Trace();
853 private:
854 cmTarget* Target;
855 cmMakefile* Makefile;
856 cmGlobalGenerator* GlobalGenerator;
857 std::queue<cmStdString> DependencyQueue;
858 std::set<cmStdString> DependenciesQueued;
859 std::set<cmSourceFile*> TargetSources;
861 void QueueOnce(std::string const& name);
862 void QueueOnce(std::vector<std::string> const& names);
863 void QueueDependencies(cmSourceFile* sf);
864 bool IsUtility(std::string const& dep);
865 void CheckCustomCommand(cmCustomCommand const& cc);
866 void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
869 //----------------------------------------------------------------------------
870 cmTargetTraceDependencies
871 ::cmTargetTraceDependencies(cmTarget* target, const char* vsProjectFile):
872 Target(target)
874 // Convenience.
875 this->Makefile = this->Target->GetMakefile();
876 this->GlobalGenerator =
877 this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
879 // Queue all the source files already specified for the target.
880 std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
881 for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
882 si != sources.end(); ++si)
884 // Queue the source file itself in case it is generated.
885 this->QueueOnce((*si)->GetFullPath());
887 // Queue the dependencies of the source file in case they are
888 // generated.
889 this->QueueDependencies(*si);
891 // Track the sources already known to the target.
892 this->TargetSources.insert(*si);
895 // Queue the VS project file to check dependencies on the rule to
896 // generate it.
897 if(vsProjectFile)
899 this->QueueOnce(vsProjectFile);
902 // Queue pre-build, pre-link, and post-build rule dependencies.
903 this->CheckCustomCommands(this->Target->GetPreBuildCommands());
904 this->CheckCustomCommands(this->Target->GetPreLinkCommands());
905 this->CheckCustomCommands(this->Target->GetPostBuildCommands());
908 //----------------------------------------------------------------------------
909 void cmTargetTraceDependencies::Trace()
911 // Process one dependency at a time until the queue is empty.
912 while(!this->DependencyQueue.empty())
914 // Get the next dependency in from queue.
915 std::string dep = this->DependencyQueue.front();
916 this->DependencyQueue.pop();
918 // Check if we know how to generate this dependency.
919 if(cmSourceFile* sf =
920 this->Makefile->GetSourceFileWithOutput(dep.c_str()))
922 // Queue dependencies needed to generate this file.
923 this->QueueDependencies(sf);
925 // Make sure this file is in the target.
926 if(this->TargetSources.insert(sf).second)
928 this->Target->AddSourceFile(sf);
934 //----------------------------------------------------------------------------
935 void cmTargetTraceDependencies::QueueOnce(std::string const& name)
937 if(this->DependenciesQueued.insert(name).second)
939 this->DependencyQueue.push(name);
943 //----------------------------------------------------------------------------
944 void
945 cmTargetTraceDependencies::QueueOnce(std::vector<std::string> const& names)
947 for(std::vector<std::string>::const_iterator i = names.begin();
948 i != names.end(); ++i)
950 this->QueueOnce(*i);
954 //----------------------------------------------------------------------------
955 bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
957 // Dependencies on targets (utilities) are supposed to be named by
958 // just the target name. However for compatibility we support
959 // naming the output file generated by the target (assuming there is
960 // no output-name property which old code would not have set). In
961 // that case the target name will be the file basename of the
962 // dependency.
963 std::string util = cmSystemTools::GetFilenameName(dep);
964 if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
966 util = cmSystemTools::GetFilenameWithoutLastExtension(util);
969 // Check for a non-imported target with this name.
970 if(cmTarget* t = this->GlobalGenerator->FindTarget(0, util.c_str()))
972 // If we find the target and the dep was given as a full path,
973 // then make sure it was not a full path to something else, and
974 // the fact that the name matched a target was just a coincidence.
975 if(cmSystemTools::FileIsFullPath(dep.c_str()))
977 // This is really only for compatibility so we do not need to
978 // worry about configuration names and output names.
979 std::string tLocation = t->GetLocation(0);
980 tLocation = cmSystemTools::GetFilenamePath(tLocation);
981 std::string depLocation = cmSystemTools::GetFilenamePath(dep);
982 depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
983 tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
984 if(depLocation == tLocation)
986 this->Target->AddUtility(util.c_str());
987 return true;
990 else
992 // The original name of the dependency was not a full path. It
993 // must name a target, so add the target-level dependency.
994 this->Target->AddUtility(util.c_str());
995 return true;
999 // The dependency does not name a target built in this project.
1000 return false;
1003 //----------------------------------------------------------------------------
1004 void cmTargetTraceDependencies::QueueDependencies(cmSourceFile* sf)
1006 // Queue dependency added explicitly by the user.
1007 if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
1009 std::vector<std::string> objDeps;
1010 cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
1011 this->QueueOnce(objDeps);
1014 // Queue dependencies added programatically by commands.
1015 this->QueueOnce(sf->GetDepends());
1017 // Queue custom command dependencies.
1018 if(cmCustomCommand const* cc = sf->GetCustomCommand())
1020 this->CheckCustomCommand(*cc);
1025 //----------------------------------------------------------------------------
1026 void
1027 cmTargetTraceDependencies
1028 ::CheckCustomCommand(cmCustomCommand const& cc)
1030 // Transform command names that reference targets built in this
1031 // project to corresponding target-level dependencies.
1032 for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
1033 cit != cc.GetCommandLines().end(); ++cit)
1035 std::string const& command = *cit->begin();
1036 // Look for a non-imported target with this name.
1037 if(cmTarget* t = this->GlobalGenerator->FindTarget(0, command.c_str()))
1039 if(t->GetType() == cmTarget::EXECUTABLE)
1041 // The command refers to an executable target built in
1042 // this project. Add the target-level dependency to make
1043 // sure the executable is up to date before this custom
1044 // command possibly runs.
1045 this->Target->AddUtility(command.c_str());
1050 // Queue the custom command dependencies.
1051 std::vector<std::string> const& depends = cc.GetDepends();
1052 for(std::vector<std::string>::const_iterator di = depends.begin();
1053 di != depends.end(); ++di)
1055 std::string const& dep = *di;
1056 if(!this->IsUtility(dep))
1058 // The dependency does not name a target and may be a file we
1059 // know how to generate. Queue it.
1060 this->QueueOnce(dep);
1065 //----------------------------------------------------------------------------
1066 void
1067 cmTargetTraceDependencies
1068 ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
1070 for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
1071 cli != commands.end(); ++cli)
1073 this->CheckCustomCommand(*cli);
1077 //----------------------------------------------------------------------------
1078 void cmTarget::TraceDependencies(const char* vsProjectFile)
1080 // Use a helper object to trace the dependencies.
1081 cmTargetTraceDependencies tracer(this, vsProjectFile);
1082 tracer.Trace();
1085 //----------------------------------------------------------------------------
1086 bool cmTarget::FindSourceFiles()
1088 for(std::vector<cmSourceFile*>::const_iterator
1089 si = this->SourceFiles.begin();
1090 si != this->SourceFiles.end(); ++si)
1092 if((*si)->GetFullPath().empty())
1094 return false;
1097 return true;
1100 //----------------------------------------------------------------------------
1101 void cmTarget::AddSources(std::vector<std::string> const& srcs)
1103 for(std::vector<std::string>::const_iterator i = srcs.begin();
1104 i != srcs.end(); ++i)
1106 this->AddSource(i->c_str());
1110 //----------------------------------------------------------------------------
1111 cmSourceFile* cmTarget::AddSource(const char* s)
1113 std::string src = s;
1115 // For backwards compatibility replace varibles in source names.
1116 // This should eventually be removed.
1117 this->Makefile->ExpandVariablesInString(src);
1119 cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
1120 this->AddSourceFile(sf);
1121 return sf;
1124 //----------------------------------------------------------------------------
1125 struct cmTarget::SourceFileFlags
1126 cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
1128 struct SourceFileFlags flags;
1129 this->ConstructSourceFileFlags();
1130 std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
1131 this->Internal->SourceFlagsMap.find(sf);
1132 if(si != this->Internal->SourceFlagsMap.end())
1134 flags = si->second;
1136 return flags;
1139 //----------------------------------------------------------------------------
1140 void cmTarget::ConstructSourceFileFlags()
1142 if(this->Internal->SourceFileFlagsConstructed)
1144 return;
1146 this->Internal->SourceFileFlagsConstructed = true;
1148 // Process public headers to mark the source files.
1149 if(const char* files = this->GetProperty("PUBLIC_HEADER"))
1151 std::vector<std::string> relFiles;
1152 cmSystemTools::ExpandListArgument(files, relFiles);
1153 for(std::vector<std::string>::iterator it = relFiles.begin();
1154 it != relFiles.end(); ++it)
1156 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1158 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1159 flags.MacFolder = "Headers";
1160 flags.Type = cmTarget::SourceFileTypePublicHeader;
1165 // Process private headers after public headers so that they take
1166 // precedence if a file is listed in both.
1167 if(const char* files = this->GetProperty("PRIVATE_HEADER"))
1169 std::vector<std::string> relFiles;
1170 cmSystemTools::ExpandListArgument(files, relFiles);
1171 for(std::vector<std::string>::iterator it = relFiles.begin();
1172 it != relFiles.end(); ++it)
1174 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1176 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1177 flags.MacFolder = "PrivateHeaders";
1178 flags.Type = cmTarget::SourceFileTypePrivateHeader;
1183 // Mark sources listed as resources.
1184 if(const char* files = this->GetProperty("RESOURCE"))
1186 std::vector<std::string> relFiles;
1187 cmSystemTools::ExpandListArgument(files, relFiles);
1188 for(std::vector<std::string>::iterator it = relFiles.begin();
1189 it != relFiles.end(); ++it)
1191 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1193 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1194 flags.MacFolder = "Resources";
1195 flags.Type = cmTarget::SourceFileTypeResource;
1200 // Handle the MACOSX_PACKAGE_LOCATION property on source files that
1201 // were not listed in one of the other lists.
1202 std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
1203 for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
1204 si != sources.end(); ++si)
1206 cmSourceFile* sf = *si;
1207 if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
1209 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1210 if(flags.Type == cmTarget::SourceFileTypeNormal)
1212 flags.MacFolder = location;
1213 if(strcmp(location, "Resources") == 0)
1215 flags.Type = cmTarget::SourceFileTypeResource;
1217 else
1219 flags.Type = cmTarget::SourceFileTypeMacContent;
1226 //----------------------------------------------------------------------------
1227 void cmTarget::MergeLinkLibraries( cmMakefile& mf,
1228 const char *selfname,
1229 const LinkLibraryVectorType& libs )
1231 // Only add on libraries we haven't added on before.
1232 // Assumption: the global link libraries could only grow, never shrink
1233 LinkLibraryVectorType::const_iterator i = libs.begin();
1234 i += this->PrevLinkedLibraries.size();
1235 for( ; i != libs.end(); ++i )
1237 // We call this so that the dependencies get written to the cache
1238 this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
1240 this->PrevLinkedLibraries = libs;
1243 //----------------------------------------------------------------------------
1244 void cmTarget::AddLinkDirectory(const char* d)
1246 // Make sure we don't add unnecessary search directories.
1247 if(this->LinkDirectoriesEmmitted.insert(d).second)
1249 this->LinkDirectories.push_back(d);
1253 //----------------------------------------------------------------------------
1254 const std::vector<std::string>& cmTarget::GetLinkDirectories()
1256 return this->LinkDirectories;
1259 //----------------------------------------------------------------------------
1260 cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
1262 // No configuration is always optimized.
1263 if(!(config && *config))
1265 return cmTarget::OPTIMIZED;
1268 // Get the list of configurations considered to be DEBUG.
1269 std::vector<std::string> const& debugConfigs =
1270 this->Makefile->GetCMakeInstance()->GetDebugConfigs();
1272 // Check if any entry in the list matches this configuration.
1273 std::string configUpper = cmSystemTools::UpperCase(config);
1274 for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
1275 i != debugConfigs.end(); ++i)
1277 if(*i == configUpper)
1279 return cmTarget::DEBUG;
1283 // The current configuration is not a debug configuration.
1284 return cmTarget::OPTIMIZED;
1287 //----------------------------------------------------------------------------
1288 void cmTarget::ClearDependencyInformation( cmMakefile& mf,
1289 const char* target )
1291 // Clear the dependencies. The cache variable must exist iff we are
1292 // recording dependency information for this target.
1293 std::string depname = target;
1294 depname += "_LIB_DEPENDS";
1295 if (this->RecordDependencies)
1297 mf.AddCacheDefinition(depname.c_str(), "",
1298 "Dependencies for target", cmCacheManager::STATIC);
1300 else
1302 if (mf.GetDefinition( depname.c_str() ))
1304 std::string message = "Target ";
1305 message += target;
1306 message += " has dependency information when it shouldn't.\n";
1307 message += "Your cache is probably stale. Please remove the entry\n ";
1308 message += depname;
1309 message += "\nfrom the cache.";
1310 cmSystemTools::Error( message.c_str() );
1315 //----------------------------------------------------------------------------
1316 void cmTarget::AddLinkLibrary(const std::string& lib,
1317 LinkLibraryType llt)
1319 this->AddFramework(lib.c_str(), llt);
1320 cmTarget::LibraryID tmp;
1321 tmp.first = lib;
1322 tmp.second = llt;
1323 this->LinkLibraries.push_back(tmp);
1324 this->OriginalLinkLibraries.push_back(tmp);
1327 //----------------------------------------------------------------------------
1328 bool cmTarget::NameResolvesToFramework(const std::string& libname)
1330 return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
1331 NameResolvesToFramework(libname);
1334 //----------------------------------------------------------------------------
1335 bool cmTarget::AddFramework(const std::string& libname, LinkLibraryType llt)
1337 (void)llt; // TODO: What is this?
1338 if(this->NameResolvesToFramework(libname.c_str()))
1340 std::string frameworkDir = libname;
1341 frameworkDir += "/../";
1342 frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
1343 std::vector<std::string>::iterator i =
1344 std::find(this->Frameworks.begin(),
1345 this->Frameworks.end(), frameworkDir);
1346 if(i == this->Frameworks.end())
1348 this->Frameworks.push_back(frameworkDir);
1350 return true;
1352 return false;
1355 //----------------------------------------------------------------------------
1356 void cmTarget::AddLinkLibrary(cmMakefile& mf,
1357 const char *target, const char* lib,
1358 LinkLibraryType llt)
1360 // Never add a self dependency, even if the user asks for it.
1361 if(strcmp( target, lib ) == 0)
1363 return;
1365 this->AddFramework(lib, llt);
1366 cmTarget::LibraryID tmp;
1367 tmp.first = lib;
1368 tmp.second = llt;
1369 this->LinkLibraries.push_back( tmp );
1370 this->OriginalLinkLibraries.push_back(tmp);
1372 // Add the explicit dependency information for this target. This is
1373 // simply a set of libraries separated by ";". There should always
1374 // be a trailing ";". These library names are not canonical, in that
1375 // they may be "-framework x", "-ly", "/path/libz.a", etc.
1376 // We shouldn't remove duplicates here because external libraries
1377 // may be purposefully duplicated to handle recursive dependencies,
1378 // and we removing one instance will break the link line. Duplicates
1379 // will be appropriately eliminated at emit time.
1380 if(this->RecordDependencies)
1382 std::string targetEntry = target;
1383 targetEntry += "_LIB_DEPENDS";
1384 std::string dependencies;
1385 const char* old_val = mf.GetDefinition( targetEntry.c_str() );
1386 if( old_val )
1388 dependencies += old_val;
1390 switch (llt)
1392 case cmTarget::GENERAL:
1393 dependencies += "general";
1394 break;
1395 case cmTarget::DEBUG:
1396 dependencies += "debug";
1397 break;
1398 case cmTarget::OPTIMIZED:
1399 dependencies += "optimized";
1400 break;
1402 dependencies += ";";
1403 dependencies += lib;
1404 dependencies += ";";
1405 mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
1406 "Dependencies for the target",
1407 cmCacheManager::STATIC );
1412 //----------------------------------------------------------------------------
1413 void
1414 cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
1416 // There are two key parts of the dependency analysis: (1)
1417 // determining the libraries in the link line, and (2) constructing
1418 // the dependency graph for those libraries.
1420 // The latter is done using the cache entries that record the
1421 // dependencies of each library.
1423 // The former is a more thorny issue, since it is not clear how to
1424 // determine if two libraries listed on the link line refer to the a
1425 // single library or not. For example, consider the link "libraries"
1426 // /usr/lib/libtiff.so -ltiff
1427 // Is this one library or two? The solution implemented here is the
1428 // simplest (and probably the only practical) one: two libraries are
1429 // the same if their "link strings" are identical. Thus, the two
1430 // libraries above are considered distinct. This also means that for
1431 // dependency analysis to be effective, the CMake user must specify
1432 // libraries build by his project without using any linker flags or
1433 // file extensions. That is,
1434 // LINK_LIBRARIES( One Two )
1435 // instead of
1436 // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
1437 // The former is probably what most users would do, but it never
1438 // hurts to document the assumptions. :-) Therefore, in the analysis
1439 // code, the "canonical name" of a library is simply its name as
1440 // given to a LINK_LIBRARIES command.
1442 // Also, we will leave the original link line intact; we will just add any
1443 // dependencies that were missing.
1445 // There is a problem with recursive external libraries
1446 // (i.e. libraries with no dependency information that are
1447 // recursively dependent). We must make sure that the we emit one of
1448 // the libraries twice to satisfy the recursion, but we shouldn't
1449 // emit it more times than necessary. In particular, we must make
1450 // sure that handling this improbable case doesn't cost us when
1451 // dealing with the common case of non-recursive libraries. The
1452 // solution is to assume that the recursion is satisfied at one node
1453 // of the dependency tree. To illustrate, assume libA and libB are
1454 // extrenal and mutually dependent. Suppose libX depends on
1455 // libA, and libY on libA and libX. Then
1456 // TARGET_LINK_LIBRARIES( Y X A B A )
1457 // TARGET_LINK_LIBRARIES( X A B A )
1458 // TARGET_LINK_LIBRARIES( Exec Y )
1459 // would result in "-lY -lX -lA -lB -lA". This is the correct way to
1460 // specify the dependencies, since the mutual dependency of A and B
1461 // is resolved *every time libA is specified*.
1463 // Something like
1464 // TARGET_LINK_LIBRARIES( Y X A B A )
1465 // TARGET_LINK_LIBRARIES( X A B )
1466 // TARGET_LINK_LIBRARIES( Exec Y )
1467 // would result in "-lY -lX -lA -lB", and the mutual dependency
1468 // information is lost. This is because in some case (Y), the mutual
1469 // dependency of A and B is listed, while in another other case (X),
1470 // it is not. Depending on which line actually emits A, the mutual
1471 // dependency may or may not be on the final link line. We can't
1472 // handle this pathalogical case cleanly without emitting extra
1473 // libraries for the normal cases. Besides, the dependency
1474 // information for X is wrong anyway: if we build an executable
1475 // depending on X alone, we would not have the mutual dependency on
1476 // A and B resolved.
1478 // IMPROVEMENTS:
1479 // -- The current algorithm will not always pick the "optimal" link line
1480 // when recursive dependencies are present. It will instead break the
1481 // cycles at an aribtrary point. The majority of projects won't have
1482 // cyclic dependencies, so this is probably not a big deal. Note that
1483 // the link line is always correct, just not necessary optimal.
1486 // Expand variables in link library names. This is for backwards
1487 // compatibility with very early CMake versions and should
1488 // eventually be removed. This code was moved here from the end of
1489 // old source list processing code which was called just before this
1490 // method.
1491 for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
1492 p != this->LinkLibraries.end(); ++p)
1494 this->Makefile->ExpandVariablesInString(p->first, true, true);
1498 typedef std::vector< std::string > LinkLine;
1500 // The dependency map.
1501 DependencyMap dep_map;
1503 // 1. Build the dependency graph
1505 for(LinkLibraryVectorType::reverse_iterator lib
1506 = this->LinkLibraries.rbegin();
1507 lib != this->LinkLibraries.rend(); ++lib)
1509 this->GatherDependencies( mf, *lib, dep_map);
1512 // 2. Remove any dependencies that are already satisfied in the original
1513 // link line.
1515 for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
1516 lib != this->LinkLibraries.end(); ++lib)
1518 for( LinkLibraryVectorType::iterator lib2 = lib;
1519 lib2 != this->LinkLibraries.end(); ++lib2)
1521 this->DeleteDependency( dep_map, *lib, *lib2);
1526 // 3. Create the new link line by simply emitting any dependencies that are
1527 // missing. Start from the back and keep adding.
1529 std::set<DependencyMap::key_type> done, visited;
1530 std::vector<DependencyMap::key_type> newLinkLibraries;
1531 for(LinkLibraryVectorType::reverse_iterator lib =
1532 this->LinkLibraries.rbegin();
1533 lib != this->LinkLibraries.rend(); ++lib)
1535 // skip zero size library entries, this may happen
1536 // if a variable expands to nothing.
1537 if (lib->first.size() != 0)
1539 this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
1543 // 4. Add the new libraries to the link line.
1545 for( std::vector<DependencyMap::key_type>::reverse_iterator k =
1546 newLinkLibraries.rbegin();
1547 k != newLinkLibraries.rend(); ++k )
1549 // get the llt from the dep_map
1550 this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
1552 this->LinkLibrariesAnalyzed = true;
1555 //----------------------------------------------------------------------------
1556 void cmTarget::InsertDependency( DependencyMap& depMap,
1557 const LibraryID& lib,
1558 const LibraryID& dep)
1560 depMap[lib].push_back(dep);
1563 //----------------------------------------------------------------------------
1564 void cmTarget::DeleteDependency( DependencyMap& depMap,
1565 const LibraryID& lib,
1566 const LibraryID& dep)
1568 // Make sure there is an entry in the map for lib. If so, delete all
1569 // dependencies to dep. There may be repeated entries because of
1570 // external libraries that are specified multiple times.
1571 DependencyMap::iterator map_itr = depMap.find( lib );
1572 if( map_itr != depMap.end() )
1574 DependencyList& depList = map_itr->second;
1575 DependencyList::iterator itr;
1576 while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
1577 depList.end() )
1579 depList.erase( itr );
1584 //----------------------------------------------------------------------------
1585 void cmTarget::Emit(const LibraryID lib,
1586 const DependencyMap& dep_map,
1587 std::set<LibraryID>& emitted,
1588 std::set<LibraryID>& visited,
1589 DependencyList& link_line )
1591 // It's already been emitted
1592 if( emitted.find(lib) != emitted.end() )
1594 return;
1597 // Emit the dependencies only if this library node hasn't been
1598 // visited before. If it has, then we have a cycle. The recursion
1599 // that got us here should take care of everything.
1601 if( visited.insert(lib).second )
1603 if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
1605 const DependencyList& dep_on = dep_map.find( lib )->second;
1606 DependencyList::const_reverse_iterator i;
1608 // To cater for recursive external libraries, we must emit
1609 // duplicates on this link line *unless* they were emitted by
1610 // some other node, in which case we assume that the recursion
1611 // was resolved then. We making the simplifying assumption that
1612 // any duplicates on a single link line are on purpose, and must
1613 // be preserved.
1615 // This variable will keep track of the libraries that were
1616 // emitted directory from the current node, and not from a
1617 // recursive call. This way, if we come across a library that
1618 // has already been emitted, we repeat it iff it has been
1619 // emitted here.
1620 std::set<DependencyMap::key_type> emitted_here;
1621 for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
1623 if( emitted_here.find(*i) != emitted_here.end() )
1625 // a repeat. Must emit.
1626 emitted.insert(*i);
1627 link_line.push_back( *i );
1629 else
1631 // Emit only if no-one else has
1632 if( emitted.find(*i) == emitted.end() )
1634 // emit dependencies
1635 Emit( *i, dep_map, emitted, visited, link_line );
1636 // emit self
1637 emitted.insert(*i);
1638 emitted_here.insert(*i);
1639 link_line.push_back( *i );
1647 //----------------------------------------------------------------------------
1648 void cmTarget::GatherDependencies( const cmMakefile& mf,
1649 const LibraryID& lib,
1650 DependencyMap& dep_map)
1652 // If the library is already in the dependency map, then it has
1653 // already been fully processed.
1654 if( dep_map.find(lib) != dep_map.end() )
1656 return;
1659 const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
1660 if( deps && strcmp(deps,"") != 0 )
1662 // Make sure this library is in the map, even if it has an empty
1663 // set of dependencies. This distinguishes the case of explicitly
1664 // no dependencies with that of unspecified dependencies.
1665 dep_map[lib];
1667 // Parse the dependency information, which is a set of
1668 // type, library pairs separated by ";". There is always a trailing ";".
1669 cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
1670 std::string depline = deps;
1671 std::string::size_type start = 0;
1672 std::string::size_type end;
1673 end = depline.find( ";", start );
1674 while( end != std::string::npos )
1676 std::string l = depline.substr( start, end-start );
1677 if( l.size() != 0 )
1679 if (l == "debug")
1681 llt = cmTarget::DEBUG;
1683 else if (l == "optimized")
1685 llt = cmTarget::OPTIMIZED;
1687 else if (l == "general")
1689 llt = cmTarget::GENERAL;
1691 else
1693 LibraryID lib2(l,llt);
1694 this->InsertDependency( dep_map, lib, lib2);
1695 this->GatherDependencies( mf, lib2, dep_map);
1696 llt = cmTarget::GENERAL;
1699 start = end+1; // skip the ;
1700 end = depline.find( ";", start );
1702 // cannot depend on itself
1703 this->DeleteDependency( dep_map, lib, lib);
1707 //----------------------------------------------------------------------------
1708 void cmTarget::SetProperty(const char* prop, const char* value)
1710 if (!prop)
1712 return;
1715 this->Properties.SetProperty(prop, value, cmProperty::TARGET);
1717 // If imported information is being set, wipe out cached
1718 // information.
1719 if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
1721 this->ImportInfoMap.clear();
1725 //----------------------------------------------------------------------------
1726 void cmTarget::AppendProperty(const char* prop, const char* value)
1728 if (!prop)
1730 return;
1732 this->Properties.AppendProperty(prop, value, cmProperty::TARGET);
1734 // If imported information is being set, wipe out cached
1735 // information.
1736 if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
1738 this->ImportInfoMap.clear();
1742 //----------------------------------------------------------------------------
1743 static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
1744 const char* prop, const char* value, cmMakefile* context, bool imported
1747 // Look for link-type keywords in the value.
1748 static cmsys::RegularExpression
1749 keys("(^|;)(debug|optimized|general)(;|$)");
1750 if(!keys.find(value))
1752 return;
1755 // Support imported and non-imported versions of the property.
1756 const char* base = (imported?
1757 "IMPORTED_LINK_INTERFACE_LIBRARIES" :
1758 "LINK_INTERFACE_LIBRARIES");
1760 // Report an error.
1761 cmOStringStream e;
1762 e << "Property " << prop << " may not contain link-type keyword \""
1763 << keys.match(2) << "\". "
1764 << "The " << base << " property has a per-configuration "
1765 << "version called " << base << "_<CONFIG> which may be "
1766 << "used to specify per-configuration rules.";
1767 if(!imported)
1769 e << " "
1770 << "Alternatively, an IMPORTED library may be created, configured "
1771 << "with a per-configuration location, and then named in the "
1772 << "property value. "
1773 << "See the add_library command's IMPORTED mode for details."
1774 << "\n"
1775 << "If you have a list of libraries that already contains the "
1776 << "keyword, use the target_link_libraries command with its "
1777 << "LINK_INTERFACE_LIBRARIES mode to set the property. "
1778 << "The command automatically recognizes link-type keywords and sets "
1779 << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
1780 << "properties accordingly.";
1782 context->IssueMessage(cmake::FATAL_ERROR, e.str());
1785 //----------------------------------------------------------------------------
1786 void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
1788 // Certain properties need checking.
1789 if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
1791 if(const char* value = this->GetProperty(prop))
1793 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
1796 if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
1798 if(const char* value = this->GetProperty(prop))
1800 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
1805 //----------------------------------------------------------------------------
1806 void cmTarget::MarkAsImported()
1808 this->IsImportedTarget = true;
1811 //----------------------------------------------------------------------------
1812 std::string cmTarget::GetDirectory(const char* config, bool implib)
1814 if (this->IsImported())
1816 // Return the directory from which the target is imported.
1817 return
1818 cmSystemTools::GetFilenamePath(
1819 this->ImportedGetFullPath(config, implib));
1821 else
1823 // Return the directory in which the target will be built.
1824 if(config && *config)
1826 // Add the configuration's subdirectory.
1827 std::string dir = this->GetOutputDir(implib);
1828 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
1829 AppendDirectoryForConfig("/", config, "", dir);
1830 return dir;
1832 else
1834 return this->GetOutputDir(implib);
1839 //----------------------------------------------------------------------------
1840 const char* cmTarget::GetLocation(const char* config)
1842 if (this->IsImported())
1844 return this->ImportedGetLocation(config);
1846 else
1848 return this->NormalGetLocation(config);
1852 //----------------------------------------------------------------------------
1853 const char* cmTarget::ImportedGetLocation(const char* config)
1855 this->Location = this->ImportedGetFullPath(config, false);
1856 return this->Location.c_str();
1859 //----------------------------------------------------------------------------
1860 const char* cmTarget::NormalGetLocation(const char* config)
1862 // Handle the configuration-specific case first.
1863 if(config)
1865 this->Location = this->GetFullPath(config, false);
1866 return this->Location.c_str();
1869 // Now handle the deprecated build-time configuration location.
1870 this->Location = this->GetDirectory();
1871 if(!this->Location.empty())
1873 this->Location += "/";
1875 const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
1876 if(cfgid && strcmp(cfgid, ".") != 0)
1878 this->Location += cfgid;
1879 this->Location += "/";
1881 if(this->IsFrameworkOnApple())
1883 this->Location += this->GetFullName(config, false);
1884 this->Location += ".framework/Versions/";
1885 this->Location += this->GetFrameworkVersion();
1886 this->Location += "/";
1888 this->Location += this->GetFullName(config, false);
1889 return this->Location.c_str();
1892 //----------------------------------------------------------------------------
1893 void cmTarget::GetTargetVersion(int& major, int& minor)
1895 int patch;
1896 this->GetTargetVersion(false, major, minor, patch);
1899 //----------------------------------------------------------------------------
1900 void cmTarget::GetTargetVersion(bool soversion,
1901 int& major, int& minor, int& patch)
1903 // Set the default values.
1904 major = 0;
1905 minor = 0;
1906 patch = 0;
1908 // Look for a VERSION or SOVERSION property.
1909 const char* prop = soversion? "SOVERSION" : "VERSION";
1910 if(const char* version = this->GetProperty(prop))
1912 // Try to parse the version number and store the results that were
1913 // successfully parsed.
1914 int parsed_major;
1915 int parsed_minor;
1916 int parsed_patch;
1917 switch(sscanf(version, "%d.%d.%d",
1918 &parsed_major, &parsed_minor, &parsed_patch))
1920 case 3: patch = parsed_patch; // no break!
1921 case 2: minor = parsed_minor; // no break!
1922 case 1: major = parsed_major; // no break!
1923 default: break;
1928 //----------------------------------------------------------------------------
1929 const char *cmTarget::GetProperty(const char* prop)
1931 return this->GetProperty(prop, cmProperty::TARGET);
1934 //----------------------------------------------------------------------------
1935 void cmTarget::ComputeObjectFiles()
1937 if (this->IsImported())
1939 return;
1941 #if 0
1942 std::vector<std::string> dirs;
1943 this->Makefile->GetLocalGenerator()->
1944 GetTargetObjectFileDirectories(this,
1945 dirs);
1946 std::string objectFiles;
1947 std::string objExtensionLookup1 = "CMAKE_";
1948 std::string objExtensionLookup2 = "_OUTPUT_EXTENSION";
1950 for(std::vector<std::string>::iterator d = dirs.begin();
1951 d != dirs.end(); ++d)
1953 for(std::vector<cmSourceFile*>::iterator s = this->SourceFiles.begin();
1954 s != this->SourceFiles.end(); ++s)
1956 cmSourceFile* sf = *s;
1957 if(const char* lang = sf->GetLanguage())
1959 std::string lookupObj = objExtensionLookup1 + lang;
1960 lookupObj += objExtensionLookup2;
1961 const char* obj = this->Makefile->GetDefinition(lookupObj.c_str());
1962 if(obj)
1964 if(objectFiles.size())
1966 objectFiles += ";";
1968 std::string objFile = *d;
1969 objFile += "/";
1970 objFile += this->Makefile->GetLocalGenerator()->
1971 GetSourceObjectName(*sf);
1972 objFile += obj;
1973 objectFiles += objFile;
1978 this->SetProperty("OBJECT_FILES", objectFiles.c_str());
1979 #endif
1982 //----------------------------------------------------------------------------
1983 const char *cmTarget::GetProperty(const char* prop,
1984 cmProperty::ScopeType scope)
1986 if(!prop)
1988 return 0;
1991 // Watch for special "computed" properties that are dependent on
1992 // other properties or variables. Always recompute them.
1993 if(this->GetType() == cmTarget::EXECUTABLE ||
1994 this->GetType() == cmTarget::STATIC_LIBRARY ||
1995 this->GetType() == cmTarget::SHARED_LIBRARY ||
1996 this->GetType() == cmTarget::MODULE_LIBRARY ||
1997 this->GetType() == cmTarget::UNKNOWN_LIBRARY)
1999 if(!this->IsImported() && strcmp(prop,"LOCATION") == 0)
2001 // Set the LOCATION property of the target. Note that this
2002 // cannot take into account the per-configuration name of the
2003 // target because the configuration type may not be known at
2004 // CMake time. It is now deprecated as described in the
2005 // documentation.
2006 this->SetProperty("LOCATION", this->GetLocation(0));
2009 // Support "LOCATION_<CONFIG>".
2010 if(strncmp(prop, "LOCATION_", 9) == 0)
2012 std::string configName = prop+9;
2013 this->SetProperty(prop, this->GetLocation(configName.c_str()));
2015 else
2017 // Support "<CONFIG>_LOCATION" for compatiblity.
2018 int len = static_cast<int>(strlen(prop));
2019 if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
2021 std::string configName(prop, len-9);
2022 if(configName != "IMPORTED")
2024 this->SetProperty(prop, this->GetLocation(configName.c_str()));
2030 if (strcmp(prop,"IMPORTED") == 0)
2032 return this->IsImported()?"TRUE":"FALSE";
2035 if(!strcmp(prop,"SOURCES"))
2037 cmOStringStream ss;
2038 const char* sep = "";
2039 for(std::vector<cmSourceFile*>::const_iterator
2040 i = this->SourceFiles.begin();
2041 i != this->SourceFiles.end(); ++i)
2043 // Separate from the previous list entries.
2044 ss << sep;
2045 sep = ";";
2047 // Construct what is known about this source file location.
2048 cmSourceFileLocation const& location = (*i)->GetLocation();
2049 std::string sname = location.GetDirectory();
2050 if(!sname.empty())
2052 sname += "/";
2054 sname += location.GetName();
2056 // Append this list entry.
2057 ss << sname;
2059 this->SetProperty("SOURCES", ss.str().c_str());
2062 // the type property returns what type the target is
2063 if (!strcmp(prop,"TYPE"))
2065 switch( this->GetType() )
2067 case cmTarget::STATIC_LIBRARY:
2068 return "STATIC_LIBRARY";
2069 // break; /* unreachable */
2070 case cmTarget::MODULE_LIBRARY:
2071 return "MODULE_LIBRARY";
2072 // break; /* unreachable */
2073 case cmTarget::SHARED_LIBRARY:
2074 return "SHARED_LIBRARY";
2075 // break; /* unreachable */
2076 case cmTarget::EXECUTABLE:
2077 return "EXECUTABLE";
2078 // break; /* unreachable */
2079 case cmTarget::UTILITY:
2080 return "UTILITY";
2081 // break; /* unreachable */
2082 case cmTarget::GLOBAL_TARGET:
2083 return "GLOBAL_TARGET";
2084 // break; /* unreachable */
2085 case cmTarget::INSTALL_FILES:
2086 return "INSTALL_FILES";
2087 // break; /* unreachable */
2088 case cmTarget::INSTALL_PROGRAMS:
2089 return "INSTALL_PROGRAMS";
2090 // break; /* unreachable */
2091 case cmTarget::INSTALL_DIRECTORY:
2092 return "INSTALL_DIRECTORY";
2093 // break; /* unreachable */
2094 case cmTarget::UNKNOWN_LIBRARY:
2095 return "UNKNOWN_LIBRARY";
2096 // break; /* unreachable */
2098 return 0;
2100 bool chain = false;
2101 const char *retVal =
2102 this->Properties.GetPropertyValue(prop, scope, chain);
2103 if (chain)
2105 return this->Makefile->GetProperty(prop,scope);
2107 return retVal;
2110 //----------------------------------------------------------------------------
2111 bool cmTarget::GetPropertyAsBool(const char* prop)
2113 return cmSystemTools::IsOn(this->GetProperty(prop));
2116 //----------------------------------------------------------------------------
2117 const char* cmTarget::GetLinkerLanguage(cmGlobalGenerator* gg)
2119 if(this->GetProperty("HAS_CXX"))
2121 const_cast<cmTarget*>(this)->SetProperty("LINKER_LANGUAGE", "CXX");
2123 const char* linkerLang = this->GetProperty("LINKER_LANGUAGE");
2124 if (linkerLang==0)
2126 // if the property has not yet been set, collect all languages in the
2127 // target and then find the language with the highest preference value
2128 std::set<cmStdString> languages;
2129 this->GetLanguages(languages);
2131 std::string linkerLangList; // only used for the error message
2132 int maxLinkerPref = 0;
2133 bool multiplePreferedLanguages = false;
2134 for(std::set<cmStdString>::const_iterator sit = languages.begin();
2135 sit != languages.end(); ++sit)
2137 int linkerPref = gg->GetLinkerPreference(sit->c_str());
2138 if ((linkerPref > maxLinkerPref) || (linkerLang==0))
2140 maxLinkerPref = linkerPref;
2141 linkerLang = sit->c_str();
2142 linkerLangList = *sit;
2143 multiplePreferedLanguages = false;
2145 else if (linkerPref == maxLinkerPref)
2147 linkerLangList += "; ";
2148 linkerLangList += *sit;
2149 multiplePreferedLanguages = true;
2153 if (linkerLang!=0)
2155 const_cast<cmTarget*>(this)->SetProperty("LINKER_LANGUAGE", linkerLang);
2157 if (multiplePreferedLanguages)
2159 cmOStringStream err;
2160 err << "Error: Target " << this->Name << " contains multiple languages "
2161 << "with the highest linker preference (" << maxLinkerPref << "): "
2162 << linkerLangList << "\n"
2163 << "You must set the LINKER_LANGUAGE property for this target.";
2164 cmSystemTools::Error(err.str().c_str());
2167 return this->GetProperty("LINKER_LANGUAGE");
2170 //----------------------------------------------------------------------------
2171 const char* cmTarget::GetCreateRuleVariable()
2173 switch(this->GetType())
2175 case cmTarget::STATIC_LIBRARY:
2176 return "_CREATE_STATIC_LIBRARY";
2177 case cmTarget::SHARED_LIBRARY:
2178 return "_CREATE_SHARED_LIBRARY";
2179 case cmTarget::MODULE_LIBRARY:
2180 return "_CREATE_SHARED_MODULE";
2181 case cmTarget::EXECUTABLE:
2182 return "_LINK_EXECUTABLE";
2183 default:
2184 break;
2186 return "";
2189 //----------------------------------------------------------------------------
2190 const char* cmTarget::GetSuffixVariableInternal(TargetType type,
2191 bool implib)
2193 switch(type)
2195 case cmTarget::STATIC_LIBRARY:
2196 return "CMAKE_STATIC_LIBRARY_SUFFIX";
2197 case cmTarget::SHARED_LIBRARY:
2198 return (implib
2199 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2200 : "CMAKE_SHARED_LIBRARY_SUFFIX");
2201 case cmTarget::MODULE_LIBRARY:
2202 return (implib
2203 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2204 : "CMAKE_SHARED_MODULE_SUFFIX");
2205 case cmTarget::EXECUTABLE:
2206 return (implib
2207 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2208 : "CMAKE_EXECUTABLE_SUFFIX");
2209 default:
2210 break;
2212 return "";
2216 //----------------------------------------------------------------------------
2217 const char* cmTarget::GetPrefixVariableInternal(TargetType type,
2218 bool implib)
2220 switch(type)
2222 case cmTarget::STATIC_LIBRARY:
2223 return "CMAKE_STATIC_LIBRARY_PREFIX";
2224 case cmTarget::SHARED_LIBRARY:
2225 return (implib
2226 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2227 : "CMAKE_SHARED_LIBRARY_PREFIX");
2228 case cmTarget::MODULE_LIBRARY:
2229 return (implib
2230 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2231 : "CMAKE_SHARED_MODULE_PREFIX");
2232 case cmTarget::EXECUTABLE:
2233 return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
2234 default:
2235 break;
2237 return "";
2240 //----------------------------------------------------------------------------
2241 std::string cmTarget::GetPDBName(const char* config)
2243 std::string prefix;
2244 std::string base;
2245 std::string suffix;
2246 this->GetFullNameInternal(this->GetType(), config, false,
2247 prefix, base, suffix);
2248 return prefix+base+".pdb";
2251 //----------------------------------------------------------------------------
2252 std::string cmTarget::GetSOName(const char* config)
2254 if(this->IsImported())
2256 // Lookup the imported soname.
2257 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
2259 if(info->NoSOName)
2261 // The imported library has no builtin soname so the name
2262 // searched at runtime will be just the filename.
2263 return cmSystemTools::GetFilenameName(info->Location);
2265 else
2267 // Use the soname given if any.
2268 return info->SOName;
2271 else
2273 return "";
2276 else
2278 // Compute the soname that will be built.
2279 std::string name;
2280 std::string soName;
2281 std::string realName;
2282 std::string impName;
2283 std::string pdbName;
2284 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
2285 return soName;
2289 //----------------------------------------------------------------------------
2290 bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
2292 if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
2294 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
2296 return info->NoSOName;
2299 return false;
2302 //----------------------------------------------------------------------------
2303 std::string cmTarget::NormalGetRealName(const char* config)
2305 // This should not be called for imported targets.
2306 // TODO: Split cmTarget into a class hierarchy to get compile-time
2307 // enforcement of the limited imported target API.
2308 if(this->IsImported())
2310 std::string msg = "NormalGetRealName called on imported target: ";
2311 msg += this->GetName();
2312 this->GetMakefile()->
2313 IssueMessage(cmake::INTERNAL_ERROR,
2314 msg.c_str());
2317 if(this->GetType() == cmTarget::EXECUTABLE)
2319 // Compute the real name that will be built.
2320 std::string name;
2321 std::string realName;
2322 std::string impName;
2323 std::string pdbName;
2324 this->GetExecutableNames(name, realName, impName, pdbName, config);
2325 return realName;
2327 else
2329 // Compute the real name that will be built.
2330 std::string name;
2331 std::string soName;
2332 std::string realName;
2333 std::string impName;
2334 std::string pdbName;
2335 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
2336 return realName;
2340 //----------------------------------------------------------------------------
2341 std::string cmTarget::GetFullName(const char* config, bool implib)
2343 if(this->IsImported())
2345 return this->GetFullNameImported(config, implib);
2347 else
2349 return this->GetFullNameInternal(this->GetType(), config, implib);
2353 //----------------------------------------------------------------------------
2354 std::string cmTarget::GetFullNameImported(const char* config, bool implib)
2356 return cmSystemTools::GetFilenameName(
2357 this->ImportedGetFullPath(config, implib));
2360 //----------------------------------------------------------------------------
2361 void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
2362 std::string& suffix, const char* config,
2363 bool implib)
2365 this->GetFullNameInternal(this->GetType(), config, implib,
2366 prefix, base, suffix);
2369 //----------------------------------------------------------------------------
2370 std::string cmTarget::GetFullPath(const char* config, bool implib,
2371 bool realname)
2373 if(this->IsImported())
2375 return this->ImportedGetFullPath(config, implib);
2377 else
2379 return this->NormalGetFullPath(config, implib, realname);
2383 //----------------------------------------------------------------------------
2384 std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
2385 bool realname)
2387 // Start with the output directory for the target.
2388 std::string fpath = this->GetDirectory(config, implib);
2389 fpath += "/";
2391 if(this->IsFrameworkOnApple())
2393 fpath += this->GetFullName(config, false);
2394 fpath += ".framework/Versions/";
2395 fpath += this->GetFrameworkVersion();
2396 fpath += "/";
2399 // Add the full name of the target.
2400 if(implib)
2402 fpath += this->GetFullName(config, true);
2404 else if(realname)
2406 fpath += this->NormalGetRealName(config);
2408 else
2410 fpath += this->GetFullName(config, false);
2412 return fpath;
2415 //----------------------------------------------------------------------------
2416 std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
2418 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
2420 if(implib)
2422 return info->ImportLibrary;
2424 else
2426 return info->Location;
2429 else
2431 std::string result = this->GetName();
2432 result += "-NOTFOUND";
2433 return result;
2437 //----------------------------------------------------------------------------
2438 std::string
2439 cmTarget::GetFullNameInternal(TargetType type, const char* config,
2440 bool implib)
2442 std::string prefix;
2443 std::string base;
2444 std::string suffix;
2445 this->GetFullNameInternal(type, config, implib, prefix, base, suffix);
2446 return prefix+base+suffix;
2449 //----------------------------------------------------------------------------
2450 void cmTarget::GetFullNameInternal(TargetType type,
2451 const char* config,
2452 bool implib,
2453 std::string& outPrefix,
2454 std::string& outBase,
2455 std::string& outSuffix)
2457 // Use just the target name for non-main target types.
2458 if(type != cmTarget::STATIC_LIBRARY &&
2459 type != cmTarget::SHARED_LIBRARY &&
2460 type != cmTarget::MODULE_LIBRARY &&
2461 type != cmTarget::EXECUTABLE)
2463 outPrefix = "";
2464 outBase = this->GetName();
2465 outSuffix = "";
2466 return;
2469 // Return an empty name for the import library if this platform
2470 // does not support import libraries.
2471 if(implib &&
2472 !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
2474 outPrefix = "";
2475 outBase = "";
2476 outSuffix = "";
2477 return;
2480 // The implib option is only allowed for shared libraries, module
2481 // libraries, and executables.
2482 if(type != cmTarget::SHARED_LIBRARY &&
2483 type != cmTarget::MODULE_LIBRARY &&
2484 type != cmTarget::EXECUTABLE)
2486 implib = false;
2489 // Compute the full name for main target types.
2490 const char* targetPrefix = (implib
2491 ? this->GetProperty("IMPORT_PREFIX")
2492 : this->GetProperty("PREFIX"));
2493 const char* targetSuffix = (implib
2494 ? this->GetProperty("IMPORT_SUFFIX")
2495 : this->GetProperty("SUFFIX"));
2496 const char* configPostfix = 0;
2497 if(config && *config)
2499 std::string configProp = cmSystemTools::UpperCase(config);
2500 configProp += "_POSTFIX";
2501 configPostfix = this->GetProperty(configProp.c_str());
2502 // Mac application bundles and frameworks have no postfix.
2503 if(configPostfix &&
2504 (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
2506 configPostfix = 0;
2509 const char* prefixVar = this->GetPrefixVariableInternal(type, implib);
2510 const char* suffixVar = this->GetSuffixVariableInternal(type, implib);
2511 const char* ll =
2512 this->GetLinkerLanguage(
2513 this->Makefile->GetLocalGenerator()->GetGlobalGenerator());
2514 // first try language specific suffix
2515 if(ll)
2517 if(!targetSuffix && suffixVar && *suffixVar)
2519 std::string langSuff = suffixVar + std::string("_") + ll;
2520 targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
2522 if(!targetPrefix && prefixVar && *prefixVar)
2524 std::string langPrefix = prefixVar + std::string("_") + ll;
2525 targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
2529 // if there is no prefix on the target use the cmake definition
2530 if(!targetPrefix && prefixVar)
2532 targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
2534 // if there is no suffix on the target use the cmake definition
2535 if(!targetSuffix && suffixVar)
2537 targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
2540 // frameworks do not have a prefix or a suffix
2541 if(this->IsFrameworkOnApple())
2543 targetPrefix = 0;
2544 targetSuffix = 0;
2547 // Begin the final name with the prefix.
2548 outPrefix = targetPrefix?targetPrefix:"";
2550 // Append the target name or property-specified name.
2551 const char* outName = 0;
2552 if(config && *config)
2554 std::string configProp = cmSystemTools::UpperCase(config);
2555 configProp += "_OUTPUT_NAME";
2556 outName = this->GetProperty(configProp.c_str());
2558 if(!outName)
2560 outName = this->GetProperty("OUTPUT_NAME");
2562 if(outName)
2564 outBase = outName;
2566 else
2568 outBase = this->GetName();
2571 // Append the per-configuration postfix.
2572 outBase += configPostfix?configPostfix:"";
2574 // Name shared libraries with their version number on some platforms.
2575 if(const char* version = this->GetProperty("VERSION"))
2577 if(type == cmTarget::SHARED_LIBRARY && !implib &&
2578 this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
2580 outBase += "-";
2581 outBase += version;
2585 // Append the suffix.
2586 outSuffix = targetSuffix?targetSuffix:"";
2589 //----------------------------------------------------------------------------
2590 void cmTarget::GetLibraryNames(std::string& name,
2591 std::string& soName,
2592 std::string& realName,
2593 std::string& impName,
2594 std::string& pdbName,
2595 const char* config)
2597 // Get the names based on the real type of the library.
2598 this->GetLibraryNamesInternal(name, soName, realName, impName, pdbName,
2599 this->GetType(), config);
2602 //----------------------------------------------------------------------------
2603 void cmTarget::GetLibraryCleanNames(std::string& staticName,
2604 std::string& sharedName,
2605 std::string& sharedSOName,
2606 std::string& sharedRealName,
2607 std::string& importName,
2608 std::string& pdbName,
2609 const char* config)
2611 // Get the name as if this were a static library.
2612 std::string soName;
2613 std::string realName;
2614 std::string impName;
2615 this->GetLibraryNamesInternal(staticName, soName, realName, impName,
2616 pdbName, cmTarget::STATIC_LIBRARY, config);
2618 // Get the names as if this were a shared library.
2619 if(this->GetType() == cmTarget::STATIC_LIBRARY)
2621 // Since the real type is static then the user either specified
2622 // STATIC or did not specify a type. In the former case the
2623 // shared library will never be present. In the latter case the
2624 // type will never be MODULE. Either way the only names that
2625 // might have to be cleaned are the shared library names.
2626 this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
2627 importName, pdbName,
2628 cmTarget::SHARED_LIBRARY, config);
2630 else
2632 // Use the name of the real type of the library (shared or module).
2633 this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
2634 importName, pdbName, this->GetType(),
2635 config);
2639 //----------------------------------------------------------------------------
2640 void cmTarget::GetLibraryNamesInternal(std::string& name,
2641 std::string& soName,
2642 std::string& realName,
2643 std::string& impName,
2644 std::string& pdbName,
2645 TargetType type,
2646 const char* config)
2648 // This should not be called for imported targets.
2649 // TODO: Split cmTarget into a class hierarchy to get compile-time
2650 // enforcement of the limited imported target API.
2651 if(this->IsImported())
2653 std::string msg = "GetLibraryNamesInternal called on imported target: ";
2654 msg += this->GetName();
2655 this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
2656 msg.c_str());
2657 return;
2660 // Construct the name of the soname flag variable for this language.
2661 const char* ll =
2662 this->GetLinkerLanguage(
2663 this->Makefile->GetLocalGenerator()->GetGlobalGenerator());
2664 std::string sonameFlag = "CMAKE_SHARED_LIBRARY_SONAME";
2665 if(ll)
2667 sonameFlag += "_";
2668 sonameFlag += ll;
2670 sonameFlag += "_FLAG";
2672 // Check for library version properties.
2673 const char* version = this->GetProperty("VERSION");
2674 const char* soversion = this->GetProperty("SOVERSION");
2675 if((type != cmTarget::SHARED_LIBRARY && type != cmTarget::MODULE_LIBRARY) ||
2676 !this->Makefile->GetDefinition(sonameFlag.c_str()) ||
2677 this->IsFrameworkOnApple())
2679 // Versioning is supported only for shared libraries and modules,
2680 // and then only when the platform supports an soname flag.
2681 version = 0;
2682 soversion = 0;
2684 if(version && !soversion)
2686 // The soversion must be set if the library version is set. Use
2687 // the library version as the soversion.
2688 soversion = version;
2691 // Get the components of the library name.
2692 std::string prefix;
2693 std::string base;
2694 std::string suffix;
2695 this->GetFullNameInternal(type, config, false, prefix, base, suffix);
2697 // The library name.
2698 name = prefix+base+suffix;
2700 // The library's soname.
2701 #if defined(__APPLE__)
2702 soName = prefix+base;
2703 #else
2704 soName = name;
2705 #endif
2706 if(soversion)
2708 soName += ".";
2709 soName += soversion;
2711 #if defined(__APPLE__)
2712 soName += suffix;
2713 #endif
2715 // The library's real name on disk.
2716 #if defined(__APPLE__)
2717 realName = prefix+base;
2718 #else
2719 realName = name;
2720 #endif
2721 if(version)
2723 realName += ".";
2724 realName += version;
2726 else if(soversion)
2728 realName += ".";
2729 realName += soversion;
2731 #if defined(__APPLE__)
2732 realName += suffix;
2733 #endif
2735 // The import library name.
2736 if(type == cmTarget::SHARED_LIBRARY ||
2737 type == cmTarget::MODULE_LIBRARY)
2739 impName = this->GetFullNameInternal(type, config, true);
2741 else
2743 impName = "";
2746 // The program database file name.
2747 pdbName = prefix+base+".pdb";
2750 //----------------------------------------------------------------------------
2751 void cmTarget::GetExecutableNames(std::string& name,
2752 std::string& realName,
2753 std::string& impName,
2754 std::string& pdbName,
2755 const char* config)
2757 // Get the names based on the real type of the executable.
2758 this->GetExecutableNamesInternal(name, realName, impName, pdbName,
2759 this->GetType(), config);
2762 //----------------------------------------------------------------------------
2763 void cmTarget::GetExecutableCleanNames(std::string& name,
2764 std::string& realName,
2765 std::string& impName,
2766 std::string& pdbName,
2767 const char* config)
2769 // Get the name and versioned name of this executable.
2770 this->GetExecutableNamesInternal(name, realName, impName, pdbName,
2771 cmTarget::EXECUTABLE, config);
2774 //----------------------------------------------------------------------------
2775 void cmTarget::GetExecutableNamesInternal(std::string& name,
2776 std::string& realName,
2777 std::string& impName,
2778 std::string& pdbName,
2779 TargetType type,
2780 const char* config)
2782 // This should not be called for imported targets.
2783 // TODO: Split cmTarget into a class hierarchy to get compile-time
2784 // enforcement of the limited imported target API.
2785 if(this->IsImported())
2787 std::string msg =
2788 "GetExecutableNamesInternal called on imported target: ";
2789 msg += this->GetName();
2790 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
2793 // This versioning is supported only for executables and then only
2794 // when the platform supports symbolic links.
2795 #if defined(_WIN32) && !defined(__CYGWIN__)
2796 const char* version = 0;
2797 #else
2798 // Check for executable version properties.
2799 const char* version = this->GetProperty("VERSION");
2800 if(type != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
2802 version = 0;
2804 #endif
2806 // Get the components of the executable name.
2807 std::string prefix;
2808 std::string base;
2809 std::string suffix;
2810 this->GetFullNameInternal(type, config, false, prefix, base, suffix);
2812 // The executable name.
2813 name = prefix+base+suffix;
2815 // The executable's real name on disk.
2816 #if defined(__CYGWIN__)
2817 realName = prefix+base;
2818 #else
2819 realName = name;
2820 #endif
2821 if(version)
2823 realName += "-";
2824 realName += version;
2826 #if defined(__CYGWIN__)
2827 realName += suffix;
2828 #endif
2830 // The import library name.
2831 impName = this->GetFullNameInternal(type, config, true);
2833 // The program database file name.
2834 pdbName = prefix+base+".pdb";
2837 //----------------------------------------------------------------------------
2838 void cmTarget::GenerateTargetManifest(const char* config)
2840 cmMakefile* mf = this->Makefile;
2841 cmLocalGenerator* lg = mf->GetLocalGenerator();
2842 cmGlobalGenerator* gg = lg->GetGlobalGenerator();
2844 // Get the names.
2845 std::string name;
2846 std::string soName;
2847 std::string realName;
2848 std::string impName;
2849 std::string pdbName;
2850 if(this->GetType() == cmTarget::EXECUTABLE)
2852 this->GetExecutableNames(name, realName, impName, pdbName, config);
2854 else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
2855 this->GetType() == cmTarget::SHARED_LIBRARY ||
2856 this->GetType() == cmTarget::MODULE_LIBRARY)
2858 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
2860 else
2862 return;
2865 // Get the directory.
2866 std::string dir = this->GetDirectory(config, false);
2868 // Add each name.
2869 std::string f;
2870 if(!name.empty())
2872 f = dir;
2873 f += "/";
2874 f += name;
2875 gg->AddToManifest(config? config:"", f);
2877 if(!soName.empty())
2879 f = dir;
2880 f += "/";
2881 f += soName;
2882 gg->AddToManifest(config? config:"", f);
2884 if(!realName.empty())
2886 f = dir;
2887 f += "/";
2888 f += realName;
2889 gg->AddToManifest(config? config:"", f);
2891 if(!pdbName.empty())
2893 f = dir;
2894 f += "/";
2895 f += pdbName;
2896 gg->AddToManifest(config? config:"", f);
2898 if(!impName.empty())
2900 f = this->GetDirectory(config, true);
2901 f += "/";
2902 f += impName;
2903 gg->AddToManifest(config? config:"", f);
2907 //----------------------------------------------------------------------------
2908 void cmTarget::SetPropertyDefault(const char* property,
2909 const char* default_value)
2911 // Compute the name of the variable holding the default value.
2912 std::string var = "CMAKE_";
2913 var += property;
2915 if(const char* value = this->Makefile->GetDefinition(var.c_str()))
2917 this->SetProperty(property, value);
2919 else if(default_value)
2921 this->SetProperty(property, default_value);
2925 //----------------------------------------------------------------------------
2926 bool cmTarget::HaveBuildTreeRPATH()
2928 return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
2929 !this->LinkLibraries.empty());
2932 //----------------------------------------------------------------------------
2933 bool cmTarget::HaveInstallTreeRPATH()
2935 const char* install_rpath = this->GetProperty("INSTALL_RPATH");
2936 return install_rpath && *install_rpath;
2939 //----------------------------------------------------------------------------
2940 bool cmTarget::NeedRelinkBeforeInstall()
2942 // Only executables and shared libraries can have an rpath and may
2943 // need relinking.
2944 if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
2945 this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
2946 this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
2948 return false;
2951 // If there is no install location this target will not be installed
2952 // and therefore does not need relinking.
2953 if(!this->GetHaveInstallRule())
2955 return false;
2958 // If skipping all rpaths completely then no relinking is needed.
2959 if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
2961 return false;
2964 // If building with the install-tree rpath no relinking is needed.
2965 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
2967 return false;
2970 // If chrpath is going to be used no relinking is needed.
2971 if(this->IsChrpathUsed())
2973 return false;
2976 // Check for rpath support on this platform.
2977 if(const char* ll = this->GetLinkerLanguage(
2978 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()))
2980 std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
2981 flagVar += ll;
2982 flagVar += "_FLAG";
2983 if(!this->Makefile->IsSet(flagVar.c_str()))
2985 // There is no rpath support on this platform so nothing needs
2986 // relinking.
2987 return false;
2990 else
2992 // No linker language is known. This error will be reported by
2993 // other code.
2994 return false;
2997 // If either a build or install tree rpath is set then the rpath
2998 // will likely change between the build tree and install tree and
2999 // this target must be relinked.
3000 return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
3003 //----------------------------------------------------------------------------
3004 std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
3005 bool for_xcode)
3007 // If building directly for installation then the build tree install_name
3008 // is the same as the install tree.
3009 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3011 return GetInstallNameDirForInstallTree(config, for_xcode);
3014 // Use the build tree directory for the target.
3015 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3016 !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
3017 !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
3019 std::string dir = this->GetDirectory(config);
3020 dir += "/";
3021 if(this->IsFrameworkOnApple() && !for_xcode)
3023 dir += this->GetFullName(config, false);
3024 dir += ".framework/Versions/";
3025 dir += this->GetFrameworkVersion();
3026 dir += "/";
3028 return dir;
3030 else
3032 return "";
3036 //----------------------------------------------------------------------------
3037 std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
3038 bool for_xcode)
3040 // Lookup the target property.
3041 const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
3042 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3043 !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
3044 install_name_dir && *install_name_dir)
3046 std::string dir = install_name_dir;
3047 dir += "/";
3048 if(this->IsFrameworkOnApple() && !for_xcode)
3050 dir += this->GetFullName(config, false);
3051 dir += ".framework/Versions/";
3052 dir += this->GetFrameworkVersion();
3053 dir += "/";
3055 return dir;
3057 else
3059 return "";
3063 //----------------------------------------------------------------------------
3064 std::string cmTarget::GetOutputDir(bool implib)
3066 // The implib option is only allowed for shared libraries, module
3067 // libraries, and executables.
3068 if(this->GetType() != cmTarget::SHARED_LIBRARY &&
3069 this->GetType() != cmTarget::MODULE_LIBRARY &&
3070 this->GetType() != cmTarget::EXECUTABLE)
3072 implib = false;
3075 // Sanity check. Only generators on platforms supporting import
3076 // libraries should be asking for the import library output
3077 // directory.
3078 if(implib &&
3079 !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
3081 std::string msg = "GetOutputDir, imlib set but there is no "
3082 "CMAKE_IMPORT_LIBRARY_SUFFIX for target: ";
3083 msg += this->GetName();
3084 this->GetMakefile()->
3085 IssueMessage(cmake::INTERNAL_ERROR,
3086 msg.c_str());
3088 if(implib && !this->DLLPlatform)
3090 std::string msg = "implib set for platform that does not "
3091 " support DLL's for target: ";
3092 msg += this->GetName();
3093 this->GetMakefile()->
3094 IssueMessage(cmake::INTERNAL_ERROR,
3095 msg.c_str());
3098 return this->ComputeBaseOutputDir(implib);
3101 //----------------------------------------------------------------------------
3102 std::string const& cmTarget::ComputeBaseOutputDir(bool implib)
3104 // Select whether we are constructing the directory for the main
3105 // target or the import library.
3106 std::string& out = implib? this->BaseOutputDirImplib : this->BaseOutputDir;
3108 // Return immediately if the directory has already been computed.
3109 if(!out.empty())
3111 return out;
3114 // Look for a target property defining the target output directory
3115 // based on the target type.
3116 const char* propertyName = 0;
3117 switch(this->GetType())
3119 case cmTarget::SHARED_LIBRARY:
3121 // For non-DLL platforms shared libraries are treated as
3122 // library targets. For DLL platforms the DLL part of a
3123 // shared library is treated as a runtime target and the
3124 // corresponding import library is treated as an archive
3125 // target.
3126 if(this->DLLPlatform)
3128 if(implib)
3130 propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
3132 else
3134 propertyName = "RUNTIME_OUTPUT_DIRECTORY";
3137 else
3139 propertyName = "LIBRARY_OUTPUT_DIRECTORY";
3141 } break;
3142 case cmTarget::STATIC_LIBRARY:
3144 // Static libraries are always treated as archive targets.
3145 propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
3146 } break;
3147 case cmTarget::MODULE_LIBRARY:
3149 // Module libraries are always treated as library targets.
3150 // Module import libraries are treated as archive targets.
3151 if(implib)
3153 propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
3155 else
3157 propertyName = "LIBRARY_OUTPUT_DIRECTORY";
3159 } break;
3160 case cmTarget::EXECUTABLE:
3162 // Executables are always treated as runtime targets.
3163 // Executable import libraries are treated as archive targets.
3164 if(implib)
3166 propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
3168 else
3170 propertyName = "RUNTIME_OUTPUT_DIRECTORY";
3172 } break;
3173 default: break;
3176 // Select an output directory.
3177 if(const char* outdir = this->GetProperty(propertyName))
3179 // Use the user-specified output directory.
3180 out = outdir;
3182 else if(this->GetType() == cmTarget::EXECUTABLE)
3184 // Lookup the output path for executables.
3185 out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
3187 else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
3188 this->GetType() == cmTarget::SHARED_LIBRARY ||
3189 this->GetType() == cmTarget::MODULE_LIBRARY)
3191 // Lookup the output path for libraries.
3192 out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
3194 if(out.empty())
3196 // Default to the current output directory.
3197 out = ".";
3200 // Convert the output path to a full path in case it is
3201 // specified as a relative path. Treat a relative path as
3202 // relative to the current output directory for this makefile.
3203 out = (cmSystemTools::CollapseFullPath
3204 (out.c_str(), this->Makefile->GetStartOutputDirectory()));
3205 return out;
3208 //----------------------------------------------------------------------------
3209 std::string cmTarget::GetFrameworkVersion()
3211 if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
3213 return fversion;
3215 else if(const char* tversion = this->GetProperty("VERSION"))
3217 return tversion;
3219 else
3221 return "A";
3225 //----------------------------------------------------------------------------
3226 const char* cmTarget::GetExportMacro()
3228 // Define the symbol for targets that export symbols.
3229 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3230 this->GetType() == cmTarget::MODULE_LIBRARY ||
3231 this->IsExecutableWithExports())
3233 if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
3235 this->ExportMacro = custom_export_name;
3237 else
3239 std::string in = this->GetName();
3240 in += "_EXPORTS";
3241 this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
3243 return this->ExportMacro.c_str();
3245 else
3247 return 0;
3251 //----------------------------------------------------------------------------
3252 void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
3254 for(std::vector<cmSourceFile*>::const_iterator
3255 i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
3257 if(const char* lang = (*i)->GetLanguage())
3259 languages.insert(lang);
3264 //----------------------------------------------------------------------------
3265 bool cmTarget::IsChrpathUsed()
3267 #if defined(CMAKE_USE_ELF_PARSER)
3268 // Only certain target types have an rpath.
3269 if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
3270 this->GetType() == cmTarget::MODULE_LIBRARY ||
3271 this->GetType() == cmTarget::EXECUTABLE))
3273 return false;
3276 // If the target will not be installed we do not need to change its
3277 // rpath.
3278 if(!this->GetHaveInstallRule())
3280 return false;
3283 // Skip chrpath if skipping rpath altogether.
3284 if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
3286 return false;
3289 // Skip chrpath if it does not need to be changed at install time.
3290 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3292 return false;
3295 // Allow the user to disable builtin chrpath explicitly.
3296 if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
3298 return false;
3301 // Enable if the rpath flag uses a separator and the target uses ELF
3302 // binaries.
3303 if(const char* ll = this->GetLinkerLanguage(
3304 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()))
3306 std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
3307 sepVar += ll;
3308 sepVar += "_FLAG_SEP";
3309 const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
3310 if(sep && *sep)
3312 // TODO: Add ELF check to ABI detection and get rid of
3313 // CMAKE_EXECUTABLE_FORMAT.
3314 if(const char* fmt =
3315 this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
3317 return strcmp(fmt, "ELF") == 0;
3321 #endif
3322 return false;
3325 //----------------------------------------------------------------------------
3326 cmTarget::ImportInfo const*
3327 cmTarget::GetImportInfo(const char* config)
3329 // There is no imported information for non-imported targets.
3330 if(!this->IsImported())
3332 return 0;
3335 // Lookup/compute/cache the import information for this
3336 // configuration.
3337 std::string config_upper;
3338 if(config && *config)
3340 config_upper = cmSystemTools::UpperCase(config);
3342 else
3344 config_upper = "NOCONFIG";
3346 ImportInfoMapType::const_iterator i =
3347 this->ImportInfoMap.find(config_upper);
3348 if(i == this->ImportInfoMap.end())
3350 ImportInfo info;
3351 this->ComputeImportInfo(config_upper, info);
3352 ImportInfoMapType::value_type entry(config_upper, info);
3353 i = this->ImportInfoMap.insert(entry).first;
3356 // If the location is empty then the target is not available for
3357 // this configuration.
3358 if(i->second.Location.empty())
3360 return 0;
3363 // Return the import information.
3364 return &i->second;
3367 //----------------------------------------------------------------------------
3368 void cmTarget::ComputeImportInfo(std::string const& desired_config,
3369 ImportInfo& info)
3371 // This method finds information about an imported target from its
3372 // properties. The "IMPORTED_" namespace is reserved for properties
3373 // defined by the project exporting the target.
3375 // Initialize members.
3376 info.NoSOName = false;
3378 // Track the configuration-specific property suffix.
3379 std::string suffix = "_";
3380 suffix += desired_config;
3382 // Look for a mapping from the current project's configuration to
3383 // the imported project's configuration.
3384 std::vector<std::string> mappedConfigs;
3386 std::string mapProp = "MAP_IMPORTED_CONFIG_";
3387 mapProp += desired_config;
3388 if(const char* mapValue = this->GetProperty(mapProp.c_str()))
3390 cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
3394 // If a mapping was found, check its configurations.
3395 const char* loc = 0;
3396 for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
3397 !loc && mci != mappedConfigs.end(); ++mci)
3399 // Look for this configuration.
3400 std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
3401 std::string locProp = "IMPORTED_LOCATION_";
3402 locProp += mcUpper;
3403 loc = this->GetProperty(locProp.c_str());
3405 // If it was found, use it for all properties below.
3406 if(loc)
3408 suffix = "_";
3409 suffix += mcUpper;
3413 // If we needed to find one of the mapped configurations but did not
3414 // then the target is not found. The project does not want any
3415 // other configuration.
3416 if(!mappedConfigs.empty() && !loc)
3418 return;
3421 // If we have not yet found it then there are no mapped
3422 // configurations. Look for an exact-match.
3423 if(!loc)
3425 std::string locProp = "IMPORTED_LOCATION";
3426 locProp += suffix;
3427 loc = this->GetProperty(locProp.c_str());
3430 // If we have not yet found it then there are no mapped
3431 // configurations and no exact match.
3432 if(!loc)
3434 // The suffix computed above is not useful.
3435 suffix = "";
3437 // Look for a configuration-less location. This may be set by
3438 // manually-written code.
3439 loc = this->GetProperty("IMPORTED_LOCATION");
3442 // If we have not yet found it then the project is willing to try
3443 // any available configuration.
3444 if(!loc)
3446 std::vector<std::string> availableConfigs;
3447 if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
3449 cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
3451 for(std::vector<std::string>::const_iterator
3452 aci = availableConfigs.begin();
3453 !loc && aci != availableConfigs.end(); ++aci)
3455 suffix = "_";
3456 suffix += cmSystemTools::UpperCase(availableConfigs[0]);
3457 std::string locProp = "IMPORTED_LOCATION";
3458 locProp += suffix;
3459 loc = this->GetProperty(locProp.c_str());
3463 // If we have not yet found it then the target is not available.
3464 if(!loc)
3466 return;
3469 // A provided configuration has been chosen. Load the
3470 // configuration's properties.
3471 info.Location = loc;
3473 // Get the soname.
3474 if(this->GetType() == cmTarget::SHARED_LIBRARY)
3476 std::string soProp = "IMPORTED_SONAME";
3477 soProp += suffix;
3478 if(const char* config_soname = this->GetProperty(soProp.c_str()))
3480 info.SOName = config_soname;
3482 else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
3484 info.SOName = soname;
3488 // Get the "no-soname" mark.
3489 if(this->GetType() == cmTarget::SHARED_LIBRARY)
3491 std::string soProp = "IMPORTED_NO_SONAME";
3492 soProp += suffix;
3493 if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
3495 info.NoSOName = cmSystemTools::IsOn(config_no_soname);
3497 else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
3499 info.NoSOName = cmSystemTools::IsOn(no_soname);
3503 // Get the import library.
3504 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3505 this->IsExecutableWithExports())
3507 std::string impProp = "IMPORTED_IMPLIB";
3508 impProp += suffix;
3509 if(const char* config_implib = this->GetProperty(impProp.c_str()))
3511 info.ImportLibrary = config_implib;
3513 else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
3515 info.ImportLibrary = implib;
3519 // Get the link interface.
3521 std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
3522 linkProp += suffix;
3523 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
3525 cmSystemTools::ExpandListArgument(config_libs,
3526 info.LinkInterface.Libraries);
3528 else if(const char* libs =
3529 this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
3531 cmSystemTools::ExpandListArgument(libs,
3532 info.LinkInterface.Libraries);
3536 // Get the link dependencies.
3538 std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
3539 linkProp += suffix;
3540 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
3542 cmSystemTools::ExpandListArgument(config_libs,
3543 info.LinkInterface.SharedDeps);
3545 else if(const char* libs =
3546 this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
3548 cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
3553 //----------------------------------------------------------------------------
3554 cmTargetLinkInterface const* cmTarget::GetLinkInterface(const char* config)
3556 // Imported targets have their own link interface.
3557 if(this->IsImported())
3559 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
3561 return &info->LinkInterface;
3563 return 0;
3566 // Link interfaces are supported only for shared libraries and
3567 // executables that export symbols.
3568 if((this->GetType() != cmTarget::SHARED_LIBRARY &&
3569 !this->IsExecutableWithExports()))
3571 return 0;
3574 // Lookup any existing link interface for this configuration.
3575 std::map<cmStdString, cmTargetLinkInterface*>::iterator
3576 i = this->LinkInterface.find(config?config:"");
3577 if(i == this->LinkInterface.end())
3579 // Compute the link interface for this configuration.
3580 cmTargetLinkInterface* iface = this->ComputeLinkInterface(config);
3582 // Store the information for this configuration.
3583 std::map<cmStdString, cmTargetLinkInterface*>::value_type
3584 entry(config?config:"", iface);
3585 i = this->LinkInterface.insert(entry).first;
3588 return i->second;
3591 //----------------------------------------------------------------------------
3592 cmTargetLinkInterface* cmTarget::ComputeLinkInterface(const char* config)
3594 // Construct the property name suffix for this configuration.
3595 std::string suffix = "_";
3596 if(config && *config)
3598 suffix += cmSystemTools::UpperCase(config);
3600 else
3602 suffix += "NOCONFIG";
3605 // Lookup the link interface libraries.
3606 const char* libs = 0;
3608 // Lookup the per-configuration property.
3609 std::string propName = "LINK_INTERFACE_LIBRARIES";
3610 propName += suffix;
3611 libs = this->GetProperty(propName.c_str());
3613 // If not set, try the generic property.
3614 if(!libs)
3616 libs = this->GetProperty("LINK_INTERFACE_LIBRARIES");
3620 // If still not set, there is no link interface.
3621 if(!libs)
3623 return 0;
3626 // Allocate the interface.
3627 cmTargetLinkInterface* iface = new cmTargetLinkInterface;
3628 if(!iface)
3630 return 0;
3633 // Expand the list of libraries in the interface.
3634 cmSystemTools::ExpandListArgument(libs, iface->Libraries);
3636 // Now we need to construct a list of shared library dependencies
3637 // not included in the interface.
3638 if(this->GetType() == cmTarget::SHARED_LIBRARY)
3640 // Use a set to keep track of what libraries have been emitted to
3641 // either list.
3642 std::set<cmStdString> emitted;
3643 for(std::vector<std::string>::const_iterator
3644 li = iface->Libraries.begin();
3645 li != iface->Libraries.end(); ++li)
3647 emitted.insert(*li);
3650 // Compute which library configuration to link.
3651 cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
3653 // Construct the list of libs linked for this configuration.
3654 cmTarget::LinkLibraryVectorType const& llibs =
3655 this->GetOriginalLinkLibraries();
3656 for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
3657 li != llibs.end(); ++li)
3659 // Skip entries that will resolve to the target itself, are empty,
3660 // or are not meant for this configuration.
3661 if(li->first == this->GetName() || li->first.empty() ||
3662 !(li->second == cmTarget::GENERAL || li->second == linkType))
3664 continue;
3667 // Skip entries that have already been emitted into either list.
3668 if(!emitted.insert(li->first).second)
3670 continue;
3673 // Add this entry if it is a shared library.
3674 if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->first.c_str()))
3676 if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
3678 iface->SharedDeps.push_back(li->first);
3681 else
3683 // TODO: Recognize shared library file names. Perhaps this
3684 // should be moved to cmComputeLinkInformation, but that creates
3685 // a chicken-and-egg problem since this list is needed for its
3686 // construction.
3691 // Return the completed interface.
3692 return iface;
3695 //----------------------------------------------------------------------------
3696 cmComputeLinkInformation*
3697 cmTarget::GetLinkInformation(const char* config)
3699 // Lookup any existing information for this configuration.
3700 std::map<cmStdString, cmComputeLinkInformation*>::iterator
3701 i = this->LinkInformation.find(config?config:"");
3702 if(i == this->LinkInformation.end())
3704 // Compute information for this configuration.
3705 cmComputeLinkInformation* info =
3706 new cmComputeLinkInformation(this, config);
3707 if(!info || !info->Compute())
3709 delete info;
3710 info = 0;
3713 // Store the information for this configuration.
3714 std::map<cmStdString, cmComputeLinkInformation*>::value_type
3715 entry(config?config:"", info);
3716 i = this->LinkInformation.insert(entry).first;
3718 return i->second;
3721 //----------------------------------------------------------------------------
3722 cmTargetLinkInformationMap
3723 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
3725 // Ideally cmTarget instances should never be copied. However until
3726 // we can make a sweep to remove that, this copy constructor avoids
3727 // allowing the resources (LinkInformation) from getting copied. In
3728 // the worst case this will lead to extra cmComputeLinkInformation
3729 // instances. We also enforce in debug mode that the map be emptied
3730 // when copied.
3731 static_cast<void>(r);
3732 assert(r.empty());
3735 //----------------------------------------------------------------------------
3736 cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
3738 for(derived::iterator i = this->begin(); i != this->end(); ++i)
3740 delete i->second;
3744 //----------------------------------------------------------------------------
3745 cmTargetLinkInterfaceMap
3746 ::cmTargetLinkInterfaceMap(cmTargetLinkInterfaceMap const& r): derived()
3748 // Ideally cmTarget instances should never be copied. However until
3749 // we can make a sweep to remove that, this copy constructor avoids
3750 // allowing the resources (LinkInterface) from getting copied. In
3751 // the worst case this will lead to extra cmTargetLinkInterface
3752 // instances. We also enforce in debug mode that the map be emptied
3753 // when copied.
3754 static_cast<void>(r);
3755 assert(r.empty());
3758 //----------------------------------------------------------------------------
3759 cmTargetLinkInterfaceMap::~cmTargetLinkInterfaceMap()
3761 for(derived::iterator i = this->begin(); i != this->end(); ++i)
3763 delete i->second;
3767 //----------------------------------------------------------------------------
3768 cmTargetInternalPointer::cmTargetInternalPointer()
3770 this->Pointer = new cmTargetInternals;
3773 //----------------------------------------------------------------------------
3774 cmTargetInternalPointer
3775 ::cmTargetInternalPointer(cmTargetInternalPointer const&)
3777 // Ideally cmTarget instances should never be copied. However until
3778 // we can make a sweep to remove that, this copy constructor avoids
3779 // allowing the resources (Internals) to be copied.
3780 this->Pointer = new cmTargetInternals;
3783 //----------------------------------------------------------------------------
3784 cmTargetInternalPointer::~cmTargetInternalPointer()
3786 delete this->Pointer;
3789 //----------------------------------------------------------------------------
3790 cmTargetInternalPointer&
3791 cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
3793 if(this == &r) { return *this; } // avoid warning on HP about self check
3794 // Ideally cmTarget instances should never be copied. However until
3795 // we can make a sweep to remove that, this copy constructor avoids
3796 // allowing the resources (Internals) to be copied.
3797 cmTargetInternals* oldPointer = this->Pointer;
3798 this->Pointer = new cmTargetInternals;
3799 delete oldPointer;
3800 return *this;