1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmTarget.cxx,v $
6 Date: $Date: 2009-08-11 13:07:42 $
7 Version: $Revision: 1.267 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
19 #include "cmMakefile.h"
20 #include "cmSourceFile.h"
21 #include "cmLocalGenerator.h"
22 #include "cmGlobalGenerator.h"
23 #include "cmComputeLinkInformation.h"
24 #include "cmListFileCache.h"
25 #include <cmsys/RegularExpression.hxx>
29 #include <stdlib.h> // required for atof
31 const char* cmTarget::TargetTypeNames
[] = {
32 "EXECUTABLE", "STATIC_LIBRARY",
33 "SHARED_LIBRARY", "MODULE_LIBRARY", "UTILITY", "GLOBAL_TARGET",
34 "INSTALL_FILES", "INSTALL_PROGRAMS", "INSTALL_DIRECTORY",
38 //----------------------------------------------------------------------------
39 struct cmTarget::OutputInfo
45 //----------------------------------------------------------------------------
46 struct cmTarget::ImportInfo
51 std::string ImportLibrary
;
52 cmTarget::LinkInterface LinkInterface
;
55 //----------------------------------------------------------------------------
56 class cmTargetInternals
61 this->SourceFileFlagsConstructed
= false;
63 typedef cmTarget::SourceFileFlags SourceFileFlags
;
64 std::map
<cmSourceFile
const*, SourceFileFlags
> SourceFlagsMap
;
65 bool SourceFileFlagsConstructed
;
67 // The backtrace when the target was created.
68 cmListFileBacktrace Backtrace
;
70 // Cache link interface computation from each configuration.
71 struct OptionalLinkInterface
: public cmTarget::LinkInterface
73 OptionalLinkInterface(): Exists(false) {}
76 typedef std::map
<cmStdString
, OptionalLinkInterface
> LinkInterfaceMapType
;
77 LinkInterfaceMapType LinkInterfaceMap
;
79 typedef std::map
<cmStdString
, cmTarget::OutputInfo
> OutputInfoMapType
;
80 OutputInfoMapType OutputInfoMap
;
82 typedef std::map
<cmStdString
, cmTarget::ImportInfo
> ImportInfoMapType
;
83 ImportInfoMapType ImportInfoMap
;
85 // Cache link implementation computation from each configuration.
86 typedef std::map
<cmStdString
, cmTarget::LinkImplementation
> LinkImplMapType
;
87 LinkImplMapType LinkImplMap
;
89 typedef std::map
<cmStdString
, cmTarget::LinkClosure
> LinkClosureMapType
;
90 LinkClosureMapType LinkClosureMap
;
93 //----------------------------------------------------------------------------
97 this->PolicyStatusCMP0003
= cmPolicies::WARN
;
98 this->PolicyStatusCMP0004
= cmPolicies::WARN
;
99 this->PolicyStatusCMP0008
= cmPolicies::WARN
;
100 this->LinkLibrariesAnalyzed
= false;
101 this->HaveInstallRule
= false;
102 this->DLLPlatform
= false;
103 this->IsImportedTarget
= false;
106 //----------------------------------------------------------------------------
107 void cmTarget::DefineProperties(cmake
*cm
)
110 ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET
,
111 "Should build tree targets have install tree rpaths.",
112 "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
113 "the target in the build tree with the INSTALL_RPATH. This takes "
114 "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
115 "before installation. "
116 "This property is initialized by the value of the variable "
117 "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
120 ("COMPILE_FLAGS", cmProperty::TARGET
,
121 "Additional flags to use when compiling this target's sources.",
122 "The COMPILE_FLAGS property sets additional compiler flags used "
123 "to build sources within the target. Use COMPILE_DEFINITIONS "
124 "to pass additional preprocessor definitions.");
127 ("COMPILE_DEFINITIONS", cmProperty::TARGET
,
128 "Preprocessor definitions for compiling a target's sources.",
129 "The COMPILE_DEFINITIONS property may be set to a "
130 "semicolon-separated list of preprocessor "
131 "definitions using the syntax VAR or VAR=value. Function-style "
132 "definitions are not supported. CMake will automatically escape "
133 "the value correctly for the native build system (note that CMake "
134 "language syntax may require escapes to specify some values). "
135 "This property may be set on a per-configuration basis using the name "
136 "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
137 "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
138 "CMake will automatically drop some definitions that "
139 "are not supported by the native build tool. "
140 "The VS6 IDE does not support definition values with spaces "
141 "(but NMake does).\n"
142 "Dislaimer: Most native build tools have poor support for escaping "
143 "certain values. CMake has work-arounds for many cases but some "
144 "values may just not be possible to pass correctly. If a value "
145 "does not seem to be escaped correctly, do not attempt to "
146 "work-around the problem by adding escape sequences to the value. "
147 "Your work-around may break in a future version of CMake that "
148 "has improved escape support. Instead consider defining the macro "
149 "in a (configured) header file. Then report the limitation.");
152 ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET
,
153 "Per-configuration preprocessor definitions on a target.",
154 "This is the configuration-specific version of COMPILE_DEFINITIONS.");
157 ("DEFINE_SYMBOL", cmProperty::TARGET
,
158 "Define a symbol when compiling this target's sources.",
159 "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
160 "compiling sources in a shared library. "
161 "If not set here then it is set to target_EXPORTS by default "
162 "(with some substitutions if the target is not a valid C "
163 "identifier). This is useful for headers to know whether they are "
164 "being included from inside their library our outside to properly "
165 "setup dllexport/dllimport decorations. ");
168 ("DEBUG_POSTFIX", cmProperty::TARGET
,
169 "See target property <CONFIG>_POSTFIX.",
170 "This property is a special case of the more-general <CONFIG>_POSTFIX "
171 "property for the DEBUG configuration.");
174 ("<CONFIG>_POSTFIX", cmProperty::TARGET
,
175 "Postfix to append to the target file name for configuration <CONFIG>.",
176 "When building with configuration <CONFIG> the value of this property "
177 "is appended to the target file name built on disk. "
178 "For non-executable targets, this property is initialized by the value "
179 "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
181 "This property is ignored on the Mac for Frameworks and App Bundles.");
184 ("EchoString", cmProperty::TARGET
,
185 "A message to be displayed when the target is built.",
186 "A message to display on some generators (such as makefiles) when "
187 "the target is built.");
190 ("FRAMEWORK", cmProperty::TARGET
,
191 "This target is a framework on the Mac.",
192 "If a shared library target has this property set to true it will "
193 "be built as a framework when built on the mac. It will have the "
194 "directory structure required for a framework and will be suitable "
195 "to be used with the -framework option");
198 ("HAS_CXX", cmProperty::TARGET
,
199 "Link the target using the C++ linker tool (obselete).",
200 "This is equivalent to setting the LINKER_LANGUAGE property to CXX. "
201 "See that property's documentation for details.");
204 ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET
,
205 "Specify #include line transforms for dependencies in a target.",
206 "This property specifies rules to transform macro-like #include lines "
207 "during implicit dependency scanning of C and C++ source files. "
208 "The list of rules must be semicolon-separated with each entry of "
209 "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
210 "During dependency scanning occurrences of A_MACRO(...) on #include "
211 "lines will be replaced by the value given with the macro argument "
212 "substituted for '%'. For example, the entry\n"
213 " MYDIR(%)=<mydir/%>\n"
214 "will convert lines of the form\n"
215 " #include MYDIR(myheader.h)\n"
217 " #include <mydir/myheader.h>\n"
218 "allowing the dependency to be followed.\n"
219 "This property applies to sources in the target on which it is set.");
222 ("IMPORT_PREFIX", cmProperty::TARGET
,
223 "What comes before the import library name.",
224 "Similar to the target property PREFIX, but used for import libraries "
225 "(typically corresponding to a DLL) instead of regular libraries. "
226 "A target property that can be set to override the prefix "
227 "(such as \"lib\") on an import library name.");
230 ("IMPORT_SUFFIX", cmProperty::TARGET
,
231 "What comes after the import library name.",
232 "Similar to the target property SUFFIX, but used for import libraries "
233 "(typically corresponding to a DLL) instead of regular libraries. "
234 "A target property that can be set to override the suffix "
235 "(such as \".lib\") on an import library name.");
238 ("IMPORTED", cmProperty::TARGET
,
239 "Read-only indication of whether a target is IMPORTED.",
240 "The boolean value of this property is true for targets created with "
241 "the IMPORTED option to add_executable or add_library. "
242 "It is false for targets built within the project.");
245 ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET
,
246 "Configurations provided for an IMPORTED target.",
247 "Lists configuration names available for an IMPORTED target. "
248 "The names correspond to configurations defined in the project from "
249 "which the target is imported. "
250 "If the importing project uses a different set of configurations "
251 "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
253 "Ignored for non-imported targets.");
256 ("IMPORTED_IMPLIB", cmProperty::TARGET
,
257 "Full path to the import library for an IMPORTED target.",
258 "Specifies the location of the \".lib\" part of a windows DLL. "
259 "Ignored for non-imported targets.");
262 ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET
,
263 "Per-configuration version of IMPORTED_IMPLIB property.",
264 "This property is used when loading settings for the <CONFIG> "
265 "configuration of an imported target. "
266 "Configuration names correspond to those provided by the project "
267 "from which the target is imported.");
270 ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET
,
271 "Dependent shared libraries of an imported shared library.",
272 "Shared libraries may be linked to other shared libraries as part "
273 "of their implementation. On some platforms the linker searches "
274 "for the dependent libraries of shared libraries they are including "
275 "in the link. This property lists "
276 "the dependent shared libraries of an imported library. The list "
277 "should be disjoint from the list of interface libraries in the "
278 "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring "
279 "dependent shared libraries to be found at link time CMake uses this "
280 "list to add appropriate files or paths to the link command line. "
281 "Ignored for non-imported targets.");
284 ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET
,
285 "Per-configuration version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
286 "This property is used when loading settings for the <CONFIG> "
287 "configuration of an imported target. "
288 "Configuration names correspond to those provided by the project "
289 "from which the target is imported. "
290 "If set, this property completely overrides the generic property "
291 "for the named configuration.");
294 ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET
,
295 "Transitive link interface of an IMPORTED target.",
296 "Lists libraries whose interface is included when an IMPORTED library "
297 "target is linked to another target. "
298 "The libraries will be included on the link line for the target. "
299 "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
300 "to all imported target types, including STATIC libraries. "
301 "This property is ignored for non-imported targets.");
304 ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET
,
305 "Per-configuration version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
306 "This property is used when loading settings for the <CONFIG> "
307 "configuration of an imported target. "
308 "Configuration names correspond to those provided by the project "
309 "from which the target is imported. "
310 "If set, this property completely overrides the generic property "
311 "for the named configuration.");
314 ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET
,
315 "Languages compiled into an IMPORTED static library.",
316 "Lists languages of soure files compiled to produce a STATIC IMPORTED "
317 "library (such as \"C\" or \"CXX\"). "
318 "CMake accounts for these languages when computing how to link a "
319 "target to the imported library. "
320 "For example, when a C executable links to an imported C++ static "
321 "library CMake chooses the C++ linker to satisfy language runtime "
322 "dependencies of the static library. "
324 "This property is ignored for targets that are not STATIC libraries. "
325 "This property is ignored for non-imported targets.");
328 ("IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>", cmProperty::TARGET
,
329 "Per-configuration version of IMPORTED_LINK_INTERFACE_LANGUAGES.",
330 "This property is used when loading settings for the <CONFIG> "
331 "configuration of an imported target. "
332 "Configuration names correspond to those provided by the project "
333 "from which the target is imported. "
334 "If set, this property completely overrides the generic property "
335 "for the named configuration.");
338 ("IMPORTED_LOCATION", cmProperty::TARGET
,
339 "Full path to the main file on disk for an IMPORTED target.",
340 "Specifies the location of an IMPORTED target file on disk. "
341 "For executables this is the location of the executable file. "
342 "For bundles on OS X this is the location of the executable file "
343 "inside Contents/MacOS under the application bundle folder. "
344 "For static libraries and modules this is the location of the "
345 "library or module. "
346 "For shared libraries on non-DLL platforms this is the location of "
347 "the shared library. "
348 "For frameworks on OS X this is the location of the library file "
349 "symlink just inside the framework folder. "
350 "For DLLs this is the location of the \".dll\" part of the library. "
351 "For UNKNOWN libraries this is the location of the file to be linked. "
352 "Ignored for non-imported targets.");
355 ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET
,
356 "Per-configuration version of IMPORTED_LOCATION property.",
357 "This property is used when loading settings for the <CONFIG> "
358 "configuration of an imported target. "
359 "Configuration names correspond to those provided by the project "
360 "from which the target is imported.");
363 ("IMPORTED_SONAME", cmProperty::TARGET
,
364 "The \"soname\" of an IMPORTED target of shared library type.",
365 "Specifies the \"soname\" embedded in an imported shared library. "
366 "This is meaningful only on platforms supporting the feature. "
367 "Ignored for non-imported targets.");
370 ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET
,
371 "Per-configuration version of IMPORTED_SONAME property.",
372 "This property is used when loading settings for the <CONFIG> "
373 "configuration of an imported target. "
374 "Configuration names correspond to those provided by the project "
375 "from which the target is imported.");
378 ("EXCLUDE_FROM_ALL", cmProperty::TARGET
,
379 "Exclude the target from the all target.",
380 "A property on a target that indicates if the target is excluded "
381 "from the default build target. If it is not, then with a Makefile "
382 "for example typing make will cause this target to be built. "
383 "The same concept applies to the default build of other generators. "
384 "Installing a target with EXCLUDE_FROM_ALL set to true has "
385 "undefined behavior.");
388 ("INSTALL_NAME_DIR", cmProperty::TARGET
,
389 "Mac OSX directory name for installed targets.",
390 "INSTALL_NAME_DIR is a string specifying the "
391 "directory portion of the \"install_name\" field of shared libraries "
392 "on Mac OSX to use in the installed targets. ");
395 ("INSTALL_RPATH", cmProperty::TARGET
,
396 "The rpath to use for installed targets.",
397 "A semicolon-separated list specifying the rpath "
398 "to use in installed targets (for platforms that support it). "
399 "This property is initialized by the value of the variable "
400 "CMAKE_INSTALL_RPATH if it is set when a target is created.");
403 ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET
,
404 "Add paths to linker search and installed rpath.",
405 "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
406 "append directories in the linker search path and outside the "
407 "project to the INSTALL_RPATH. "
408 "This property is initialized by the value of the variable "
409 "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
413 ("LABELS", cmProperty::TARGET
,
414 "Specify a list of text labels associated with a target.",
415 "Target label semantics are currently unspecified.");
418 ("LINK_FLAGS", cmProperty::TARGET
,
419 "Additional flags to use when linking this target.",
420 "The LINK_FLAGS property can be used to add extra flags to the "
421 "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
422 "configuration <CONFIG>, "
423 "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
426 ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET
,
427 "Per-configuration linker flags for a target.",
428 "This is the configuration-specific version of LINK_FLAGS.");
431 ("LINK_SEARCH_END_STATIC", cmProperty::TARGET
,
432 "End a link line such that static system libraries are used.",
433 "Some linkers support switches such as -Bstatic and -Bdynamic "
434 "to determine whether to use static or shared libraries for -lXXX "
435 "options. CMake uses these options to set the link type for "
436 "libraries whose full paths are not known or (in some cases) are in "
437 "implicit link directories for the platform. By default the "
438 "linker search type is left at -Bdynamic by the end of the library "
439 "list. This property switches the final linker search type to "
443 ("LINKER_LANGUAGE", cmProperty::TARGET
,
444 "Specifies language whose compiler will invoke the linker.",
445 "For executables, shared libraries, and modules, this sets the "
446 "language whose compiler is used to link the target "
447 "(such as \"C\" or \"CXX\"). "
448 "A typical value for an executable is the language of the source "
449 "file providing the program entry point (main). "
450 "If not set, the language with the highest linker preference "
451 "value is the default. "
452 "See documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables.");
455 ("LOCATION", cmProperty::TARGET
,
456 "Read-only location of a target on disk.",
457 "For an imported target, this read-only property returns the value of "
458 "the LOCATION_<CONFIG> property for an unspecified configuration "
459 "<CONFIG> provided by the target.\n"
460 "For a non-imported target, this property is provided for compatibility "
461 "with CMake 2.4 and below. "
462 "It was meant to get the location of an executable target's output file "
463 "for use in add_custom_command. "
464 "The path may contain a build-system-specific portion that "
465 "is replaced at build time with the configuration getting built "
466 "(such as \"$(ConfigurationName)\" in VS). "
467 "In CMake 2.6 and above add_custom_command automatically recognizes a "
468 "target name in its COMMAND and DEPENDS options and computes the "
470 "Therefore this property is not needed for creating custom commands.");
473 ("LOCATION_<CONFIG>", cmProperty::TARGET
,
474 "Read-only property providing a target location on disk.",
475 "A read-only property that indicates where a target's main file is "
476 "located on disk for the configuration <CONFIG>. "
477 "The property is defined only for library and executable targets. "
478 "An imported target may provide a set of configurations different "
479 "from that of the importing project. "
480 "By default CMake looks for an exact-match but otherwise uses an "
481 "arbitrary available configuration. "
482 "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
483 "configurations explicitly.");
486 ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET
,
487 "List public interface libraries for a shared library or executable.",
488 "By default linking to a shared library target transitively "
489 "links to targets with which the library itself was linked. "
490 "For an executable with exports (see the ENABLE_EXPORTS property) "
491 "no default transitive link dependencies are used. "
492 "This property replaces the default transitive link dependencies with "
494 "When the target is linked into another target the libraries "
495 "listed (and recursively their link interface libraries) will be "
496 "provided to the other target also. "
497 "If the list is empty then no transitive link dependencies will be "
498 "incorporated when this target is linked into another target even if "
499 "the default set is non-empty. "
500 "This property is ignored for STATIC libraries.");
503 ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET
,
504 "Per-configuration list of public interface libraries for a target.",
505 "This is the configuration-specific version of "
506 "LINK_INTERFACE_LIBRARIES. "
507 "If set, this property completely overrides the generic property "
508 "for the named configuration.");
511 ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET
,
512 "Map from project configuration to IMPORTED target's configuration.",
513 "List configurations of an imported target that may be used for "
514 "the current project's <CONFIG> configuration. "
515 "Targets imported from another project may not provide the same set "
516 "of configuration names available in the current project. "
517 "Setting this property tells CMake what imported configurations are "
518 "suitable for use when building the <CONFIG> configuration. "
519 "The first configuration in the list found to be provided by the "
520 "imported target is selected. If no matching configurations are "
521 "available the imported target is considered to be not found. "
522 "This property is ignored for non-imported targets.",
523 false /* TODO: make this chained */ );
526 ("OUTPUT_NAME", cmProperty::TARGET
,
527 "Output name for target files.",
528 "This sets the base name for output files created for an executable or "
530 "If not set, the logical target name is used by default.");
533 ("OUTPUT_NAME_<CONFIG>", cmProperty::TARGET
,
534 "Per-configuration target file base name.",
535 "This is the configuration-specific version of OUTPUT_NAME.");
538 ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET
,
539 "Old per-configuration target file base name.",
540 "This is a configuration-specific version of OUTPUT_NAME. "
541 "Use OUTPUT_NAME_<CONFIG> instead.");
544 ("PRE_INSTALL_SCRIPT", cmProperty::TARGET
,
545 "Deprecated install support.",
546 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
547 "old way to specify CMake scripts to run before and after "
548 "installing a target. They are used only when the old "
549 "INSTALL_TARGETS command is used to install the target. Use the "
550 "INSTALL command instead.");
553 ("PREFIX", cmProperty::TARGET
,
554 "What comes before the library name.",
555 "A target property that can be set to override the prefix "
556 "(such as \"lib\") on a library name.");
559 ("POST_INSTALL_SCRIPT", cmProperty::TARGET
,
560 "Deprecated install support.",
561 "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
562 "old way to specify CMake scripts to run before and after "
563 "installing a target. They are used only when the old "
564 "INSTALL_TARGETS command is used to install the target. Use the "
565 "INSTALL command instead.");
568 ("PRIVATE_HEADER", cmProperty::TARGET
,
569 "Specify private header files in a FRAMEWORK shared library target.",
570 "Shared library targets marked with the FRAMEWORK property generate "
571 "frameworks on OS X and normal shared libraries on other platforms. "
572 "This property may be set to a list of header files to be placed "
573 "in the PrivateHeaders directory inside the framework folder. "
574 "On non-Apple platforms these headers may be installed using the "
575 "PRIVATE_HEADER option to the install(TARGETS) command.");
578 ("PUBLIC_HEADER", cmProperty::TARGET
,
579 "Specify public header files in a FRAMEWORK shared library target.",
580 "Shared library targets marked with the FRAMEWORK property generate "
581 "frameworks on OS X and normal shared libraries on other platforms. "
582 "This property may be set to a list of header files to be placed "
583 "in the Headers directory inside the framework folder. "
584 "On non-Apple platforms these headers may be installed using the "
585 "PUBLIC_HEADER option to the install(TARGETS) command.");
588 ("RESOURCE", cmProperty::TARGET
,
589 "Specify resource files in a FRAMEWORK shared library target.",
590 "Shared library targets marked with the FRAMEWORK property generate "
591 "frameworks on OS X and normal shared libraries on other platforms. "
592 "This property may be set to a list of files to be placed "
593 "in the Resources directory inside the framework folder. "
594 "On non-Apple platforms these files may be installed using the "
595 "RESOURCE option to the install(TARGETS) command.");
598 ("RULE_LAUNCH_COMPILE", cmProperty::TARGET
,
599 "Specify a launcher for compile rules.",
600 "See the global property of the same name for details. "
601 "This overrides the global and directory property for a target.",
604 ("RULE_LAUNCH_LINK", cmProperty::TARGET
,
605 "Specify a launcher for link rules.",
606 "See the global property of the same name for details. "
607 "This overrides the global and directory property for a target.",
610 ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET
,
611 "Specify a launcher for custom rules.",
612 "See the global property of the same name for details. "
613 "This overrides the global and directory property for a target.",
617 ("SKIP_BUILD_RPATH", cmProperty::TARGET
,
618 "Should rpaths be used for the build tree.",
619 "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
620 "generation of an rpath allowing the target to run from the "
622 "This property is initialized by the value of the variable "
623 "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
626 ("SOVERSION", cmProperty::TARGET
,
627 "What version number is this target.",
628 "For shared libraries VERSION and SOVERSION can be used to specify "
629 "the build version and api version respectively. When building or "
630 "installing appropriate symlinks are created if the platform "
631 "supports symlinks and the linker supports so-names. "
632 "If only one of both is specified the missing is assumed to have "
633 "the same version number. "
634 "For shared libraries and executables on Windows the VERSION "
635 "attribute is parsed to extract a \"major.minor\" version number. "
636 "These numbers are used as the image version of the binary. ");
639 ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET
,
640 "Extra flags to use when linking static libraries.",
641 "Extra flags to use when linking a static library.");
644 ("SUFFIX", cmProperty::TARGET
,
645 "What comes after the library name.",
646 "A target property that can be set to override the suffix "
647 "(such as \".so\") on a library name.");
650 ("TYPE", cmProperty::TARGET
,
651 "The type of the target.",
652 "This read-only property can be used to test the type of the given "
653 "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
654 "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
657 ("VERSION", cmProperty::TARGET
,
658 "What version number is this target.",
659 "For shared libraries VERSION and SOVERSION can be used to specify "
660 "the build version and api version respectively. When building or "
661 "installing appropriate symlinks are created if the platform "
662 "supports symlinks and the linker supports so-names. "
663 "If only one of both is specified the missing is assumed to have "
664 "the same version number. "
665 "For executables VERSION can be used to specify the build version. "
666 "When building or installing appropriate symlinks are created if "
667 "the platform supports symlinks. "
668 "For shared libraries and executables on Windows the VERSION "
669 "attribute is parsed to extract a \"major.minor\" version number. "
670 "These numbers are used as the image version of the binary. ");
674 ("WIN32_EXECUTABLE", cmProperty::TARGET
,
675 "Build an executable with a WinMain entry point on windows.",
676 "When this property is set to true the executable when linked "
677 "on Windows will be created with a WinMain() entry point instead "
679 "This makes it a GUI executable instead of a console application. "
680 "See the CMAKE_MFC_FLAG variable documentation to configure use "
681 "of MFC for WinMain executables.");
684 ("MACOSX_BUNDLE", cmProperty::TARGET
,
685 "Build an executable as an application bundle on Mac OS X.",
686 "When this property is set to true the executable when built "
687 "on Mac OS X will be created as an application bundle. "
688 "This makes it a GUI executable that can be launched from "
690 "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
691 "about creation of the Info.plist file for the application bundle.");
694 ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET
,
695 "Specify a custom Info.plist template for a Mac OS X App Bundle.",
696 "An executable target with MACOSX_BUNDLE enabled will be built as an "
697 "application bundle on Mac OS X. "
698 "By default its Info.plist file is created by configuring a template "
699 "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
700 "This property specifies an alternative template file name which "
701 "may be a full path.\n"
702 "The following target properties may be set to specify content to "
703 "be configured into the file:\n"
704 " MACOSX_BUNDLE_INFO_STRING\n"
705 " MACOSX_BUNDLE_ICON_FILE\n"
706 " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
707 " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
708 " MACOSX_BUNDLE_BUNDLE_NAME\n"
709 " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
710 " MACOSX_BUNDLE_BUNDLE_VERSION\n"
711 " MACOSX_BUNDLE_COPYRIGHT\n"
712 "CMake variables of the same name may be set to affect all targets "
713 "in a directory that do not have each specific property set. "
714 "If a custom Info.plist is specified by this property it may of course "
715 "hard-code all the settings instead of using the target properties.");
718 ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET
,
719 "Specify a custom Info.plist template for a Mac OS X Framework.",
720 "An library target with FRAMEWORK enabled will be built as a "
721 "framework on Mac OS X. "
722 "By default its Info.plist file is created by configuring a template "
723 "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
724 "This property specifies an alternative template file name which "
725 "may be a full path.\n"
726 "The following target properties may be set to specify content to "
727 "be configured into the file:\n"
728 " MACOSX_FRAMEWORK_ICON_FILE\n"
729 " MACOSX_FRAMEWORK_IDENTIFIER\n"
730 " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
731 " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
732 "CMake variables of the same name may be set to affect all targets "
733 "in a directory that do not have each specific property set. "
734 "If a custom Info.plist is specified by this property it may of course "
735 "hard-code all the settings instead of using the target properties.");
738 ("ENABLE_EXPORTS", cmProperty::TARGET
,
739 "Specify whether an executable exports symbols for loadable modules.",
740 "Normally an executable does not export any symbols because it is "
741 "the final program. It is possible for an executable to export "
742 "symbols to be used by loadable modules. When this property is "
743 "set to true CMake will allow other targets to \"link\" to the "
744 "executable with the TARGET_LINK_LIBRARIES command. "
745 "On all platforms a target-level dependency on the executable is "
746 "created for targets that link to it. "
747 "For non-DLL platforms the link rule is simply ignored since "
748 "the dynamic loader will automatically bind symbols when the "
750 "For DLL platforms an import library will be created for the "
751 "exported symbols and then used for linking. "
752 "All Windows-based systems including Cygwin are DLL platforms.");
755 ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET
,
756 "Specify output directory for Fortran modules provided by the target.",
757 "If the target contains Fortran source files that provide modules "
758 "and the compiler supports a module output directory this specifies "
759 "the directory in which the modules will be placed. "
760 "When this property is not set the modules will be placed in the "
761 "build directory corresponding to the target's source directory. "
762 "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
763 "is created its value is used to initialize this property.");
766 ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET
,
767 "Set Xcode target attributes directly.",
768 "Tell the Xcode generator to set '<an-attribute>' to a given value "
769 "in the generated Xcode project. Ignored on other generators.");
772 ("GENERATOR_FILE_NAME", cmProperty::TARGET
,
773 "Generator's file for this target.",
774 "An internal property used by some generators to record the name of "
775 "project or dsp file associated with this target.");
778 ("SOURCES", cmProperty::TARGET
,
779 "Source names specified for a target.",
780 "Read-only list of sources specified for a target. "
781 "The names returned are suitable for passing to the "
782 "set_source_files_properties command.");
785 ("PROJECT_LABEL", cmProperty::TARGET
,
786 "Change the name of a target in an IDE.",
787 "Can be used to change the name of the target in an IDE "
788 "like visual stuido. ");
790 ("VS_KEYWORD", cmProperty::TARGET
,
791 "Visual Studio project keyword.",
792 "Can be set to change the visual studio keyword, for example "
793 "QT integration works better if this is set to Qt4VSv1.0. ");
795 ("VS_SCC_PROVIDER", cmProperty::TARGET
,
796 "Visual Studio Source Code Control Provider.",
797 "Can be set to change the visual studio source code control "
798 "provider property.");
800 ("VS_SCC_LOCALPATH", cmProperty::TARGET
,
801 "Visual Studio Source Code Control Provider.",
802 "Can be set to change the visual studio source code control "
803 "local path property.");
805 ("VS_SCC_PROJECTNAME", cmProperty::TARGET
,
806 "Visual Studio Source Code Control Project.",
807 "Can be set to change the visual studio source code control "
808 "project name property.");
812 ("OBJECT_FILES", cmProperty::TARGET
,
813 "Used to get the resulting list of object files that make up a "
815 "This can be used to put object files from one library "
816 "into another library. It is a read only property. It "
817 "converts the source list for the target into a list of full "
818 "paths to object names that will be produced by the target.");
821 #define CM_TARGET_FILE_TYPES_DOC \
822 "There are three kinds of target files that may be built: " \
823 "archive, library, and runtime. " \
824 "Executables are always treated as runtime targets. " \
825 "Static libraries are always treated as archive targets. " \
826 "Module libraries are always treated as library targets. " \
827 "For non-DLL platforms shared libraries are treated as library " \
829 "For DLL platforms the DLL part of a shared library is treated as " \
830 "a runtime target and the corresponding import library is treated as " \
831 "an archive target. " \
832 "All Windows-based systems including Cygwin are DLL platforms."
835 ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET
,
836 "Output directory in which to build ARCHIVE target files.",
837 "This property specifies the directory into which archive target files "
839 CM_TARGET_FILE_TYPES_DOC
" "
840 "This property is initialized by the value of the variable "
841 "CMAKE_ARCHIVE_OUTPUT_DIRECTORY if it is set when a target is created.");
843 ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET
,
844 "Output directory in which to build LIBRARY target files.",
845 "This property specifies the directory into which library target files "
847 CM_TARGET_FILE_TYPES_DOC
" "
848 "This property is initialized by the value of the variable "
849 "CMAKE_LIBRARY_OUTPUT_DIRECTORY if it is set when a target is created.");
851 ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET
,
852 "Output directory in which to build RUNTIME target files.",
853 "This property specifies the directory into which runtime target files "
855 CM_TARGET_FILE_TYPES_DOC
" "
856 "This property is initialized by the value of the variable "
857 "CMAKE_RUNTIME_OUTPUT_DIRECTORY if it is set when a target is created.");
860 ("ARCHIVE_OUTPUT_NAME", cmProperty::TARGET
,
861 "Output name for ARCHIVE target files.",
862 "This property specifies the base name for archive target files. "
863 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
864 CM_TARGET_FILE_TYPES_DOC
);
866 ("ARCHIVE_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET
,
867 "Per-configuration output name for ARCHIVE target files.",
868 "This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.");
870 ("LIBRARY_OUTPUT_NAME", cmProperty::TARGET
,
871 "Output name for LIBRARY target files.",
872 "This property specifies the base name for library target files. "
873 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
874 CM_TARGET_FILE_TYPES_DOC
);
876 ("LIBRARY_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET
,
877 "Per-configuration output name for LIBRARY target files.",
878 "This is the configuration-specific version of LIBRARY_OUTPUT_NAME.");
880 ("RUNTIME_OUTPUT_NAME", cmProperty::TARGET
,
881 "Output name for RUNTIME target files.",
882 "This property specifies the base name for runtime target files. "
883 "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
884 CM_TARGET_FILE_TYPES_DOC
);
886 ("RUNTIME_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET
,
887 "Per-configuration output name for RUNTIME target files.",
888 "This is the configuration-specific version of RUNTIME_OUTPUT_NAME.");
891 void cmTarget::SetType(TargetType type
, const char* name
)
894 if(type
== cmTarget::INSTALL_FILES
||
895 type
== cmTarget::INSTALL_PROGRAMS
||
896 type
== cmTarget::INSTALL_DIRECTORY
)
899 IssueMessage(cmake::INTERNAL_ERROR
,
900 "SetType called on cmTarget for INSTALL_FILES, "
901 "INSTALL_PROGRAMS, or INSTALL_DIRECTORY ");
904 // only add dependency information for library targets
905 this->TargetTypeValue
= type
;
906 if(this->TargetTypeValue
>= STATIC_LIBRARY
907 && this->TargetTypeValue
<= MODULE_LIBRARY
)
909 this->RecordDependencies
= true;
913 this->RecordDependencies
= false;
917 //----------------------------------------------------------------------------
918 void cmTarget::SetMakefile(cmMakefile
* mf
)
923 // set the cmake instance of the properties
924 this->Properties
.SetCMakeInstance(mf
->GetCMakeInstance());
926 // Check whether this is a DLL platform.
927 this->DLLPlatform
= (this->Makefile
->IsOn("WIN32") ||
928 this->Makefile
->IsOn("CYGWIN") ||
929 this->Makefile
->IsOn("MINGW"));
931 // Setup default property values.
932 this->SetPropertyDefault("INSTALL_NAME_DIR", "");
933 this->SetPropertyDefault("INSTALL_RPATH", "");
934 this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
935 this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
936 this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
937 this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
938 this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
939 this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
940 this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
942 // Collect the set of configuration types.
943 std::vector
<std::string
> configNames
;
944 if(const char* configurationTypes
=
945 mf
->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
947 cmSystemTools::ExpandListArgument(configurationTypes
, configNames
);
949 else if(const char* buildType
= mf
->GetDefinition("CMAKE_BUILD_TYPE"))
953 configNames
.push_back(buildType
);
957 // Setup per-configuration property default values.
958 for(std::vector
<std::string
>::iterator ci
= configNames
.begin();
959 ci
!= configNames
.end(); ++ci
)
961 // Initialize per-configuration name postfix property from the
962 // variable only for non-executable targets. This preserves
963 // compatibility with previous CMake versions in which executables
964 // did not support this variable. Projects may still specify the
965 // property directly. TODO: Make this depend on backwards
966 // compatibility setting.
967 if(this->TargetTypeValue
!= cmTarget::EXECUTABLE
)
969 std::string property
= cmSystemTools::UpperCase(*ci
);
970 property
+= "_POSTFIX";
971 this->SetPropertyDefault(property
.c_str(), 0);
975 // Save the backtrace of target construction.
976 this->Makefile
->GetBacktrace(this->Internal
->Backtrace
);
978 // Record current policies for later use.
979 this->PolicyStatusCMP0003
=
980 this->Makefile
->GetPolicyStatus(cmPolicies::CMP0003
);
981 this->PolicyStatusCMP0004
=
982 this->Makefile
->GetPolicyStatus(cmPolicies::CMP0004
);
983 this->PolicyStatusCMP0008
=
984 this->Makefile
->GetPolicyStatus(cmPolicies::CMP0008
);
987 //----------------------------------------------------------------------------
988 cmListFileBacktrace
const& cmTarget::GetBacktrace() const
990 return this->Internal
->Backtrace
;
993 //----------------------------------------------------------------------------
994 std::string
cmTarget::GetSupportDirectory() const
996 std::string dir
= this->Makefile
->GetCurrentOutputDirectory();
997 dir
+= cmake::GetCMakeFilesDirectory();
1008 //----------------------------------------------------------------------------
1009 bool cmTarget::IsExecutableWithExports()
1011 return (this->GetType() == cmTarget::EXECUTABLE
&&
1012 this->GetPropertyAsBool("ENABLE_EXPORTS"));
1015 //----------------------------------------------------------------------------
1016 bool cmTarget::IsLinkable()
1018 return (this->GetType() == cmTarget::STATIC_LIBRARY
||
1019 this->GetType() == cmTarget::SHARED_LIBRARY
||
1020 this->GetType() == cmTarget::MODULE_LIBRARY
||
1021 this->GetType() == cmTarget::UNKNOWN_LIBRARY
||
1022 this->IsExecutableWithExports());
1025 //----------------------------------------------------------------------------
1026 bool cmTarget::HasImportLibrary()
1028 return (this->DLLPlatform
&&
1029 (this->GetType() == cmTarget::SHARED_LIBRARY
||
1030 this->IsExecutableWithExports()));
1033 //----------------------------------------------------------------------------
1034 bool cmTarget::IsFrameworkOnApple()
1036 return (this->GetType() == cmTarget::SHARED_LIBRARY
&&
1037 this->Makefile
->IsOn("APPLE") &&
1038 this->GetPropertyAsBool("FRAMEWORK"));
1041 //----------------------------------------------------------------------------
1042 bool cmTarget::IsAppBundleOnApple()
1044 return (this->GetType() == cmTarget::EXECUTABLE
&&
1045 this->Makefile
->IsOn("APPLE") &&
1046 this->GetPropertyAsBool("MACOSX_BUNDLE"));
1049 //----------------------------------------------------------------------------
1050 class cmTargetTraceDependencies
1053 cmTargetTraceDependencies(cmTarget
* target
, const char* vsProjectFile
);
1057 cmMakefile
* Makefile
;
1058 cmGlobalGenerator
* GlobalGenerator
;
1059 std::queue
<cmStdString
> DependencyQueue
;
1060 std::set
<cmStdString
> DependenciesQueued
;
1061 std::set
<cmSourceFile
*> TargetSources
;
1063 void QueueOnce(std::string
const& name
);
1064 void QueueOnce(std::vector
<std::string
> const& names
);
1065 void QueueDependencies(cmSourceFile
* sf
);
1066 bool IsUtility(std::string
const& dep
);
1067 void CheckCustomCommand(cmCustomCommand
const& cc
);
1068 void CheckCustomCommands(const std::vector
<cmCustomCommand
>& commands
);
1071 //----------------------------------------------------------------------------
1072 cmTargetTraceDependencies
1073 ::cmTargetTraceDependencies(cmTarget
* target
, const char* vsProjectFile
):
1077 this->Makefile
= this->Target
->GetMakefile();
1078 this->GlobalGenerator
=
1079 this->Makefile
->GetLocalGenerator()->GetGlobalGenerator();
1081 // Queue all the source files already specified for the target.
1082 std::vector
<cmSourceFile
*> const& sources
= this->Target
->GetSourceFiles();
1083 for(std::vector
<cmSourceFile
*>::const_iterator si
= sources
.begin();
1084 si
!= sources
.end(); ++si
)
1086 // Queue the source file itself in case it is generated.
1087 this->QueueOnce((*si
)->GetFullPath());
1089 // Queue the dependencies of the source file in case they are
1091 this->QueueDependencies(*si
);
1093 // Track the sources already known to the target.
1094 this->TargetSources
.insert(*si
);
1097 // Queue the VS project file to check dependencies on the rule to
1101 this->QueueOnce(vsProjectFile
);
1104 // Queue pre-build, pre-link, and post-build rule dependencies.
1105 this->CheckCustomCommands(this->Target
->GetPreBuildCommands());
1106 this->CheckCustomCommands(this->Target
->GetPreLinkCommands());
1107 this->CheckCustomCommands(this->Target
->GetPostBuildCommands());
1110 //----------------------------------------------------------------------------
1111 void cmTargetTraceDependencies::Trace()
1113 // Process one dependency at a time until the queue is empty.
1114 while(!this->DependencyQueue
.empty())
1116 // Get the next dependency in from queue.
1117 std::string dep
= this->DependencyQueue
.front();
1118 this->DependencyQueue
.pop();
1120 // Check if we know how to generate this dependency.
1121 if(cmSourceFile
* sf
=
1122 this->Makefile
->GetSourceFileWithOutput(dep
.c_str()))
1124 // Queue dependencies needed to generate this file.
1125 this->QueueDependencies(sf
);
1127 // Make sure this file is in the target.
1128 if(this->TargetSources
.insert(sf
).second
)
1130 this->Target
->AddSourceFile(sf
);
1136 //----------------------------------------------------------------------------
1137 void cmTargetTraceDependencies::QueueOnce(std::string
const& name
)
1139 if(this->DependenciesQueued
.insert(name
).second
)
1141 this->DependencyQueue
.push(name
);
1145 //----------------------------------------------------------------------------
1147 cmTargetTraceDependencies::QueueOnce(std::vector
<std::string
> const& names
)
1149 for(std::vector
<std::string
>::const_iterator i
= names
.begin();
1150 i
!= names
.end(); ++i
)
1152 this->QueueOnce(*i
);
1156 //----------------------------------------------------------------------------
1157 bool cmTargetTraceDependencies::IsUtility(std::string
const& dep
)
1159 // Dependencies on targets (utilities) are supposed to be named by
1160 // just the target name. However for compatibility we support
1161 // naming the output file generated by the target (assuming there is
1162 // no output-name property which old code would not have set). In
1163 // that case the target name will be the file basename of the
1165 std::string util
= cmSystemTools::GetFilenameName(dep
);
1166 if(cmSystemTools::GetFilenameLastExtension(util
) == ".exe")
1168 util
= cmSystemTools::GetFilenameWithoutLastExtension(util
);
1171 // Check for a non-imported target with this name.
1172 if(cmTarget
* t
= this->GlobalGenerator
->FindTarget(0, util
.c_str()))
1174 // If we find the target and the dep was given as a full path,
1175 // then make sure it was not a full path to something else, and
1176 // the fact that the name matched a target was just a coincidence.
1177 if(cmSystemTools::FileIsFullPath(dep
.c_str()))
1179 // This is really only for compatibility so we do not need to
1180 // worry about configuration names and output names.
1181 std::string tLocation
= t
->GetLocation(0);
1182 tLocation
= cmSystemTools::GetFilenamePath(tLocation
);
1183 std::string depLocation
= cmSystemTools::GetFilenamePath(dep
);
1184 depLocation
= cmSystemTools::CollapseFullPath(depLocation
.c_str());
1185 tLocation
= cmSystemTools::CollapseFullPath(tLocation
.c_str());
1186 if(depLocation
== tLocation
)
1188 this->Target
->AddUtility(util
.c_str());
1194 // The original name of the dependency was not a full path. It
1195 // must name a target, so add the target-level dependency.
1196 this->Target
->AddUtility(util
.c_str());
1201 // The dependency does not name a target built in this project.
1205 //----------------------------------------------------------------------------
1206 void cmTargetTraceDependencies::QueueDependencies(cmSourceFile
* sf
)
1208 // Queue dependency added explicitly by the user.
1209 if(const char* additionalDeps
= sf
->GetProperty("OBJECT_DEPENDS"))
1211 std::vector
<std::string
> objDeps
;
1212 cmSystemTools::ExpandListArgument(additionalDeps
, objDeps
);
1213 this->QueueOnce(objDeps
);
1216 // Queue dependencies added programatically by commands.
1217 this->QueueOnce(sf
->GetDepends());
1219 // Queue custom command dependencies.
1220 if(cmCustomCommand
const* cc
= sf
->GetCustomCommand())
1222 this->CheckCustomCommand(*cc
);
1227 //----------------------------------------------------------------------------
1229 cmTargetTraceDependencies
1230 ::CheckCustomCommand(cmCustomCommand
const& cc
)
1232 // Transform command names that reference targets built in this
1233 // project to corresponding target-level dependencies.
1234 for(cmCustomCommandLines::const_iterator cit
= cc
.GetCommandLines().begin();
1235 cit
!= cc
.GetCommandLines().end(); ++cit
)
1237 std::string
const& command
= *cit
->begin();
1238 // Look for a non-imported target with this name.
1239 if(cmTarget
* t
= this->GlobalGenerator
->FindTarget(0, command
.c_str()))
1241 if(t
->GetType() == cmTarget::EXECUTABLE
)
1243 // The command refers to an executable target built in
1244 // this project. Add the target-level dependency to make
1245 // sure the executable is up to date before this custom
1246 // command possibly runs.
1247 this->Target
->AddUtility(command
.c_str());
1252 // Queue the custom command dependencies.
1253 std::vector
<std::string
> const& depends
= cc
.GetDepends();
1254 for(std::vector
<std::string
>::const_iterator di
= depends
.begin();
1255 di
!= depends
.end(); ++di
)
1257 std::string
const& dep
= *di
;
1258 if(!this->IsUtility(dep
))
1260 // The dependency does not name a target and may be a file we
1261 // know how to generate. Queue it.
1262 this->QueueOnce(dep
);
1267 //----------------------------------------------------------------------------
1269 cmTargetTraceDependencies
1270 ::CheckCustomCommands(const std::vector
<cmCustomCommand
>& commands
)
1272 for(std::vector
<cmCustomCommand
>::const_iterator cli
= commands
.begin();
1273 cli
!= commands
.end(); ++cli
)
1275 this->CheckCustomCommand(*cli
);
1279 //----------------------------------------------------------------------------
1280 void cmTarget::TraceDependencies(const char* vsProjectFile
)
1282 // Use a helper object to trace the dependencies.
1283 cmTargetTraceDependencies
tracer(this, vsProjectFile
);
1287 //----------------------------------------------------------------------------
1288 bool cmTarget::FindSourceFiles()
1290 for(std::vector
<cmSourceFile
*>::const_iterator
1291 si
= this->SourceFiles
.begin();
1292 si
!= this->SourceFiles
.end(); ++si
)
1294 if((*si
)->GetFullPath().empty())
1302 //----------------------------------------------------------------------------
1303 void cmTarget::AddSources(std::vector
<std::string
> const& srcs
)
1305 for(std::vector
<std::string
>::const_iterator i
= srcs
.begin();
1306 i
!= srcs
.end(); ++i
)
1308 this->AddSource(i
->c_str());
1312 //----------------------------------------------------------------------------
1313 cmSourceFile
* cmTarget::AddSource(const char* s
)
1315 std::string src
= s
;
1317 // For backwards compatibility replace varibles in source names.
1318 // This should eventually be removed.
1319 this->Makefile
->ExpandVariablesInString(src
);
1321 cmSourceFile
* sf
= this->Makefile
->GetOrCreateSource(src
.c_str());
1322 this->AddSourceFile(sf
);
1326 //----------------------------------------------------------------------------
1327 struct cmTarget::SourceFileFlags
1328 cmTarget::GetTargetSourceFileFlags(const cmSourceFile
* sf
)
1330 struct SourceFileFlags flags
;
1331 this->ConstructSourceFileFlags();
1332 std::map
<cmSourceFile
const*, SourceFileFlags
>::iterator si
=
1333 this->Internal
->SourceFlagsMap
.find(sf
);
1334 if(si
!= this->Internal
->SourceFlagsMap
.end())
1341 //----------------------------------------------------------------------------
1342 void cmTarget::ConstructSourceFileFlags()
1344 if(this->Internal
->SourceFileFlagsConstructed
)
1348 this->Internal
->SourceFileFlagsConstructed
= true;
1350 // Process public headers to mark the source files.
1351 if(const char* files
= this->GetProperty("PUBLIC_HEADER"))
1353 std::vector
<std::string
> relFiles
;
1354 cmSystemTools::ExpandListArgument(files
, relFiles
);
1355 for(std::vector
<std::string
>::iterator it
= relFiles
.begin();
1356 it
!= relFiles
.end(); ++it
)
1358 if(cmSourceFile
* sf
= this->Makefile
->GetSource(it
->c_str()))
1360 SourceFileFlags
& flags
= this->Internal
->SourceFlagsMap
[sf
];
1361 flags
.MacFolder
= "Headers";
1362 flags
.Type
= cmTarget::SourceFileTypePublicHeader
;
1367 // Process private headers after public headers so that they take
1368 // precedence if a file is listed in both.
1369 if(const char* files
= this->GetProperty("PRIVATE_HEADER"))
1371 std::vector
<std::string
> relFiles
;
1372 cmSystemTools::ExpandListArgument(files
, relFiles
);
1373 for(std::vector
<std::string
>::iterator it
= relFiles
.begin();
1374 it
!= relFiles
.end(); ++it
)
1376 if(cmSourceFile
* sf
= this->Makefile
->GetSource(it
->c_str()))
1378 SourceFileFlags
& flags
= this->Internal
->SourceFlagsMap
[sf
];
1379 flags
.MacFolder
= "PrivateHeaders";
1380 flags
.Type
= cmTarget::SourceFileTypePrivateHeader
;
1385 // Mark sources listed as resources.
1386 if(const char* files
= this->GetProperty("RESOURCE"))
1388 std::vector
<std::string
> relFiles
;
1389 cmSystemTools::ExpandListArgument(files
, relFiles
);
1390 for(std::vector
<std::string
>::iterator it
= relFiles
.begin();
1391 it
!= relFiles
.end(); ++it
)
1393 if(cmSourceFile
* sf
= this->Makefile
->GetSource(it
->c_str()))
1395 SourceFileFlags
& flags
= this->Internal
->SourceFlagsMap
[sf
];
1396 flags
.MacFolder
= "Resources";
1397 flags
.Type
= cmTarget::SourceFileTypeResource
;
1402 // Handle the MACOSX_PACKAGE_LOCATION property on source files that
1403 // were not listed in one of the other lists.
1404 std::vector
<cmSourceFile
*> const& sources
= this->GetSourceFiles();
1405 for(std::vector
<cmSourceFile
*>::const_iterator si
= sources
.begin();
1406 si
!= sources
.end(); ++si
)
1408 cmSourceFile
* sf
= *si
;
1409 if(const char* location
= sf
->GetProperty("MACOSX_PACKAGE_LOCATION"))
1411 SourceFileFlags
& flags
= this->Internal
->SourceFlagsMap
[sf
];
1412 if(flags
.Type
== cmTarget::SourceFileTypeNormal
)
1414 flags
.MacFolder
= location
;
1415 if(strcmp(location
, "Resources") == 0)
1417 flags
.Type
= cmTarget::SourceFileTypeResource
;
1421 flags
.Type
= cmTarget::SourceFileTypeMacContent
;
1428 //----------------------------------------------------------------------------
1429 void cmTarget::MergeLinkLibraries( cmMakefile
& mf
,
1430 const char *selfname
,
1431 const LinkLibraryVectorType
& libs
)
1433 // Only add on libraries we haven't added on before.
1434 // Assumption: the global link libraries could only grow, never shrink
1435 LinkLibraryVectorType::const_iterator i
= libs
.begin();
1436 i
+= this->PrevLinkedLibraries
.size();
1437 for( ; i
!= libs
.end(); ++i
)
1439 // We call this so that the dependencies get written to the cache
1440 this->AddLinkLibrary( mf
, selfname
, i
->first
.c_str(), i
->second
);
1442 this->PrevLinkedLibraries
= libs
;
1445 //----------------------------------------------------------------------------
1446 void cmTarget::AddLinkDirectory(const char* d
)
1448 // Make sure we don't add unnecessary search directories.
1449 if(this->LinkDirectoriesEmmitted
.insert(d
).second
)
1451 this->LinkDirectories
.push_back(d
);
1455 //----------------------------------------------------------------------------
1456 const std::vector
<std::string
>& cmTarget::GetLinkDirectories()
1458 return this->LinkDirectories
;
1461 //----------------------------------------------------------------------------
1462 cmTarget::LinkLibraryType
cmTarget::ComputeLinkType(const char* config
)
1464 // No configuration is always optimized.
1465 if(!(config
&& *config
))
1467 return cmTarget::OPTIMIZED
;
1470 // Get the list of configurations considered to be DEBUG.
1471 std::vector
<std::string
> const& debugConfigs
=
1472 this->Makefile
->GetCMakeInstance()->GetDebugConfigs();
1474 // Check if any entry in the list matches this configuration.
1475 std::string configUpper
= cmSystemTools::UpperCase(config
);
1476 for(std::vector
<std::string
>::const_iterator i
= debugConfigs
.begin();
1477 i
!= debugConfigs
.end(); ++i
)
1479 if(*i
== configUpper
)
1481 return cmTarget::DEBUG
;
1485 // The current configuration is not a debug configuration.
1486 return cmTarget::OPTIMIZED
;
1489 //----------------------------------------------------------------------------
1490 void cmTarget::ClearDependencyInformation( cmMakefile
& mf
,
1491 const char* target
)
1493 // Clear the dependencies. The cache variable must exist iff we are
1494 // recording dependency information for this target.
1495 std::string depname
= target
;
1496 depname
+= "_LIB_DEPENDS";
1497 if (this->RecordDependencies
)
1499 mf
.AddCacheDefinition(depname
.c_str(), "",
1500 "Dependencies for target", cmCacheManager::STATIC
);
1504 if (mf
.GetDefinition( depname
.c_str() ))
1506 std::string message
= "Target ";
1508 message
+= " has dependency information when it shouldn't.\n";
1509 message
+= "Your cache is probably stale. Please remove the entry\n ";
1511 message
+= "\nfrom the cache.";
1512 cmSystemTools::Error( message
.c_str() );
1517 //----------------------------------------------------------------------------
1518 void cmTarget::AddLinkLibrary(const std::string
& lib
,
1519 LinkLibraryType llt
)
1521 this->AddFramework(lib
.c_str(), llt
);
1522 cmTarget::LibraryID tmp
;
1525 this->LinkLibraries
.push_back(tmp
);
1526 this->OriginalLinkLibraries
.push_back(tmp
);
1529 //----------------------------------------------------------------------------
1530 bool cmTarget::NameResolvesToFramework(const std::string
& libname
)
1532 return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
1533 NameResolvesToFramework(libname
);
1536 //----------------------------------------------------------------------------
1537 bool cmTarget::AddFramework(const std::string
& libname
, LinkLibraryType llt
)
1539 (void)llt
; // TODO: What is this?
1540 if(this->NameResolvesToFramework(libname
.c_str()))
1542 std::string frameworkDir
= libname
;
1543 frameworkDir
+= "/../";
1544 frameworkDir
= cmSystemTools::CollapseFullPath(frameworkDir
.c_str());
1545 std::vector
<std::string
>::iterator i
=
1546 std::find(this->Frameworks
.begin(),
1547 this->Frameworks
.end(), frameworkDir
);
1548 if(i
== this->Frameworks
.end())
1550 this->Frameworks
.push_back(frameworkDir
);
1557 //----------------------------------------------------------------------------
1558 void cmTarget::AddLinkLibrary(cmMakefile
& mf
,
1559 const char *target
, const char* lib
,
1560 LinkLibraryType llt
)
1562 // Never add a self dependency, even if the user asks for it.
1563 if(strcmp( target
, lib
) == 0)
1567 this->AddFramework(lib
, llt
);
1568 cmTarget::LibraryID tmp
;
1571 this->LinkLibraries
.push_back( tmp
);
1572 this->OriginalLinkLibraries
.push_back(tmp
);
1574 // Add the explicit dependency information for this target. This is
1575 // simply a set of libraries separated by ";". There should always
1576 // be a trailing ";". These library names are not canonical, in that
1577 // they may be "-framework x", "-ly", "/path/libz.a", etc.
1578 // We shouldn't remove duplicates here because external libraries
1579 // may be purposefully duplicated to handle recursive dependencies,
1580 // and we removing one instance will break the link line. Duplicates
1581 // will be appropriately eliminated at emit time.
1582 if(this->RecordDependencies
)
1584 std::string targetEntry
= target
;
1585 targetEntry
+= "_LIB_DEPENDS";
1586 std::string dependencies
;
1587 const char* old_val
= mf
.GetDefinition( targetEntry
.c_str() );
1590 dependencies
+= old_val
;
1594 case cmTarget::GENERAL
:
1595 dependencies
+= "general";
1597 case cmTarget::DEBUG
:
1598 dependencies
+= "debug";
1600 case cmTarget::OPTIMIZED
:
1601 dependencies
+= "optimized";
1604 dependencies
+= ";";
1605 dependencies
+= lib
;
1606 dependencies
+= ";";
1607 mf
.AddCacheDefinition( targetEntry
.c_str(), dependencies
.c_str(),
1608 "Dependencies for the target",
1609 cmCacheManager::STATIC
);
1614 //----------------------------------------------------------------------------
1616 cmTarget::AnalyzeLibDependencies( const cmMakefile
& mf
)
1618 // There are two key parts of the dependency analysis: (1)
1619 // determining the libraries in the link line, and (2) constructing
1620 // the dependency graph for those libraries.
1622 // The latter is done using the cache entries that record the
1623 // dependencies of each library.
1625 // The former is a more thorny issue, since it is not clear how to
1626 // determine if two libraries listed on the link line refer to the a
1627 // single library or not. For example, consider the link "libraries"
1628 // /usr/lib/libtiff.so -ltiff
1629 // Is this one library or two? The solution implemented here is the
1630 // simplest (and probably the only practical) one: two libraries are
1631 // the same if their "link strings" are identical. Thus, the two
1632 // libraries above are considered distinct. This also means that for
1633 // dependency analysis to be effective, the CMake user must specify
1634 // libraries build by his project without using any linker flags or
1635 // file extensions. That is,
1636 // LINK_LIBRARIES( One Two )
1638 // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
1639 // The former is probably what most users would do, but it never
1640 // hurts to document the assumptions. :-) Therefore, in the analysis
1641 // code, the "canonical name" of a library is simply its name as
1642 // given to a LINK_LIBRARIES command.
1644 // Also, we will leave the original link line intact; we will just add any
1645 // dependencies that were missing.
1647 // There is a problem with recursive external libraries
1648 // (i.e. libraries with no dependency information that are
1649 // recursively dependent). We must make sure that the we emit one of
1650 // the libraries twice to satisfy the recursion, but we shouldn't
1651 // emit it more times than necessary. In particular, we must make
1652 // sure that handling this improbable case doesn't cost us when
1653 // dealing with the common case of non-recursive libraries. The
1654 // solution is to assume that the recursion is satisfied at one node
1655 // of the dependency tree. To illustrate, assume libA and libB are
1656 // extrenal and mutually dependent. Suppose libX depends on
1657 // libA, and libY on libA and libX. Then
1658 // TARGET_LINK_LIBRARIES( Y X A B A )
1659 // TARGET_LINK_LIBRARIES( X A B A )
1660 // TARGET_LINK_LIBRARIES( Exec Y )
1661 // would result in "-lY -lX -lA -lB -lA". This is the correct way to
1662 // specify the dependencies, since the mutual dependency of A and B
1663 // is resolved *every time libA is specified*.
1666 // TARGET_LINK_LIBRARIES( Y X A B A )
1667 // TARGET_LINK_LIBRARIES( X A B )
1668 // TARGET_LINK_LIBRARIES( Exec Y )
1669 // would result in "-lY -lX -lA -lB", and the mutual dependency
1670 // information is lost. This is because in some case (Y), the mutual
1671 // dependency of A and B is listed, while in another other case (X),
1672 // it is not. Depending on which line actually emits A, the mutual
1673 // dependency may or may not be on the final link line. We can't
1674 // handle this pathalogical case cleanly without emitting extra
1675 // libraries for the normal cases. Besides, the dependency
1676 // information for X is wrong anyway: if we build an executable
1677 // depending on X alone, we would not have the mutual dependency on
1678 // A and B resolved.
1681 // -- The current algorithm will not always pick the "optimal" link line
1682 // when recursive dependencies are present. It will instead break the
1683 // cycles at an aribtrary point. The majority of projects won't have
1684 // cyclic dependencies, so this is probably not a big deal. Note that
1685 // the link line is always correct, just not necessary optimal.
1688 // Expand variables in link library names. This is for backwards
1689 // compatibility with very early CMake versions and should
1690 // eventually be removed. This code was moved here from the end of
1691 // old source list processing code which was called just before this
1693 for(LinkLibraryVectorType::iterator p
= this->LinkLibraries
.begin();
1694 p
!= this->LinkLibraries
.end(); ++p
)
1696 this->Makefile
->ExpandVariablesInString(p
->first
, true, true);
1700 typedef std::vector
< std::string
> LinkLine
;
1702 // The dependency map.
1703 DependencyMap dep_map
;
1705 // 1. Build the dependency graph
1707 for(LinkLibraryVectorType::reverse_iterator lib
1708 = this->LinkLibraries
.rbegin();
1709 lib
!= this->LinkLibraries
.rend(); ++lib
)
1711 this->GatherDependencies( mf
, *lib
, dep_map
);
1714 // 2. Remove any dependencies that are already satisfied in the original
1717 for(LinkLibraryVectorType::iterator lib
= this->LinkLibraries
.begin();
1718 lib
!= this->LinkLibraries
.end(); ++lib
)
1720 for( LinkLibraryVectorType::iterator lib2
= lib
;
1721 lib2
!= this->LinkLibraries
.end(); ++lib2
)
1723 this->DeleteDependency( dep_map
, *lib
, *lib2
);
1728 // 3. Create the new link line by simply emitting any dependencies that are
1729 // missing. Start from the back and keep adding.
1731 std::set
<DependencyMap::key_type
> done
, visited
;
1732 std::vector
<DependencyMap::key_type
> newLinkLibraries
;
1733 for(LinkLibraryVectorType::reverse_iterator lib
=
1734 this->LinkLibraries
.rbegin();
1735 lib
!= this->LinkLibraries
.rend(); ++lib
)
1737 // skip zero size library entries, this may happen
1738 // if a variable expands to nothing.
1739 if (lib
->first
.size() != 0)
1741 this->Emit( *lib
, dep_map
, done
, visited
, newLinkLibraries
);
1745 // 4. Add the new libraries to the link line.
1747 for( std::vector
<DependencyMap::key_type
>::reverse_iterator k
=
1748 newLinkLibraries
.rbegin();
1749 k
!= newLinkLibraries
.rend(); ++k
)
1751 // get the llt from the dep_map
1752 this->LinkLibraries
.push_back( std::make_pair(k
->first
,k
->second
) );
1754 this->LinkLibrariesAnalyzed
= true;
1757 //----------------------------------------------------------------------------
1758 void cmTarget::InsertDependency( DependencyMap
& depMap
,
1759 const LibraryID
& lib
,
1760 const LibraryID
& dep
)
1762 depMap
[lib
].push_back(dep
);
1765 //----------------------------------------------------------------------------
1766 void cmTarget::DeleteDependency( DependencyMap
& depMap
,
1767 const LibraryID
& lib
,
1768 const LibraryID
& dep
)
1770 // Make sure there is an entry in the map for lib. If so, delete all
1771 // dependencies to dep. There may be repeated entries because of
1772 // external libraries that are specified multiple times.
1773 DependencyMap::iterator map_itr
= depMap
.find( lib
);
1774 if( map_itr
!= depMap
.end() )
1776 DependencyList
& depList
= map_itr
->second
;
1777 DependencyList::iterator itr
;
1778 while( (itr
= std::find(depList
.begin(), depList
.end(), dep
)) !=
1781 depList
.erase( itr
);
1786 //----------------------------------------------------------------------------
1787 void cmTarget::Emit(const LibraryID lib
,
1788 const DependencyMap
& dep_map
,
1789 std::set
<LibraryID
>& emitted
,
1790 std::set
<LibraryID
>& visited
,
1791 DependencyList
& link_line
)
1793 // It's already been emitted
1794 if( emitted
.find(lib
) != emitted
.end() )
1799 // Emit the dependencies only if this library node hasn't been
1800 // visited before. If it has, then we have a cycle. The recursion
1801 // that got us here should take care of everything.
1803 if( visited
.insert(lib
).second
)
1805 if( dep_map
.find(lib
) != dep_map
.end() ) // does it have dependencies?
1807 const DependencyList
& dep_on
= dep_map
.find( lib
)->second
;
1808 DependencyList::const_reverse_iterator i
;
1810 // To cater for recursive external libraries, we must emit
1811 // duplicates on this link line *unless* they were emitted by
1812 // some other node, in which case we assume that the recursion
1813 // was resolved then. We making the simplifying assumption that
1814 // any duplicates on a single link line are on purpose, and must
1817 // This variable will keep track of the libraries that were
1818 // emitted directory from the current node, and not from a
1819 // recursive call. This way, if we come across a library that
1820 // has already been emitted, we repeat it iff it has been
1822 std::set
<DependencyMap::key_type
> emitted_here
;
1823 for( i
= dep_on
.rbegin(); i
!= dep_on
.rend(); ++i
)
1825 if( emitted_here
.find(*i
) != emitted_here
.end() )
1827 // a repeat. Must emit.
1829 link_line
.push_back( *i
);
1833 // Emit only if no-one else has
1834 if( emitted
.find(*i
) == emitted
.end() )
1836 // emit dependencies
1837 Emit( *i
, dep_map
, emitted
, visited
, link_line
);
1840 emitted_here
.insert(*i
);
1841 link_line
.push_back( *i
);
1849 //----------------------------------------------------------------------------
1850 void cmTarget::GatherDependencies( const cmMakefile
& mf
,
1851 const LibraryID
& lib
,
1852 DependencyMap
& dep_map
)
1854 // If the library is already in the dependency map, then it has
1855 // already been fully processed.
1856 if( dep_map
.find(lib
) != dep_map
.end() )
1861 const char* deps
= mf
.GetDefinition( (lib
.first
+"_LIB_DEPENDS").c_str() );
1862 if( deps
&& strcmp(deps
,"") != 0 )
1864 // Make sure this library is in the map, even if it has an empty
1865 // set of dependencies. This distinguishes the case of explicitly
1866 // no dependencies with that of unspecified dependencies.
1869 // Parse the dependency information, which is a set of
1870 // type, library pairs separated by ";". There is always a trailing ";".
1871 cmTarget::LinkLibraryType llt
= cmTarget::GENERAL
;
1872 std::string depline
= deps
;
1873 std::string::size_type start
= 0;
1874 std::string::size_type end
;
1875 end
= depline
.find( ";", start
);
1876 while( end
!= std::string::npos
)
1878 std::string l
= depline
.substr( start
, end
-start
);
1883 llt
= cmTarget::DEBUG
;
1885 else if (l
== "optimized")
1887 llt
= cmTarget::OPTIMIZED
;
1889 else if (l
== "general")
1891 llt
= cmTarget::GENERAL
;
1895 LibraryID
lib2(l
,llt
);
1896 this->InsertDependency( dep_map
, lib
, lib2
);
1897 this->GatherDependencies( mf
, lib2
, dep_map
);
1898 llt
= cmTarget::GENERAL
;
1901 start
= end
+1; // skip the ;
1902 end
= depline
.find( ";", start
);
1904 // cannot depend on itself
1905 this->DeleteDependency( dep_map
, lib
, lib
);
1909 //----------------------------------------------------------------------------
1910 void cmTarget::SetProperty(const char* prop
, const char* value
)
1917 this->Properties
.SetProperty(prop
, value
, cmProperty::TARGET
);
1919 // If imported information is being set, wipe out cached
1921 if(this->IsImported() && strncmp(prop
, "IMPORTED", 8) == 0)
1923 this->Internal
->ImportInfoMap
.clear();
1927 //----------------------------------------------------------------------------
1928 void cmTarget::AppendProperty(const char* prop
, const char* value
)
1934 this->Properties
.AppendProperty(prop
, value
, cmProperty::TARGET
);
1936 // If imported information is being set, wipe out cached
1938 if(this->IsImported() && strncmp(prop
, "IMPORTED", 8) == 0)
1940 this->Internal
->ImportInfoMap
.clear();
1944 //----------------------------------------------------------------------------
1945 static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
1946 const char* prop
, const char* value
, cmMakefile
* context
, bool imported
1949 // Look for link-type keywords in the value.
1950 static cmsys::RegularExpression
1951 keys("(^|;)(debug|optimized|general)(;|$)");
1952 if(!keys
.find(value
))
1957 // Support imported and non-imported versions of the property.
1958 const char* base
= (imported
?
1959 "IMPORTED_LINK_INTERFACE_LIBRARIES" :
1960 "LINK_INTERFACE_LIBRARIES");
1964 e
<< "Property " << prop
<< " may not contain link-type keyword \""
1965 << keys
.match(2) << "\". "
1966 << "The " << base
<< " property has a per-configuration "
1967 << "version called " << base
<< "_<CONFIG> which may be "
1968 << "used to specify per-configuration rules.";
1972 << "Alternatively, an IMPORTED library may be created, configured "
1973 << "with a per-configuration location, and then named in the "
1974 << "property value. "
1975 << "See the add_library command's IMPORTED mode for details."
1977 << "If you have a list of libraries that already contains the "
1978 << "keyword, use the target_link_libraries command with its "
1979 << "LINK_INTERFACE_LIBRARIES mode to set the property. "
1980 << "The command automatically recognizes link-type keywords and sets "
1981 << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
1982 << "properties accordingly.";
1984 context
->IssueMessage(cmake::FATAL_ERROR
, e
.str());
1987 //----------------------------------------------------------------------------
1988 void cmTarget::CheckProperty(const char* prop
, cmMakefile
* context
)
1990 // Certain properties need checking.
1991 if(strncmp(prop
, "LINK_INTERFACE_LIBRARIES", 24) == 0)
1993 if(const char* value
= this->GetProperty(prop
))
1995 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop
, value
, context
, false);
1998 if(strncmp(prop
, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
2000 if(const char* value
= this->GetProperty(prop
))
2002 cmTargetCheckLINK_INTERFACE_LIBRARIES(prop
, value
, context
, true);
2007 //----------------------------------------------------------------------------
2008 void cmTarget::MarkAsImported()
2010 this->IsImportedTarget
= true;
2013 //----------------------------------------------------------------------------
2014 cmTarget::OutputInfo
const* cmTarget::GetOutputInfo(const char* config
)
2016 // There is no output information for imported targets.
2017 if(this->IsImported())
2022 // Only libraries and executables have well-defined output files.
2023 if(this->GetType() != cmTarget::STATIC_LIBRARY
&&
2024 this->GetType() != cmTarget::SHARED_LIBRARY
&&
2025 this->GetType() != cmTarget::MODULE_LIBRARY
&&
2026 this->GetType() != cmTarget::EXECUTABLE
)
2028 std::string msg
= "cmTarget::GetOutputInfo called for ";
2029 msg
+= this->GetName();
2030 msg
+= " which has type ";
2031 msg
+= cmTarget::TargetTypeNames
[this->GetType()];
2032 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR
, msg
);
2037 // Lookup/compute/cache the output information for this configuration.
2038 std::string config_upper
;
2039 if(config
&& *config
)
2041 config_upper
= cmSystemTools::UpperCase(config
);
2043 typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType
;
2044 OutputInfoMapType::const_iterator i
=
2045 this->Internal
->OutputInfoMap
.find(config_upper
);
2046 if(i
== this->Internal
->OutputInfoMap
.end())
2049 this->ComputeOutputDir(config
, false, info
.OutDir
);
2050 this->ComputeOutputDir(config
, true, info
.ImpDir
);
2051 OutputInfoMapType::value_type
entry(config_upper
, info
);
2052 i
= this->Internal
->OutputInfoMap
.insert(entry
).first
;
2057 //----------------------------------------------------------------------------
2058 std::string
cmTarget::GetDirectory(const char* config
, bool implib
)
2060 if (this->IsImported())
2062 // Return the directory from which the target is imported.
2064 cmSystemTools::GetFilenamePath(
2065 this->ImportedGetFullPath(config
, implib
));
2067 else if(OutputInfo
const* info
= this->GetOutputInfo(config
))
2069 // Return the directory in which the target will be built.
2070 return implib
? info
->ImpDir
: info
->OutDir
;
2075 //----------------------------------------------------------------------------
2076 const char* cmTarget::GetLocation(const char* config
)
2078 if (this->IsImported())
2080 return this->ImportedGetLocation(config
);
2084 return this->NormalGetLocation(config
);
2088 //----------------------------------------------------------------------------
2089 const char* cmTarget::ImportedGetLocation(const char* config
)
2091 this->Location
= this->ImportedGetFullPath(config
, false);
2092 return this->Location
.c_str();
2095 //----------------------------------------------------------------------------
2096 const char* cmTarget::NormalGetLocation(const char* config
)
2098 // Handle the configuration-specific case first.
2101 this->Location
= this->GetFullPath(config
, false);
2102 return this->Location
.c_str();
2105 // Now handle the deprecated build-time configuration location.
2106 this->Location
= this->GetDirectory();
2107 if(!this->Location
.empty())
2109 this->Location
+= "/";
2111 const char* cfgid
= this->Makefile
->GetDefinition("CMAKE_CFG_INTDIR");
2112 if(cfgid
&& strcmp(cfgid
, ".") != 0)
2114 this->Location
+= cfgid
;
2115 this->Location
+= "/";
2117 if(this->IsAppBundleOnApple())
2119 this->Location
+= this->GetFullName(config
, false);
2120 this->Location
+= ".app/Contents/MacOS/";
2122 if(this->IsFrameworkOnApple())
2124 this->Location
+= this->GetFullName(config
, false);
2125 this->Location
+= ".framework/Versions/";
2126 this->Location
+= this->GetFrameworkVersion();
2127 this->Location
+= "/";
2129 this->Location
+= this->GetFullName(config
, false);
2130 return this->Location
.c_str();
2133 //----------------------------------------------------------------------------
2134 void cmTarget::GetTargetVersion(int& major
, int& minor
)
2137 this->GetTargetVersion(false, major
, minor
, patch
);
2140 //----------------------------------------------------------------------------
2141 void cmTarget::GetTargetVersion(bool soversion
,
2142 int& major
, int& minor
, int& patch
)
2144 // Set the default values.
2149 // Look for a VERSION or SOVERSION property.
2150 const char* prop
= soversion
? "SOVERSION" : "VERSION";
2151 if(const char* version
= this->GetProperty(prop
))
2153 // Try to parse the version number and store the results that were
2154 // successfully parsed.
2158 switch(sscanf(version
, "%d.%d.%d",
2159 &parsed_major
, &parsed_minor
, &parsed_patch
))
2161 case 3: patch
= parsed_patch
; // no break!
2162 case 2: minor
= parsed_minor
; // no break!
2163 case 1: major
= parsed_major
; // no break!
2169 //----------------------------------------------------------------------------
2170 const char *cmTarget::GetProperty(const char* prop
)
2172 return this->GetProperty(prop
, cmProperty::TARGET
);
2175 //----------------------------------------------------------------------------
2176 void cmTarget::ComputeObjectFiles()
2178 if (this->IsImported())
2183 std::vector
<std::string
> dirs
;
2184 this->Makefile
->GetLocalGenerator()->
2185 GetTargetObjectFileDirectories(this,
2187 std::string objectFiles
;
2188 std::string objExtensionLookup1
= "CMAKE_";
2189 std::string objExtensionLookup2
= "_OUTPUT_EXTENSION";
2191 for(std::vector
<std::string
>::iterator d
= dirs
.begin();
2192 d
!= dirs
.end(); ++d
)
2194 for(std::vector
<cmSourceFile
*>::iterator s
= this->SourceFiles
.begin();
2195 s
!= this->SourceFiles
.end(); ++s
)
2197 cmSourceFile
* sf
= *s
;
2198 if(const char* lang
= sf
->GetLanguage())
2200 std::string lookupObj
= objExtensionLookup1
+ lang
;
2201 lookupObj
+= objExtensionLookup2
;
2202 const char* obj
= this->Makefile
->GetDefinition(lookupObj
.c_str());
2205 if(objectFiles
.size())
2209 std::string objFile
= *d
;
2211 objFile
+= this->Makefile
->GetLocalGenerator()->
2212 GetSourceObjectName(*sf
);
2214 objectFiles
+= objFile
;
2219 this->SetProperty("OBJECT_FILES", objectFiles
.c_str());
2223 //----------------------------------------------------------------------------
2224 const char *cmTarget::GetProperty(const char* prop
,
2225 cmProperty::ScopeType scope
)
2232 // Watch for special "computed" properties that are dependent on
2233 // other properties or variables. Always recompute them.
2234 if(this->GetType() == cmTarget::EXECUTABLE
||
2235 this->GetType() == cmTarget::STATIC_LIBRARY
||
2236 this->GetType() == cmTarget::SHARED_LIBRARY
||
2237 this->GetType() == cmTarget::MODULE_LIBRARY
||
2238 this->GetType() == cmTarget::UNKNOWN_LIBRARY
)
2240 if(strcmp(prop
,"LOCATION") == 0)
2242 // Set the LOCATION property of the target.
2244 // For an imported target this is the location of an arbitrary
2245 // available configuration.
2247 // For a non-imported target this is deprecated because it
2248 // cannot take into account the per-configuration name of the
2249 // target because the configuration type may not be known at
2251 this->SetProperty("LOCATION", this->GetLocation(0));
2254 // Support "LOCATION_<CONFIG>".
2255 if(strncmp(prop
, "LOCATION_", 9) == 0)
2257 std::string configName
= prop
+9;
2258 this->SetProperty(prop
, this->GetLocation(configName
.c_str()));
2262 // Support "<CONFIG>_LOCATION" for compatiblity.
2263 int len
= static_cast<int>(strlen(prop
));
2264 if(len
> 9 && strcmp(prop
+len
-9, "_LOCATION") == 0)
2266 std::string
configName(prop
, len
-9);
2267 if(configName
!= "IMPORTED")
2269 this->SetProperty(prop
, this->GetLocation(configName
.c_str()));
2275 if (strcmp(prop
,"IMPORTED") == 0)
2277 return this->IsImported()?"TRUE":"FALSE";
2280 if(!strcmp(prop
,"SOURCES"))
2283 const char* sep
= "";
2284 for(std::vector
<cmSourceFile
*>::const_iterator
2285 i
= this->SourceFiles
.begin();
2286 i
!= this->SourceFiles
.end(); ++i
)
2288 // Separate from the previous list entries.
2292 // Construct what is known about this source file location.
2293 cmSourceFileLocation
const& location
= (*i
)->GetLocation();
2294 std::string sname
= location
.GetDirectory();
2299 sname
+= location
.GetName();
2301 // Append this list entry.
2304 this->SetProperty("SOURCES", ss
.str().c_str());
2307 // the type property returns what type the target is
2308 if (!strcmp(prop
,"TYPE"))
2310 switch( this->GetType() )
2312 case cmTarget::STATIC_LIBRARY
:
2313 return "STATIC_LIBRARY";
2314 // break; /* unreachable */
2315 case cmTarget::MODULE_LIBRARY
:
2316 return "MODULE_LIBRARY";
2317 // break; /* unreachable */
2318 case cmTarget::SHARED_LIBRARY
:
2319 return "SHARED_LIBRARY";
2320 // break; /* unreachable */
2321 case cmTarget::EXECUTABLE
:
2322 return "EXECUTABLE";
2323 // break; /* unreachable */
2324 case cmTarget::UTILITY
:
2326 // break; /* unreachable */
2327 case cmTarget::GLOBAL_TARGET
:
2328 return "GLOBAL_TARGET";
2329 // break; /* unreachable */
2330 case cmTarget::INSTALL_FILES
:
2331 return "INSTALL_FILES";
2332 // break; /* unreachable */
2333 case cmTarget::INSTALL_PROGRAMS
:
2334 return "INSTALL_PROGRAMS";
2335 // break; /* unreachable */
2336 case cmTarget::INSTALL_DIRECTORY
:
2337 return "INSTALL_DIRECTORY";
2338 // break; /* unreachable */
2339 case cmTarget::UNKNOWN_LIBRARY
:
2340 return "UNKNOWN_LIBRARY";
2341 // break; /* unreachable */
2346 const char *retVal
=
2347 this->Properties
.GetPropertyValue(prop
, scope
, chain
);
2350 return this->Makefile
->GetProperty(prop
,scope
);
2355 //----------------------------------------------------------------------------
2356 bool cmTarget::GetPropertyAsBool(const char* prop
)
2358 return cmSystemTools::IsOn(this->GetProperty(prop
));
2361 //----------------------------------------------------------------------------
2362 class cmTargetCollectLinkLanguages
2365 cmTargetCollectLinkLanguages(cmTarget
* target
, const char* config
,
2366 std::set
<cmStdString
>& languages
):
2367 Config(config
), Languages(languages
) { this->Visited
.insert(target
); }
2368 void Visit(cmTarget
* target
)
2370 if(!target
|| !this->Visited
.insert(target
).second
)
2375 cmTarget::LinkInterface
const* iface
=
2376 target
->GetLinkInterface(this->Config
);
2377 if(!iface
) { return; }
2379 for(std::vector
<std::string
>::const_iterator
2380 li
= iface
->Languages
.begin(); li
!= iface
->Languages
.end(); ++li
)
2382 this->Languages
.insert(*li
);
2385 cmMakefile
* mf
= target
->GetMakefile();
2386 for(std::vector
<std::string
>::const_iterator
2387 li
= iface
->Libraries
.begin(); li
!= iface
->Libraries
.end(); ++li
)
2389 this->Visit(mf
->FindTargetToUse(li
->c_str()));
2394 std::set
<cmStdString
>& Languages
;
2395 std::set
<cmTarget
*> Visited
;
2398 //----------------------------------------------------------------------------
2399 const char* cmTarget::GetLinkerLanguage(const char* config
)
2401 const char* lang
= this->GetLinkClosure(config
)->LinkerLanguage
.c_str();
2402 return *lang
? lang
: 0;
2405 //----------------------------------------------------------------------------
2406 cmTarget::LinkClosure
const* cmTarget::GetLinkClosure(const char* config
)
2408 std::string key
= cmSystemTools::UpperCase(config
? config
: "");
2409 cmTargetInternals::LinkClosureMapType::iterator
2410 i
= this->Internal
->LinkClosureMap
.find(key
);
2411 if(i
== this->Internal
->LinkClosureMap
.end())
2414 this->ComputeLinkClosure(config
, lc
);
2415 cmTargetInternals::LinkClosureMapType::value_type
entry(key
, lc
);
2416 i
= this->Internal
->LinkClosureMap
.insert(entry
).first
;
2421 //----------------------------------------------------------------------------
2422 class cmTargetSelectLinker
2426 cmMakefile
* Makefile
;
2427 cmGlobalGenerator
* GG
;
2428 std::set
<cmStdString
> Preferred
;
2430 cmTargetSelectLinker(cmTarget
* target
): Preference(0), Target(target
)
2432 this->Makefile
= this->Target
->GetMakefile();
2433 this->GG
= this->Makefile
->GetLocalGenerator()->GetGlobalGenerator();
2435 void Consider(const char* lang
)
2437 int preference
= this->GG
->GetLinkerPreference(lang
);
2438 if(preference
> this->Preference
)
2440 this->Preference
= preference
;
2441 this->Preferred
.clear();
2443 if(preference
== this->Preference
)
2445 this->Preferred
.insert(lang
);
2448 std::string
Choose()
2450 if(this->Preferred
.empty())
2454 else if(this->Preferred
.size() > 1)
2457 e
<< "Target " << this->Target
->GetName()
2458 << " contains multiple languages with the highest linker preference"
2459 << " (" << this->Preference
<< "):\n";
2460 for(std::set
<cmStdString
>::const_iterator
2461 li
= this->Preferred
.begin(); li
!= this->Preferred
.end(); ++li
)
2463 e
<< " " << *li
<< "\n";
2465 e
<< "Set the LINKER_LANGUAGE property for this target.";
2466 cmake
* cm
= this->Makefile
->GetCMakeInstance();
2467 cm
->IssueMessage(cmake::FATAL_ERROR
, e
.str(),
2468 this->Target
->GetBacktrace());
2470 return *this->Preferred
.begin();
2474 //----------------------------------------------------------------------------
2475 void cmTarget::ComputeLinkClosure(const char* config
, LinkClosure
& lc
)
2477 // Get languages built in this target.
2478 std::set
<cmStdString
> languages
;
2479 LinkImplementation
const* impl
= this->GetLinkImplementation(config
);
2480 for(std::vector
<std::string
>::const_iterator li
= impl
->Languages
.begin();
2481 li
!= impl
->Languages
.end(); ++li
)
2483 languages
.insert(*li
);
2486 // Add interface languages from linked targets.
2487 cmTargetCollectLinkLanguages
cll(this, config
, languages
);
2488 for(std::vector
<std::string
>::const_iterator li
= impl
->Libraries
.begin();
2489 li
!= impl
->Libraries
.end(); ++li
)
2491 cll
.Visit(this->Makefile
->FindTargetToUse(li
->c_str()));
2494 // Store the transitive closure of languages.
2495 for(std::set
<cmStdString
>::const_iterator li
= languages
.begin();
2496 li
!= languages
.end(); ++li
)
2498 lc
.Languages
.push_back(*li
);
2501 // Choose the language whose linker should be used.
2502 if(this->GetProperty("HAS_CXX"))
2504 lc
.LinkerLanguage
= "CXX";
2506 else if(const char* linkerLang
= this->GetProperty("LINKER_LANGUAGE"))
2508 lc
.LinkerLanguage
= linkerLang
;
2512 // Find the language with the highest preference value.
2513 cmTargetSelectLinker
tsl(this);
2515 // First select from the languages compiled directly in this target.
2516 for(std::vector
<std::string
>::const_iterator li
= impl
->Languages
.begin();
2517 li
!= impl
->Languages
.end(); ++li
)
2519 tsl
.Consider(li
->c_str());
2522 // Now consider languages that propagate from linked targets.
2523 for(std::set
<cmStdString
>::const_iterator sit
= languages
.begin();
2524 sit
!= languages
.end(); ++sit
)
2526 std::string propagates
= "CMAKE_"+*sit
+"_LINKER_PREFERENCE_PROPAGATES";
2527 if(this->Makefile
->IsOn(propagates
.c_str()))
2529 tsl
.Consider(sit
->c_str());
2533 lc
.LinkerLanguage
= tsl
.Choose();
2537 //----------------------------------------------------------------------------
2538 const char* cmTarget::GetCreateRuleVariable()
2540 switch(this->GetType())
2542 case cmTarget::STATIC_LIBRARY
:
2543 return "_CREATE_STATIC_LIBRARY";
2544 case cmTarget::SHARED_LIBRARY
:
2545 return "_CREATE_SHARED_LIBRARY";
2546 case cmTarget::MODULE_LIBRARY
:
2547 return "_CREATE_SHARED_MODULE";
2548 case cmTarget::EXECUTABLE
:
2549 return "_LINK_EXECUTABLE";
2556 //----------------------------------------------------------------------------
2557 const char* cmTarget::GetSuffixVariableInternal(bool implib
)
2559 switch(this->GetType())
2561 case cmTarget::STATIC_LIBRARY
:
2562 return "CMAKE_STATIC_LIBRARY_SUFFIX";
2563 case cmTarget::SHARED_LIBRARY
:
2565 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2566 : "CMAKE_SHARED_LIBRARY_SUFFIX");
2567 case cmTarget::MODULE_LIBRARY
:
2569 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2570 : "CMAKE_SHARED_MODULE_SUFFIX");
2571 case cmTarget::EXECUTABLE
:
2573 ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
2574 : "CMAKE_EXECUTABLE_SUFFIX");
2582 //----------------------------------------------------------------------------
2583 const char* cmTarget::GetPrefixVariableInternal(bool implib
)
2585 switch(this->GetType())
2587 case cmTarget::STATIC_LIBRARY
:
2588 return "CMAKE_STATIC_LIBRARY_PREFIX";
2589 case cmTarget::SHARED_LIBRARY
:
2591 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2592 : "CMAKE_SHARED_LIBRARY_PREFIX");
2593 case cmTarget::MODULE_LIBRARY
:
2595 ? "CMAKE_IMPORT_LIBRARY_PREFIX"
2596 : "CMAKE_SHARED_MODULE_PREFIX");
2597 case cmTarget::EXECUTABLE
:
2598 return (implib
? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
2605 //----------------------------------------------------------------------------
2606 std::string
cmTarget::GetPDBName(const char* config
)
2611 this->GetFullNameInternal(config
, false, prefix
, base
, suffix
);
2612 return prefix
+base
+".pdb";
2615 //----------------------------------------------------------------------------
2616 std::string
cmTarget::GetSOName(const char* config
)
2618 if(this->IsImported())
2620 // Lookup the imported soname.
2621 if(cmTarget::ImportInfo
const* info
= this->GetImportInfo(config
))
2625 // The imported library has no builtin soname so the name
2626 // searched at runtime will be just the filename.
2627 return cmSystemTools::GetFilenameName(info
->Location
);
2631 // Use the soname given if any.
2632 return info
->SOName
;
2642 // Compute the soname that will be built.
2645 std::string realName
;
2646 std::string impName
;
2647 std::string pdbName
;
2648 this->GetLibraryNames(name
, soName
, realName
, impName
, pdbName
, config
);
2653 //----------------------------------------------------------------------------
2654 bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config
)
2656 if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY
)
2658 if(cmTarget::ImportInfo
const* info
= this->GetImportInfo(config
))
2660 return info
->NoSOName
;
2666 //----------------------------------------------------------------------------
2667 std::string
cmTarget::NormalGetRealName(const char* config
)
2669 // This should not be called for imported targets.
2670 // TODO: Split cmTarget into a class hierarchy to get compile-time
2671 // enforcement of the limited imported target API.
2672 if(this->IsImported())
2674 std::string msg
= "NormalGetRealName called on imported target: ";
2675 msg
+= this->GetName();
2676 this->GetMakefile()->
2677 IssueMessage(cmake::INTERNAL_ERROR
,
2681 if(this->GetType() == cmTarget::EXECUTABLE
)
2683 // Compute the real name that will be built.
2685 std::string realName
;
2686 std::string impName
;
2687 std::string pdbName
;
2688 this->GetExecutableNames(name
, realName
, impName
, pdbName
, config
);
2693 // Compute the real name that will be built.
2696 std::string realName
;
2697 std::string impName
;
2698 std::string pdbName
;
2699 this->GetLibraryNames(name
, soName
, realName
, impName
, pdbName
, config
);
2704 //----------------------------------------------------------------------------
2705 std::string
cmTarget::GetFullName(const char* config
, bool implib
)
2707 if(this->IsImported())
2709 return this->GetFullNameImported(config
, implib
);
2713 return this->GetFullNameInternal(config
, implib
);
2717 //----------------------------------------------------------------------------
2718 std::string
cmTarget::GetFullNameImported(const char* config
, bool implib
)
2720 return cmSystemTools::GetFilenameName(
2721 this->ImportedGetFullPath(config
, implib
));
2724 //----------------------------------------------------------------------------
2725 void cmTarget::GetFullNameComponents(std::string
& prefix
, std::string
& base
,
2726 std::string
& suffix
, const char* config
,
2729 this->GetFullNameInternal(config
, implib
, prefix
, base
, suffix
);
2732 //----------------------------------------------------------------------------
2733 std::string
cmTarget::GetFullPath(const char* config
, bool implib
,
2736 if(this->IsImported())
2738 return this->ImportedGetFullPath(config
, implib
);
2742 return this->NormalGetFullPath(config
, implib
, realname
);
2746 //----------------------------------------------------------------------------
2747 std::string
cmTarget::NormalGetFullPath(const char* config
, bool implib
,
2750 // Start with the output directory for the target.
2751 std::string fpath
= this->GetDirectory(config
, implib
);
2754 if(this->IsAppBundleOnApple())
2756 fpath
+= this->GetFullName(config
, false);
2757 fpath
+= ".app/Contents/MacOS/";
2759 if(this->IsFrameworkOnApple())
2761 fpath
+= this->GetFullName(config
, false);
2762 fpath
+= ".framework/Versions/";
2763 fpath
+= this->GetFrameworkVersion();
2767 // Add the full name of the target.
2770 fpath
+= this->GetFullName(config
, true);
2774 fpath
+= this->NormalGetRealName(config
);
2778 fpath
+= this->GetFullName(config
, false);
2783 //----------------------------------------------------------------------------
2784 std::string
cmTarget::ImportedGetFullPath(const char* config
, bool implib
)
2787 if(cmTarget::ImportInfo
const* info
= this->GetImportInfo(config
))
2789 result
= implib
? info
->ImportLibrary
: info
->Location
;
2793 result
= this->GetName();
2794 result
+= "-NOTFOUND";
2799 //----------------------------------------------------------------------------
2800 std::string
cmTarget::GetFullNameInternal(const char* config
, bool implib
)
2805 this->GetFullNameInternal(config
, implib
, prefix
, base
, suffix
);
2806 return prefix
+base
+suffix
;
2809 //----------------------------------------------------------------------------
2810 void cmTarget::GetFullNameInternal(const char* config
,
2812 std::string
& outPrefix
,
2813 std::string
& outBase
,
2814 std::string
& outSuffix
)
2816 // Use just the target name for non-main target types.
2817 if(this->GetType() != cmTarget::STATIC_LIBRARY
&&
2818 this->GetType() != cmTarget::SHARED_LIBRARY
&&
2819 this->GetType() != cmTarget::MODULE_LIBRARY
&&
2820 this->GetType() != cmTarget::EXECUTABLE
)
2823 outBase
= this->GetName();
2828 // Return an empty name for the import library if this platform
2829 // does not support import libraries.
2831 !this->Makefile
->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
2839 // The implib option is only allowed for shared libraries, module
2840 // libraries, and executables.
2841 if(this->GetType() != cmTarget::SHARED_LIBRARY
&&
2842 this->GetType() != cmTarget::MODULE_LIBRARY
&&
2843 this->GetType() != cmTarget::EXECUTABLE
)
2848 // Compute the full name for main target types.
2849 const char* targetPrefix
= (implib
2850 ? this->GetProperty("IMPORT_PREFIX")
2851 : this->GetProperty("PREFIX"));
2852 const char* targetSuffix
= (implib
2853 ? this->GetProperty("IMPORT_SUFFIX")
2854 : this->GetProperty("SUFFIX"));
2855 const char* configPostfix
= 0;
2856 if(config
&& *config
)
2858 std::string configProp
= cmSystemTools::UpperCase(config
);
2859 configProp
+= "_POSTFIX";
2860 configPostfix
= this->GetProperty(configProp
.c_str());
2861 // Mac application bundles and frameworks have no postfix.
2863 (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
2868 const char* prefixVar
= this->GetPrefixVariableInternal(implib
);
2869 const char* suffixVar
= this->GetSuffixVariableInternal(implib
);
2871 // Check for language-specific default prefix and suffix.
2872 if(const char* ll
= this->GetLinkerLanguage(config
))
2874 if(!targetSuffix
&& suffixVar
&& *suffixVar
)
2876 std::string langSuff
= suffixVar
+ std::string("_") + ll
;
2877 targetSuffix
= this->Makefile
->GetDefinition(langSuff
.c_str());
2879 if(!targetPrefix
&& prefixVar
&& *prefixVar
)
2881 std::string langPrefix
= prefixVar
+ std::string("_") + ll
;
2882 targetPrefix
= this->Makefile
->GetDefinition(langPrefix
.c_str());
2886 // if there is no prefix on the target use the cmake definition
2887 if(!targetPrefix
&& prefixVar
)
2889 targetPrefix
= this->Makefile
->GetSafeDefinition(prefixVar
);
2891 // if there is no suffix on the target use the cmake definition
2892 if(!targetSuffix
&& suffixVar
)
2894 targetSuffix
= this->Makefile
->GetSafeDefinition(suffixVar
);
2897 // frameworks do not have a prefix or a suffix
2898 if(this->IsFrameworkOnApple())
2904 // Begin the final name with the prefix.
2905 outPrefix
= targetPrefix
?targetPrefix
:"";
2907 // Append the target name or property-specified name.
2908 outBase
+= this->GetOutputName(config
, implib
);
2910 // Append the per-configuration postfix.
2911 outBase
+= configPostfix
?configPostfix
:"";
2913 // Name shared libraries with their version number on some platforms.
2914 if(const char* version
= this->GetProperty("VERSION"))
2916 if(this->GetType() == cmTarget::SHARED_LIBRARY
&& !implib
&&
2917 this->Makefile
->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
2924 // Append the suffix.
2925 outSuffix
= targetSuffix
?targetSuffix
:"";
2928 //----------------------------------------------------------------------------
2929 void cmTarget::GetLibraryNames(std::string
& name
,
2930 std::string
& soName
,
2931 std::string
& realName
,
2932 std::string
& impName
,
2933 std::string
& pdbName
,
2936 // This should not be called for imported targets.
2937 // TODO: Split cmTarget into a class hierarchy to get compile-time
2938 // enforcement of the limited imported target API.
2939 if(this->IsImported())
2941 std::string msg
= "GetLibraryNames called on imported target: ";
2942 msg
+= this->GetName();
2943 this->Makefile
->IssueMessage(cmake::INTERNAL_ERROR
,
2948 // Construct the name of the soname flag variable for this language.
2949 const char* ll
= this->GetLinkerLanguage(config
);
2950 std::string sonameFlag
= "CMAKE_SHARED_LIBRARY_SONAME";
2956 sonameFlag
+= "_FLAG";
2958 // Check for library version properties.
2959 const char* version
= this->GetProperty("VERSION");
2960 const char* soversion
= this->GetProperty("SOVERSION");
2961 if((this->GetType() != cmTarget::SHARED_LIBRARY
&&
2962 this->GetType() != cmTarget::MODULE_LIBRARY
) ||
2963 !this->Makefile
->GetDefinition(sonameFlag
.c_str()) ||
2964 this->IsFrameworkOnApple())
2966 // Versioning is supported only for shared libraries and modules,
2967 // and then only when the platform supports an soname flag.
2971 if(version
&& !soversion
)
2973 // The soversion must be set if the library version is set. Use
2974 // the library version as the soversion.
2975 soversion
= version
;
2978 // Get the components of the library name.
2982 this->GetFullNameInternal(config
, false, prefix
, base
, suffix
);
2984 // The library name.
2985 name
= prefix
+base
+suffix
;
2987 // The library's soname.
2988 #if defined(__APPLE__)
2989 soName
= prefix
+base
;
2996 soName
+= soversion
;
2998 #if defined(__APPLE__)
3002 // The library's real name on disk.
3003 #if defined(__APPLE__)
3004 realName
= prefix
+base
;
3011 realName
+= version
;
3016 realName
+= soversion
;
3018 #if defined(__APPLE__)
3022 // The import library name.
3023 if(this->GetType() == cmTarget::SHARED_LIBRARY
||
3024 this->GetType() == cmTarget::MODULE_LIBRARY
)
3026 impName
= this->GetFullNameInternal(config
, true);
3033 // The program database file name.
3034 pdbName
= prefix
+base
+".pdb";
3037 //----------------------------------------------------------------------------
3038 void cmTarget::GetExecutableNames(std::string
& name
,
3039 std::string
& realName
,
3040 std::string
& impName
,
3041 std::string
& pdbName
,
3044 // This should not be called for imported targets.
3045 // TODO: Split cmTarget into a class hierarchy to get compile-time
3046 // enforcement of the limited imported target API.
3047 if(this->IsImported())
3050 "GetExecutableNames called on imported target: ";
3051 msg
+= this->GetName();
3052 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR
, msg
.c_str());
3055 // This versioning is supported only for executables and then only
3056 // when the platform supports symbolic links.
3057 #if defined(_WIN32) && !defined(__CYGWIN__)
3058 const char* version
= 0;
3060 // Check for executable version properties.
3061 const char* version
= this->GetProperty("VERSION");
3062 if(this->GetType() != cmTarget::EXECUTABLE
|| this->Makefile
->IsOn("XCODE"))
3068 // Get the components of the executable name.
3072 this->GetFullNameInternal(config
, false, prefix
, base
, suffix
);
3074 // The executable name.
3075 name
= prefix
+base
+suffix
;
3077 // The executable's real name on disk.
3078 #if defined(__CYGWIN__)
3079 realName
= prefix
+base
;
3086 realName
+= version
;
3088 #if defined(__CYGWIN__)
3092 // The import library name.
3093 impName
= this->GetFullNameInternal(config
, true);
3095 // The program database file name.
3096 pdbName
= prefix
+base
+".pdb";
3099 //----------------------------------------------------------------------------
3100 void cmTarget::GenerateTargetManifest(const char* config
)
3102 cmMakefile
* mf
= this->Makefile
;
3103 cmLocalGenerator
* lg
= mf
->GetLocalGenerator();
3104 cmGlobalGenerator
* gg
= lg
->GetGlobalGenerator();
3109 std::string realName
;
3110 std::string impName
;
3111 std::string pdbName
;
3112 if(this->GetType() == cmTarget::EXECUTABLE
)
3114 this->GetExecutableNames(name
, realName
, impName
, pdbName
, config
);
3116 else if(this->GetType() == cmTarget::STATIC_LIBRARY
||
3117 this->GetType() == cmTarget::SHARED_LIBRARY
||
3118 this->GetType() == cmTarget::MODULE_LIBRARY
)
3120 this->GetLibraryNames(name
, soName
, realName
, impName
, pdbName
, config
);
3127 // Get the directory.
3128 std::string dir
= this->GetDirectory(config
, false);
3137 gg
->AddToManifest(config
? config
:"", f
);
3144 gg
->AddToManifest(config
? config
:"", f
);
3146 if(!realName
.empty())
3151 gg
->AddToManifest(config
? config
:"", f
);
3153 if(!pdbName
.empty())
3158 gg
->AddToManifest(config
? config
:"", f
);
3160 if(!impName
.empty())
3162 f
= this->GetDirectory(config
, true);
3165 gg
->AddToManifest(config
? config
:"", f
);
3169 //----------------------------------------------------------------------------
3170 void cmTarget::SetPropertyDefault(const char* property
,
3171 const char* default_value
)
3173 // Compute the name of the variable holding the default value.
3174 std::string var
= "CMAKE_";
3177 if(const char* value
= this->Makefile
->GetDefinition(var
.c_str()))
3179 this->SetProperty(property
, value
);
3181 else if(default_value
)
3183 this->SetProperty(property
, default_value
);
3187 //----------------------------------------------------------------------------
3188 bool cmTarget::HaveBuildTreeRPATH()
3190 return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
3191 !this->LinkLibraries
.empty());
3194 //----------------------------------------------------------------------------
3195 bool cmTarget::HaveInstallTreeRPATH()
3197 const char* install_rpath
= this->GetProperty("INSTALL_RPATH");
3198 return install_rpath
&& *install_rpath
;
3201 //----------------------------------------------------------------------------
3202 bool cmTarget::NeedRelinkBeforeInstall(const char* config
)
3204 // Only executables and shared libraries can have an rpath and may
3206 if(this->TargetTypeValue
!= cmTarget::EXECUTABLE
&&
3207 this->TargetTypeValue
!= cmTarget::SHARED_LIBRARY
&&
3208 this->TargetTypeValue
!= cmTarget::MODULE_LIBRARY
)
3213 // If there is no install location this target will not be installed
3214 // and therefore does not need relinking.
3215 if(!this->GetHaveInstallRule())
3220 // If skipping all rpaths completely then no relinking is needed.
3221 if(this->Makefile
->IsOn("CMAKE_SKIP_RPATH"))
3226 // If building with the install-tree rpath no relinking is needed.
3227 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3232 // If chrpath is going to be used no relinking is needed.
3233 if(this->IsChrpathUsed(config
))
3238 // Check for rpath support on this platform.
3239 if(const char* ll
= this->GetLinkerLanguage(config
))
3241 std::string flagVar
= "CMAKE_SHARED_LIBRARY_RUNTIME_";
3244 if(!this->Makefile
->IsSet(flagVar
.c_str()))
3246 // There is no rpath support on this platform so nothing needs
3253 // No linker language is known. This error will be reported by
3258 // If either a build or install tree rpath is set then the rpath
3259 // will likely change between the build tree and install tree and
3260 // this target must be relinked.
3261 return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
3264 //----------------------------------------------------------------------------
3265 std::string
cmTarget::GetInstallNameDirForBuildTree(const char* config
,
3268 // If building directly for installation then the build tree install_name
3269 // is the same as the install tree.
3270 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3272 return GetInstallNameDirForInstallTree(config
, for_xcode
);
3275 // Use the build tree directory for the target.
3276 if(this->Makefile
->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3277 !this->Makefile
->IsOn("CMAKE_SKIP_RPATH") &&
3278 !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
3280 std::string dir
= this->GetDirectory(config
);
3282 if(this->IsFrameworkOnApple() && !for_xcode
)
3284 dir
+= this->GetFullName(config
, false);
3285 dir
+= ".framework/Versions/";
3286 dir
+= this->GetFrameworkVersion();
3297 //----------------------------------------------------------------------------
3298 std::string
cmTarget::GetInstallNameDirForInstallTree(const char* config
,
3301 // Lookup the target property.
3302 const char* install_name_dir
= this->GetProperty("INSTALL_NAME_DIR");
3303 if(this->Makefile
->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
3304 !this->Makefile
->IsOn("CMAKE_SKIP_RPATH") &&
3305 install_name_dir
&& *install_name_dir
)
3307 std::string dir
= install_name_dir
;
3309 if(this->IsFrameworkOnApple() && !for_xcode
)
3311 dir
+= this->GetFullName(config
, false);
3312 dir
+= ".framework/Versions/";
3313 dir
+= this->GetFrameworkVersion();
3324 //----------------------------------------------------------------------------
3325 const char* cmTarget::GetOutputTargetType(bool implib
)
3327 switch(this->GetType())
3329 case cmTarget::SHARED_LIBRARY
:
3330 if(this->DLLPlatform
)
3334 // A DLL import library is treated as an archive target.
3339 // A DLL shared library is treated as a runtime target.
3345 // For non-DLL platforms shared libraries are treated as
3349 case cmTarget::STATIC_LIBRARY
:
3350 // Static libraries are always treated as archive targets.
3352 case cmTarget::MODULE_LIBRARY
:
3355 // Module libraries are always treated as library targets.
3360 // Module import libraries are treated as archive targets.
3363 case cmTarget::EXECUTABLE
:
3366 // Executable import libraries are treated as archive targets.
3371 // Executables are always treated as runtime targets.
3380 //----------------------------------------------------------------------------
3381 void cmTarget::ComputeOutputDir(const char* config
,
3382 bool implib
, std::string
& out
)
3384 // Look for a target property defining the target output directory
3385 // based on the target type.
3386 const char* propertyName
= 0;
3387 std::string propertyNameStr
= this->GetOutputTargetType(implib
);
3388 if(!propertyNameStr
.empty())
3390 propertyNameStr
+= "_OUTPUT_DIRECTORY";
3391 propertyName
= propertyNameStr
.c_str();
3394 // Select an output directory.
3395 if(const char* outdir
= this->GetProperty(propertyName
))
3397 // Use the user-specified output directory.
3400 else if(this->GetType() == cmTarget::EXECUTABLE
)
3402 // Lookup the output path for executables.
3403 out
= this->Makefile
->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
3405 else if(this->GetType() == cmTarget::STATIC_LIBRARY
||
3406 this->GetType() == cmTarget::SHARED_LIBRARY
||
3407 this->GetType() == cmTarget::MODULE_LIBRARY
)
3409 // Lookup the output path for libraries.
3410 out
= this->Makefile
->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
3414 // Default to the current output directory.
3418 // Convert the output path to a full path in case it is
3419 // specified as a relative path. Treat a relative path as
3420 // relative to the current output directory for this makefile.
3421 out
= (cmSystemTools::CollapseFullPath
3422 (out
.c_str(), this->Makefile
->GetStartOutputDirectory()));
3424 // The generator may add the configuration's subdirectory.
3425 if(config
&& *config
)
3427 this->Makefile
->GetLocalGenerator()->GetGlobalGenerator()->
3428 AppendDirectoryForConfig("/", config
, "", out
);
3432 //----------------------------------------------------------------------------
3433 std::string
cmTarget::GetOutputName(const char* config
, bool implib
)
3435 std::vector
<std::string
> props
;
3436 std::string type
= this->GetOutputTargetType(implib
);
3437 std::string configUpper
= cmSystemTools::UpperCase(config
? config
: "");
3438 if(!type
.empty() && !configUpper
.empty())
3440 // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
3441 props
.push_back(type
+ "_OUTPUT_NAME_" + configUpper
);
3445 // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
3446 props
.push_back(type
+ "_OUTPUT_NAME");
3448 if(!configUpper
.empty())
3450 // OUTPUT_NAME_<CONFIG>
3451 props
.push_back("OUTPUT_NAME_" + configUpper
);
3452 // <CONFIG>_OUTPUT_NAME
3453 props
.push_back(configUpper
+ "_OUTPUT_NAME");
3456 props
.push_back("OUTPUT_NAME");
3458 for(std::vector
<std::string
>::const_iterator i
= props
.begin();
3459 i
!= props
.end(); ++i
)
3461 if(const char* outName
= this->GetProperty(i
->c_str()))
3466 return this->GetName();
3469 //----------------------------------------------------------------------------
3470 std::string
cmTarget::GetFrameworkVersion()
3472 if(const char* fversion
= this->GetProperty("FRAMEWORK_VERSION"))
3476 else if(const char* tversion
= this->GetProperty("VERSION"))
3486 //----------------------------------------------------------------------------
3487 const char* cmTarget::GetExportMacro()
3489 // Define the symbol for targets that export symbols.
3490 if(this->GetType() == cmTarget::SHARED_LIBRARY
||
3491 this->GetType() == cmTarget::MODULE_LIBRARY
||
3492 this->IsExecutableWithExports())
3494 if(const char* custom_export_name
= this->GetProperty("DEFINE_SYMBOL"))
3496 this->ExportMacro
= custom_export_name
;
3500 std::string in
= this->GetName();
3502 this->ExportMacro
= cmSystemTools::MakeCindentifier(in
.c_str());
3504 return this->ExportMacro
.c_str();
3512 //----------------------------------------------------------------------------
3513 void cmTarget::GetLanguages(std::set
<cmStdString
>& languages
) const
3515 for(std::vector
<cmSourceFile
*>::const_iterator
3516 i
= this->SourceFiles
.begin(); i
!= this->SourceFiles
.end(); ++i
)
3518 if(const char* lang
= (*i
)->GetLanguage())
3520 languages
.insert(lang
);
3525 //----------------------------------------------------------------------------
3526 bool cmTarget::IsChrpathUsed(const char* config
)
3528 #if defined(CMAKE_USE_ELF_PARSER)
3529 // Only certain target types have an rpath.
3530 if(!(this->GetType() == cmTarget::SHARED_LIBRARY
||
3531 this->GetType() == cmTarget::MODULE_LIBRARY
||
3532 this->GetType() == cmTarget::EXECUTABLE
))
3537 // If the target will not be installed we do not need to change its
3539 if(!this->GetHaveInstallRule())
3544 // Skip chrpath if skipping rpath altogether.
3545 if(this->Makefile
->IsOn("CMAKE_SKIP_RPATH"))
3550 // Skip chrpath if it does not need to be changed at install time.
3551 if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
3556 // Allow the user to disable builtin chrpath explicitly.
3557 if(this->Makefile
->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
3562 // Enable if the rpath flag uses a separator and the target uses ELF
3564 if(const char* ll
= this->GetLinkerLanguage(config
))
3566 std::string sepVar
= "CMAKE_SHARED_LIBRARY_RUNTIME_";
3568 sepVar
+= "_FLAG_SEP";
3569 const char* sep
= this->Makefile
->GetDefinition(sepVar
.c_str());
3572 // TODO: Add ELF check to ABI detection and get rid of
3573 // CMAKE_EXECUTABLE_FORMAT.
3574 if(const char* fmt
=
3575 this->Makefile
->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
3577 return strcmp(fmt
, "ELF") == 0;
3582 static_cast<void>(config
);
3586 //----------------------------------------------------------------------------
3587 cmTarget::ImportInfo
const*
3588 cmTarget::GetImportInfo(const char* config
)
3590 // There is no imported information for non-imported targets.
3591 if(!this->IsImported())
3596 // Lookup/compute/cache the import information for this
3598 std::string config_upper
;
3599 if(config
&& *config
)
3601 config_upper
= cmSystemTools::UpperCase(config
);
3605 config_upper
= "NOCONFIG";
3607 typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType
;
3608 ImportInfoMapType::const_iterator i
=
3609 this->Internal
->ImportInfoMap
.find(config_upper
);
3610 if(i
== this->Internal
->ImportInfoMap
.end())
3613 this->ComputeImportInfo(config_upper
, info
);
3614 ImportInfoMapType::value_type
entry(config_upper
, info
);
3615 i
= this->Internal
->ImportInfoMap
.insert(entry
).first
;
3618 // If the location is empty then the target is not available for
3619 // this configuration.
3620 if(i
->second
.Location
.empty() && i
->second
.ImportLibrary
.empty())
3625 // Return the import information.
3629 //----------------------------------------------------------------------------
3630 void cmTarget::ComputeImportInfo(std::string
const& desired_config
,
3633 // This method finds information about an imported target from its
3634 // properties. The "IMPORTED_" namespace is reserved for properties
3635 // defined by the project exporting the target.
3637 // Initialize members.
3638 info
.NoSOName
= false;
3640 // Track the configuration-specific property suffix.
3641 std::string suffix
= "_";
3642 suffix
+= desired_config
;
3644 // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
3645 // library or an executable with exports.
3646 bool allowImp
= this->HasImportLibrary();
3648 // Look for a mapping from the current project's configuration to
3649 // the imported project's configuration.
3650 std::vector
<std::string
> mappedConfigs
;
3652 std::string mapProp
= "MAP_IMPORTED_CONFIG_";
3653 mapProp
+= desired_config
;
3654 if(const char* mapValue
= this->GetProperty(mapProp
.c_str()))
3656 cmSystemTools::ExpandListArgument(mapValue
, mappedConfigs
);
3660 // If a mapping was found, check its configurations.
3661 const char* loc
= 0;
3662 const char* imp
= 0;
3663 for(std::vector
<std::string
>::const_iterator mci
= mappedConfigs
.begin();
3664 !loc
&& !imp
&& mci
!= mappedConfigs
.end(); ++mci
)
3666 // Look for this configuration.
3667 std::string mcUpper
= cmSystemTools::UpperCase(mci
->c_str());
3668 std::string locProp
= "IMPORTED_LOCATION_";
3670 loc
= this->GetProperty(locProp
.c_str());
3673 std::string impProp
= "IMPORTED_IMPLIB_";
3675 imp
= this->GetProperty(impProp
.c_str());
3678 // If it was found, use it for all properties below.
3686 // If we needed to find one of the mapped configurations but did not
3687 // then the target is not found. The project does not want any
3688 // other configuration.
3689 if(!mappedConfigs
.empty() && !loc
&& !imp
)
3694 // If we have not yet found it then there are no mapped
3695 // configurations. Look for an exact-match.
3698 std::string locProp
= "IMPORTED_LOCATION";
3700 loc
= this->GetProperty(locProp
.c_str());
3703 std::string impProp
= "IMPORTED_IMPLIB";
3705 imp
= this->GetProperty(impProp
.c_str());
3709 // If we have not yet found it then there are no mapped
3710 // configurations and no exact match.
3713 // The suffix computed above is not useful.
3716 // Look for a configuration-less location. This may be set by
3717 // manually-written code.
3718 loc
= this->GetProperty("IMPORTED_LOCATION");
3721 imp
= this->GetProperty("IMPORTED_IMPLIB");
3725 // If we have not yet found it then the project is willing to try
3726 // any available configuration.
3729 std::vector
<std::string
> availableConfigs
;
3730 if(const char* iconfigs
= this->GetProperty("IMPORTED_CONFIGURATIONS"))
3732 cmSystemTools::ExpandListArgument(iconfigs
, availableConfigs
);
3734 for(std::vector
<std::string
>::const_iterator
3735 aci
= availableConfigs
.begin();
3736 !loc
&& !imp
&& aci
!= availableConfigs
.end(); ++aci
)
3739 suffix
+= cmSystemTools::UpperCase(*aci
);
3740 std::string locProp
= "IMPORTED_LOCATION";
3742 loc
= this->GetProperty(locProp
.c_str());
3745 std::string impProp
= "IMPORTED_IMPLIB";
3747 imp
= this->GetProperty(impProp
.c_str());
3752 // If we have not yet found it then the target is not available.
3758 // A provided configuration has been chosen. Load the
3759 // configuration's properties.
3761 // Get the location.
3764 info
.Location
= loc
;
3768 std::string impProp
= "IMPORTED_LOCATION";
3770 if(const char* config_location
= this->GetProperty(impProp
.c_str()))
3772 info
.Location
= config_location
;
3774 else if(const char* location
= this->GetProperty("IMPORTED_LOCATION"))
3776 info
.Location
= location
;
3781 if(this->GetType() == cmTarget::SHARED_LIBRARY
)
3783 std::string soProp
= "IMPORTED_SONAME";
3785 if(const char* config_soname
= this->GetProperty(soProp
.c_str()))
3787 info
.SOName
= config_soname
;
3789 else if(const char* soname
= this->GetProperty("IMPORTED_SONAME"))
3791 info
.SOName
= soname
;
3795 // Get the "no-soname" mark.
3796 if(this->GetType() == cmTarget::SHARED_LIBRARY
)
3798 std::string soProp
= "IMPORTED_NO_SONAME";
3800 if(const char* config_no_soname
= this->GetProperty(soProp
.c_str()))
3802 info
.NoSOName
= cmSystemTools::IsOn(config_no_soname
);
3804 else if(const char* no_soname
= this->GetProperty("IMPORTED_NO_SONAME"))
3806 info
.NoSOName
= cmSystemTools::IsOn(no_soname
);
3810 // Get the import library.
3813 info
.ImportLibrary
= imp
;
3815 else if(this->GetType() == cmTarget::SHARED_LIBRARY
||
3816 this->IsExecutableWithExports())
3818 std::string impProp
= "IMPORTED_IMPLIB";
3820 if(const char* config_implib
= this->GetProperty(impProp
.c_str()))
3822 info
.ImportLibrary
= config_implib
;
3824 else if(const char* implib
= this->GetProperty("IMPORTED_IMPLIB"))
3826 info
.ImportLibrary
= implib
;
3830 // Get the link interface.
3832 std::string linkProp
= "IMPORTED_LINK_INTERFACE_LIBRARIES";
3834 if(const char* config_libs
= this->GetProperty(linkProp
.c_str()))
3836 cmSystemTools::ExpandListArgument(config_libs
,
3837 info
.LinkInterface
.Libraries
);
3839 else if(const char* libs
=
3840 this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
3842 cmSystemTools::ExpandListArgument(libs
,
3843 info
.LinkInterface
.Libraries
);
3847 // Get the link dependencies.
3849 std::string linkProp
= "IMPORTED_LINK_DEPENDENT_LIBRARIES";
3851 if(const char* config_libs
= this->GetProperty(linkProp
.c_str()))
3853 cmSystemTools::ExpandListArgument(config_libs
,
3854 info
.LinkInterface
.SharedDeps
);
3856 else if(const char* libs
=
3857 this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
3859 cmSystemTools::ExpandListArgument(libs
, info
.LinkInterface
.SharedDeps
);
3863 // Get the link languages.
3864 if(this->GetType() == cmTarget::STATIC_LIBRARY
)
3866 std::string linkProp
= "IMPORTED_LINK_INTERFACE_LANGUAGES";
3868 if(const char* config_libs
= this->GetProperty(linkProp
.c_str()))
3870 cmSystemTools::ExpandListArgument(config_libs
,
3871 info
.LinkInterface
.Languages
);
3873 else if(const char* libs
=
3874 this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
3876 cmSystemTools::ExpandListArgument(libs
,
3877 info
.LinkInterface
.Languages
);
3882 //----------------------------------------------------------------------------
3883 cmTarget::LinkInterface
const* cmTarget::GetLinkInterface(const char* config
)
3885 // Imported targets have their own link interface.
3886 if(this->IsImported())
3888 if(cmTarget::ImportInfo
const* info
= this->GetImportInfo(config
))
3890 return &info
->LinkInterface
;
3895 // Link interfaces are not supported for executables that do not
3897 if(this->GetType() == cmTarget::EXECUTABLE
&&
3898 !this->IsExecutableWithExports())
3903 // Lookup any existing link interface for this configuration.
3904 std::string key
= cmSystemTools::UpperCase(config
? config
: "");
3905 cmTargetInternals::LinkInterfaceMapType::iterator
3906 i
= this->Internal
->LinkInterfaceMap
.find(key
);
3907 if(i
== this->Internal
->LinkInterfaceMap
.end())
3909 // Compute the link interface for this configuration.
3910 cmTargetInternals::OptionalLinkInterface iface
;
3911 iface
.Exists
= this->ComputeLinkInterface(config
, iface
);
3913 // Store the information for this configuration.
3914 cmTargetInternals::LinkInterfaceMapType::value_type
entry(key
, iface
);
3915 i
= this->Internal
->LinkInterfaceMap
.insert(entry
).first
;
3918 return i
->second
.Exists
? &i
->second
: 0;
3921 //----------------------------------------------------------------------------
3922 bool cmTarget::ComputeLinkInterface(const char* config
, LinkInterface
& iface
)
3924 // Construct the property name suffix for this configuration.
3925 std::string suffix
= "_";
3926 if(config
&& *config
)
3928 suffix
+= cmSystemTools::UpperCase(config
);
3932 suffix
+= "NOCONFIG";
3935 // An explicit list of interface libraries may be set for shared
3936 // libraries and executables that export symbols.
3937 const char* explicitLibraries
= 0;
3938 if(this->GetType() == cmTarget::SHARED_LIBRARY
||
3939 this->IsExecutableWithExports())
3941 // Lookup the per-configuration property.
3942 std::string propName
= "LINK_INTERFACE_LIBRARIES";
3944 explicitLibraries
= this->GetProperty(propName
.c_str());
3946 // If not set, try the generic property.
3947 if(!explicitLibraries
)
3949 explicitLibraries
= this->GetProperty("LINK_INTERFACE_LIBRARIES");
3953 // There is no implicit link interface for executables, so if none
3954 // was explicitly set, there is no link interface.
3955 if(!explicitLibraries
&& this->GetType() == cmTarget::EXECUTABLE
)
3960 if(explicitLibraries
)
3962 // The interface libraries have been explicitly set.
3963 cmSystemTools::ExpandListArgument(explicitLibraries
, iface
.Libraries
);
3965 if(this->GetType() == cmTarget::SHARED_LIBRARY
)
3967 // Shared libraries may have runtime implementation dependencies
3968 // on other shared libraries that are not in the interface.
3969 std::set
<cmStdString
> emitted
;
3970 for(std::vector
<std::string
>::const_iterator
3971 li
= iface
.Libraries
.begin(); li
!= iface
.Libraries
.end(); ++li
)
3973 emitted
.insert(*li
);
3975 LinkImplementation
const* impl
= this->GetLinkImplementation(config
);
3976 for(std::vector
<std::string
>::const_iterator
3977 li
= impl
->Libraries
.begin(); li
!= impl
->Libraries
.end(); ++li
)
3979 if(emitted
.insert(*li
).second
)
3981 if(cmTarget
* tgt
= this->Makefile
->FindTargetToUse(li
->c_str()))
3983 // This is a runtime dependency on another shared library.
3984 if(tgt
->GetType() == cmTarget::SHARED_LIBRARY
)
3986 iface
.SharedDeps
.push_back(*li
);
3991 // TODO: Recognize shared library file names. Perhaps this
3992 // should be moved to cmComputeLinkInformation, but that creates
3993 // a chicken-and-egg problem since this list is needed for its
4002 // The link implementation is the default link interface.
4003 LinkImplementation
const* impl
= this->GetLinkImplementation(config
);
4004 iface
.Libraries
= impl
->Libraries
;
4005 iface
.WrongConfigLibraries
= impl
->WrongConfigLibraries
;
4006 if(this->GetType() == cmTarget::STATIC_LIBRARY
)
4008 // Targets using this archive need its language runtime libraries.
4009 iface
.Languages
= impl
->Languages
;
4016 //----------------------------------------------------------------------------
4017 cmTarget::LinkImplementation
const*
4018 cmTarget::GetLinkImplementation(const char* config
)
4020 // There is no link implementation for imported targets.
4021 if(this->IsImported())
4026 // Lookup any existing link implementation for this configuration.
4027 std::string key
= cmSystemTools::UpperCase(config
? config
: "");
4028 cmTargetInternals::LinkImplMapType::iterator
4029 i
= this->Internal
->LinkImplMap
.find(key
);
4030 if(i
== this->Internal
->LinkImplMap
.end())
4032 // Compute the link implementation for this configuration.
4033 LinkImplementation impl
;
4034 this->ComputeLinkImplementation(config
, impl
);
4036 // Store the information for this configuration.
4037 cmTargetInternals::LinkImplMapType::value_type
entry(key
, impl
);
4038 i
= this->Internal
->LinkImplMap
.insert(entry
).first
;
4044 //----------------------------------------------------------------------------
4045 void cmTarget::ComputeLinkImplementation(const char* config
,
4046 LinkImplementation
& impl
)
4048 // Compute which library configuration to link.
4049 cmTarget::LinkLibraryType linkType
= this->ComputeLinkType(config
);
4051 // Collect libraries directly linked in this configuration.
4052 LinkLibraryVectorType
const& llibs
= this->GetOriginalLinkLibraries();
4053 for(cmTarget::LinkLibraryVectorType::const_iterator li
= llibs
.begin();
4054 li
!= llibs
.end(); ++li
)
4056 // Skip entries that resolve to the target itself or are empty.
4057 std::string item
= this->CheckCMP0004(li
->first
);
4058 if(item
== this->GetName() || item
.empty())
4063 if(li
->second
== cmTarget::GENERAL
|| li
->second
== linkType
)
4065 // The entry is meant for this configuration.
4066 impl
.Libraries
.push_back(item
);
4070 // Support OLD behavior for CMP0003.
4071 impl
.WrongConfigLibraries
.push_back(item
);
4075 // This target needs runtime libraries for its source languages.
4076 std::set
<cmStdString
> languages
;
4077 this->GetLanguages(languages
);
4078 for(std::set
<cmStdString
>::iterator li
= languages
.begin();
4079 li
!= languages
.end(); ++li
)
4081 impl
.Languages
.push_back(*li
);
4085 //----------------------------------------------------------------------------
4086 std::string
cmTarget::CheckCMP0004(std::string
const& item
)
4088 // Strip whitespace off the library names because we used to do this
4089 // in case variables were expanded at generate time. We no longer
4090 // do the expansion but users link to libraries like " ${VAR} ".
4091 std::string lib
= item
;
4092 std::string::size_type pos
= lib
.find_first_not_of(" \t\r\n");
4095 lib
= lib
.substr(pos
, lib
.npos
);
4097 pos
= lib
.find_last_not_of(" \t\r\n");
4100 lib
= lib
.substr(0, pos
+1);
4104 cmake
* cm
= this->Makefile
->GetCMakeInstance();
4105 switch(this->PolicyStatusCMP0004
)
4107 case cmPolicies::WARN
:
4110 w
<< (this->Makefile
->GetPolicies()
4111 ->GetPolicyWarning(cmPolicies::CMP0004
)) << "\n"
4112 << "Target \"" << this->GetName() << "\" links to item \""
4113 << item
<< "\" which has leading or trailing whitespace.";
4114 cm
->IssueMessage(cmake::AUTHOR_WARNING
, w
.str(),
4115 this->GetBacktrace());
4117 case cmPolicies::OLD
:
4119 case cmPolicies::NEW
:
4122 e
<< "Target \"" << this->GetName() << "\" links to item \""
4123 << item
<< "\" which has leading or trailing whitespace. "
4124 << "This is now an error according to policy CMP0004.";
4125 cm
->IssueMessage(cmake::FATAL_ERROR
, e
.str(), this->GetBacktrace());
4128 case cmPolicies::REQUIRED_IF_USED
:
4129 case cmPolicies::REQUIRED_ALWAYS
:
4132 e
<< (this->Makefile
->GetPolicies()
4133 ->GetRequiredPolicyError(cmPolicies::CMP0004
)) << "\n"
4134 << "Target \"" << this->GetName() << "\" links to item \""
4135 << item
<< "\" which has leading or trailing whitespace.";
4136 cm
->IssueMessage(cmake::FATAL_ERROR
, e
.str(), this->GetBacktrace());
4144 //----------------------------------------------------------------------------
4145 cmComputeLinkInformation
*
4146 cmTarget::GetLinkInformation(const char* config
)
4148 // Lookup any existing information for this configuration.
4149 std::map
<cmStdString
, cmComputeLinkInformation
*>::iterator
4150 i
= this->LinkInformation
.find(config
?config
:"");
4151 if(i
== this->LinkInformation
.end())
4153 // Compute information for this configuration.
4154 cmComputeLinkInformation
* info
=
4155 new cmComputeLinkInformation(this, config
);
4156 if(!info
|| !info
->Compute())
4162 // Store the information for this configuration.
4163 std::map
<cmStdString
, cmComputeLinkInformation
*>::value_type
4164 entry(config
?config
:"", info
);
4165 i
= this->LinkInformation
.insert(entry
).first
;
4170 //----------------------------------------------------------------------------
4171 cmTargetLinkInformationMap
4172 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap
const& r
): derived()
4174 // Ideally cmTarget instances should never be copied. However until
4175 // we can make a sweep to remove that, this copy constructor avoids
4176 // allowing the resources (LinkInformation) from getting copied. In
4177 // the worst case this will lead to extra cmComputeLinkInformation
4178 // instances. We also enforce in debug mode that the map be emptied
4180 static_cast<void>(r
);
4184 //----------------------------------------------------------------------------
4185 cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
4187 for(derived::iterator i
= this->begin(); i
!= this->end(); ++i
)
4193 //----------------------------------------------------------------------------
4194 cmTargetInternalPointer::cmTargetInternalPointer()
4196 this->Pointer
= new cmTargetInternals
;
4199 //----------------------------------------------------------------------------
4200 cmTargetInternalPointer
4201 ::cmTargetInternalPointer(cmTargetInternalPointer
const&)
4203 // Ideally cmTarget instances should never be copied. However until
4204 // we can make a sweep to remove that, this copy constructor avoids
4205 // allowing the resources (Internals) to be copied.
4206 this->Pointer
= new cmTargetInternals
;
4209 //----------------------------------------------------------------------------
4210 cmTargetInternalPointer::~cmTargetInternalPointer()
4212 delete this->Pointer
;
4215 //----------------------------------------------------------------------------
4216 cmTargetInternalPointer
&
4217 cmTargetInternalPointer::operator=(cmTargetInternalPointer
const& r
)
4219 if(this == &r
) { return *this; } // avoid warning on HP about self check
4220 // Ideally cmTarget instances should never be copied. However until
4221 // we can make a sweep to remove that, this copy constructor avoids
4222 // allowing the resources (Internals) to be copied.
4223 cmTargetInternals
* oldPointer
= this->Pointer
;
4224 this->Pointer
= new cmTargetInternals
;