blob: dee6a97c96be45e250e508cfc290fc391b557e23 [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>get_filename_component &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="get_property" href="get_property.html" />
<link rel="prev" title="get_directory_property" href="get_directory_property.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="get_property.html" title="get_property"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="get_directory_property.html" title="get_directory_property"
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="get-filename-component">
<span id="command:get_filename_component"></span><h1>get_filename_component<a class="headerlink" href="#get-filename-component" title="Permalink to this headline">ΒΆ</a></h1>
<p>Get a specific component of a full filename.</p>
<hr class="docutils" />
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">get_filename_component</span><span class="p">(</span><span class="o">&lt;</span><span class="n">VAR</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">FileName</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">COMP</span><span class="o">&gt;</span> <span class="p">[</span><span class="n">CACHE</span><span class="p">])</span>
</pre></div>
</div>
<p>Set <code class="docutils literal"><span class="pre">&lt;VAR&gt;</span></code> to a component of <code class="docutils literal"><span class="pre">&lt;FileName&gt;</span></code>, where <code class="docutils literal"><span class="pre">&lt;COMP&gt;</span></code> is one of:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">DIRECTORY</span> <span class="o">=</span> <span class="n">Directory</span> <span class="n">without</span> <span class="n">file</span> <span class="n">name</span>
<span class="n">NAME</span> <span class="o">=</span> <span class="n">File</span> <span class="n">name</span> <span class="n">without</span> <span class="n">directory</span>
<span class="n">EXT</span> <span class="o">=</span> <span class="n">File</span> <span class="n">name</span> <span class="n">longest</span> <span class="n">extension</span> <span class="p">(</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">c</span> <span class="kn">from</span> <span class="nn">d</span><span class="o">/</span><span class="n">a</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">c</span><span class="p">)</span>
<span class="n">NAME_WE</span> <span class="o">=</span> <span class="n">File</span> <span class="n">name</span> <span class="n">without</span> <span class="n">directory</span> <span class="ow">or</span> <span class="n">longest</span> <span class="n">extension</span>
<span class="n">PATH</span> <span class="o">=</span> <span class="n">Legacy</span> <span class="n">alias</span> <span class="k">for</span> <span class="n">DIRECTORY</span> <span class="p">(</span><span class="n">use</span> <span class="k">for</span> <span class="n">CMake</span> <span class="o">&lt;=</span> <span class="mf">2.8</span><span class="o">.</span><span class="mi">11</span><span class="p">)</span>
</pre></div>
</div>
<p>Paths are returned with forward slashes and have no trailing slashes.
The longest file extension is always considered. If the optional
<code class="docutils literal"><span class="pre">CACHE</span></code> argument is specified, the result variable is added to the
cache.</p>
<hr class="docutils" />
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">get_filename_component</span><span class="p">(</span><span class="o">&lt;</span><span class="n">VAR</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">FileName</span><span class="o">&gt;</span>
<span class="o">&lt;</span><span class="n">COMP</span><span class="o">&gt;</span> <span class="p">[</span><span class="n">BASE_DIR</span> <span class="o">&lt;</span><span class="n">BASE_DIR</span><span class="o">&gt;</span><span class="p">]</span>
<span class="p">[</span><span class="n">CACHE</span><span class="p">])</span>
</pre></div>
</div>
<p>Set <code class="docutils literal"><span class="pre">&lt;VAR&gt;</span></code> to the absolute path of <code class="docutils literal"><span class="pre">&lt;FileName&gt;</span></code>, where <code class="docutils literal"><span class="pre">&lt;COMP&gt;</span></code> is one
of:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">ABSOLUTE</span> <span class="o">=</span> <span class="n">Full</span> <span class="n">path</span> <span class="n">to</span> <span class="n">file</span>
<span class="n">REALPATH</span> <span class="o">=</span> <span class="n">Full</span> <span class="n">path</span> <span class="n">to</span> <span class="n">existing</span> <span class="n">file</span> <span class="k">with</span> <span class="n">symlinks</span> <span class="n">resolved</span>
</pre></div>
</div>
<p>If the provided <code class="docutils literal"><span class="pre">&lt;FileName&gt;</span></code> is a relative path, it is evaluated relative
to the given base directory <code class="docutils literal"><span class="pre">&lt;BASE_DIR&gt;</span></code>. If no base directory is
provided, the default base directory will be
<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>.</p>
<p>Paths are returned with forward slashes and have no trailing slahes. If the
optional <code class="docutils literal"><span class="pre">CACHE</span></code> argument is specified, the result variable is added to the
cache.</p>
<hr class="docutils" />
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">get_filename_component</span><span class="p">(</span><span class="o">&lt;</span><span class="n">VAR</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">FileName</span><span class="o">&gt;</span>
<span class="n">PROGRAM</span> <span class="p">[</span><span class="n">PROGRAM_ARGS</span> <span class="o">&lt;</span><span class="n">ARG_VAR</span><span class="o">&gt;</span><span class="p">]</span>
<span class="p">[</span><span class="n">CACHE</span><span class="p">])</span>
</pre></div>
</div>
<p>The program in <code class="docutils literal"><span class="pre">&lt;FileName&gt;</span></code> will be found in the system search path or
left as a full path. If <code class="docutils literal"><span class="pre">PROGRAM_ARGS</span></code> is present with <code class="docutils literal"><span class="pre">PROGRAM</span></code>, then
any command-line arguments present in the <code class="docutils literal"><span class="pre">&lt;FileName&gt;</span></code> string are split
from the program name and stored in <code class="docutils literal"><span class="pre">&lt;ARG_VAR&gt;</span></code>. This is used to
separate a program name from its arguments in a command line string.</p>
</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="get_directory_property.html"
title="previous chapter">get_directory_property</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="get_property.html"
title="next chapter">get_property</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/command/get_filename_component.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="get_property.html" title="get_property"
>next</a> |</li>
<li class="right" >
<a href="get_directory_property.html" title="get_directory_property"
>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>