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