blob: cf8fd99048f312509945e729a7d0e3532500d321 [file] [log] [blame]
<!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>configure_file &mdash; 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="continue" href="continue.html" />
<link rel="prev" title="cmake_policy" href="cmake_policy.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="continue.html" title="continue"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="cmake_policy.html" title="cmake_policy"
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.8.2 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>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="configure-file">
<span id="command:configure_file"></span><h1>configure_file<a class="headerlink" href="#configure-file" title="Permalink to this headline"></a></h1>
<p>Copy a file to another location and modify its contents.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">configure_file</span><span class="p">(</span><span class="o">&lt;</span><span class="nb">input</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">output</span><span class="o">&gt;</span>
<span class="p">[</span><span class="n">COPYONLY</span><span class="p">]</span> <span class="p">[</span><span class="n">ESCAPE_QUOTES</span><span class="p">]</span> <span class="p">[</span><span class="nd">@ONLY</span><span class="p">]</span>
<span class="p">[</span><span class="n">NEWLINE_STYLE</span> <span class="p">[</span><span class="n">UNIX</span><span class="o">|</span><span class="n">DOS</span><span class="o">|</span><span class="n">WIN32</span><span class="o">|</span><span class="n">LF</span><span class="o">|</span><span class="n">CRLF</span><span class="p">]</span> <span class="p">])</span>
</pre></div>
</div>
<p>Copies an <code class="docutils literal"><span class="pre">&lt;input&gt;</span></code> file to an <code class="docutils literal"><span class="pre">&lt;output&gt;</span></code> file and substitutes
variable values referenced as <code class="docutils literal"><span class="pre">&#64;VAR&#64;</span></code> or <code class="docutils literal"><span class="pre">${VAR}</span></code> in the input
file content. Each variable reference will be replaced with the
current value of the variable, or the empty string if the variable
is not defined. Furthermore, input lines of the form:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1">#cmakedefine VAR ...</span>
</pre></div>
</div>
<p>will be replaced with either:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1">#define VAR ...</span>
</pre></div>
</div>
<p>or:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">/*</span> <span class="c1">#undef VAR */</span>
</pre></div>
</div>
<p>depending on whether <code class="docutils literal"><span class="pre">VAR</span></code> is set in CMake to any value not considered
a false constant by the <span class="target" id="index-0-command:if"></span><a class="reference internal" href="if.html#command:if" title="if"><code class="xref cmake cmake-command docutils literal"><span class="pre">if()</span></code></a> command. The &#8221;...&#8221; content on the
line after the variable name, if any, is processed as above.
Input file lines of the form <code class="docutils literal"><span class="pre">#cmakedefine01</span> <span class="pre">VAR</span></code> will be replaced with
either <code class="docutils literal"><span class="pre">#define</span> <span class="pre">VAR</span> <span class="pre">1</span></code> or <code class="docutils literal"><span class="pre">#define</span> <span class="pre">VAR</span> <span class="pre">0</span></code> similarly.</p>
<p>If the input file is modified the build system will re-run CMake to
re-configure the file and generate the build system again.</p>
<p>The arguments are:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">&lt;input&gt;</span></code></dt>
<dd>Path to the input file. A relative path is treated with respect to
the value of <span class="target" id="index-0-variable:CMAKE_CURRENT_SOURCE_DIR"></span><a class="reference internal" href="../variable/CMAKE_CURRENT_SOURCE_DIR.html#variable:CMAKE_CURRENT_SOURCE_DIR" title="CMAKE_CURRENT_SOURCE_DIR"><code class="xref cmake cmake-variable docutils literal"><span class="pre">CMAKE_CURRENT_SOURCE_DIR</span></code></a>. The input path
must be a file, not a directory.</dd>
<dt><code class="docutils literal"><span class="pre">&lt;output&gt;</span></code></dt>
<dd>Path to the output file or directory. A relative path is treated
with respect to the value of <span class="target" id="index-0-variable:CMAKE_CURRENT_BINARY_DIR"></span><a class="reference internal" href="../variable/CMAKE_CURRENT_BINARY_DIR.html#variable:CMAKE_CURRENT_BINARY_DIR" title="CMAKE_CURRENT_BINARY_DIR"><code class="xref cmake cmake-variable docutils literal"><span class="pre">CMAKE_CURRENT_BINARY_DIR</span></code></a>.
If the path names an existing directory the output file is placed
in that directory with the same file name as the input file.</dd>
<dt><code class="docutils literal"><span class="pre">COPYONLY</span></code></dt>
<dd>Copy the file without replacing any variable references or other
content. This option may not be used with <code class="docutils literal"><span class="pre">NEWLINE_STYLE</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">ESCAPE_QUOTES</span></code></dt>
<dd>Escape any substituted quotes with backslashes (C-style).</dd>
<dt><code class="docutils literal"><span class="pre">&#64;ONLY</span></code></dt>
<dd>Restrict variable replacement to references of the form <code class="docutils literal"><span class="pre">&#64;VAR&#64;</span></code>.
This is useful for configuring scripts that use <code class="docutils literal"><span class="pre">${VAR}</span></code> syntax.</dd>
<dt><code class="docutils literal"><span class="pre">NEWLINE_STYLE</span> <span class="pre">&lt;style&gt;</span></code></dt>
<dd>Specify the newline style for the output file. Specify
<code class="docutils literal"><span class="pre">UNIX</span></code> or <code class="docutils literal"><span class="pre">LF</span></code> for <code class="docutils literal"><span class="pre">\n</span></code> newlines, or specify
<code class="docutils literal"><span class="pre">DOS</span></code>, <code class="docutils literal"><span class="pre">WIN32</span></code>, or <code class="docutils literal"><span class="pre">CRLF</span></code> for <code class="docutils literal"><span class="pre">\r\n</span></code> newlines.
This option may not be used with <code class="docutils literal"><span class="pre">COPYONLY</span></code>.</dd>
</dl>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline"></a></h2>
<p>Consider a source tree containing a <code class="docutils literal"><span class="pre">foo.h.in</span></code> file:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="cp">#cmakedefine FOO_ENABLE</span>
<span class="cp">#cmakedefine FOO_STRING &quot;@FOO_STRING@&quot;</span>
</pre></div>
</div>
<p>An adjacent <code class="docutils literal"><span class="pre">CMakeLists.txt</span></code> may use <code class="docutils literal"><span class="pre">configure_file</span></code> to
configure the header:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">option</span><span class="p">(</span><span class="s">FOO_ENABLE</span> <span class="s2">&quot;Enable Foo&quot;</span> <span class="s">ON</span><span class="p">)</span>
<span class="nb">if</span><span class="p">(</span><span class="s">FOO_ENABLE</span><span class="p">)</span>
<span class="nb">set</span><span class="p">(</span><span class="s">FOO_STRING</span> <span class="s2">&quot;foo&quot;</span><span class="p">)</span>
<span class="nb">endif</span><span class="p">()</span>
<span class="nb">configure_file</span><span class="p">(</span><span class="s">foo.h.in</span> <span class="s">foo.h</span> <span class="s">@ONLY</span><span class="p">)</span>
</pre></div>
</div>
<p>This creates a <code class="docutils literal"><span class="pre">foo.h</span></code> in the build directory corresponding to
this source directory. If the <code class="docutils literal"><span class="pre">FOO_ENABLE</span></code> option is on, the
configured file will contain:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="cp">#define FOO_ENABLE</span>
<span class="cp">#define FOO_STRING &quot;foo&quot;</span>
</pre></div>
</div>
<p>Otherwise it will contain:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="cm">/* #undef FOO_ENABLE */</span>
<span class="cm">/* #undef FOO_STRING */</span>
</pre></div>
</div>
<p>One may then use the <span class="target" id="index-0-command:include_directories"></span><a class="reference internal" href="include_directories.html#command:include_directories" title="include_directories"><code class="xref cmake cmake-command docutils literal"><span class="pre">include_directories()</span></code></a> command to
specify the output directory as an include directory:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">include_directories</span><span class="p">(</span><span class="o">${</span><span class="nv">CMAKE_CURRENT_BINARY_DIR</span><span class="o">}</span><span class="p">)</span>
</pre></div>
</div>
<p>so that sources may include the header as <code class="docutils literal"><span class="pre">#include</span> <span class="pre">&lt;foo.h&gt;</span></code>.</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="#">configure_file</a><ul>
<li><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="cmake_policy.html"
title="previous chapter">cmake_policy</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="continue.html"
title="next chapter">continue</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/command/configure_file.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="continue.html" title="continue"
>next</a> |</li>
<li class="right" >
<a href="cmake_policy.html" title="cmake_policy"
>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.8.2 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="../manual/cmake-commands.7.html" >cmake-commands(7)</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2000-2017 Kitware, Inc. and Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.2.
</div>
</body>
</html>