blob: b8e2bac35a74121171d63ca23b5da2769fc9502e [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>CheckPIESupported &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="CheckPrototypeDefinition" href="CheckPrototypeDefinition.html" />
<link rel="prev" title="CheckOBJCXXSourceRuns" href="CheckOBJCXXSourceRuns.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="CheckPrototypeDefinition.html" title="CheckPrototypeDefinition"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="CheckOBJCXXSourceRuns.html" title="CheckOBJCXXSourceRuns"
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-modules.7.html" accesskey="U">cmake-modules(7)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">CheckPIESupported</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="checkpiesupported">
<span id="module:CheckPIESupported"></span><h1>CheckPIESupported<a class="headerlink" href="#checkpiesupported" title="Permalink to this headline"></a></h1>
<div class="versionadded">
<p><span class="versionmodified added">New in version 3.14.</span></p>
</div>
<p>Check whether the linker supports Position Independent Code (PIE) or No
Position Independent Code (NO_PIE) for executables.
Use this to ensure that the <span class="target" id="index-0-prop_tgt:POSITION_INDEPENDENT_CODE"></span><a class="reference internal" href="../prop_tgt/POSITION_INDEPENDENT_CODE.html#prop_tgt:POSITION_INDEPENDENT_CODE" title="POSITION_INDEPENDENT_CODE"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">POSITION_INDEPENDENT_CODE</span></code></a> target
property for executables will be honored at link time.</p>
<dl class="cmake command">
<dt class="sig sig-object cmake" id="command:check_pie_supported">
<span class="sig-name descname"><span class="pre">check_pie_supported</span></span><a class="headerlink" href="#command:check_pie_supported" title="Permalink to this definition"></a></dt>
<dd><div class="highlight-none notranslate"><div class="highlight"><pre><span></span>check_pie_supported([OUTPUT_VARIABLE &lt;output&gt;]
[LANGUAGES &lt;lang&gt;...])
</pre></div>
</div>
<p>Options are:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">OUTPUT_VARIABLE</span> <span class="pre">&lt;output&gt;</span></code></dt><dd><p>Set <code class="docutils literal notranslate"><span class="pre">&lt;output&gt;</span></code> variable with details about any error. If the check is
bypassed because it uses cached results from a previous call, the output
will be empty even if errors were present in the previous call.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">LANGUAGES</span> <span class="pre">&lt;lang&gt;...</span></code></dt><dd><p>Check the linkers used for each of the specified languages.
If this option is not provided, the command checks all enabled languages.</p>
<p><code class="docutils literal notranslate"><span class="pre">C</span></code>, <code class="docutils literal notranslate"><span class="pre">CXX</span></code>, <code class="docutils literal notranslate"><span class="pre">Fortran</span></code> are supported.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 3.23: </span><code class="docutils literal notranslate"><span class="pre">OBJC</span></code>, <code class="docutils literal notranslate"><span class="pre">OBJCXX</span></code>, <code class="docutils literal notranslate"><span class="pre">CUDA</span></code>, and <code class="docutils literal notranslate"><span class="pre">HIP</span></code> are supported.</p>
</div>
</dd>
</dl>
</dd></dl>
<p>It makes no sense to use this module when <span class="target" id="index-0-policy:CMP0083"></span><a class="reference internal" href="../policy/CMP0083.html#policy:CMP0083" title="CMP0083"><code class="xref cmake cmake-policy docutils literal notranslate"><span class="pre">CMP0083</span></code></a> is set to <code class="docutils literal notranslate"><span class="pre">OLD</span></code>,
so the command will return an error in this case. See policy <span class="target" id="index-1-policy:CMP0083"></span><a class="reference internal" href="../policy/CMP0083.html#policy:CMP0083" title="CMP0083"><code class="xref cmake cmake-policy docutils literal notranslate"><span class="pre">CMP0083</span></code></a>
for details.</p>
<div class="section" id="variables">
<h2>Variables<a class="headerlink" href="#variables" title="Permalink to this headline"></a></h2>
<p>For each language checked, two boolean cache variables are defined.</p>
<blockquote>
<div><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_&lt;lang&gt;_LINK_PIE_SUPPORTED</span></code></dt><dd><p>Set to true if <code class="docutils literal notranslate"><span class="pre">PIE</span></code> is supported by the linker and false otherwise.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_&lt;lang&gt;_LINK_NO_PIE_SUPPORTED</span></code></dt><dd><p>Set to true if <code class="docutils literal notranslate"><span class="pre">NO_PIE</span></code> is supported by the linker and false otherwise.</p>
</dd>
</dl>
</div></blockquote>
</div>
<div class="section" id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h2>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">check_pie_supported()</span><span class="w"></span>
<span class="nf">set_property(</span><span class="no">TARGET</span><span class="w"> </span><span class="nb">foo</span><span class="w"> </span><span class="no">PROPERTY</span><span class="w"> </span><span class="no">POSITION_INDEPENDENT_CODE</span><span class="w"> </span><span class="no">TRUE</span><span class="nf">)</span><span class="w"></span>
</pre></div>
</div>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="c"># Retrieve any error message.</span>
<span class="nf">check_pie_supported(</span><span class="no">OUTPUT_VARIABLE</span><span class="w"> </span><span class="nb">output</span><span class="w"> </span><span class="no">LANGUAGES</span><span class="w"> </span><span class="no">C</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">foo</span><span class="w"> </span><span class="no">PROPERTY</span><span class="w"> </span><span class="no">POSITION_INDEPENDENT_CODE</span><span class="w"> </span><span class="no">TRUE</span><span class="nf">)</span><span class="w"></span>
<span class="nf">if(</span><span class="no">NOT</span><span class="w"> </span><span class="no">CMAKE_C_LINK_PIE_SUPPORTED</span><span class="nf">)</span><span class="w"></span>
<span class="w"> </span><span class="nf">message(</span><span class="no">WARNING</span><span class="w"> </span><span class="s">&quot;PIE is not supported at link time: ${output}.\n&quot;</span><span class="w"></span>
<span class="w"> </span><span class="s">&quot;PIE link options will not be passed to linker.&quot;</span><span class="nf">)</span><span class="w"></span>
<span class="nf">endif()</span><span class="w"></span>
</pre></div>
</div>
</div>
</div>
<div class="clearer"></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="#">CheckPIESupported</a><ul>
<li><a class="reference internal" href="#variables">Variables</a></li>
<li><a class="reference internal" href="#examples">Examples</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="CheckOBJCXXSourceRuns.html"
title="previous chapter">CheckOBJCXXSourceRuns</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="CheckPrototypeDefinition.html"
title="next chapter">CheckPrototypeDefinition</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/module/CheckPIESupported.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="CheckPrototypeDefinition.html" title="CheckPrototypeDefinition"
>next</a> |</li>
<li class="right" >
<a href="CheckOBJCXXSourceRuns.html" title="CheckOBJCXXSourceRuns"
>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-modules.7.html" >cmake-modules(7)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">CheckPIESupported</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>