cmTargetLinkLibrariesCommand.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmTargetLinkLibrariesCommand_h
  14. #define cmTargetLinkLibrariesCommand_h
  15. #include "cmCommand.h"
  16. /** \class cmTargetLinkLibrariesCommand
  17. * \brief Specify a list of libraries to link into executables.
  18. *
  19. * cmTargetLinkLibrariesCommand is used to specify a list of libraries to link
  20. * into executable(s) or shared objects. The names of the libraries
  21. * should be those defined by the LIBRARY(library) command(s).
  22. */
  23. class cmTargetLinkLibrariesCommand : public cmCommand
  24. {
  25. public:
  26. /**
  27. * This is a virtual constructor for the command.
  28. */
  29. virtual cmCommand* Clone()
  30. {
  31. return new cmTargetLinkLibrariesCommand;
  32. }
  33. /**
  34. * This is called when the command is first encountered in
  35. * the CMakeLists.txt file.
  36. */
  37. virtual bool InitialPass(std::vector<std::string> const& args,
  38. cmExecutionStatus &status);
  39. /**
  40. * The name of the command as specified in CMakeList.txt.
  41. */
  42. virtual const char* GetName() { return "target_link_libraries";}
  43. /**
  44. * Succinct documentation.
  45. */
  46. virtual const char* GetTerseDocumentation()
  47. {
  48. return
  49. "Link a target to given libraries.";
  50. }
  51. /**
  52. * More documentation.
  53. */
  54. virtual const char* GetFullDocumentation()
  55. {
  56. return
  57. " target_link_libraries(<target> [item1 [item2 [...]]]\n"
  58. " [[debug|optimized|general] <item>] ...)\n"
  59. "Specify libraries or flags to use when linking a given target. "
  60. "If a library name matches that of another target in the project "
  61. "a dependency will automatically be added in the build system to make "
  62. "sure the library being linked is up-to-date before the target links. "
  63. "Item names starting with '-', but not '-l' or '-framework', are "
  64. "treated as linker flags."
  65. "\n"
  66. "A \"debug\", \"optimized\", or \"general\" keyword indicates that "
  67. "the library immediately following it is to be used only for the "
  68. "corresponding build configuration. "
  69. "The \"debug\" keyword corresponds to the Debug configuration "
  70. "(or to configurations named in the DEBUG_CONFIGURATIONS global "
  71. "property if it is set). "
  72. "The \"optimized\" keyword corresponds to all other configurations. "
  73. "The \"general\" keyword corresponds to all configurations, and is "
  74. "purely optional (assumed if omitted). "
  75. "Higher granularity may be achieved for per-configuration rules "
  76. "by creating and linking to IMPORTED library targets. "
  77. "See the IMPORTED mode of the add_library command for more "
  78. "information. "
  79. "\n"
  80. "Library dependencies are transitive by default. "
  81. "When this target is linked into another target then the libraries "
  82. "linked to this target will appear on the link line for the other "
  83. "target too. "
  84. "See the LINK_INTERFACE_LIBRARIES target property to override the "
  85. "set of transitive link dependencies for a target."
  86. "\n"
  87. " target_link_libraries(<target> LINK_INTERFACE_LIBRARIES\n"
  88. " [[debug|optimized|general] <lib>] ...)\n"
  89. "The LINK_INTERFACE_LIBRARIES mode appends the libraries "
  90. "to the LINK_INTERFACE_LIBRARIES and its per-configuration equivalent "
  91. "target properties instead of using them for linking. "
  92. "Libraries specified as \"debug\" are appended to the "
  93. "the LINK_INTERFACE_LIBRARIES_DEBUG property (or to the properties "
  94. "corresponding to configurations listed in the DEBUG_CONFIGURATIONS "
  95. "global property if it is set). "
  96. "Libraries specified as \"optimized\" are appended to the "
  97. "the LINK_INTERFACE_LIBRARIES property. "
  98. "Libraries specified as \"general\" (or without any keyword) are "
  99. "treated as if specified for both \"debug\" and \"optimized\"."
  100. ;
  101. }
  102. cmTypeMacro(cmTargetLinkLibrariesCommand, cmCommand);
  103. private:
  104. void LinkLibraryTypeSpecifierWarning(int left, int right);
  105. static const char* LinkLibraryTypeNames[3];
  106. cmTarget* Target;
  107. bool DoingInterface;
  108. void HandleLibrary(const char* lib, cmTarget::LinkLibraryType llt);
  109. };
  110. #endif