| |
| <!DOCTYPE html> |
| |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| <title>LINK_LIBRARIES_ONLY_TARGETS — CMake 3.23.1 Documentation</title> |
| |
| <link rel="stylesheet" type="text/css" href="../_static/pygments.css" /> |
| <link rel="stylesheet" type="text/css" href="../_static/cmake.css" /> |
| |
| <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script> |
| <script src="../_static/jquery.js"></script> |
| <script src="../_static/underscore.js"></script> |
| <script 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="LINK_OPTIONS" href="LINK_OPTIONS.html" /> |
| <link rel="prev" title="LINK_LIBRARIES" href="LINK_LIBRARIES.html" /> |
| |
| |
| </head><body> |
| |
| <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="LINK_OPTIONS.html" title="LINK_OPTIONS" |
| accesskey="N">next</a> |</li> |
| <li class="right" > |
| <a href="LINK_LIBRARIES.html" title="LINK_LIBRARIES" |
| 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.23.1 Documentation</a> » |
| </li> |
| |
| <li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" accesskey="U">cmake-properties(7)</a> »</li> |
| <li class="nav-item nav-item-this"><a href="">LINK_LIBRARIES_ONLY_TARGETS</a></li> |
| </ul> |
| </div> |
| |
| <div class="document"> |
| <div class="documentwrapper"> |
| <div class="bodywrapper"> |
| <div class="body" role="main"> |
| |
| <div class="section" id="link-libraries-only-targets"> |
| <span id="prop_tgt:LINK_LIBRARIES_ONLY_TARGETS"></span><h1>LINK_LIBRARIES_ONLY_TARGETS<a class="headerlink" href="#link-libraries-only-targets" title="Permalink to this headline">ΒΆ</a></h1> |
| <div class="versionadded"> |
| <p><span class="versionmodified added">New in version 3.23.</span></p> |
| </div> |
| <p>Enforce that link items that can be target names are actually existing targets.</p> |
| <p>Set this property to a true value to enable additional checks on the contents |
| of the <span class="target" id="index-0-prop_tgt:LINK_LIBRARIES"></span><a class="reference internal" href="LINK_LIBRARIES.html#prop_tgt:LINK_LIBRARIES" title="LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">LINK_LIBRARIES</span></code></a> and <span class="target" id="index-0-prop_tgt:INTERFACE_LINK_LIBRARIES"></span><a class="reference internal" href="INTERFACE_LINK_LIBRARIES.html#prop_tgt:INTERFACE_LINK_LIBRARIES" title="INTERFACE_LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">INTERFACE_LINK_LIBRARIES</span></code></a> |
| target properties, typically populated by <span class="target" id="index-0-command:target_link_libraries"></span><a class="reference internal" href="../command/target_link_libraries.html#command:target_link_libraries" title="target_link_libraries"><code class="xref cmake cmake-command docutils literal notranslate"><span class="pre">target_link_libraries()</span></code></a>. |
| CMake will verify that link items that might be target names actually name |
| existing targets. An item is considered a possible target name if:</p> |
| <ul class="simple"> |
| <li><p>it does not contain a <code class="docutils literal notranslate"><span class="pre">/</span></code> or <code class="docutils literal notranslate"><span class="pre">\</span></code>, and</p></li> |
| <li><p>it does not start in <code class="docutils literal notranslate"><span class="pre">-</span></code>, and</p></li> |
| <li><p>(for historical reasons) it does not start in <code class="docutils literal notranslate"><span class="pre">$</span></code> or <code class="docutils literal notranslate"><span class="pre">`</span></code>.</p></li> |
| </ul> |
| <p>This property is initialized by the value of the |
| <span class="target" id="index-0-variable:CMAKE_LINK_LIBRARIES_ONLY_TARGETS"></span><a class="reference internal" href="../variable/CMAKE_LINK_LIBRARIES_ONLY_TARGETS.html#variable:CMAKE_LINK_LIBRARIES_ONLY_TARGETS" title="CMAKE_LINK_LIBRARIES_ONLY_TARGETS"><code class="xref cmake cmake-variable docutils literal notranslate"><span class="pre">CMAKE_LINK_LIBRARIES_ONLY_TARGETS</span></code></a> variable when a non-imported |
| target is created. The property may be explicitly enabled on an imported |
| target to check its link interface.</p> |
| <p>In the following example, CMake will halt with an error at configure time |
| because <code class="docutils literal notranslate"><span class="pre">miLib</span></code> is not a target:</p> |
| <div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">set(</span><span class="no">CMAKE_LINK_LIBRARIES_ONLY_TARGETS</span><span class="w"> </span><span class="no">ON</span><span class="nf">)</span><span class="w"></span> |
| <span class="nf">add_library(</span><span class="nb">myLib</span><span class="w"> </span><span class="no">STATIC</span><span class="w"> </span><span class="nb">myLib.c</span><span class="nf">)</span><span class="w"></span> |
| <span class="nf">add_executable(</span><span class="nb">myExe</span><span class="w"> </span><span class="nb">myExe.c</span><span class="nf">)</span><span class="w"></span> |
| <span class="nf">target_link_libraries(</span><span class="nb">myExe</span><span class="w"> </span><span class="no">PRIVATE</span><span class="w"> </span><span class="nb">miLib</span><span class="nf">)</span><span class="w"> </span><span class="c"># typo for myLib</span> |
| </pre></div> |
| </div> |
| <p>In order to link toolchain-provided libraries by name while still |
| enforcing <code class="docutils literal notranslate"><span class="pre">LINK_LIBRARIES_ONLY_TARGETS</span></code>, use an |
| <a class="reference internal" href="../manual/cmake-buildsystem.7.html#imported-targets"><span class="std std-ref">imported</span></a> |
| <a class="reference internal" href="../manual/cmake-buildsystem.7.html#interface-libraries"><span class="std std-ref">Interface Library</span></a> with the |
| <span class="target" id="index-0-prop_tgt:IMPORTED_LIBNAME"></span><a class="reference internal" href="IMPORTED_LIBNAME.html#prop_tgt:IMPORTED_LIBNAME" title="IMPORTED_LIBNAME"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">IMPORTED_LIBNAME</span></code></a> target property:</p> |
| <div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">add_library(</span><span class="nb">toolchain</span><span class="o">::</span><span class="nb">m</span><span class="w"> </span><span class="no">INTERFACE</span><span class="w"> </span><span class="no">IMPORTED</span><span class="nf">)</span><span class="w"></span> |
| <span class="nf">set_property(</span><span class="no">TARGET</span><span class="w"> </span><span class="nb">toolchain</span><span class="o">::</span><span class="nb">m</span><span class="w"> </span><span class="no">PROPERTY</span><span class="w"> </span><span class="no">IMPORTED_LIBNAME</span><span class="w"> </span><span class="s">"m"</span><span class="nf">)</span><span class="w"></span> |
| <span class="nf">target_link_libraries(</span><span class="nb">myExe</span><span class="w"> </span><span class="no">PRIVATE</span><span class="w"> </span><span class="nb">toolchain</span><span class="o">::</span><span class="nb">m</span><span class="nf">)</span><span class="w"></span> |
| </pre></div> |
| </div> |
| <p>See also 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 notranslate"><span class="pre">CMP0028</span></code></a>.</p> |
| <div class="admonition note"> |
| <p class="admonition-title">Note</p> |
| <p>If <span class="target" id="index-1-prop_tgt:INTERFACE_LINK_LIBRARIES"></span><a class="reference internal" href="INTERFACE_LINK_LIBRARIES.html#prop_tgt:INTERFACE_LINK_LIBRARIES" title="INTERFACE_LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">INTERFACE_LINK_LIBRARIES</span></code></a> contains generator expressions, |
| its actual list of link items may depend on the type and properties of |
| the consuming target. In such cases CMake may not always detect names |
| of missing targets that only appear for specific consumers. |
| A future version of CMake with improved heuristics may start triggering |
| errors on projects accepted by previous versions of CMake.</p> |
| </div> |
| </div> |
| |
| |
| <div class="clearer"></div> |
| </div> |
| </div> |
| </div> |
| <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
| <div class="sphinxsidebarwrapper"> |
| <h4>Previous topic</h4> |
| <p class="topless"><a href="LINK_LIBRARIES.html" |
| title="previous chapter">LINK_LIBRARIES</a></p> |
| <h4>Next topic</h4> |
| <p class="topless"><a href="LINK_OPTIONS.html" |
| title="next chapter">LINK_OPTIONS</a></p> |
| <div role="note" aria-label="source link"> |
| <h3>This Page</h3> |
| <ul class="this-page-menu"> |
| <li><a href="../_sources/prop_tgt/LINK_LIBRARIES_ONLY_TARGETS.rst.txt" |
| rel="nofollow">Show Source</a></li> |
| </ul> |
| </div> |
| <div id="searchbox" style="display: none" role="search"> |
| <h3 id="searchlabel">Quick search</h3> |
| <div class="searchformwrapper"> |
| <form class="search" action="../search.html" method="get"> |
| <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> |
| <input type="submit" value="Go" /> |
| </form> |
| </div> |
| </div> |
| <script>$('#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="LINK_OPTIONS.html" title="LINK_OPTIONS" |
| >next</a> |</li> |
| <li class="right" > |
| <a href="LINK_LIBRARIES.html" title="LINK_LIBRARIES" |
| >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.23.1 Documentation</a> » |
| </li> |
| |
| <li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" >cmake-properties(7)</a> »</li> |
| <li class="nav-item nav-item-this"><a href="">LINK_LIBRARIES_ONLY_TARGETS</a></li> |
| </ul> |
| </div> |
| |
| <div class="footer" role="contentinfo"> |
| © Copyright 2000-2022 Kitware, Inc. and Contributors. |
| Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2. |
| </div> |
| </body> |
| </html> |