| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| |
| |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| |
| <title>target_link_libraries — CMake 3.8.2 Documentation</title> |
| |
| |
| <link rel="stylesheet" href="../_static/cmake.css" type="text/css" /> |
| <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
| |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT: '../', |
| VERSION: '3.8.2', |
| COLLAPSE_INDEX: false, |
| FILE_SUFFIX: '.html', |
| HAS_SOURCE: true, |
| SOURCELINK_SUFFIX: '.txt' |
| }; |
| </script> |
| <script type="text/javascript" src="../_static/jquery.js"></script> |
| <script type="text/javascript" src="../_static/underscore.js"></script> |
| <script type="text/javascript" src="../_static/doctools.js"></script> |
| <link rel="shortcut icon" href="../_static/cmake-favicon.ico"/> |
| <link rel="index" title="Index" href="../genindex.html" /> |
| <link rel="search" title="Search" href="../search.html" /> |
| <link rel="next" title="target_sources" href="target_sources.html" /> |
| <link rel="prev" title="target_include_directories" href="target_include_directories.html" /> |
| </head> |
| <body role="document"> |
| <div class="related" role="navigation" aria-label="related navigation"> |
| <h3>Navigation</h3> |
| <ul> |
| <li class="right" style="margin-right: 10px"> |
| <a href="../genindex.html" title="General Index" |
| accesskey="I">index</a></li> |
| <li class="right" > |
| <a href="target_sources.html" title="target_sources" |
| accesskey="N">next</a> |</li> |
| <li class="right" > |
| <a href="target_include_directories.html" title="target_include_directories" |
| accesskey="P">previous</a> |</li> |
| <li> |
| <img src="../_static/cmake-logo-16.png" alt="" |
| style="vertical-align: middle; margin-top: -2px" /> |
| </li> |
| <li> |
| <a href="https://cmake.org/">CMake</a> » |
| </li> |
| <li> |
| <a href="../index.html">3.8.2 Documentation</a> » |
| </li> |
| |
| <li class="nav-item nav-item-1"><a href="../manual/cmake-commands.7.html" accesskey="U">cmake-commands(7)</a> »</li> |
| </ul> |
| </div> |
| |
| <div class="document"> |
| <div class="documentwrapper"> |
| <div class="bodywrapper"> |
| <div class="body" role="main"> |
| |
| <div class="section" id="target-link-libraries"> |
| <span id="command:target_link_libraries"></span><h1><a class="toc-backref" href="#id1">target_link_libraries</a><a class="headerlink" href="#target-link-libraries" title="Permalink to this headline">¶</a></h1> |
| <div class="contents topic" id="contents"> |
| <p class="topic-title first">Contents</p> |
| <ul class="simple"> |
| <li><a class="reference internal" href="#target-link-libraries" id="id1">target_link_libraries</a><ul> |
| <li><a class="reference internal" href="#overview" id="id2">Overview</a></li> |
| <li><a class="reference internal" href="#libraries-for-a-target-and-or-its-dependents" id="id3">Libraries for a Target and/or its Dependents</a></li> |
| <li><a class="reference internal" href="#libraries-for-both-a-target-and-its-dependents" id="id4">Libraries for both a Target and its Dependents</a></li> |
| <li><a class="reference internal" href="#libraries-for-a-target-and-or-its-dependents-legacy" id="id5">Libraries for a Target and/or its Dependents (Legacy)</a></li> |
| <li><a class="reference internal" href="#libraries-for-dependents-only-legacy" id="id6">Libraries for Dependents Only (Legacy)</a></li> |
| <li><a class="reference internal" href="#cyclic-dependencies-of-static-libraries" id="id7">Cyclic Dependencies of Static Libraries</a></li> |
| <li><a class="reference internal" href="#creating-relocatable-packages" id="id8">Creating Relocatable Packages</a></li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <p>Specify libraries or flags to use when linking a given target and/or |
| its dependents. <a class="reference internal" href="../manual/cmake-buildsystem.7.html#target-usage-requirements"><span class="std std-ref">Usage requirements</span></a> |
| from linked library targets will be propagated. Usage requirements |
| of a target’s dependencies affect compilation of its own sources.</p> |
| <div class="section" id="overview"> |
| <h2><a class="toc-backref" href="#id2">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2> |
| <p>This command has several signatures as detailed in subsections below. |
| All of them have the general form:</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">target_link_libraries</span><span class="p">(</span><span class="o"><</span><span class="n">target</span><span class="o">></span> <span class="o">...</span> <span class="o"><</span><span class="n">item</span><span class="o">>...</span> <span class="o">...</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>The named <code class="docutils literal"><span class="pre"><target></span></code> must have been created in the current directory by |
| a command such as <span class="target" id="index-0-command:add_executable"></span><a class="reference internal" href="add_executable.html#command:add_executable" title="add_executable"><code class="xref cmake cmake-command docutils literal"><span class="pre">add_executable()</span></code></a> or <span class="target" id="index-0-command:add_library"></span><a class="reference internal" href="add_library.html#command:add_library" title="add_library"><code class="xref cmake cmake-command docutils literal"><span class="pre">add_library()</span></code></a>. |
| Repeated calls for the same <code class="docutils literal"><span class="pre"><target></span></code> append items in the order called. |
| Each <code class="docutils literal"><span class="pre"><item></span></code> may be:</p> |
| <ul> |
| <li><p class="first"><strong>A library target name</strong>: The generated link line will have the |
| full path to the linkable library file associated with the target. |
| The buildsystem will have a dependency to re-link <code class="docutils literal"><span class="pre"><target></span></code> if |
| the library file changes.</p> |
| <p>The named target must be created by <span class="target" id="index-1-command:add_library"></span><a class="reference internal" href="add_library.html#command:add_library" title="add_library"><code class="xref cmake cmake-command docutils literal"><span class="pre">add_library()</span></code></a> within |
| the project or as an <a class="reference internal" href="../manual/cmake-buildsystem.7.html#imported-targets"><span class="std std-ref">IMPORTED library</span></a>. |
| If it is created within the project an ordering dependency will |
| automatically be added in the build system to make sure the named |
| library target is up-to-date before the <code class="docutils literal"><span class="pre"><target></span></code> links.</p> |
| <p>If an imported library has the <span class="target" id="index-0-prop_tgt:IMPORTED_NO_SONAME"></span><a class="reference internal" href="../prop_tgt/IMPORTED_NO_SONAME.html#prop_tgt:IMPORTED_NO_SONAME" title="IMPORTED_NO_SONAME"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">IMPORTED_NO_SONAME</span></code></a> |
| target property set, CMake may ask the linker to search for |
| the library instead of using the full path |
| (e.g. <code class="docutils literal"><span class="pre">/usr/lib/libfoo.so</span></code> becomes <code class="docutils literal"><span class="pre">-lfoo</span></code>).</p> |
| </li> |
| <li><p class="first"><strong>A full path to a library file</strong>: The generated link line will |
| normally preserve the full path to the file. The buildsystem will |
| have a dependency to re-link <code class="docutils literal"><span class="pre"><target></span></code> if the library file changes.</p> |
| <p>There are some cases where CMake may ask the linker to search for |
| the library (e.g. <code class="docutils literal"><span class="pre">/usr/lib/libfoo.so</span></code> becomes <code class="docutils literal"><span class="pre">-lfoo</span></code>), such |
| as when a shared library is detected to have no <code class="docutils literal"><span class="pre">SONAME</span></code> field. |
| See policy <span class="target" id="index-0-policy:CMP0060"></span><a class="reference internal" href="../policy/CMP0060.html#policy:CMP0060" title="CMP0060"><code class="xref cmake cmake-policy docutils literal"><span class="pre">CMP0060</span></code></a> for discussion of another case.</p> |
| <p>If the library file is in a Mac OSX framework, the <code class="docutils literal"><span class="pre">Headers</span></code> directory |
| of the framework will also be processed as a |
| <a class="reference internal" href="../manual/cmake-buildsystem.7.html#target-usage-requirements"><span class="std std-ref">usage requirement</span></a>. This has the same |
| effect as passing the framework directory as an include directory.</p> |
| <p>On <a class="reference internal" href="../manual/cmake-generators.7.html#visual-studio-generators"><span class="std std-ref">Visual Studio Generators</span></a> for VS 2010 and above, library files |
| ending in <code class="docutils literal"><span class="pre">.targets</span></code> will be treated as MSBuild targets files and |
| imported into generated project files. This is not supported by other |
| generators.</p> |
| </li> |
| <li><p class="first"><strong>A plain library name</strong>: The generated link line will ask the linker |
| to search for the library (e.g. <code class="docutils literal"><span class="pre">foo</span></code> becomes <code class="docutils literal"><span class="pre">-lfoo</span></code> or <code class="docutils literal"><span class="pre">foo.lib</span></code>).</p> |
| </li> |
| <li><p class="first"><strong>A link flag</strong>: Item names starting with <code class="docutils literal"><span class="pre">-</span></code>, but not <code class="docutils literal"><span class="pre">-l</span></code> or |
| <code class="docutils literal"><span class="pre">-framework</span></code>, are treated as linker flags. Note that such flags will |
| be treated like any other library link item for purposes of transitive |
| dependencies, so they are generally safe to specify only as private link |
| items that will not propagate to dependents.</p> |
| <p>Link flags specified here are inserted into the link command in the same |
| place as the link libraries. This might not be correct, depending on |
| the linker. Use the <span class="target" id="index-0-prop_tgt:LINK_FLAGS"></span><a class="reference internal" href="../prop_tgt/LINK_FLAGS.html#prop_tgt:LINK_FLAGS" title="LINK_FLAGS"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">LINK_FLAGS</span></code></a> target property to add link |
| flags explicitly. The flags will then be placed at the toolchain-defined |
| flag position in the link command.</p> |
| </li> |
| <li><p class="first">A <code class="docutils literal"><span class="pre">debug</span></code>, <code class="docutils literal"><span class="pre">optimized</span></code>, or <code class="docutils literal"><span class="pre">general</span></code> keyword immediately followed |
| by another <code class="docutils literal"><span class="pre"><item></span></code>. The item following such a keyword will be used |
| only for the corresponding build configuration. The <code class="docutils literal"><span class="pre">debug</span></code> keyword |
| corresponds to the <code class="docutils literal"><span class="pre">Debug</span></code> configuration (or to configurations named |
| in the <span class="target" id="index-0-prop_gbl:DEBUG_CONFIGURATIONS"></span><a class="reference internal" href="../prop_gbl/DEBUG_CONFIGURATIONS.html#prop_gbl:DEBUG_CONFIGURATIONS" title="DEBUG_CONFIGURATIONS"><code class="xref cmake cmake-prop_gbl docutils literal"><span class="pre">DEBUG_CONFIGURATIONS</span></code></a> global property if it is set). |
| The <code class="docutils literal"><span class="pre">optimized</span></code> keyword corresponds to all other configurations. The |
| <code class="docutils literal"><span class="pre">general</span></code> keyword corresponds to all configurations, and is purely |
| optional. Higher granularity may be achieved for per-configuration |
| rules by creating and linking to |
| <a class="reference internal" href="../manual/cmake-buildsystem.7.html#imported-targets"><span class="std std-ref">IMPORTED library targets</span></a>.</p> |
| </li> |
| </ul> |
| <p>Items containing <code class="docutils literal"><span class="pre">::</span></code>, such as <code class="docutils literal"><span class="pre">Foo::Bar</span></code>, are assumed to be |
| <a class="reference internal" href="../manual/cmake-buildsystem.7.html#imported-targets"><span class="std std-ref">IMPORTED</span></a> or <a class="reference internal" href="../manual/cmake-buildsystem.7.html#alias-targets"><span class="std std-ref">ALIAS</span></a> library |
| target names and will cause an error if no such target exists. |
| See policy <span class="target" id="index-0-policy:CMP0028"></span><a class="reference internal" href="../policy/CMP0028.html#policy:CMP0028" title="CMP0028"><code class="xref cmake cmake-policy docutils literal"><span class="pre">CMP0028</span></code></a>.</p> |
| <p>Arguments to <code class="docutils literal"><span class="pre">target_link_libraries</span></code> may use “generator expressions” |
| with the syntax <code class="docutils literal"><span class="pre">$<...></span></code>. Note however, that generator expressions |
| will not be used in OLD handling of <span class="target" id="index-0-policy:CMP0003"></span><a class="reference internal" href="../policy/CMP0003.html#policy:CMP0003" title="CMP0003"><code class="xref cmake cmake-policy docutils literal"><span class="pre">CMP0003</span></code></a> or <span class="target" id="index-0-policy:CMP0004"></span><a class="reference internal" href="../policy/CMP0004.html#policy:CMP0004" title="CMP0004"><code class="xref cmake cmake-policy docutils literal"><span class="pre">CMP0004</span></code></a>. |
| See the <span class="target" id="index-0-manual:cmake-generator-expressions(7)"></span><a class="reference internal" href="../manual/cmake-generator-expressions.7.html#manual:cmake-generator-expressions(7)" title="cmake-generator-expressions(7)"><code class="xref cmake cmake-manual docutils literal"><span class="pre">cmake-generator-expressions(7)</span></code></a> manual for available |
| expressions. See the <span class="target" id="index-0-manual:cmake-buildsystem(7)"></span><a class="reference internal" href="../manual/cmake-buildsystem.7.html#manual:cmake-buildsystem(7)" title="cmake-buildsystem(7)"><code class="xref cmake cmake-manual docutils literal"><span class="pre">cmake-buildsystem(7)</span></code></a> manual for more on |
| defining buildsystem properties.</p> |
| </div> |
| <div class="section" id="libraries-for-a-target-and-or-its-dependents"> |
| <h2><a class="toc-backref" href="#id3">Libraries for a Target and/or its Dependents</a><a class="headerlink" href="#libraries-for-a-target-and-or-its-dependents" title="Permalink to this headline">¶</a></h2> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">target_link_libraries</span><span class="p">(</span><span class="o"><</span><span class="n">target</span><span class="o">></span> |
| <span class="o"><</span><span class="n">PRIVATE</span><span class="o">|</span><span class="n">PUBLIC</span><span class="o">|</span><span class="n">INTERFACE</span><span class="o">></span> <span class="o"><</span><span class="n">item</span><span class="o">>...</span> |
| <span class="p">[</span><span class="o"><</span><span class="n">PRIVATE</span><span class="o">|</span><span class="n">PUBLIC</span><span class="o">|</span><span class="n">INTERFACE</span><span class="o">></span> <span class="o"><</span><span class="n">item</span><span class="o">>...</span><span class="p">]</span><span class="o">...</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>The <code class="docutils literal"><span class="pre">PUBLIC</span></code>, <code class="docutils literal"><span class="pre">PRIVATE</span></code> and <code class="docutils literal"><span class="pre">INTERFACE</span></code> keywords can be used to |
| specify both the link dependencies and the link interface in one command. |
| Libraries and targets following <code class="docutils literal"><span class="pre">PUBLIC</span></code> are linked to, and are made |
| part of the link interface. Libraries and targets following <code class="docutils literal"><span class="pre">PRIVATE</span></code> |
| are linked to, but are not made part of the link interface. Libraries |
| following <code class="docutils literal"><span class="pre">INTERFACE</span></code> are appended to the link interface and are not |
| used for linking <code class="docutils literal"><span class="pre"><target></span></code>.</p> |
| </div> |
| <div class="section" id="libraries-for-both-a-target-and-its-dependents"> |
| <h2><a class="toc-backref" href="#id4">Libraries for both a Target and its Dependents</a><a class="headerlink" href="#libraries-for-both-a-target-and-its-dependents" title="Permalink to this headline">¶</a></h2> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">target_link_libraries</span><span class="p">(</span><span class="o"><</span><span class="n">target</span><span class="o">></span> <span class="o"><</span><span class="n">item</span><span class="o">>...</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>Library dependencies are transitive by default with this signature. |
| When this target is linked into another target then the libraries |
| linked to this target will appear on the link line for the other |
| target too. This transitive “link interface” is stored in the |
| <span class="target" id="index-0-prop_tgt:INTERFACE_LINK_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/INTERFACE_LINK_LIBRARIES.html#prop_tgt:INTERFACE_LINK_LIBRARIES" title="INTERFACE_LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">INTERFACE_LINK_LIBRARIES</span></code></a> target property and may be overridden |
| by setting the property directly. When <span class="target" id="index-0-policy:CMP0022"></span><a class="reference internal" href="../policy/CMP0022.html#policy:CMP0022" title="CMP0022"><code class="xref cmake cmake-policy docutils literal"><span class="pre">CMP0022</span></code></a> is not set to |
| <code class="docutils literal"><span class="pre">NEW</span></code>, transitive linking is built in but may be overridden by the |
| <span class="target" id="index-0-prop_tgt:LINK_INTERFACE_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/LINK_INTERFACE_LIBRARIES.html#prop_tgt:LINK_INTERFACE_LIBRARIES" title="LINK_INTERFACE_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">LINK_INTERFACE_LIBRARIES</span></code></a> property. Calls to other signatures |
| of this command may set the property making any libraries linked |
| exclusively by this signature private.</p> |
| </div> |
| <div class="section" id="libraries-for-a-target-and-or-its-dependents-legacy"> |
| <h2><a class="toc-backref" href="#id5">Libraries for a Target and/or its Dependents (Legacy)</a><a class="headerlink" href="#libraries-for-a-target-and-or-its-dependents-legacy" title="Permalink to this headline">¶</a></h2> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">target_link_libraries</span><span class="p">(</span><span class="o"><</span><span class="n">target</span><span class="o">></span> |
| <span class="o"><</span><span class="n">LINK_PRIVATE</span><span class="o">|</span><span class="n">LINK_PUBLIC</span><span class="o">></span> <span class="o"><</span><span class="n">lib</span><span class="o">>...</span> |
| <span class="p">[</span><span class="o"><</span><span class="n">LINK_PRIVATE</span><span class="o">|</span><span class="n">LINK_PUBLIC</span><span class="o">></span> <span class="o"><</span><span class="n">lib</span><span class="o">>...</span><span class="p">]</span><span class="o">...</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>The <code class="docutils literal"><span class="pre">LINK_PUBLIC</span></code> and <code class="docutils literal"><span class="pre">LINK_PRIVATE</span></code> modes can be used to specify both |
| the link dependencies and the link interface in one command.</p> |
| <p>This signature is for compatibility only. Prefer the <code class="docutils literal"><span class="pre">PUBLIC</span></code> or |
| <code class="docutils literal"><span class="pre">PRIVATE</span></code> keywords instead.</p> |
| <p>Libraries and targets following <code class="docutils literal"><span class="pre">LINK_PUBLIC</span></code> are linked to, and are |
| made part of the <span class="target" id="index-1-prop_tgt:INTERFACE_LINK_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/INTERFACE_LINK_LIBRARIES.html#prop_tgt:INTERFACE_LINK_LIBRARIES" title="INTERFACE_LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">INTERFACE_LINK_LIBRARIES</span></code></a>. If policy |
| <span class="target" id="index-1-policy:CMP0022"></span><a class="reference internal" href="../policy/CMP0022.html#policy:CMP0022" title="CMP0022"><code class="xref cmake cmake-policy docutils literal"><span class="pre">CMP0022</span></code></a> is not <code class="docutils literal"><span class="pre">NEW</span></code>, they are also made part of the |
| <span class="target" id="index-1-prop_tgt:LINK_INTERFACE_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/LINK_INTERFACE_LIBRARIES.html#prop_tgt:LINK_INTERFACE_LIBRARIES" title="LINK_INTERFACE_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">LINK_INTERFACE_LIBRARIES</span></code></a>. Libraries and targets following |
| <code class="docutils literal"><span class="pre">LINK_PRIVATE</span></code> are linked to, but are not made part of the |
| <span class="target" id="index-2-prop_tgt:INTERFACE_LINK_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/INTERFACE_LINK_LIBRARIES.html#prop_tgt:INTERFACE_LINK_LIBRARIES" title="INTERFACE_LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">INTERFACE_LINK_LIBRARIES</span></code></a> (or <span class="target" id="index-2-prop_tgt:LINK_INTERFACE_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/LINK_INTERFACE_LIBRARIES.html#prop_tgt:LINK_INTERFACE_LIBRARIES" title="LINK_INTERFACE_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">LINK_INTERFACE_LIBRARIES</span></code></a>).</p> |
| </div> |
| <div class="section" id="libraries-for-dependents-only-legacy"> |
| <h2><a class="toc-backref" href="#id6">Libraries for Dependents Only (Legacy)</a><a class="headerlink" href="#libraries-for-dependents-only-legacy" title="Permalink to this headline">¶</a></h2> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">target_link_libraries</span><span class="p">(</span><span class="o"><</span><span class="n">target</span><span class="o">></span> <span class="n">LINK_INTERFACE_LIBRARIES</span> <span class="o"><</span><span class="n">item</span><span class="o">>...</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>The <code class="docutils literal"><span class="pre">LINK_INTERFACE_LIBRARIES</span></code> mode appends the libraries to the |
| <span class="target" id="index-3-prop_tgt:INTERFACE_LINK_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/INTERFACE_LINK_LIBRARIES.html#prop_tgt:INTERFACE_LINK_LIBRARIES" title="INTERFACE_LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">INTERFACE_LINK_LIBRARIES</span></code></a> target property instead of using them |
| for linking. If policy <span class="target" id="index-2-policy:CMP0022"></span><a class="reference internal" href="../policy/CMP0022.html#policy:CMP0022" title="CMP0022"><code class="xref cmake cmake-policy docutils literal"><span class="pre">CMP0022</span></code></a> is not <code class="docutils literal"><span class="pre">NEW</span></code>, then this mode |
| also appends libraries to the <span class="target" id="index-3-prop_tgt:LINK_INTERFACE_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/LINK_INTERFACE_LIBRARIES.html#prop_tgt:LINK_INTERFACE_LIBRARIES" title="LINK_INTERFACE_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">LINK_INTERFACE_LIBRARIES</span></code></a> and its |
| per-configuration equivalent.</p> |
| <p>This signature is for compatibility only. Prefer the <code class="docutils literal"><span class="pre">INTERFACE</span></code> mode |
| instead.</p> |
| <p>Libraries specified as <code class="docutils literal"><span class="pre">debug</span></code> are wrapped in a generator expression to |
| correspond to debug builds. If policy <span class="target" id="index-3-policy:CMP0022"></span><a class="reference internal" href="../policy/CMP0022.html#policy:CMP0022" title="CMP0022"><code class="xref cmake cmake-policy docutils literal"><span class="pre">CMP0022</span></code></a> is |
| not <code class="docutils literal"><span class="pre">NEW</span></code>, the libraries are also appended to the |
| <span class="target" id="index-0-prop_tgt:LINK_INTERFACE_LIBRARIES_<CONFIG>"></span><a class="reference internal" href="../prop_tgt/LINK_INTERFACE_LIBRARIES_CONFIG.html#prop_tgt:LINK_INTERFACE_LIBRARIES_<CONFIG>" title="LINK_INTERFACE_LIBRARIES_<CONFIG>"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">LINK_INTERFACE_LIBRARIES_DEBUG</span></code></a> |
| property (or to the properties corresponding to configurations listed in |
| the <span class="target" id="index-1-prop_gbl:DEBUG_CONFIGURATIONS"></span><a class="reference internal" href="../prop_gbl/DEBUG_CONFIGURATIONS.html#prop_gbl:DEBUG_CONFIGURATIONS" title="DEBUG_CONFIGURATIONS"><code class="xref cmake cmake-prop_gbl docutils literal"><span class="pre">DEBUG_CONFIGURATIONS</span></code></a> global property if it is set). |
| Libraries specified as <code class="docutils literal"><span class="pre">optimized</span></code> are appended to the |
| <span class="target" id="index-4-prop_tgt:INTERFACE_LINK_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/INTERFACE_LINK_LIBRARIES.html#prop_tgt:INTERFACE_LINK_LIBRARIES" title="INTERFACE_LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">INTERFACE_LINK_LIBRARIES</span></code></a> property. If policy <span class="target" id="index-4-policy:CMP0022"></span><a class="reference internal" href="../policy/CMP0022.html#policy:CMP0022" title="CMP0022"><code class="xref cmake cmake-policy docutils literal"><span class="pre">CMP0022</span></code></a> |
| is not <code class="docutils literal"><span class="pre">NEW</span></code>, they are also appended to the |
| <span class="target" id="index-4-prop_tgt:LINK_INTERFACE_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/LINK_INTERFACE_LIBRARIES.html#prop_tgt:LINK_INTERFACE_LIBRARIES" title="LINK_INTERFACE_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">LINK_INTERFACE_LIBRARIES</span></code></a> property. Libraries specified as |
| <code class="docutils literal"><span class="pre">general</span></code> (or without any keyword) are treated as if specified for both |
| <code class="docutils literal"><span class="pre">debug</span></code> and <code class="docutils literal"><span class="pre">optimized</span></code>.</p> |
| </div> |
| <div class="section" id="cyclic-dependencies-of-static-libraries"> |
| <h2><a class="toc-backref" href="#id7">Cyclic Dependencies of Static Libraries</a><a class="headerlink" href="#cyclic-dependencies-of-static-libraries" title="Permalink to this headline">¶</a></h2> |
| <p>The library dependency graph is normally acyclic (a DAG), but in the case |
| of mutually-dependent <code class="docutils literal"><span class="pre">STATIC</span></code> libraries CMake allows the graph to |
| contain cycles (strongly connected components). When another target links |
| to one of the libraries, CMake repeats the entire connected component. |
| For example, the code</p> |
| <div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">add_library</span><span class="p">(</span><span class="s">A</span> <span class="s">STATIC</span> <span class="s">a.c</span><span class="p">)</span> |
| <span class="nb">add_library</span><span class="p">(</span><span class="s">B</span> <span class="s">STATIC</span> <span class="s">b.c</span><span class="p">)</span> |
| <span class="nb">target_link_libraries</span><span class="p">(</span><span class="s">A</span> <span class="s">B</span><span class="p">)</span> |
| <span class="nb">target_link_libraries</span><span class="p">(</span><span class="s">B</span> <span class="s">A</span><span class="p">)</span> |
| <span class="nb">add_executable</span><span class="p">(</span><span class="s">main</span> <span class="s">main.c</span><span class="p">)</span> |
| <span class="nb">target_link_libraries</span><span class="p">(</span><span class="s">main</span> <span class="s">A</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>links <code class="docutils literal"><span class="pre">main</span></code> to <code class="docutils literal"><span class="pre">A</span> <span class="pre">B</span> <span class="pre">A</span> <span class="pre">B</span></code>. While one repetition is usually |
| sufficient, pathological object file and symbol arrangements can require |
| more. One may handle such cases by using the |
| <span class="target" id="index-0-prop_tgt:LINK_INTERFACE_MULTIPLICITY"></span><a class="reference internal" href="../prop_tgt/LINK_INTERFACE_MULTIPLICITY.html#prop_tgt:LINK_INTERFACE_MULTIPLICITY" title="LINK_INTERFACE_MULTIPLICITY"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">LINK_INTERFACE_MULTIPLICITY</span></code></a> target property or by manually |
| repeating the component in the last <code class="docutils literal"><span class="pre">target_link_libraries</span></code> call. |
| However, if two archives are really so interdependent they should probably |
| be combined into a single archive, perhaps by using <a class="reference internal" href="../manual/cmake-buildsystem.7.html#object-libraries"><span class="std std-ref">Object Libraries</span></a>.</p> |
| </div> |
| <div class="section" id="creating-relocatable-packages"> |
| <h2><a class="toc-backref" href="#id8">Creating Relocatable Packages</a><a class="headerlink" href="#creating-relocatable-packages" title="Permalink to this headline">¶</a></h2> |
| <p>Note that it is not advisable to populate the |
| <span class="target" id="index-6-prop_tgt:INTERFACE_LINK_LIBRARIES"></span><a class="reference internal" href="../prop_tgt/INTERFACE_LINK_LIBRARIES.html#prop_tgt:INTERFACE_LINK_LIBRARIES" title="INTERFACE_LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">INTERFACE_LINK_LIBRARIES</span></code></a> of a target with absolute paths to dependencies. |
| That would hard-code into installed packages the library file paths |
| for dependencies <strong>as found on the machine the package was made on</strong>.</p> |
| <p>See the <a class="reference internal" href="../manual/cmake-packages.7.html#creating-relocatable-packages"><span class="std std-ref">Creating Relocatable Packages</span></a> section of the |
| <span class="target" id="index-0-manual:cmake-packages(7)"></span><a class="reference internal" href="../manual/cmake-packages.7.html#manual:cmake-packages(7)" title="cmake-packages(7)"><code class="xref cmake cmake-manual docutils literal"><span class="pre">cmake-packages(7)</span></code></a> manual for discussion of additional care |
| that must be taken when specifying usage requirements while creating |
| packages for redistribution.</p> |
| </div> |
| </div> |
| |
| |
| </div> |
| </div> |
| </div> |
| <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
| <div class="sphinxsidebarwrapper"> |
| <h3><a href="../index.html">Table Of Contents</a></h3> |
| <ul> |
| <li><a class="reference internal" href="#">target_link_libraries</a><ul> |
| <li><a class="reference internal" href="#overview">Overview</a></li> |
| <li><a class="reference internal" href="#libraries-for-a-target-and-or-its-dependents">Libraries for a Target and/or its Dependents</a></li> |
| <li><a class="reference internal" href="#libraries-for-both-a-target-and-its-dependents">Libraries for both a Target and its Dependents</a></li> |
| <li><a class="reference internal" href="#libraries-for-a-target-and-or-its-dependents-legacy">Libraries for a Target and/or its Dependents (Legacy)</a></li> |
| <li><a class="reference internal" href="#libraries-for-dependents-only-legacy">Libraries for Dependents Only (Legacy)</a></li> |
| <li><a class="reference internal" href="#cyclic-dependencies-of-static-libraries">Cyclic Dependencies of Static Libraries</a></li> |
| <li><a class="reference internal" href="#creating-relocatable-packages">Creating Relocatable Packages</a></li> |
| </ul> |
| </li> |
| </ul> |
| |
| <h4>Previous topic</h4> |
| <p class="topless"><a href="target_include_directories.html" |
| title="previous chapter">target_include_directories</a></p> |
| <h4>Next topic</h4> |
| <p class="topless"><a href="target_sources.html" |
| title="next chapter">target_sources</a></p> |
| <div role="note" aria-label="source link"> |
| <h3>This Page</h3> |
| <ul class="this-page-menu"> |
| <li><a href="../_sources/command/target_link_libraries.rst.txt" |
| rel="nofollow">Show Source</a></li> |
| </ul> |
| </div> |
| <div id="searchbox" style="display: none" role="search"> |
| <h3>Quick search</h3> |
| <form class="search" action="../search.html" method="get"> |
| <div><input type="text" name="q" /></div> |
| <div><input type="submit" value="Go" /></div> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| </div> |
| <script type="text/javascript">$('#searchbox').show(0);</script> |
| </div> |
| </div> |
| <div class="clearer"></div> |
| </div> |
| <div class="related" role="navigation" aria-label="related navigation"> |
| <h3>Navigation</h3> |
| <ul> |
| <li class="right" style="margin-right: 10px"> |
| <a href="../genindex.html" title="General Index" |
| >index</a></li> |
| <li class="right" > |
| <a href="target_sources.html" title="target_sources" |
| >next</a> |</li> |
| <li class="right" > |
| <a href="target_include_directories.html" title="target_include_directories" |
| >previous</a> |</li> |
| <li> |
| <img src="../_static/cmake-logo-16.png" alt="" |
| style="vertical-align: middle; margin-top: -2px" /> |
| </li> |
| <li> |
| <a href="https://cmake.org/">CMake</a> » |
| </li> |
| <li> |
| <a href="../index.html">3.8.2 Documentation</a> » |
| </li> |
| |
| <li class="nav-item nav-item-1"><a href="../manual/cmake-commands.7.html" >cmake-commands(7)</a> »</li> |
| </ul> |
| </div> |
| <div class="footer" role="contentinfo"> |
| © Copyright 2000-2017 Kitware, Inc. and Contributors. |
| Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.2. |
| </div> |
| </body> |
| </html> |