cmTargetLinkLibrariesCommand.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmTargetLinkLibrariesCommand_h
  11. #define cmTargetLinkLibrariesCommand_h
  12. #include "cmCommand.h"
  13. /** \class cmTargetLinkLibrariesCommand
  14. * \brief Specify a list of libraries to link into executables.
  15. *
  16. * cmTargetLinkLibrariesCommand is used to specify a list of libraries to link
  17. * into executable(s) or shared objects. The names of the libraries
  18. * should be those defined by the LIBRARY(library) command(s).
  19. */
  20. class cmTargetLinkLibrariesCommand : public cmCommand
  21. {
  22. public:
  23. /**
  24. * This is a virtual constructor for the command.
  25. */
  26. virtual cmCommand* Clone()
  27. {
  28. return new cmTargetLinkLibrariesCommand;
  29. }
  30. /**
  31. * This is called when the command is first encountered in
  32. * the CMakeLists.txt file.
  33. */
  34. virtual bool InitialPass(std::vector<std::string> const& args,
  35. cmExecutionStatus &status);
  36. /**
  37. * The name of the command as specified in CMakeList.txt.
  38. */
  39. virtual const char* GetName() { return "target_link_libraries";}
  40. /**
  41. * Succinct documentation.
  42. */
  43. virtual const char* GetTerseDocumentation()
  44. {
  45. return
  46. "Link a target to given libraries.";
  47. }
  48. /**
  49. * More documentation.
  50. */
  51. virtual const char* GetFullDocumentation()
  52. {
  53. return
  54. " target_link_libraries(<target> [item1 [item2 [...]]]\n"
  55. " [[debug|optimized|general] <item>] ...)\n"
  56. "Specify libraries or flags to use when linking a given target. "
  57. "The named <target> must have been created in the current directory "
  58. "by a command such as add_executable or add_library. "
  59. "The remaining arguments specify library names or flags."
  60. "\n"
  61. "If a library name matches that of another target in the project "
  62. "a dependency will automatically be added in the build system to make "
  63. "sure the library being linked is up-to-date before the target links. "
  64. "Item names starting with '-', but not '-l' or '-framework', are "
  65. "treated as linker flags."
  66. "\n"
  67. "A \"debug\", \"optimized\", or \"general\" keyword indicates that "
  68. "the library immediately following it is to be used only for the "
  69. "corresponding build configuration. "
  70. "The \"debug\" keyword corresponds to the Debug configuration "
  71. "(or to configurations named in the DEBUG_CONFIGURATIONS global "
  72. "property if it is set). "
  73. "The \"optimized\" keyword corresponds to all other configurations. "
  74. "The \"general\" keyword corresponds to all configurations, and is "
  75. "purely optional (assumed if omitted). "
  76. "Higher granularity may be achieved for per-configuration rules "
  77. "by creating and linking to IMPORTED library targets. "
  78. "See the IMPORTED mode of the add_library command for more "
  79. "information. "
  80. "\n"
  81. "Library dependencies are transitive by default. "
  82. "When this target is linked into another target then the libraries "
  83. "linked to this target will appear on the link line for the other "
  84. "target too. "
  85. "See the LINK_INTERFACE_LIBRARIES target property to override the "
  86. "set of transitive link dependencies for a target."
  87. "\n"
  88. " target_link_libraries(<target> LINK_INTERFACE_LIBRARIES\n"
  89. " [[debug|optimized|general] <lib>] ...)\n"
  90. "The LINK_INTERFACE_LIBRARIES mode appends the libraries "
  91. "to the LINK_INTERFACE_LIBRARIES and its per-configuration equivalent "
  92. "target properties instead of using them for linking. "
  93. "Libraries specified as \"debug\" are appended to the "
  94. "the LINK_INTERFACE_LIBRARIES_DEBUG property (or to the properties "
  95. "corresponding to configurations listed in the DEBUG_CONFIGURATIONS "
  96. "global property if it is set). "
  97. "Libraries specified as \"optimized\" are appended to the "
  98. "the LINK_INTERFACE_LIBRARIES property. "
  99. "Libraries specified as \"general\" (or without any keyword) are "
  100. "treated as if specified for both \"debug\" and \"optimized\"."
  101. "\n"
  102. "The library dependency graph is normally acyclic (a DAG), but in the "
  103. "case of mutually-dependent STATIC libraries CMake allows the graph "
  104. "to contain cycles (strongly connected components). "
  105. "When another target links to one of the libraries CMake repeats "
  106. "the entire connected component. "
  107. "For example, the code\n"
  108. " add_library(A STATIC a.c)\n"
  109. " add_library(B STATIC b.c)\n"
  110. " target_link_libraries(A B)\n"
  111. " target_link_libraries(B A)\n"
  112. " add_executable(main main.c)\n"
  113. " target_link_libraries(main A)\n"
  114. "links 'main' to 'A B A B'. "
  115. "("
  116. "While one repetition is usually sufficient, pathological object "
  117. "file and symbol arrangements can require more. "
  118. "One may handle such cases by manually repeating the component in "
  119. "the last target_link_libraries call. "
  120. "However, if two archives are really so interdependent they should "
  121. "probably be combined into a single archive."
  122. ")"
  123. ;
  124. }
  125. cmTypeMacro(cmTargetLinkLibrariesCommand, cmCommand);
  126. private:
  127. void LinkLibraryTypeSpecifierWarning(int left, int right);
  128. static const char* LinkLibraryTypeNames[3];
  129. cmTarget* Target;
  130. bool DoingInterface;
  131. void HandleLibrary(const char* lib, cmTarget::LinkLibraryType llt);
  132. };
  133. #endif