blob: 3d1f211e3c1dfca5fe827054d5481e2ed0c4402b [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SOURCES &mdash; 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="SOVERSION" href="SOVERSION.html" />
<link rel="prev" title="SOURCE_DIR" href="SOURCE_DIR.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="SOVERSION.html" title="SOVERSION"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="SOURCE_DIR.html" title="SOURCE_DIR"
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> &#187;
</li>
<li>
<a href="../index.html">3.23.1 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" accesskey="U">cmake-properties(7)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">SOURCES</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="sources">
<span id="prop_tgt:SOURCES"></span><h1>SOURCES<a class="headerlink" href="#sources" title="Permalink to this headline">ΒΆ</a></h1>
<p>This specifies the list of paths to source files for the target.
The following commands all set or add to the <code class="docutils literal notranslate"><span class="pre">SOURCES</span></code> target property
and are the usual way to manipulate it:</p>
<ul class="simple">
<li><p><span class="target" id="index-0-command:add_executable"></span><a class="reference internal" href="../command/add_executable.html#command:add_executable" title="add_executable"><code class="xref cmake cmake-command docutils literal notranslate"><span class="pre">add_executable()</span></code></a></p></li>
<li><p><span class="target" id="index-0-command:add_library"></span><a class="reference internal" href="../command/add_library.html#command:add_library" title="add_library"><code class="xref cmake cmake-command docutils literal notranslate"><span class="pre">add_library()</span></code></a></p></li>
<li><p><span class="target" id="index-0-command:add_custom_target"></span><a class="reference internal" href="../command/add_custom_target.html#command:add_custom_target" title="add_custom_target"><code class="xref cmake cmake-command docutils literal notranslate"><span class="pre">add_custom_target()</span></code></a></p></li>
<li><p><span class="target" id="index-0-command:target_sources"></span><a class="reference internal" href="../command/target_sources.html#command:target_sources" title="target_sources"><code class="xref cmake cmake-command docutils literal notranslate"><span class="pre">target_sources()</span></code></a></p></li>
</ul>
<p>Contents of <code class="docutils literal notranslate"><span class="pre">SOURCES</span></code> may use
<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 notranslate"><span class="pre">generator</span> <span class="pre">expressions</span></code></a>.
If a path starts with a generator expression, it is expected to
evaluate to an absolute path. Not doing so is considered undefined behavior.</p>
<p>Paths that are for files generated by the build will be treated
as relative to the build directory of the target, if the path is not
already specified as an absolute path. Note that whether a file is seen as
generated may be affected by policy <span class="target" id="index-0-policy:CMP0118"></span><a class="reference internal" href="../policy/CMP0118.html#policy:CMP0118" title="CMP0118"><code class="xref cmake cmake-policy docutils literal notranslate"><span class="pre">CMP0118</span></code></a>.</p>
<p>If a path does not start with a generator expression, is not an
absolute path and is not a generated file, it will be treated as relative to
the location selected by the first of the following that matches:</p>
<ul class="simple">
<li><p>If a file by the specified path exists relative to the target's source
directory, use that file.</p></li>
<li><p>If policy <span class="target" id="index-0-policy:CMP0115"></span><a class="reference internal" href="../policy/CMP0115.html#policy:CMP0115" title="CMP0115"><code class="xref cmake cmake-policy docutils literal notranslate"><span class="pre">CMP0115</span></code></a> is not set to <code class="docutils literal notranslate"><span class="pre">NEW</span></code>, try appending each
known source file extension to the path and check if that exists
relative to the target's source directory.</p></li>
<li><p>Repeat the above two steps, this time relative to the target's binary
directory instead.</p></li>
</ul>
<p>Note that the above decisions are made at generation time, not build time.</p>
<p>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 notranslate"><span class="pre">cmake-buildsystem(7)</span></code></a> manual for more on defining
buildsystem properties.</p>
</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="SOURCE_DIR.html"
title="previous chapter">SOURCE_DIR</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="SOVERSION.html"
title="next chapter">SOVERSION</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/prop_tgt/SOURCES.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="SOVERSION.html" title="SOVERSION"
>next</a> |</li>
<li class="right" >
<a href="SOURCE_DIR.html" title="SOURCE_DIR"
>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> &#187;
</li>
<li>
<a href="../index.html">3.23.1 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" >cmake-properties(7)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">SOURCES</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2000-2022 Kitware, Inc. and Contributors.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
</div>
</body>
</html>