blob: 5c0f6d0f7644ecbdfd57512bdf2887141fd24ae1 [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>separate_arguments &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="set" href="set.html" />
<link rel="prev" title="return" href="return.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="set.html" title="set"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="return.html" title="return"
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-commands.7.html" accesskey="U">cmake-commands(7)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">separate_arguments</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="separate-arguments">
<span id="command:separate_arguments"></span><h1>separate_arguments<a class="headerlink" href="#separate-arguments" title="Permalink to this headline">ΒΆ</a></h1>
<p>Parse command-line arguments into a semicolon-separated list.</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">separate_arguments(</span><span class="nv">&lt;variable&gt;</span><span class="w"> </span><span class="nv">&lt;mode&gt;</span><span class="w"> </span><span class="p">[</span><span class="no">PROGRAM</span><span class="w"> </span><span class="p">[</span><span class="no">SEPARATE_ARGS</span><span class="p">]]</span><span class="w"> </span><span class="nv">&lt;args&gt;</span><span class="nf">)</span><span class="w"></span>
</pre></div>
</div>
<p>Parses a space-separated string <code class="docutils literal notranslate"><span class="pre">&lt;args&gt;</span></code> into a list of items,
and stores this list in semicolon-separated standard form in <code class="docutils literal notranslate"><span class="pre">&lt;variable&gt;</span></code>.</p>
<p>This function is intended for parsing command-line arguments.
The entire command line must be passed as one string in the
argument <code class="docutils literal notranslate"><span class="pre">&lt;args&gt;</span></code>.</p>
<p>The exact parsing rules depend on the operating system.
They are specified by the <code class="docutils literal notranslate"><span class="pre">&lt;mode&gt;</span></code> argument which must
be one of the following keywords:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">UNIX_COMMAND</span></code></dt><dd><p>Arguments are separated by unquoted whitespace.
Both single-quote and double-quote pairs are respected.
A backslash escapes the next literal character (<code class="docutils literal notranslate"><span class="pre">\&quot;</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;</span></code>);
there are no special escapes (<code class="docutils literal notranslate"><span class="pre">\n</span></code> is just <code class="docutils literal notranslate"><span class="pre">n</span></code>).</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">WINDOWS_COMMAND</span></code></dt><dd><p>A Windows command-line is parsed using the same
syntax the runtime library uses to construct argv at startup. It
separates arguments by whitespace that is not double-quoted.
Backslashes are literal unless they precede double-quotes. See the
MSDN article <a class="reference external" href="https://msdn.microsoft.com/library/a1y7w461.aspx">Parsing C Command-Line Arguments</a> for details.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">NATIVE_COMMAND</span></code></dt><dd><div class="versionadded">
<p><span class="versionmodified added">New in version 3.9.</span></p>
</div>
<p>Proceeds as in <code class="docutils literal notranslate"><span class="pre">WINDOWS_COMMAND</span></code> mode if the host system is Windows.
Otherwise proceeds as in <code class="docutils literal notranslate"><span class="pre">UNIX_COMMAND</span></code> mode.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">PROGRAM</span></code></dt><dd><div class="versionadded">
<p><span class="versionmodified added">New in version 3.19.</span></p>
</div>
<p>The first item in <code class="docutils literal notranslate"><span class="pre">&lt;args&gt;</span></code> is assumed to be an executable and will be
searched in the system search path or left as a full path. If not found,
<code class="docutils literal notranslate"><span class="pre">&lt;variable&gt;</span></code> will be empty. Otherwise, <code class="docutils literal notranslate"><span class="pre">&lt;variable&gt;</span></code> is a list of 2
elements:</p>
<blockquote>
<div><ol class="arabic simple" start="0">
<li><p>Absolute path of the program</p></li>
<li><p>Any command-line arguments present in <code class="docutils literal notranslate"><span class="pre">&lt;args&gt;</span></code> as a string</p></li>
</ol>
</div></blockquote>
<p>For example:</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">separate_arguments</span> <span class="nf">(</span><span class="nb">out</span><span class="w"> </span><span class="no">UNIX_COMMAND</span><span class="w"> </span><span class="no">PROGRAM</span><span class="w"> </span><span class="s">&quot;cc -c main.c&quot;</span><span class="nf">)</span><span class="w"></span>
</pre></div>
</div>
<ul class="simple">
<li><p>First element of the list: <code class="docutils literal notranslate"><span class="pre">/path/to/cc</span></code></p></li>
<li><p>Second element of the list: <code class="docutils literal notranslate"><span class="pre">&quot;</span> <span class="pre">-c</span> <span class="pre">main.c&quot;</span></code></p></li>
</ul>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">SEPARATE_ARGS</span></code></dt><dd><p>When this sub-option of <code class="docutils literal notranslate"><span class="pre">PROGRAM</span></code> option is specified, command-line
arguments will be split as well and stored in <code class="docutils literal notranslate"><span class="pre">&lt;variable&gt;</span></code>.</p>
<p>For example:</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">separate_arguments</span> <span class="nf">(</span><span class="nb">out</span><span class="w"> </span><span class="no">UNIX_COMMAND</span><span class="w"> </span><span class="no">PROGRAM</span><span class="w"> </span><span class="no">SEPARATE_ARGS</span><span class="w"> </span><span class="s">&quot;cc -c main.c&quot;</span><span class="nf">)</span><span class="w"></span>
</pre></div>
</div>
<p>The contents of <code class="docutils literal notranslate"><span class="pre">out</span></code> will be: <code class="docutils literal notranslate"><span class="pre">/path/to/cc;-c;main.c</span></code></p>
</dd>
</dl>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">separate_arguments(</span><span class="nv">&lt;var&gt;</span><span class="nf">)</span><span class="w"></span>
</pre></div>
</div>
<p>Convert the value of <code class="docutils literal notranslate"><span class="pre">&lt;var&gt;</span></code> to a semi-colon separated list. All
spaces are replaced with ';'. This helps with generating command
lines.</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="return.html"
title="previous chapter">return</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="set.html"
title="next chapter">set</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/command/separate_arguments.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="set.html" title="set"
>next</a> |</li>
<li class="right" >
<a href="return.html" title="return"
>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-commands.7.html" >cmake-commands(7)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">separate_arguments</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>