STYLE: Fix line-too-long
[cmake.git] / Source / cmTarget.cxx
blob03eae9c27b3da1136a53ef7ee1b5db5ee099338e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmTarget.cxx,v $
5 Language: C++
6 Date: $Date: 2008-10-07 20:46:25 $
7 Version: $Revision: 1.229 $
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 ("TYPE", cmProperty::TARGET,
532 "The type of the target.",
533 "This read-only property can be used to test the type of the given "
534 "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
535 "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
537 cm->DefineProperty
538 ("VERSION", cmProperty::TARGET,
539 "What version number is this target.",
540 "For shared libraries VERSION and SOVERSION can be used to specify "
541 "the build version and api version respectively. When building or "
542 "installing appropriate symlinks are created if the platform "
543 "supports symlinks and the linker supports so-names. "
544 "If only one of both is specified the missing is assumed to have "
545 "the same version number. "
546 "For executables VERSION can be used to specify the build version. "
547 "When building or installing appropriate symlinks are created if "
548 "the platform supports symlinks. "
549 "For shared libraries and executables on Windows the VERSION "
550 "attribute is parsed to extract a \"major.minor\" version number. "
551 "These numbers are used as the image version of the binary. ");
554 cm->DefineProperty
555 ("WIN32_EXECUTABLE", cmProperty::TARGET,
556 "Build an executable with a WinMain entry point on windows.",
557 "When this property is set to true the executable when linked "
558 "on Windows will be created with a WinMain() entry point instead "
559 "of of just main()."
560 "This makes it a GUI executable instead of a console application. "
561 "See the CMAKE_MFC_FLAG variable documentation to configure use "
562 "of MFC for WinMain executables.");
564 cm->DefineProperty
565 ("MACOSX_BUNDLE", cmProperty::TARGET,
566 "Build an executable as an application bundle on Mac OS X.",
567 "When this property is set to true the executable when built "
568 "on Mac OS X will be created as an application bundle. "
569 "This makes it a GUI executable that can be launched from "
570 "the Finder. "
571 "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
572 "about creation of the Info.plist file for the application bundle.");
574 cm->DefineProperty
575 ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
576 "Specify a custom Info.plist template for a Mac OS X App Bundle.",
577 "An executable target with MACOSX_BUNDLE enabled will be built as an "
578 "application bundle on Mac OS X. "
579 "By default its Info.plist file is created by configuring a template "
580 "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
581 "This property specifies an alternative template file name which "
582 "may be a full path.\n"
583 "The following target properties may be set to specify content to "
584 "be configured into the file:\n"
585 " MACOSX_BUNDLE_INFO_STRING\n"
586 " MACOSX_BUNDLE_ICON_FILE\n"
587 " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
588 " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
589 " MACOSX_BUNDLE_BUNDLE_NAME\n"
590 " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
591 " MACOSX_BUNDLE_BUNDLE_VERSION\n"
592 " MACOSX_BUNDLE_COPYRIGHT\n"
593 "CMake variables of the same name may be set to affect all targets "
594 "in a directory that do not have each specific property set. "
595 "If a custom Info.plist is specified by this property it may of course "
596 "hard-code all the settings instead of using the target properties.");
598 cm->DefineProperty
599 ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
600 "Specify a custom Info.plist template for a Mac OS X Framework.",
601 "An library target with FRAMEWORK enabled will be built as a "
602 "framework on Mac OS X. "
603 "By default its Info.plist file is created by configuring a template "
604 "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
605 "This property specifies an alternative template file name which "
606 "may be a full path.\n"
607 "The following target properties may be set to specify content to "
608 "be configured into the file:\n"
609 " MACOSX_FRAMEWORK_ICON_FILE\n"
610 " MACOSX_FRAMEWORK_IDENTIFIER\n"
611 " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
612 " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
613 "CMake variables of the same name may be set to affect all targets "
614 "in a directory that do not have each specific property set. "
615 "If a custom Info.plist is specified by this property it may of course "
616 "hard-code all the settings instead of using the target properties.");
618 cm->DefineProperty
619 ("ENABLE_EXPORTS", cmProperty::TARGET,
620 "Specify whether an executable exports symbols for loadable modules.",
621 "Normally an executable does not export any symbols because it is "
622 "the final program. It is possible for an executable to export "
623 "symbols to be used by loadable modules. When this property is "
624 "set to true CMake will allow other targets to \"link\" to the "
625 "executable with the TARGET_LINK_LIBRARIES command. "
626 "On all platforms a target-level dependency on the executable is "
627 "created for targets that link to it. "
628 "For non-DLL platforms the link rule is simply ignored since "
629 "the dynamic loader will automatically bind symbols when the "
630 "module is loaded. "
631 "For DLL platforms an import library will be created for the "
632 "exported symbols and then used for linking. "
633 "All Windows-based systems including Cygwin are DLL platforms.");
635 cm->DefineProperty
636 ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
637 "Specify output directory for Fortran modules provided by the target.",
638 "If the target contains Fortran source files that provide modules "
639 "and the compiler supports a module output directory this specifies "
640 "the directory in which the modules will be placed. "
641 "When this property is not set the modules will be placed in the "
642 "build directory corresponding to the target's source directory. "
643 "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
644 "is created its value is used to initialize this property.");
646 cm->DefineProperty
647 ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
648 "Set Xcode target attributes directly.",
649 "Tell the Xcode generator to set '<an-attribute>' to a given value "
650 "in the generated Xcode project. Ignored on other generators.");
652 cm->DefineProperty
653 ("GENERATOR_FILE_NAME", cmProperty::TARGET,
654 "Generator's file for this target.",
655 "An internal property used by some generators to record the name of "
656 "project or dsp file associated with this target.");
658 cm->DefineProperty
659 ("SOURCES", cmProperty::TARGET,
660 "Source names specified for a target.",
661 "Read-only list of sources specified for a target. "
662 "The names returned are suitable for passing to the "
663 "set_source_files_properties command.");
665 cm->DefineProperty
666 ("PROJECT_LABEL", cmProperty::TARGET,
667 "Change the name of a target in an IDE.",
668 "Can be used to change the name of the target in an IDE "
669 "like visual stuido. ");
670 cm->DefineProperty
671 ("VS_KEYWORD", cmProperty::TARGET,
672 "Visual Studio project keyword.",
673 "Can be set to change the visual studio keyword, for example "
674 "QT integration works better if this is set to Qt4VSv1.0. ");
675 cm->DefineProperty
676 ("VS_SCC_PROVIDER", cmProperty::TARGET,
677 "Visual Studio Source Code Control Provider.",
678 "Can be set to change the visual studio source code control "
679 "provider property.");
680 cm->DefineProperty
681 ("VS_SCC_LOCALPATH", cmProperty::TARGET,
682 "Visual Studio Source Code Control Provider.",
683 "Can be set to change the visual studio source code control "
684 "local path property.");
685 cm->DefineProperty
686 ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
687 "Visual Studio Source Code Control Project.",
688 "Can be set to change the visual studio source code control "
689 "project name property.");
691 #if 0
692 cm->DefineProperty
693 ("OBJECT_FILES", cmProperty::TARGET,
694 "Used to get the resulting list of object files that make up a "
695 "target.",
696 "This can be used to put object files from one library "
697 "into another library. It is a read only property. It "
698 "converts the source list for the target into a list of full "
699 "paths to object names that will be produced by the target.");
700 #endif
702 #define CM_TARGET_FILE_TYPES_DOC \
703 "There are three kinds of target files that may be built: " \
704 "archive, library, and runtime. " \
705 "Executables are always treated as runtime targets. " \
706 "Static libraries are always treated as archive targets. " \
707 "Module libraries are always treated as library targets. " \
708 "For non-DLL platforms shared libraries are treated as library " \
709 "targets. " \
710 "For DLL platforms the DLL part of a shared library is treated as " \
711 "a runtime target and the corresponding import library is treated as " \
712 "an archive target. " \
713 "All Windows-based systems including Cygwin are DLL platforms."
715 cm->DefineProperty
716 ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
717 "Output directory in which to build ARCHIVE target files.",
718 "This property specifies the directory into which archive target files "
719 "should be built. "
720 CM_TARGET_FILE_TYPES_DOC " "
721 "This property is initialized by the value of the variable "
722 "CMAKE_ARCHIVE_OUTPUT_DIRECTORY if it is set when a target is created.");
723 cm->DefineProperty
724 ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
725 "Output directory in which to build LIBRARY target files.",
726 "This property specifies the directory into which library target files "
727 "should be built. "
728 CM_TARGET_FILE_TYPES_DOC " "
729 "This property is initialized by the value of the variable "
730 "CMAKE_LIBRARY_OUTPUT_DIRECTORY if it is set when a target is created.");
731 cm->DefineProperty
732 ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
733 "Output directory in which to build RUNTIME target files.",
734 "This property specifies the directory into which runtime target files "
735 "should be built. "
736 CM_TARGET_FILE_TYPES_DOC " "
737 "This property is initialized by the value of the variable "
738 "CMAKE_RUNTIME_OUTPUT_DIRECTORY if it is set when a target is created.");
740 // define some properties without documentation
741 cm->DefineProperty("DEBUG_OUTPUT_NAME", cmProperty::TARGET,0,0);
742 cm->DefineProperty("RELEASE_OUTPUT_NAME", cmProperty::TARGET,0,0);
745 void cmTarget::SetType(TargetType type, const char* name)
747 this->Name = name;
748 if(type == cmTarget::INSTALL_FILES ||
749 type == cmTarget::INSTALL_PROGRAMS ||
750 type == cmTarget::INSTALL_DIRECTORY)
752 this->Makefile->
753 IssueMessage(cmake::INTERNAL_ERROR,
754 "SetType called on cmTarget for INSTALL_FILES, "
755 "INSTALL_PROGRAMS, or INSTALL_DIRECTORY ");
756 return;
758 // only add dependency information for library targets
759 this->TargetTypeValue = type;
760 if(this->TargetTypeValue >= STATIC_LIBRARY
761 && this->TargetTypeValue <= MODULE_LIBRARY)
763 this->RecordDependencies = true;
765 else
767 this->RecordDependencies = false;
771 //----------------------------------------------------------------------------
772 void cmTarget::SetMakefile(cmMakefile* mf)
774 // Set our makefile.
775 this->Makefile = mf;
777 // set the cmake instance of the properties
778 this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
780 // Check whether this is a DLL platform.
781 this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
782 this->Makefile->IsOn("CYGWIN") ||
783 this->Makefile->IsOn("MINGW"));
785 // Setup default property values.
786 this->SetPropertyDefault("INSTALL_NAME_DIR", "");
787 this->SetPropertyDefault("INSTALL_RPATH", "");
788 this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
789 this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
790 this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
791 this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
792 this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
793 this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
794 this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
796 // Collect the set of configuration types.
797 std::vector<std::string> configNames;
798 if(const char* configurationTypes =
799 mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
801 cmSystemTools::ExpandListArgument(configurationTypes, configNames);
803 else if(const char* buildType = mf->GetDefinition("CMAKE_BUILD_TYPE"))
805 if(*buildType)
807 configNames.push_back(buildType);
811 // Setup per-configuration property default values.
812 for(std::vector<std::string>::iterator ci = configNames.begin();
813 ci != configNames.end(); ++ci)
815 // Initialize per-configuration name postfix property from the
816 // variable only for non-executable targets. This preserves
817 // compatibility with previous CMake versions in which executables
818 // did not support this variable. Projects may still specify the
819 // property directly. TODO: Make this depend on backwards
820 // compatibility setting.
821 if(this->TargetTypeValue != cmTarget::EXECUTABLE)
823 std::string property = cmSystemTools::UpperCase(*ci);
824 property += "_POSTFIX";
825 this->SetPropertyDefault(property.c_str(), 0);
829 // Save the backtrace of target construction.
830 this->Makefile->GetBacktrace(this->Internal->Backtrace);
832 // Record current policies for later use.
833 this->PolicyStatusCMP0003 =
834 this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
835 this->PolicyStatusCMP0004 =
836 this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
837 this->PolicyStatusCMP0008 =
838 this->Makefile->GetPolicyStatus(cmPolicies::CMP0008);
841 //----------------------------------------------------------------------------
842 cmListFileBacktrace const& cmTarget::GetBacktrace() const
844 return this->Internal->Backtrace;
847 //----------------------------------------------------------------------------
848 bool cmTarget::IsExecutableWithExports()
850 return (this->GetType() == cmTarget::EXECUTABLE &&
851 this->GetPropertyAsBool("ENABLE_EXPORTS"));
854 //----------------------------------------------------------------------------
855 bool cmTarget::IsLinkable()
857 return (this->GetType() == cmTarget::STATIC_LIBRARY ||
858 this->GetType() == cmTarget::SHARED_LIBRARY ||
859 this->GetType() == cmTarget::MODULE_LIBRARY ||
860 this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
861 this->IsExecutableWithExports());
864 //----------------------------------------------------------------------------
865 bool cmTarget::IsFrameworkOnApple()
867 return (this->GetType() == cmTarget::SHARED_LIBRARY &&
868 this->Makefile->IsOn("APPLE") &&
869 this->GetPropertyAsBool("FRAMEWORK"));
872 //----------------------------------------------------------------------------
873 bool cmTarget::IsAppBundleOnApple()
875 return (this->GetType() == cmTarget::EXECUTABLE &&
876 this->Makefile->IsOn("APPLE") &&
877 this->GetPropertyAsBool("MACOSX_BUNDLE"));
880 //----------------------------------------------------------------------------
881 class cmTargetTraceDependencies
883 public:
884 cmTargetTraceDependencies(cmTarget* target, const char* vsProjectFile);
885 void Trace();
886 private:
887 cmTarget* Target;
888 cmMakefile* Makefile;
889 cmGlobalGenerator* GlobalGenerator;
890 std::queue<cmStdString> DependencyQueue;
891 std::set<cmStdString> DependenciesQueued;
892 std::set<cmSourceFile*> TargetSources;
894 void QueueOnce(std::string const& name);
895 void QueueOnce(std::vector<std::string> const& names);
896 void QueueDependencies(cmSourceFile* sf);
897 bool IsUtility(std::string const& dep);
898 void CheckCustomCommand(cmCustomCommand const& cc);
899 void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
902 //----------------------------------------------------------------------------
903 cmTargetTraceDependencies
904 ::cmTargetTraceDependencies(cmTarget* target, const char* vsProjectFile):
905 Target(target)
907 // Convenience.
908 this->Makefile = this->Target->GetMakefile();
909 this->GlobalGenerator =
910 this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
912 // Queue all the source files already specified for the target.
913 std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
914 for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
915 si != sources.end(); ++si)
917 // Queue the source file itself in case it is generated.
918 this->QueueOnce((*si)->GetFullPath());
920 // Queue the dependencies of the source file in case they are
921 // generated.
922 this->QueueDependencies(*si);
924 // Track the sources already known to the target.
925 this->TargetSources.insert(*si);
928 // Queue the VS project file to check dependencies on the rule to
929 // generate it.
930 if(vsProjectFile)
932 this->QueueOnce(vsProjectFile);
935 // Queue pre-build, pre-link, and post-build rule dependencies.
936 this->CheckCustomCommands(this->Target->GetPreBuildCommands());
937 this->CheckCustomCommands(this->Target->GetPreLinkCommands());
938 this->CheckCustomCommands(this->Target->GetPostBuildCommands());
941 //----------------------------------------------------------------------------
942 void cmTargetTraceDependencies::Trace()
944 // Process one dependency at a time until the queue is empty.
945 while(!this->DependencyQueue.empty())
947 // Get the next dependency in from queue.
948 std::string dep = this->DependencyQueue.front();
949 this->DependencyQueue.pop();
951 // Check if we know how to generate this dependency.
952 if(cmSourceFile* sf =
953 this->Makefile->GetSourceFileWithOutput(dep.c_str()))
955 // Queue dependencies needed to generate this file.
956 this->QueueDependencies(sf);
958 // Make sure this file is in the target.
959 if(this->TargetSources.insert(sf).second)
961 this->Target->AddSourceFile(sf);
967 //----------------------------------------------------------------------------
968 void cmTargetTraceDependencies::QueueOnce(std::string const& name)
970 if(this->DependenciesQueued.insert(name).second)
972 this->DependencyQueue.push(name);
976 //----------------------------------------------------------------------------
977 void
978 cmTargetTraceDependencies::QueueOnce(std::vector<std::string> const& names)
980 for(std::vector<std::string>::const_iterator i = names.begin();
981 i != names.end(); ++i)
983 this->QueueOnce(*i);
987 //----------------------------------------------------------------------------
988 bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
990 // Dependencies on targets (utilities) are supposed to be named by
991 // just the target name. However for compatibility we support
992 // naming the output file generated by the target (assuming there is
993 // no output-name property which old code would not have set). In
994 // that case the target name will be the file basename of the
995 // dependency.
996 std::string util = cmSystemTools::GetFilenameName(dep);
997 if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
999 util = cmSystemTools::GetFilenameWithoutLastExtension(util);
1002 // Check for a non-imported target with this name.
1003 if(cmTarget* t = this->GlobalGenerator->FindTarget(0, util.c_str()))
1005 // If we find the target and the dep was given as a full path,
1006 // then make sure it was not a full path to something else, and
1007 // the fact that the name matched a target was just a coincidence.
1008 if(cmSystemTools::FileIsFullPath(dep.c_str()))
1010 // This is really only for compatibility so we do not need to
1011 // worry about configuration names and output names.
1012 std::string tLocation = t->GetLocation(0);
1013 tLocation = cmSystemTools::GetFilenamePath(tLocation);
1014 std::string depLocation = cmSystemTools::GetFilenamePath(dep);
1015 depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
1016 tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
1017 if(depLocation == tLocation)
1019 this->Target->AddUtility(util.c_str());
1020 return true;
1023 else
1025 // The original name of the dependency was not a full path. It
1026 // must name a target, so add the target-level dependency.
1027 this->Target->AddUtility(util.c_str());
1028 return true;
1032 // The dependency does not name a target built in this project.
1033 return false;
1036 //----------------------------------------------------------------------------
1037 void cmTargetTraceDependencies::QueueDependencies(cmSourceFile* sf)
1039 // Queue dependency added explicitly by the user.
1040 if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
1042 std::vector<std::string> objDeps;
1043 cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
1044 this->QueueOnce(objDeps);
1047 // Queue dependencies added programatically by commands.
1048 this->QueueOnce(sf->GetDepends());
1050 // Queue custom command dependencies.
1051 if(cmCustomCommand const* cc = sf->GetCustomCommand())
1053 this->CheckCustomCommand(*cc);
1058 //----------------------------------------------------------------------------
1059 void
1060 cmTargetTraceDependencies
1061 ::CheckCustomCommand(cmCustomCommand const& cc)
1063 // Transform command names that reference targets built in this
1064 // project to corresponding target-level dependencies.
1065 for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
1066 cit != cc.GetCommandLines().end(); ++cit)
1068 std::string const& command = *cit->begin();
1069 // Look for a non-imported target with this name.
1070 if(cmTarget* t = this->GlobalGenerator->FindTarget(0, command.c_str()))
1072 if(t->GetType() == cmTarget::EXECUTABLE)
1074 // The command refers to an executable target built in
1075 // this project. Add the target-level dependency to make
1076 // sure the executable is up to date before this custom
1077 // command possibly runs.
1078 this->Target->AddUtility(command.c_str());
1083 // Queue the custom command dependencies.
1084 std::vector<std::string> const& depends = cc.GetDepends();
1085 for(std::vector<std::string>::const_iterator di = depends.begin();
1086 di != depends.end(); ++di)
1088 std::string const& dep = *di;
1089 if(!this->IsUtility(dep))
1091 // The dependency does not name a target and may be a file we
1092 // know how to generate. Queue it.
1093 this->QueueOnce(dep);
1098 //----------------------------------------------------------------------------
1099 void
1100 cmTargetTraceDependencies
1101 ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
1103 for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
1104 cli != commands.end(); ++cli)
1106 this->CheckCustomCommand(*cli);
1110 //----------------------------------------------------------------------------
1111 void cmTarget::TraceDependencies(const char* vsProjectFile)
1113 // Use a helper object to trace the dependencies.
1114 cmTargetTraceDependencies tracer(this, vsProjectFile);
1115 tracer.Trace();
1118 //----------------------------------------------------------------------------
1119 bool cmTarget::FindSourceFiles()
1121 for(std::vector<cmSourceFile*>::const_iterator
1122 si = this->SourceFiles.begin();
1123 si != this->SourceFiles.end(); ++si)
1125 if((*si)->GetFullPath().empty())
1127 return false;
1130 return true;
1133 //----------------------------------------------------------------------------
1134 void cmTarget::AddSources(std::vector<std::string> const& srcs)
1136 for(std::vector<std::string>::const_iterator i = srcs.begin();
1137 i != srcs.end(); ++i)
1139 this->AddSource(i->c_str());
1143 //----------------------------------------------------------------------------
1144 cmSourceFile* cmTarget::AddSource(const char* s)
1146 std::string src = s;
1148 // For backwards compatibility replace varibles in source names.
1149 // This should eventually be removed.
1150 this->Makefile->ExpandVariablesInString(src);
1152 cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
1153 this->AddSourceFile(sf);
1154 return sf;
1157 //----------------------------------------------------------------------------
1158 struct cmTarget::SourceFileFlags
1159 cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
1161 struct SourceFileFlags flags;
1162 this->ConstructSourceFileFlags();
1163 std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
1164 this->Internal->SourceFlagsMap.find(sf);
1165 if(si != this->Internal->SourceFlagsMap.end())
1167 flags = si->second;
1169 return flags;
1172 //----------------------------------------------------------------------------
1173 void cmTarget::ConstructSourceFileFlags()
1175 if(this->Internal->SourceFileFlagsConstructed)
1177 return;
1179 this->Internal->SourceFileFlagsConstructed = true;
1181 // Process public headers to mark the source files.
1182 if(const char* files = this->GetProperty("PUBLIC_HEADER"))
1184 std::vector<std::string> relFiles;
1185 cmSystemTools::ExpandListArgument(files, relFiles);
1186 for(std::vector<std::string>::iterator it = relFiles.begin();
1187 it != relFiles.end(); ++it)
1189 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1191 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1192 flags.MacFolder = "Headers";
1193 flags.Type = cmTarget::SourceFileTypePublicHeader;
1198 // Process private headers after public headers so that they take
1199 // precedence if a file is listed in both.
1200 if(const char* files = this->GetProperty("PRIVATE_HEADER"))
1202 std::vector<std::string> relFiles;
1203 cmSystemTools::ExpandListArgument(files, relFiles);
1204 for(std::vector<std::string>::iterator it = relFiles.begin();
1205 it != relFiles.end(); ++it)
1207 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1209 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1210 flags.MacFolder = "PrivateHeaders";
1211 flags.Type = cmTarget::SourceFileTypePrivateHeader;
1216 // Mark sources listed as resources.
1217 if(const char* files = this->GetProperty("RESOURCE"))
1219 std::vector<std::string> relFiles;
1220 cmSystemTools::ExpandListArgument(files, relFiles);
1221 for(std::vector<std::string>::iterator it = relFiles.begin();
1222 it != relFiles.end(); ++it)
1224 if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
1226 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1227 flags.MacFolder = "Resources";
1228 flags.Type = cmTarget::SourceFileTypeResource;
1233 // Handle the MACOSX_PACKAGE_LOCATION property on source files that
1234 // were not listed in one of the other lists.
1235 std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
1236 for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
1237 si != sources.end(); ++si)
1239 cmSourceFile* sf = *si;
1240 if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
1242 SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
1243 if(flags.Type == cmTarget::SourceFileTypeNormal)
1245 flags.MacFolder = location;
1246 if(strcmp(location, "Resources") == 0)
1248 flags.Type = cmTarget::SourceFileTypeResource;
1250 else
1252 flags.Type = cmTarget::SourceFileTypeMacContent;
1259 //----------------------------------------------------------------------------
1260 void cmTarget::MergeLinkLibraries( cmMakefile& mf,
1261 const char *selfname,
1262 const LinkLibraryVectorType& libs )
1264 // Only add on libraries we haven't added on before.
1265 // Assumption: the global link libraries could only grow, never shrink
1266 LinkLibraryVectorType::const_iterator i = libs.begin();
1267 i += this->PrevLinkedLibraries.size();
1268 for( ; i != libs.end(); ++i )
1270 // We call this so that the dependencies get written to the cache
1271 this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
1273 this->PrevLinkedLibraries = libs;
1276 //----------------------------------------------------------------------------
1277 void cmTarget::AddLinkDirectory(const char* d)
1279 // Make sure we don't add unnecessary search directories.
1280 if(this->LinkDirectoriesEmmitted.insert(d).second)
1282 this->LinkDirectories.push_back(d);
1286 //----------------------------------------------------------------------------
1287 const std::vector<std::string>& cmTarget::GetLinkDirectories()
1289 return this->LinkDirectories;
1292 //----------------------------------------------------------------------------
1293 cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
1295 // No configuration is always optimized.
1296 if(!(config && *config))
1298 return cmTarget::OPTIMIZED;
1301 // Get the list of configurations considered to be DEBUG.
1302 std::vector<std::string> const& debugConfigs =
1303 this->Makefile->GetCMakeInstance()->GetDebugConfigs();
1305 // Check if any entry in the list matches this configuration.
1306 std::string configUpper = cmSystemTools::UpperCase(config);
1307 for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
1308 i != debugConfigs.end(); ++i)
1310 if(*i == configUpper)
1312 return cmTarget::DEBUG;
1316 // The current configuration is not a debug configuration.
1317 return cmTarget::OPTIMIZED;
1320 //----------------------------------------------------------------------------
1321 void cmTarget::ClearDependencyInformation( cmMakefile& mf,
1322 const char* target )
1324 // Clear the dependencies. The cache variable must exist iff we are
1325 // recording dependency information for this target.
1326 std::string depname = target;
1327 depname += "_LIB_DEPENDS";
1328 if (this->RecordDependencies)
1330 mf.AddCacheDefinition(depname.c_str(), "",
1331 "Dependencies for target", cmCacheManager::STATIC);
1333 else
1335 if (mf.GetDefinition( depname.c_str() ))
1337 std::string message = "Target ";
1338 message += target;
1339 message += " has dependency information when it shouldn't.\n";
1340 message += "Your cache is probably stale. Please remove the entry\n ";
1341 message += depname;
1342 message += "\nfrom the cache.";
1343 cmSystemTools::Error( message.c_str() );
1348 //----------------------------------------------------------------------------
1349 void cmTarget::AddLinkLibrary(const std::string& lib,
1350 LinkLibraryType llt)
1352 this->AddFramework(lib.c_str(), llt);
1353 cmTarget::LibraryID tmp;
1354 tmp.first = lib;
1355 tmp.second = llt;
1356 this->LinkLibraries.push_back(tmp);
1357 this->OriginalLinkLibraries.push_back(tmp);
1360 //----------------------------------------------------------------------------
1361 bool cmTarget::NameResolvesToFramework(const std::string& libname)
1363 return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
1364 NameResolvesToFramework(libname);
1367 //----------------------------------------------------------------------------
1368 bool cmTarget::AddFramework(const std::string& libname, LinkLibraryType llt)
1370 (void)llt; // TODO: What is this?
1371 if(this->NameResolvesToFramework(libname.c_str()))
1373 std::string frameworkDir = libname;
1374 frameworkDir += "/../";
1375 frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
1376 std::vector<std::string>::iterator i =
1377 std::find(this->Frameworks.begin(),
1378 this->Frameworks.end(), frameworkDir);
1379 if(i == this->Frameworks.end())
1381 this->Frameworks.push_back(frameworkDir);
1383 return true;
1385 return false;
1388 //----------------------------------------------------------------------------
1389 void cmTarget::AddLinkLibrary(cmMakefile& mf,
1390 const char *target, const char* lib,
1391 LinkLibraryType llt)
1393 // Never add a self dependency, even if the user asks for it.
1394 if(strcmp( target, lib ) == 0)
1396 return;
1398 this->AddFramework(lib, llt);
1399 cmTarget::LibraryID tmp;
1400 tmp.first = lib;
1401 tmp.second = llt;
1402 this->LinkLibraries.push_back( tmp );
1403 this->OriginalLinkLibraries.push_back(tmp);
1405 // Add the explicit dependency information for this target. This is
1406 // simply a set of libraries separated by ";". There should always
1407 // be a trailing ";". These library names are not canonical, in that
1408 // they may be "-framework x", "-ly", "/path/libz.a", etc.
1409 // We shouldn't remove duplicates here because external libraries
1410 // may be purposefully duplicated to handle recursive dependencies,
1411 // and we removing one instance will break the link line. Duplicates
1412 // will be appropriately eliminated at emit time.
1413 if(this->RecordDependencies)
1415 std::string targetEntry = target;
1416 targetEntry += "_LIB_DEPENDS";
1417 std::string dependencies;
1418 const char* old_val = mf.GetDefinition( targetEntry.c_str() );
1419 if( old_val )
1421 dependencies += old_val;
1423 switch (llt)
1425 case cmTarget::GENERAL:
1426 dependencies += "general";
1427 break;
1428 case cmTarget::DEBUG:
1429 dependencies += "debug";
1430 break;
1431 case cmTarget::OPTIMIZED:
1432 dependencies += "optimized";
1433 break;
1435 dependencies += ";";
1436 dependencies += lib;
1437 dependencies += ";";
1438 mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
1439 "Dependencies for the target",
1440 cmCacheManager::STATIC );
1445 //----------------------------------------------------------------------------
1446 void
1447 cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
1449 // There are two key parts of the dependency analysis: (1)
1450 // determining the libraries in the link line, and (2) constructing
1451 // the dependency graph for those libraries.
1453 // The latter is done using the cache entries that record the
1454 // dependencies of each library.
1456 // The former is a more thorny issue, since it is not clear how to
1457 // determine if two libraries listed on the link line refer to the a
1458 // single library or not. For example, consider the link "libraries"
1459 // /usr/lib/libtiff.so -ltiff
1460 // Is this one library or two? The solution implemented here is the
1461 // simplest (and probably the only practical) one: two libraries are
1462 // the same if their "link strings" are identical. Thus, the two
1463 // libraries above are considered distinct. This also means that for
1464 // dependency analysis to be effective, the CMake user must specify
1465 // libraries build by his project without using any linker flags or
1466 // file extensions. That is,
1467 // LINK_LIBRARIES( One Two )
1468 // instead of
1469 // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
1470 // The former is probably what most users would do, but it never
1471 // hurts to document the assumptions. :-) Therefore, in the analysis
1472 // code, the "canonical name" of a library is simply its name as
1473 // given to a LINK_LIBRARIES command.
1475 // Also, we will leave the original link line intact; we will just add any
1476 // dependencies that were missing.
1478 // There is a problem with recursive external libraries
1479 // (i.e. libraries with no dependency information that are
1480 // recursively dependent). We must make sure that the we emit one of
1481 // the libraries twice to satisfy the recursion, but we shouldn't
1482 // emit it more times than necessary. In particular, we must make
1483 // sure that handling this improbable case doesn't cost us when
1484 // dealing with the common case of non-recursive libraries. The
1485 // solution is to assume that the recursion is satisfied at one node
1486 // of the dependency tree. To illustrate, assume libA and libB are
1487 // extrenal and mutually dependent. Suppose libX depends on
1488 // libA, and libY on libA and libX. Then
1489 // TARGET_LINK_LIBRARIES( Y X A B A )
1490 // TARGET_LINK_LIBRARIES( X A B A )
1491 // TARGET_LINK_LIBRARIES( Exec Y )
1492 // would result in "-lY -lX -lA -lB -lA". This is the correct way to
1493 // specify the dependencies, since the mutual dependency of A and B
1494 // is resolved *every time libA is specified*.
1496 // Something like
1497 // TARGET_LINK_LIBRARIES( Y X A B A )
1498 // TARGET_LINK_LIBRARIES( X A B )
1499 // TARGET_LINK_LIBRARIES( Exec Y )
1500 // would result in "-lY -lX -lA -lB", and the mutual dependency
1501 // information is lost. This is because in some case (Y), the mutual
1502 // dependency of A and B is listed, while in another other case (X),
1503 // it is not. Depending on which line actually emits A, the mutual
1504 // dependency may or may not be on the final link line. We can't
1505 // handle this pathalogical case cleanly without emitting extra
1506 // libraries for the normal cases. Besides, the dependency
1507 // information for X is wrong anyway: if we build an executable
1508 // depending on X alone, we would not have the mutual dependency on
1509 // A and B resolved.
1511 // IMPROVEMENTS:
1512 // -- The current algorithm will not always pick the "optimal" link line
1513 // when recursive dependencies are present. It will instead break the
1514 // cycles at an aribtrary point. The majority of projects won't have
1515 // cyclic dependencies, so this is probably not a big deal. Note that
1516 // the link line is always correct, just not necessary optimal.
1519 // Expand variables in link library names. This is for backwards
1520 // compatibility with very early CMake versions and should
1521 // eventually be removed. This code was moved here from the end of
1522 // old source list processing code which was called just before this
1523 // method.
1524 for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
1525 p != this->LinkLibraries.end(); ++p)
1527 this->Makefile->ExpandVariablesInString(p->first, true, true);
1531 typedef std::vector< std::string > LinkLine;
1533 // The dependency map.
1534 DependencyMap dep_map;
1536 // 1. Build the dependency graph
1538 for(LinkLibraryVectorType::reverse_iterator lib
1539 = this->LinkLibraries.rbegin();
1540 lib != this->LinkLibraries.rend(); ++lib)
1542 this->GatherDependencies( mf, *lib, dep_map);
1545 // 2. Remove any dependencies that are already satisfied in the original
1546 // link line.
1548 for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
1549 lib != this->LinkLibraries.end(); ++lib)
1551 for( LinkLibraryVectorType::iterator lib2 = lib;
1552 lib2 != this->LinkLibraries.end(); ++lib2)
1554 this->DeleteDependency( dep_map, *lib, *lib2);
1559 // 3. Create the new link line by simply emitting any dependencies that are
1560 // missing. Start from the back and keep adding.
1562 std::set<DependencyMap::key_type> done, visited;
1563 std::vector<DependencyMap::key_type> newLinkLibraries;
1564 for(LinkLibraryVectorType::reverse_iterator lib =
1565 this->LinkLibraries.rbegin();
1566 lib != this->LinkLibraries.rend(); ++lib)
1568 // skip zero size library entries, this may happen
1569 // if a variable expands to nothing.
1570 if (lib->first.size() != 0)
1572 this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
1576 // 4. Add the new libraries to the link line.
1578 for( std::vector<DependencyMap::key_type>::reverse_iterator k =
1579 newLinkLibraries.rbegin();
1580 k != newLinkLibraries.rend(); ++k )
1582 // get the llt from the dep_map
1583 this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
1585 this->LinkLibrariesAnalyzed = true;
1588 //----------------------------------------------------------------------------
1589 void cmTarget::InsertDependency( DependencyMap& depMap,
1590 const LibraryID& lib,
1591 const LibraryID& dep)
1593 depMap[lib].push_back(dep);
1596 //----------------------------------------------------------------------------
1597 void cmTarget::DeleteDependency( DependencyMap& depMap,
1598 const LibraryID& lib,
1599 const LibraryID& dep)
1601 // Make sure there is an entry in the map for lib. If so, delete all
1602 // dependencies to dep. There may be repeated entries because of
1603 // external libraries that are specified multiple times.
1604 DependencyMap::iterator map_itr = depMap.find( lib );
1605 if( map_itr != depMap.end() )
1607 DependencyList& depList = map_itr->second;
1608 DependencyList::iterator itr;
1609 while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
1610 depList.end() )
1612 depList.erase( itr );
1617 //----------------------------------------------------------------------------
1618 void cmTarget::Emit(const LibraryID lib,
1619 const DependencyMap& dep_map,
1620 std::set<LibraryID>& emitted,
1621 std::set<LibraryID>& visited,
1622 DependencyList& link_line )
1624 // It's already been emitted
1625 if( emitted.find(lib) != emitted.end() )
1627 return;
1630 // Emit the dependencies only if this library node hasn't been
1631 // visited before. If it has, then we have a cycle. The recursion
1632 // that got us here should take care of everything.
1634 if( visited.insert(lib).second )
1636 if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
1638 const DependencyList& dep_on = dep_map.find( lib )->second;
1639 DependencyList::const_reverse_iterator i;
1641 // To cater for recursive external libraries, we must emit
1642 // duplicates on this link line *unless* they were emitted by
1643 // some other node, in which case we assume that the recursion
1644 // was resolved then. We making the simplifying assumption that
1645 // any duplicates on a single link line are on purpose, and must
1646 // be preserved.
1648 // This variable will keep track of the libraries that were
1649 // emitted directory from the current node, and not from a
1650 // recursive call. This way, if we come across a library that
1651 // has already been emitted, we repeat it iff it has been
1652 // emitted here.
1653 std::set<DependencyMap::key_type> emitted_here;
1654 for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
1656 if( emitted_here.find(*i) != emitted_here.end() )
1658 // a repeat. Must emit.
1659 emitted.insert(*i);
1660 link_line.push_back( *i );
1662 else
1664 // Emit only if no-one else has
1665 if( emitted.find(*i) == emitted.end() )
1667 // emit dependencies
1668 Emit( *i, dep_map, emitted, visited, link_line );
1669 // emit self
1670 emitted.insert(*i);
1671 emitted_here.insert(*i);
1672 link_line.push_back( *i );
1680 //----------------------------------------------------------------------------
1681 void cmTarget::GatherDependencies( const cmMakefile& mf,
1682 const LibraryID& lib,
1683 DependencyMap& dep_map)
1685 // If the library is already in the dependency map, then it has
1686 // already been fully processed.
1687 if( dep_map.find(lib) != dep_map.end() )
1689 return;
1692 const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
1693 if( deps && strcmp(deps,"") != 0 )
1695 // Make sure this library is in the map, even if it has an empty
1696 // set of dependencies. This distinguishes the case of explicitly
1697 // no dependencies with that of unspecified dependencies.
1698 dep_map[lib];
1700 // Parse the dependency information, which is a set of
1701 // type, library pairs separated by ";". There is always a trailing ";".
1702 cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
1703 std::string depline = deps;
1704 std::string::size_type start = 0;
1705 std::string::size_type end;
1706 end = depline.find( ";", start );
1707 while( end != std::string::npos )
1709 std::string l = depline.substr( start, end-start );
1710 if( l.size() != 0 )
1712 if (l == "debug")
1714 llt = cmTarget::DEBUG;
1716 else if (l == "optimized")
1718 llt = cmTarget::OPTIMIZED;
1720 else if (l == "general")
1722 llt = cmTarget::GENERAL;
1724 else
1726 LibraryID lib2(l,llt);
1727 this->InsertDependency( dep_map, lib, lib2);
1728 this->GatherDependencies( mf, lib2, dep_map);
1729 llt = cmTarget::GENERAL;
1732 start = end+1; // skip the ;
1733 end = depline.find( ";", start );
1735 // cannot depend on itself
1736 this->DeleteDependency( dep_map, lib, lib);
1740 //----------------------------------------------------------------------------
1741 void cmTarget::SetProperty(const char* prop, const char* value)
1743 if (!prop)
1745 return;
1748 this->Properties.SetProperty(prop, value, cmProperty::TARGET);
1750 // If imported information is being set, wipe out cached
1751 // information.
1752 if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
1754 this->ImportInfoMap.clear();
1758 //----------------------------------------------------------------------------
1759 void cmTarget::AppendProperty(const char* prop, const char* value)
1761 if (!prop)
1763 return;
1765 this->Properties.AppendProperty(prop, value, cmProperty::TARGET);
1767 // If imported information is being set, wipe out cached
1768 // information.
1769 if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
1771 this->ImportInfoMap.clear();
1775 //----------------------------------------------------------------------------
1776 static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
1777 const char* prop, const char* value, cmMakefile* context, bool imported
1780 // Look for link-type keywords in the value.
1781 static cmsys::RegularExpression
1782 keys("(^|;)(debug|optimized|general)(;|$)");
1783 if(!keys.find(value))
1785 return;
1788 // Support imported and non-imported versions of the property.
1789 const char* base = (imported?
1790 "IMPORTED_LINK_INTERFACE_LIBRARIES" :
1791 "LINK_INTERFACE_LIBRARIES");
1793 // Report an error.
1794 cmOStringStream e;
1795 e << "Property " << prop << " may not contain link-type keyword \""
1796 << keys.match(2) << "\". "
1797 << "The " << base << " property has a per-configuration "
1798 << "version called " << base << "_<CONFIG> which may be "
1799 << "used to specify per-configuration rules.";
1800 if(!imported)
1802 e << " "
1803 << "Alternatively, an IMPORTED library may be created, configured "
1804 << "with a per-configuration location, and then named in the "
1805 << "property value. "
1806 << "See the add_library command's IMPORTED mode for details."
1807 << "\n"
1808 << "If you have a list of libraries that already contains the "
1809 << "keyword, use the target_link_libraries command with its "
1810 << "LINK_INTERFACE_LIBRARIES mode to set the property. "
1811 << "The command automatically recognizes link-type keywords and sets "
1812 << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
1813 << "properties accordingly.";
1815 context->IssueMessage(cmake::FATAL_ERROR, e.str());
1818 //----------------------------------------------------------------------------
1819 void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
1821 // Certain properties need checking.
1822 if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
1824 if(const char* value = this->GetProperty(prop))
1826 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
1829 if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
1831 if(const char* value = this->GetProperty(prop))
1833 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
1838 //----------------------------------------------------------------------------
1839 void cmTarget::MarkAsImported()
1841 this->IsImportedTarget = true;
1844 //----------------------------------------------------------------------------
1845 std::string cmTarget::GetDirectory(const char* config, bool implib)
1847 if (this->IsImported())
1849 // Return the directory from which the target is imported.
1850 return
1851 cmSystemTools::GetFilenamePath(
1852 this->ImportedGetFullPath(config, implib));
1854 else
1856 // Return the directory in which the target will be built.
1857 if(config && *config)
1859 // Add the configuration's subdirectory.
1860 std::string dir = this->GetOutputDir(implib);
1861 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
1862 AppendDirectoryForConfig("/", config, "", dir);
1863 return dir;
1865 else
1867 return this->GetOutputDir(implib);
1872 //----------------------------------------------------------------------------
1873 const char* cmTarget::GetLocation(const char* config)
1875 if (this->IsImported())
1877 return this->ImportedGetLocation(config);
1879 else
1881 return this->NormalGetLocation(config);
1885 //----------------------------------------------------------------------------
1886 const char* cmTarget::ImportedGetLocation(const char* config)
1888 this->Location = this->ImportedGetFullPath(config, false);
1889 return this->Location.c_str();
1892 //----------------------------------------------------------------------------
1893 const char* cmTarget::NormalGetLocation(const char* config)
1895 // Handle the configuration-specific case first.
1896 if(config)
1898 this->Location = this->GetFullPath(config, false);
1899 return this->Location.c_str();
1902 // Now handle the deprecated build-time configuration location.
1903 this->Location = this->GetDirectory();
1904 if(!this->Location.empty())
1906 this->Location += "/";
1908 const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
1909 if(cfgid && strcmp(cfgid, ".") != 0)
1911 this->Location += cfgid;
1912 this->Location += "/";
1914 if(this->IsFrameworkOnApple())
1916 this->Location += this->GetFullName(config, false);
1917 this->Location += ".framework/Versions/";
1918 this->Location += this->GetFrameworkVersion();
1919 this->Location += "/";
1921 this->Location += this->GetFullName(config, false);
1922 return this->Location.c_str();
1925 //----------------------------------------------------------------------------
1926 void cmTarget::GetTargetVersion(int& major, int& minor)
1928 int patch;
1929 this->GetTargetVersion(false, major, minor, patch);
1932 //----------------------------------------------------------------------------
1933 void cmTarget::GetTargetVersion(bool soversion,
1934 int& major, int& minor, int& patch)
1936 // Set the default values.
1937 major = 0;
1938 minor = 0;
1939 patch = 0;
1941 // Look for a VERSION or SOVERSION property.
1942 const char* prop = soversion? "SOVERSION" : "VERSION";
1943 if(const char* version = this->GetProperty(prop))
1945 // Try to parse the version number and store the results that were
1946 // successfully parsed.
1947 int parsed_major;
1948 int parsed_minor;
1949 int parsed_patch;
1950 switch(sscanf(version, "%d.%d.%d",
1951 &parsed_major, &parsed_minor, &parsed_patch))
1953 case 3: patch = parsed_patch; // no break!
1954 case 2: minor = parsed_minor; // no break!
1955 case 1: major = parsed_major; // no break!
1956 default: break;
1961 //----------------------------------------------------------------------------
1962 const char *cmTarget::GetProperty(const char* prop)
1964 return this->GetProperty(prop, cmProperty::TARGET);
1967 //----------------------------------------------------------------------------
1968 void cmTarget::ComputeObjectFiles()
1970 if (this->IsImported())
1972 return;
1974 #if 0
1975 std::vector<std::string> dirs;
1976 this->Makefile->GetLocalGenerator()->
1977 GetTargetObjectFileDirectories(this,
1978 dirs);
1979 std::string objectFiles;
1980 std::string objExtensionLookup1 = "CMAKE_";
1981 std::string objExtensionLookup2 = "_OUTPUT_EXTENSION";
1983 for(std::vector<std::string>::iterator d = dirs.begin();
1984 d != dirs.end(); ++d)
1986 for(std::vector<cmSourceFile*>::iterator s = this->SourceFiles.begin();
1987 s != this->SourceFiles.end(); ++s)
1989 cmSourceFile* sf = *s;
1990 if(const char* lang = sf->GetLanguage())
1992 std::string lookupObj = objExtensionLookup1 + lang;
1993 lookupObj += objExtensionLookup2;
1994 const char* obj = this->Makefile->GetDefinition(lookupObj.c_str());
1995 if(obj)
1997 if(objectFiles.size())
1999 objectFiles += ";";
2001 std::string objFile = *d;
2002 objFile += "/";
2003 objFile += this->Makefile->GetLocalGenerator()->
2004 GetSourceObjectName(*sf);
2005 objFile += obj;
2006 objectFiles += objFile;
2011 this->SetProperty("OBJECT_FILES", objectFiles.c_str());
2012 #endif
2015 //----------------------------------------------------------------------------
2016 const char *cmTarget::GetProperty(const char* prop,
2017 cmProperty::ScopeType scope)
2019 if(!prop)
2021 return 0;
2024 // Watch for special "computed" properties that are dependent on
2025 // other properties or variables. Always recompute them.
2026 if(this->GetType() == cmTarget::EXECUTABLE ||
2027 this->GetType() == cmTarget::STATIC_LIBRARY ||
2028 this->GetType() == cmTarget::SHARED_LIBRARY ||
2029 this->GetType() == cmTarget::MODULE_LIBRARY ||
2030 this->GetType() == cmTarget::UNKNOWN_LIBRARY)
2032 if(!this->IsImported() && strcmp(prop,"LOCATION") == 0)
2034 // Set the LOCATION property of the target. Note that this
2035 // cannot take into account the per-configuration name of the
2036 // target because the configuration type may not be known at
2037 // CMake time. It is now deprecated as described in the
2038 // documentation.
2039 this->SetProperty("LOCATION", this->GetLocation(0));
2042 // Support "LOCATION_<CONFIG>".
2043 if(strncmp(prop, "LOCATION_", 9) == 0)
2045 std::string configName = prop+9;
2046 this->SetProperty(prop, this->GetLocation(configName.c_str()));
2048 else
2050 // Support "<CONFIG>_LOCATION" for compatiblity.
2051 int len = static_cast<int>(strlen(prop));
2052 if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
2054 std::string configName(prop, len-9);
2055 if(configName != "IMPORTED")
2057 this->SetProperty(prop, this->GetLocation(configName.c_str()));
2063 if (strcmp(prop,"IMPORTED") == 0)
2065 return this->IsImported()?"TRUE":"FALSE";
2068 if(!strcmp(prop,"SOURCES"))
2070 cmOStringStream ss;
2071 const char* sep = "";
2072 for(std::vector<cmSourceFile*>::const_iterator
2073 i = this->SourceFiles.begin();
2074 i != this->SourceFiles.end(); ++i)
2076 // Separate from the previous list entries.
2077 ss << sep;
2078 sep = ";";
2080 // Construct what is known about this source file location.
2081 cmSourceFileLocation const& location = (*i)->GetLocation();
2082 std::string sname = location.GetDirectory();
2083 if(!sname.empty())
2085 sname += "/";
2087 sname += location.GetName();
2089 // Append this list entry.
2090 ss << sname;
2092 this->SetProperty("SOURCES", ss.str().c_str());
2095 // the type property returns what type the target is
2096 if (!strcmp(prop,"TYPE"))
2098 switch( this->GetType() )
2100 case cmTarget::STATIC_LIBRARY:
2101 return "STATIC_LIBRARY";
2102 // break; /* unreachable */
2103 case cmTarget::MODULE_LIBRARY:
2104 return "MODULE_LIBRARY";
2105 // break; /* unreachable */
2106 case cmTarget::SHARED_LIBRARY:
2107 return "SHARED_LIBRARY";
2108 // break; /* unreachable */
2109 case cmTarget::EXECUTABLE:
2110 return "EXECUTABLE";
2111 // break; /* unreachable */
2112 case cmTarget::UTILITY:
2113 return "UTILITY";
2114 // break; /* unreachable */
2115 case cmTarget::GLOBAL_TARGET:
2116 return "GLOBAL_TARGET";
2117 // break; /* unreachable */
2118 case cmTarget::INSTALL_FILES:
2119 return "INSTALL_FILES";
2120 // break; /* unreachable */
2121 case cmTarget::INSTALL_PROGRAMS:
2122 return "INSTALL_PROGRAMS";
2123 // break; /* unreachable */
2124 case cmTarget::INSTALL_DIRECTORY:
2125 return "INSTALL_DIRECTORY";
2126 // break; /* unreachable */
2127 case cmTarget::UNKNOWN_LIBRARY:
2128 return "UNKNOWN_LIBRARY";
2129 // break; /* unreachable */
2131 return 0;
2133 bool chain = false;
2134 const char *retVal =
2135 this->Properties.GetPropertyValue(prop, scope, chain);
2136 if (chain)
2138 return this->Makefile->GetProperty(prop,scope);
2140 return retVal;
2143 //----------------------------------------------------------------------------
2144 bool cmTarget::GetPropertyAsBool(const char* prop)
2146 return cmSystemTools::IsOn(this->GetProperty(prop));
2149 //----------------------------------------------------------------------------
2150 const char* cmTarget::GetLinkerLanguage(cmGlobalGenerator* gg)
2152 if(this->GetProperty("HAS_CXX"))
2154 const_cast<cmTarget*>(this)->SetProperty("LINKER_LANGUAGE", "CXX");
2156 const char* linkerLang = this->GetProperty("LINKER_LANGUAGE");
2157 if (linkerLang==0)
2159 // if the property has not yet been set, collect all languages in the
2160 // target and then find the language with the highest preference value
2161 std::set<cmStdString> languages;
2162 this->GetLanguages(languages);
2164 std::string linkerLangList; // only used for the error message
2165 int maxLinkerPref = 0;
2166 bool multiplePreferedLanguages = false;
2167 for(std::set<cmStdString>::const_iterator sit = languages.begin();
2168 sit != languages.end(); ++sit)
2170 int linkerPref = gg->GetLinkerPreference(sit->c_str());
2171 if ((linkerPref > maxLinkerPref) || (linkerLang==0))
2173 maxLinkerPref = linkerPref;
2174 linkerLang = sit->c_str();
2175 linkerLangList = *sit;
2176 multiplePreferedLanguages = false;
2178 else if (linkerPref == maxLinkerPref)
2180 linkerLangList += "; ";
2181 linkerLangList += *sit;
2182 multiplePreferedLanguages = true;
2186 if (linkerLang!=0)
2188 const_cast<cmTarget*>(this)->SetProperty("LINKER_LANGUAGE", linkerLang);
2190 if (multiplePreferedLanguages)
2192 cmOStringStream err;
2193 err << "Error: Target " << this->Name << " contains multiple languages "
2194 << "with the highest linker preference (" << maxLinkerPref << "): "
2195 << linkerLangList << "\n"
2196 << "You must set the LINKER_LANGUAGE property for this target.";
2197 cmSystemTools::Error(err.str().c_str());
2200 return this->GetProperty("LINKER_LANGUAGE");
2203 //----------------------------------------------------------------------------
2204 const char* cmTarget::GetCreateRuleVariable()
2206 switch(this->GetType())
2208 case cmTarget::STATIC_LIBRARY:
2209 return "_CREATE_STATIC_LIBRARY";
2210 case cmTarget::SHARED_LIBRARY:
2211 return "_CREATE_SHARED_LIBRARY";
2212 case cmTarget::MODULE_LIBRARY:
2213 return "_CREATE_SHARED_MODULE";
2214 case cmTarget::EXECUTABLE:
2215 return "_LINK_EXECUTABLE";
2216 default:
2217 break;
2219 return "";
2222 //----------------------------------------------------------------------------
2223 const char* cmTarget::GetSuffixVariableInternal(TargetType type,
2224 bool implib)
2226 switch(type)
2228 case cmTarget::STATIC_LIBRARY:
2229 return "CMAKE_STATIC_LIBRARY_SUFFIX";
2230 case cmTarget::SHARED_LIBRARY:
2231 return (implib
2232 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2233 : "CMAKE_SHARED_LIBRARY_SUFFIX");
2234 case cmTarget::MODULE_LIBRARY:
2235 return (implib
2236 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2237 : "CMAKE_SHARED_MODULE_SUFFIX");
2238 case cmTarget::EXECUTABLE:
2239 return (implib
2240 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2241 : "CMAKE_EXECUTABLE_SUFFIX");
2242 default:
2243 break;
2245 return "";
2249 //----------------------------------------------------------------------------
2250 const char* cmTarget::GetPrefixVariableInternal(TargetType type,
2251 bool implib)
2253 switch(type)
2255 case cmTarget::STATIC_LIBRARY:
2256 return "CMAKE_STATIC_LIBRARY_PREFIX";
2257 case cmTarget::SHARED_LIBRARY:
2258 return (implib
2259 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2260 : "CMAKE_SHARED_LIBRARY_PREFIX");
2261 case cmTarget::MODULE_LIBRARY:
2262 return (implib
2263 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2264 : "CMAKE_SHARED_MODULE_PREFIX");
2265 case cmTarget::EXECUTABLE:
2266 return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
2267 default:
2268 break;
2270 return "";
2273 //----------------------------------------------------------------------------
2274 std::string cmTarget::GetPDBName(const char* config)
2276 std::string prefix;
2277 std::string base;
2278 std::string suffix;
2279 this->GetFullNameInternal(this->GetType(), config, false,
2280 prefix, base, suffix);
2281 return prefix+base+".pdb";
2284 //----------------------------------------------------------------------------
2285 std::string cmTarget::GetSOName(const char* config)
2287 if(this->IsImported())
2289 // Lookup the imported soname.
2290 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
2292 if(info->NoSOName)
2294 // The imported library has no builtin soname so the name
2295 // searched at runtime will be just the filename.
2296 return cmSystemTools::GetFilenameName(info->Location);
2298 else
2300 // Use the soname given if any.
2301 return info->SOName;
2304 else
2306 return "";
2309 else
2311 // Compute the soname that will be built.
2312 std::string name;
2313 std::string soName;
2314 std::string realName;
2315 std::string impName;
2316 std::string pdbName;
2317 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
2318 return soName;
2322 //----------------------------------------------------------------------------
2323 bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
2325 if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
2327 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
2329 return info->NoSOName;
2332 return false;
2335 //----------------------------------------------------------------------------
2336 std::string cmTarget::NormalGetRealName(const char* config)
2338 // This should not be called for imported targets.
2339 // TODO: Split cmTarget into a class hierarchy to get compile-time
2340 // enforcement of the limited imported target API.
2341 if(this->IsImported())
2343 std::string msg = "NormalGetRealName called on imported target: ";
2344 msg += this->GetName();
2345 this->GetMakefile()->
2346 IssueMessage(cmake::INTERNAL_ERROR,
2347 msg.c_str());
2350 if(this->GetType() == cmTarget::EXECUTABLE)
2352 // Compute the real name that will be built.
2353 std::string name;
2354 std::string realName;
2355 std::string impName;
2356 std::string pdbName;
2357 this->GetExecutableNames(name, realName, impName, pdbName, config);
2358 return realName;
2360 else
2362 // Compute the real name that will be built.
2363 std::string name;
2364 std::string soName;
2365 std::string realName;
2366 std::string impName;
2367 std::string pdbName;
2368 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
2369 return realName;
2373 //----------------------------------------------------------------------------
2374 std::string cmTarget::GetFullName(const char* config, bool implib)
2376 if(this->IsImported())
2378 return this->GetFullNameImported(config, implib);
2380 else
2382 return this->GetFullNameInternal(this->GetType(), config, implib);
2386 //----------------------------------------------------------------------------
2387 std::string cmTarget::GetFullNameImported(const char* config, bool implib)
2389 return cmSystemTools::GetFilenameName(
2390 this->ImportedGetFullPath(config, implib));
2393 //----------------------------------------------------------------------------
2394 void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
2395 std::string& suffix, const char* config,
2396 bool implib)
2398 this->GetFullNameInternal(this->GetType(), config, implib,
2399 prefix, base, suffix);
2402 //----------------------------------------------------------------------------
2403 std::string cmTarget::GetFullPath(const char* config, bool implib,
2404 bool realname)
2406 if(this->IsImported())
2408 return this->ImportedGetFullPath(config, implib);
2410 else
2412 return this->NormalGetFullPath(config, implib, realname);
2416 //----------------------------------------------------------------------------
2417 std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
2418 bool realname)
2420 // Start with the output directory for the target.
2421 std::string fpath = this->GetDirectory(config, implib);
2422 fpath += "/";
2424 if(this->IsFrameworkOnApple())
2426 fpath += this->GetFullName(config, false);
2427 fpath += ".framework/Versions/";
2428 fpath += this->GetFrameworkVersion();
2429 fpath += "/";
2432 // Add the full name of the target.
2433 if(implib)
2435 fpath += this->GetFullName(config, true);
2437 else if(realname)
2439 fpath += this->NormalGetRealName(config);
2441 else
2443 fpath += this->GetFullName(config, false);
2445 return fpath;
2448 //----------------------------------------------------------------------------
2449 std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
2451 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
2453 if(implib)
2455 return info->ImportLibrary;
2457 else
2459 return info->Location;
2462 else
2464 std::string result = this->GetName();
2465 result += "-NOTFOUND";
2466 return result;
2470 //----------------------------------------------------------------------------
2471 std::string
2472 cmTarget::GetFullNameInternal(TargetType type, const char* config,
2473 bool implib)
2475 std::string prefix;
2476 std::string base;
2477 std::string suffix;
2478 this->GetFullNameInternal(type, config, implib, prefix, base, suffix);
2479 return prefix+base+suffix;
2482 //----------------------------------------------------------------------------
2483 void cmTarget::GetFullNameInternal(TargetType type,
2484 const char* config,
2485 bool implib,
2486 std::string& outPrefix,
2487 std::string& outBase,
2488 std::string& outSuffix)
2490 // Use just the target name for non-main target types.
2491 if(type != cmTarget::STATIC_LIBRARY &&
2492 type != cmTarget::SHARED_LIBRARY &&
2493 type != cmTarget::MODULE_LIBRARY &&
2494 type != cmTarget::EXECUTABLE)
2496 outPrefix = "";
2497 outBase = this->GetName();
2498 outSuffix = "";
2499 return;
2502 // Return an empty name for the import library if this platform
2503 // does not support import libraries.
2504 if(implib &&
2505 !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
2507 outPrefix = "";
2508 outBase = "";
2509 outSuffix = "";
2510 return;
2513 // The implib option is only allowed for shared libraries, module
2514 // libraries, and executables.
2515 if(type != cmTarget::SHARED_LIBRARY &&
2516 type != cmTarget::MODULE_LIBRARY &&
2517 type != cmTarget::EXECUTABLE)
2519 implib = false;
2522 // Compute the full name for main target types.
2523 const char* targetPrefix = (implib
2524 ? this->GetProperty("IMPORT_PREFIX")
2525 : this->GetProperty("PREFIX"));
2526 const char* targetSuffix = (implib
2527 ? this->GetProperty("IMPORT_SUFFIX")
2528 : this->GetProperty("SUFFIX"));
2529 const char* configPostfix = 0;
2530 if(config && *config)
2532 std::string configProp = cmSystemTools::UpperCase(config);
2533 configProp += "_POSTFIX";
2534 configPostfix = this->GetProperty(configProp.c_str());
2535 // Mac application bundles and frameworks have no postfix.
2536 if(configPostfix &&
2537 (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
2539 configPostfix = 0;
2542 const char* prefixVar = this->GetPrefixVariableInternal(type, implib);
2543 const char* suffixVar = this->GetSuffixVariableInternal(type, implib);
2544 const char* ll =
2545 this->GetLinkerLanguage(
2546 this->Makefile->GetLocalGenerator()->GetGlobalGenerator());
2547 // first try language specific suffix
2548 if(ll)
2550 if(!targetSuffix && suffixVar && *suffixVar)
2552 std::string langSuff = suffixVar + std::string("_") + ll;
2553 targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
2555 if(!targetPrefix && prefixVar && *prefixVar)
2557 std::string langPrefix = prefixVar + std::string("_") + ll;
2558 targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
2562 // if there is no prefix on the target use the cmake definition
2563 if(!targetPrefix && prefixVar)
2565 targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
2567 // if there is no suffix on the target use the cmake definition
2568 if(!targetSuffix && suffixVar)
2570 targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
2573 // frameworks do not have a prefix or a suffix
2574 if(this->IsFrameworkOnApple())
2576 targetPrefix = 0;
2577 targetSuffix = 0;
2580 // Begin the final name with the prefix.
2581 outPrefix = targetPrefix?targetPrefix:"";
2583 // Append the target name or property-specified name.
2584 const char* outName = 0;
2585 if(config && *config)
2587 std::string configProp = cmSystemTools::UpperCase(config);
2588 configProp += "_OUTPUT_NAME";
2589 outName = this->GetProperty(configProp.c_str());
2591 if(!outName)
2593 outName = this->GetProperty("OUTPUT_NAME");
2595 if(outName)
2597 outBase = outName;
2599 else
2601 outBase = this->GetName();
2604 // Append the per-configuration postfix.
2605 outBase += configPostfix?configPostfix:"";
2607 // Name shared libraries with their version number on some platforms.
2608 if(const char* version = this->GetProperty("VERSION"))
2610 if(type == cmTarget::SHARED_LIBRARY && !implib &&
2611 this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
2613 outBase += "-";
2614 outBase += version;
2618 // Append the suffix.
2619 outSuffix = targetSuffix?targetSuffix:"";
2622 //----------------------------------------------------------------------------
2623 void cmTarget::GetLibraryNames(std::string& name,
2624 std::string& soName,
2625 std::string& realName,
2626 std::string& impName,
2627 std::string& pdbName,
2628 const char* config)
2630 // Get the names based on the real type of the library.
2631 this->GetLibraryNamesInternal(name, soName, realName, impName, pdbName,
2632 this->GetType(), config);
2635 //----------------------------------------------------------------------------
2636 void cmTarget::GetLibraryCleanNames(std::string& staticName,
2637 std::string& sharedName,
2638 std::string& sharedSOName,
2639 std::string& sharedRealName,
2640 std::string& importName,
2641 std::string& pdbName,
2642 const char* config)
2644 // Get the name as if this were a static library.
2645 std::string soName;
2646 std::string realName;
2647 std::string impName;
2648 this->GetLibraryNamesInternal(staticName, soName, realName, impName,
2649 pdbName, cmTarget::STATIC_LIBRARY, config);
2651 // Get the names as if this were a shared library.
2652 if(this->GetType() == cmTarget::STATIC_LIBRARY)
2654 // Since the real type is static then the user either specified
2655 // STATIC or did not specify a type. In the former case the
2656 // shared library will never be present. In the latter case the
2657 // type will never be MODULE. Either way the only names that
2658 // might have to be cleaned are the shared library names.
2659 this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
2660 importName, pdbName,
2661 cmTarget::SHARED_LIBRARY, config);
2663 else
2665 // Use the name of the real type of the library (shared or module).
2666 this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
2667 importName, pdbName, this->GetType(),
2668 config);
2672 //----------------------------------------------------------------------------
2673 void cmTarget::GetLibraryNamesInternal(std::string& name,
2674 std::string& soName,
2675 std::string& realName,
2676 std::string& impName,
2677 std::string& pdbName,
2678 TargetType type,
2679 const char* config)
2681 // This should not be called for imported targets.
2682 // TODO: Split cmTarget into a class hierarchy to get compile-time
2683 // enforcement of the limited imported target API.
2684 if(this->IsImported())
2686 std::string msg = "GetLibraryNamesInternal called on imported target: ";
2687 msg += this->GetName();
2688 this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
2689 msg.c_str());
2690 return;
2693 // Construct the name of the soname flag variable for this language.
2694 const char* ll =
2695 this->GetLinkerLanguage(
2696 this->Makefile->GetLocalGenerator()->GetGlobalGenerator());
2697 std::string sonameFlag = "CMAKE_SHARED_LIBRARY_SONAME";
2698 if(ll)
2700 sonameFlag += "_";
2701 sonameFlag += ll;
2703 sonameFlag += "_FLAG";
2705 // Check for library version properties.
2706 const char* version = this->GetProperty("VERSION");
2707 const char* soversion = this->GetProperty("SOVERSION");
2708 if((type != cmTarget::SHARED_LIBRARY && type != cmTarget::MODULE_LIBRARY) ||
2709 !this->Makefile->GetDefinition(sonameFlag.c_str()) ||
2710 this->IsFrameworkOnApple())
2712 // Versioning is supported only for shared libraries and modules,
2713 // and then only when the platform supports an soname flag.
2714 version = 0;
2715 soversion = 0;
2717 if(version && !soversion)
2719 // The soversion must be set if the library version is set. Use
2720 // the library version as the soversion.
2721 soversion = version;
2724 // Get the components of the library name.
2725 std::string prefix;
2726 std::string base;
2727 std::string suffix;
2728 this->GetFullNameInternal(type, config, false, prefix, base, suffix);
2730 // The library name.
2731 name = prefix+base+suffix;
2733 // The library's soname.
2734 #if defined(__APPLE__)
2735 soName = prefix+base;
2736 #else
2737 soName = name;
2738 #endif
2739 if(soversion)
2741 soName += ".";
2742 soName += soversion;
2744 #if defined(__APPLE__)
2745 soName += suffix;
2746 #endif
2748 // The library's real name on disk.
2749 #if defined(__APPLE__)
2750 realName = prefix+base;
2751 #else
2752 realName = name;
2753 #endif
2754 if(version)
2756 realName += ".";
2757 realName += version;
2759 else if(soversion)
2761 realName += ".";
2762 realName += soversion;
2764 #if defined(__APPLE__)
2765 realName += suffix;
2766 #endif
2768 // The import library name.
2769 if(type == cmTarget::SHARED_LIBRARY ||
2770 type == cmTarget::MODULE_LIBRARY)
2772 impName = this->GetFullNameInternal(type, config, true);
2774 else
2776 impName = "";
2779 // The program database file name.
2780 pdbName = prefix+base+".pdb";
2783 //----------------------------------------------------------------------------
2784 void cmTarget::GetExecutableNames(std::string& name,
2785 std::string& realName,
2786 std::string& impName,
2787 std::string& pdbName,
2788 const char* config)
2790 // Get the names based on the real type of the executable.
2791 this->GetExecutableNamesInternal(name, realName, impName, pdbName,
2792 this->GetType(), config);
2795 //----------------------------------------------------------------------------
2796 void cmTarget::GetExecutableCleanNames(std::string& name,
2797 std::string& realName,
2798 std::string& impName,
2799 std::string& pdbName,
2800 const char* config)
2802 // Get the name and versioned name of this executable.
2803 this->GetExecutableNamesInternal(name, realName, impName, pdbName,
2804 cmTarget::EXECUTABLE, config);
2807 //----------------------------------------------------------------------------
2808 void cmTarget::GetExecutableNamesInternal(std::string& name,
2809 std::string& realName,
2810 std::string& impName,
2811 std::string& pdbName,
2812 TargetType type,
2813 const char* config)
2815 // This should not be called for imported targets.
2816 // TODO: Split cmTarget into a class hierarchy to get compile-time
2817 // enforcement of the limited imported target API.
2818 if(this->IsImported())
2820 std::string msg =
2821 "GetExecutableNamesInternal called on imported target: ";
2822 msg += this->GetName();
2823 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
2826 // This versioning is supported only for executables and then only
2827 // when the platform supports symbolic links.
2828 #if defined(_WIN32) && !defined(__CYGWIN__)
2829 const char* version = 0;
2830 #else
2831 // Check for executable version properties.
2832 const char* version = this->GetProperty("VERSION");
2833 if(type != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
2835 version = 0;
2837 #endif
2839 // Get the components of the executable name.
2840 std::string prefix;
2841 std::string base;
2842 std::string suffix;
2843 this->GetFullNameInternal(type, config, false, prefix, base, suffix);
2845 // The executable name.
2846 name = prefix+base+suffix;
2848 // The executable's real name on disk.
2849 #if defined(__CYGWIN__)
2850 realName = prefix+base;
2851 #else
2852 realName = name;
2853 #endif
2854 if(version)
2856 realName += "-";
2857 realName += version;
2859 #if defined(__CYGWIN__)
2860 realName += suffix;
2861 #endif
2863 // The import library name.
2864 impName = this->GetFullNameInternal(type, config, true);
2866 // The program database file name.
2867 pdbName = prefix+base+".pdb";
2870 //----------------------------------------------------------------------------
2871 void cmTarget::GenerateTargetManifest(const char* config)
2873 cmMakefile* mf = this->Makefile;
2874 cmLocalGenerator* lg = mf->GetLocalGenerator();
2875 cmGlobalGenerator* gg = lg->GetGlobalGenerator();
2877 // Get the names.
2878 std::string name;
2879 std::string soName;
2880 std::string realName;
2881 std::string impName;
2882 std::string pdbName;
2883 if(this->GetType() == cmTarget::EXECUTABLE)
2885 this->GetExecutableNames(name, realName, impName, pdbName, config);
2887 else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
2888 this->GetType() == cmTarget::SHARED_LIBRARY ||
2889 this->GetType() == cmTarget::MODULE_LIBRARY)
2891 this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
2893 else
2895 return;
2898 // Get the directory.
2899 std::string dir = this->GetDirectory(config, false);
2901 // Add each name.
2902 std::string f;
2903 if(!name.empty())
2905 f = dir;
2906 f += "/";
2907 f += name;
2908 gg->AddToManifest(config? config:"", f);
2910 if(!soName.empty())
2912 f = dir;
2913 f += "/";
2914 f += soName;
2915 gg->AddToManifest(config? config:"", f);
2917 if(!realName.empty())
2919 f = dir;
2920 f += "/";
2921 f += realName;
2922 gg->AddToManifest(config? config:"", f);
2924 if(!pdbName.empty())
2926 f = dir;
2927 f += "/";
2928 f += pdbName;
2929 gg->AddToManifest(config? config:"", f);
2931 if(!impName.empty())
2933 f = this->GetDirectory(config, true);
2934 f += "/";
2935 f += impName;
2936 gg->AddToManifest(config? config:"", f);
2940 //----------------------------------------------------------------------------
2941 void cmTarget::SetPropertyDefault(const char* property,
2942 const char* default_value)
2944 // Compute the name of the variable holding the default value.
2945 std::string var = "CMAKE_";
2946 var += property;
2948 if(const char* value = this->Makefile->GetDefinition(var.c_str()))
2950 this->SetProperty(property, value);
2952 else if(default_value)
2954 this->SetProperty(property, default_value);
2958 //----------------------------------------------------------------------------
2959 bool cmTarget::HaveBuildTreeRPATH()
2961 return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
2962 !this->LinkLibraries.empty());
2965 //----------------------------------------------------------------------------
2966 bool cmTarget::HaveInstallTreeRPATH()
2968 const char* install_rpath = this->GetProperty("INSTALL_RPATH");
2969 return install_rpath && *install_rpath;
2972 //----------------------------------------------------------------------------
2973 bool cmTarget::NeedRelinkBeforeInstall()
2975 // Only executables and shared libraries can have an rpath and may
2976 // need relinking.
2977 if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
2978 this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
2979 this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
2981 return false;
2984 // If there is no install location this target will not be installed
2985 // and therefore does not need relinking.
2986 if(!this->GetHaveInstallRule())
2988 return false;
2991 // If skipping all rpaths completely then no relinking is needed.
2992 if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
2994 return false;
2997 // If building with the install-tree rpath no relinking is needed.
2998 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3000 return false;
3003 // If chrpath is going to be used no relinking is needed.
3004 if(this->IsChrpathUsed())
3006 return false;
3009 // Check for rpath support on this platform.
3010 if(const char* ll = this->GetLinkerLanguage(
3011 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()))
3013 std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
3014 flagVar += ll;
3015 flagVar += "_FLAG";
3016 if(!this->Makefile->IsSet(flagVar.c_str()))
3018 // There is no rpath support on this platform so nothing needs
3019 // relinking.
3020 return false;
3023 else
3025 // No linker language is known. This error will be reported by
3026 // other code.
3027 return false;
3030 // If either a build or install tree rpath is set then the rpath
3031 // will likely change between the build tree and install tree and
3032 // this target must be relinked.
3033 return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
3036 //----------------------------------------------------------------------------
3037 std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
3038 bool for_xcode)
3040 // If building directly for installation then the build tree install_name
3041 // is the same as the install tree.
3042 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3044 return GetInstallNameDirForInstallTree(config, for_xcode);
3047 // Use the build tree directory for the target.
3048 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3049 !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
3050 !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
3052 std::string dir = this->GetDirectory(config);
3053 dir += "/";
3054 if(this->IsFrameworkOnApple() && !for_xcode)
3056 dir += this->GetFullName(config, false);
3057 dir += ".framework/Versions/";
3058 dir += this->GetFrameworkVersion();
3059 dir += "/";
3061 return dir;
3063 else
3065 return "";
3069 //----------------------------------------------------------------------------
3070 std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
3071 bool for_xcode)
3073 // Lookup the target property.
3074 const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
3075 if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3076 !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
3077 install_name_dir && *install_name_dir)
3079 std::string dir = install_name_dir;
3080 dir += "/";
3081 if(this->IsFrameworkOnApple() && !for_xcode)
3083 dir += this->GetFullName(config, false);
3084 dir += ".framework/Versions/";
3085 dir += this->GetFrameworkVersion();
3086 dir += "/";
3088 return dir;
3090 else
3092 return "";
3096 //----------------------------------------------------------------------------
3097 std::string cmTarget::GetOutputDir(bool implib)
3099 // The implib option is only allowed for shared libraries, module
3100 // libraries, and executables.
3101 if(this->GetType() != cmTarget::SHARED_LIBRARY &&
3102 this->GetType() != cmTarget::MODULE_LIBRARY &&
3103 this->GetType() != cmTarget::EXECUTABLE)
3105 implib = false;
3108 // Sanity check. Only generators on platforms supporting import
3109 // libraries should be asking for the import library output
3110 // directory.
3111 if(implib &&
3112 !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
3114 std::string msg = "GetOutputDir, imlib set but there is no "
3115 "CMAKE_IMPORT_LIBRARY_SUFFIX for target: ";
3116 msg += this->GetName();
3117 this->GetMakefile()->
3118 IssueMessage(cmake::INTERNAL_ERROR,
3119 msg.c_str());
3121 if(implib && !this->DLLPlatform)
3123 std::string msg = "implib set for platform that does not "
3124 " support DLL's for target: ";
3125 msg += this->GetName();
3126 this->GetMakefile()->
3127 IssueMessage(cmake::INTERNAL_ERROR,
3128 msg.c_str());
3131 return this->ComputeBaseOutputDir(implib);
3134 //----------------------------------------------------------------------------
3135 std::string const& cmTarget::ComputeBaseOutputDir(bool implib)
3137 // Select whether we are constructing the directory for the main
3138 // target or the import library.
3139 std::string& out = implib? this->BaseOutputDirImplib : this->BaseOutputDir;
3141 // Return immediately if the directory has already been computed.
3142 if(!out.empty())
3144 return out;
3147 // Look for a target property defining the target output directory
3148 // based on the target type.
3149 const char* propertyName = 0;
3150 switch(this->GetType())
3152 case cmTarget::SHARED_LIBRARY:
3154 // For non-DLL platforms shared libraries are treated as
3155 // library targets. For DLL platforms the DLL part of a
3156 // shared library is treated as a runtime target and the
3157 // corresponding import library is treated as an archive
3158 // target.
3159 if(this->DLLPlatform)
3161 if(implib)
3163 propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
3165 else
3167 propertyName = "RUNTIME_OUTPUT_DIRECTORY";
3170 else
3172 propertyName = "LIBRARY_OUTPUT_DIRECTORY";
3174 } break;
3175 case cmTarget::STATIC_LIBRARY:
3177 // Static libraries are always treated as archive targets.
3178 propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
3179 } break;
3180 case cmTarget::MODULE_LIBRARY:
3182 // Module libraries are always treated as library targets.
3183 // Module import libraries are treated as archive targets.
3184 if(implib)
3186 propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
3188 else
3190 propertyName = "LIBRARY_OUTPUT_DIRECTORY";
3192 } break;
3193 case cmTarget::EXECUTABLE:
3195 // Executables are always treated as runtime targets.
3196 // Executable import libraries are treated as archive targets.
3197 if(implib)
3199 propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
3201 else
3203 propertyName = "RUNTIME_OUTPUT_DIRECTORY";
3205 } break;
3206 default: break;
3209 // Select an output directory.
3210 if(const char* outdir = this->GetProperty(propertyName))
3212 // Use the user-specified output directory.
3213 out = outdir;
3215 else if(this->GetType() == cmTarget::EXECUTABLE)
3217 // Lookup the output path for executables.
3218 out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
3220 else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
3221 this->GetType() == cmTarget::SHARED_LIBRARY ||
3222 this->GetType() == cmTarget::MODULE_LIBRARY)
3224 // Lookup the output path for libraries.
3225 out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
3227 if(out.empty())
3229 // Default to the current output directory.
3230 out = ".";
3233 // Convert the output path to a full path in case it is
3234 // specified as a relative path. Treat a relative path as
3235 // relative to the current output directory for this makefile.
3236 out = (cmSystemTools::CollapseFullPath
3237 (out.c_str(), this->Makefile->GetStartOutputDirectory()));
3238 return out;
3241 //----------------------------------------------------------------------------
3242 std::string cmTarget::GetFrameworkVersion()
3244 if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
3246 return fversion;
3248 else if(const char* tversion = this->GetProperty("VERSION"))
3250 return tversion;
3252 else
3254 return "A";
3258 //----------------------------------------------------------------------------
3259 const char* cmTarget::GetExportMacro()
3261 // Define the symbol for targets that export symbols.
3262 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3263 this->GetType() == cmTarget::MODULE_LIBRARY ||
3264 this->IsExecutableWithExports())
3266 if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
3268 this->ExportMacro = custom_export_name;
3270 else
3272 std::string in = this->GetName();
3273 in += "_EXPORTS";
3274 this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
3276 return this->ExportMacro.c_str();
3278 else
3280 return 0;
3284 //----------------------------------------------------------------------------
3285 void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
3287 for(std::vector<cmSourceFile*>::const_iterator
3288 i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
3290 if(const char* lang = (*i)->GetLanguage())
3292 languages.insert(lang);
3297 //----------------------------------------------------------------------------
3298 bool cmTarget::IsChrpathUsed()
3300 #if defined(CMAKE_USE_ELF_PARSER)
3301 // Only certain target types have an rpath.
3302 if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
3303 this->GetType() == cmTarget::MODULE_LIBRARY ||
3304 this->GetType() == cmTarget::EXECUTABLE))
3306 return false;
3309 // If the target will not be installed we do not need to change its
3310 // rpath.
3311 if(!this->GetHaveInstallRule())
3313 return false;
3316 // Skip chrpath if skipping rpath altogether.
3317 if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
3319 return false;
3322 // Skip chrpath if it does not need to be changed at install time.
3323 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3325 return false;
3328 // Allow the user to disable builtin chrpath explicitly.
3329 if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
3331 return false;
3334 // Enable if the rpath flag uses a separator and the target uses ELF
3335 // binaries.
3336 if(const char* ll = this->GetLinkerLanguage(
3337 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()))
3339 std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
3340 sepVar += ll;
3341 sepVar += "_FLAG_SEP";
3342 const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
3343 if(sep && *sep)
3345 // TODO: Add ELF check to ABI detection and get rid of
3346 // CMAKE_EXECUTABLE_FORMAT.
3347 if(const char* fmt =
3348 this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
3350 return strcmp(fmt, "ELF") == 0;
3354 #endif
3355 return false;
3358 //----------------------------------------------------------------------------
3359 cmTarget::ImportInfo const*
3360 cmTarget::GetImportInfo(const char* config)
3362 // There is no imported information for non-imported targets.
3363 if(!this->IsImported())
3365 return 0;
3368 // Lookup/compute/cache the import information for this
3369 // configuration.
3370 std::string config_upper;
3371 if(config && *config)
3373 config_upper = cmSystemTools::UpperCase(config);
3375 else
3377 config_upper = "NOCONFIG";
3379 ImportInfoMapType::const_iterator i =
3380 this->ImportInfoMap.find(config_upper);
3381 if(i == this->ImportInfoMap.end())
3383 ImportInfo info;
3384 this->ComputeImportInfo(config_upper, info);
3385 ImportInfoMapType::value_type entry(config_upper, info);
3386 i = this->ImportInfoMap.insert(entry).first;
3389 // If the location is empty then the target is not available for
3390 // this configuration.
3391 if(i->second.Location.empty())
3393 return 0;
3396 // Return the import information.
3397 return &i->second;
3400 //----------------------------------------------------------------------------
3401 void cmTarget::ComputeImportInfo(std::string const& desired_config,
3402 ImportInfo& info)
3404 // This method finds information about an imported target from its
3405 // properties. The "IMPORTED_" namespace is reserved for properties
3406 // defined by the project exporting the target.
3408 // Initialize members.
3409 info.NoSOName = false;
3411 // Track the configuration-specific property suffix.
3412 std::string suffix = "_";
3413 suffix += desired_config;
3415 // Look for a mapping from the current project's configuration to
3416 // the imported project's configuration.
3417 std::vector<std::string> mappedConfigs;
3419 std::string mapProp = "MAP_IMPORTED_CONFIG_";
3420 mapProp += desired_config;
3421 if(const char* mapValue = this->GetProperty(mapProp.c_str()))
3423 cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
3427 // If a mapping was found, check its configurations.
3428 const char* loc = 0;
3429 for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
3430 !loc && mci != mappedConfigs.end(); ++mci)
3432 // Look for this configuration.
3433 std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
3434 std::string locProp = "IMPORTED_LOCATION_";
3435 locProp += mcUpper;
3436 loc = this->GetProperty(locProp.c_str());
3438 // If it was found, use it for all properties below.
3439 if(loc)
3441 suffix = "_";
3442 suffix += mcUpper;
3446 // If we needed to find one of the mapped configurations but did not
3447 // then the target is not found. The project does not want any
3448 // other configuration.
3449 if(!mappedConfigs.empty() && !loc)
3451 return;
3454 // If we have not yet found it then there are no mapped
3455 // configurations. Look for an exact-match.
3456 if(!loc)
3458 std::string locProp = "IMPORTED_LOCATION";
3459 locProp += suffix;
3460 loc = this->GetProperty(locProp.c_str());
3463 // If we have not yet found it then there are no mapped
3464 // configurations and no exact match.
3465 if(!loc)
3467 // The suffix computed above is not useful.
3468 suffix = "";
3470 // Look for a configuration-less location. This may be set by
3471 // manually-written code.
3472 loc = this->GetProperty("IMPORTED_LOCATION");
3475 // If we have not yet found it then the project is willing to try
3476 // any available configuration.
3477 if(!loc)
3479 std::vector<std::string> availableConfigs;
3480 if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
3482 cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
3484 for(std::vector<std::string>::const_iterator
3485 aci = availableConfigs.begin();
3486 !loc && aci != availableConfigs.end(); ++aci)
3488 suffix = "_";
3489 suffix += cmSystemTools::UpperCase(availableConfigs[0]);
3490 std::string locProp = "IMPORTED_LOCATION";
3491 locProp += suffix;
3492 loc = this->GetProperty(locProp.c_str());
3496 // If we have not yet found it then the target is not available.
3497 if(!loc)
3499 return;
3502 // A provided configuration has been chosen. Load the
3503 // configuration's properties.
3504 info.Location = loc;
3506 // Get the soname.
3507 if(this->GetType() == cmTarget::SHARED_LIBRARY)
3509 std::string soProp = "IMPORTED_SONAME";
3510 soProp += suffix;
3511 if(const char* config_soname = this->GetProperty(soProp.c_str()))
3513 info.SOName = config_soname;
3515 else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
3517 info.SOName = soname;
3521 // Get the "no-soname" mark.
3522 if(this->GetType() == cmTarget::SHARED_LIBRARY)
3524 std::string soProp = "IMPORTED_NO_SONAME";
3525 soProp += suffix;
3526 if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
3528 info.NoSOName = cmSystemTools::IsOn(config_no_soname);
3530 else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
3532 info.NoSOName = cmSystemTools::IsOn(no_soname);
3536 // Get the import library.
3537 if(this->GetType() == cmTarget::SHARED_LIBRARY ||
3538 this->IsExecutableWithExports())
3540 std::string impProp = "IMPORTED_IMPLIB";
3541 impProp += suffix;
3542 if(const char* config_implib = this->GetProperty(impProp.c_str()))
3544 info.ImportLibrary = config_implib;
3546 else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
3548 info.ImportLibrary = implib;
3552 // Get the link interface.
3554 std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
3555 linkProp += suffix;
3556 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
3558 cmSystemTools::ExpandListArgument(config_libs,
3559 info.LinkInterface.Libraries);
3561 else if(const char* libs =
3562 this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
3564 cmSystemTools::ExpandListArgument(libs,
3565 info.LinkInterface.Libraries);
3569 // Get the link dependencies.
3571 std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
3572 linkProp += suffix;
3573 if(const char* config_libs = this->GetProperty(linkProp.c_str()))
3575 cmSystemTools::ExpandListArgument(config_libs,
3576 info.LinkInterface.SharedDeps);
3578 else if(const char* libs =
3579 this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
3581 cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
3586 //----------------------------------------------------------------------------
3587 cmTargetLinkInterface const* cmTarget::GetLinkInterface(const char* config)
3589 // Imported targets have their own link interface.
3590 if(this->IsImported())
3592 if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
3594 return &info->LinkInterface;
3596 return 0;
3599 // Link interfaces are supported only for shared libraries and
3600 // executables that export symbols.
3601 if((this->GetType() != cmTarget::SHARED_LIBRARY &&
3602 !this->IsExecutableWithExports()))
3604 return 0;
3607 // Lookup any existing link interface for this configuration.
3608 std::map<cmStdString, cmTargetLinkInterface*>::iterator
3609 i = this->LinkInterface.find(config?config:"");
3610 if(i == this->LinkInterface.end())
3612 // Compute the link interface for this configuration.
3613 cmTargetLinkInterface* iface = this->ComputeLinkInterface(config);
3615 // Store the information for this configuration.
3616 std::map<cmStdString, cmTargetLinkInterface*>::value_type
3617 entry(config?config:"", iface);
3618 i = this->LinkInterface.insert(entry).first;
3621 return i->second;
3624 //----------------------------------------------------------------------------
3625 cmTargetLinkInterface* cmTarget::ComputeLinkInterface(const char* config)
3627 // Construct the property name suffix for this configuration.
3628 std::string suffix = "_";
3629 if(config && *config)
3631 suffix += cmSystemTools::UpperCase(config);
3633 else
3635 suffix += "NOCONFIG";
3638 // Lookup the link interface libraries.
3639 const char* libs = 0;
3641 // Lookup the per-configuration property.
3642 std::string propName = "LINK_INTERFACE_LIBRARIES";
3643 propName += suffix;
3644 libs = this->GetProperty(propName.c_str());
3646 // If not set, try the generic property.
3647 if(!libs)
3649 libs = this->GetProperty("LINK_INTERFACE_LIBRARIES");
3653 // If still not set, there is no link interface.
3654 if(!libs)
3656 return 0;
3659 // Allocate the interface.
3660 cmTargetLinkInterface* iface = new cmTargetLinkInterface;
3661 if(!iface)
3663 return 0;
3666 // Expand the list of libraries in the interface.
3667 cmSystemTools::ExpandListArgument(libs, iface->Libraries);
3669 // Now we need to construct a list of shared library dependencies
3670 // not included in the interface.
3671 if(this->GetType() == cmTarget::SHARED_LIBRARY)
3673 // Use a set to keep track of what libraries have been emitted to
3674 // either list.
3675 std::set<cmStdString> emitted;
3676 for(std::vector<std::string>::const_iterator
3677 li = iface->Libraries.begin();
3678 li != iface->Libraries.end(); ++li)
3680 emitted.insert(*li);
3683 // Compute which library configuration to link.
3684 cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
3686 // Construct the list of libs linked for this configuration.
3687 cmTarget::LinkLibraryVectorType const& llibs =
3688 this->GetOriginalLinkLibraries();
3689 for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
3690 li != llibs.end(); ++li)
3692 // Skip entries that will resolve to the target itself, are empty,
3693 // or are not meant for this configuration.
3694 if(li->first == this->GetName() || li->first.empty() ||
3695 !(li->second == cmTarget::GENERAL || li->second == linkType))
3697 continue;
3700 // Skip entries that have already been emitted into either list.
3701 if(!emitted.insert(li->first).second)
3703 continue;
3706 // Add this entry if it is a shared library.
3707 if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->first.c_str()))
3709 if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
3711 iface->SharedDeps.push_back(li->first);
3714 else
3716 // TODO: Recognize shared library file names. Perhaps this
3717 // should be moved to cmComputeLinkInformation, but that creates
3718 // a chicken-and-egg problem since this list is needed for its
3719 // construction.
3724 // Return the completed interface.
3725 return iface;
3728 //----------------------------------------------------------------------------
3729 cmComputeLinkInformation*
3730 cmTarget::GetLinkInformation(const char* config)
3732 // Lookup any existing information for this configuration.
3733 std::map<cmStdString, cmComputeLinkInformation*>::iterator
3734 i = this->LinkInformation.find(config?config:"");
3735 if(i == this->LinkInformation.end())
3737 // Compute information for this configuration.
3738 cmComputeLinkInformation* info =
3739 new cmComputeLinkInformation(this, config);
3740 if(!info || !info->Compute())
3742 delete info;
3743 info = 0;
3746 // Store the information for this configuration.
3747 std::map<cmStdString, cmComputeLinkInformation*>::value_type
3748 entry(config?config:"", info);
3749 i = this->LinkInformation.insert(entry).first;
3751 return i->second;
3754 //----------------------------------------------------------------------------
3755 cmTargetLinkInformationMap
3756 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
3758 // Ideally cmTarget instances should never be copied. However until
3759 // we can make a sweep to remove that, this copy constructor avoids
3760 // allowing the resources (LinkInformation) from getting copied. In
3761 // the worst case this will lead to extra cmComputeLinkInformation
3762 // instances. We also enforce in debug mode that the map be emptied
3763 // when copied.
3764 static_cast<void>(r);
3765 assert(r.empty());
3768 //----------------------------------------------------------------------------
3769 cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
3771 for(derived::iterator i = this->begin(); i != this->end(); ++i)
3773 delete i->second;
3777 //----------------------------------------------------------------------------
3778 cmTargetLinkInterfaceMap
3779 ::cmTargetLinkInterfaceMap(cmTargetLinkInterfaceMap const& r): derived()
3781 // Ideally cmTarget instances should never be copied. However until
3782 // we can make a sweep to remove that, this copy constructor avoids
3783 // allowing the resources (LinkInterface) from getting copied. In
3784 // the worst case this will lead to extra cmTargetLinkInterface
3785 // instances. We also enforce in debug mode that the map be emptied
3786 // when copied.
3787 static_cast<void>(r);
3788 assert(r.empty());
3791 //----------------------------------------------------------------------------
3792 cmTargetLinkInterfaceMap::~cmTargetLinkInterfaceMap()
3794 for(derived::iterator i = this->begin(); i != this->end(); ++i)
3796 delete i->second;
3800 //----------------------------------------------------------------------------
3801 cmTargetInternalPointer::cmTargetInternalPointer()
3803 this->Pointer = new cmTargetInternals;
3806 //----------------------------------------------------------------------------
3807 cmTargetInternalPointer
3808 ::cmTargetInternalPointer(cmTargetInternalPointer const&)
3810 // Ideally cmTarget instances should never be copied. However until
3811 // we can make a sweep to remove that, this copy constructor avoids
3812 // allowing the resources (Internals) to be copied.
3813 this->Pointer = new cmTargetInternals;
3816 //----------------------------------------------------------------------------
3817 cmTargetInternalPointer::~cmTargetInternalPointer()
3819 delete this->Pointer;
3822 //----------------------------------------------------------------------------
3823 cmTargetInternalPointer&
3824 cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
3826 if(this == &r) { return *this; } // avoid warning on HP about self check
3827 // Ideally cmTarget instances should never be copied. However until
3828 // we can make a sweep to remove that, this copy constructor avoids
3829 // allowing the resources (Internals) to be copied.
3830 cmTargetInternals* oldPointer = this->Pointer;
3831 this->Pointer = new cmTargetInternals;
3832 delete oldPointer;
3833 return *this;