blob: 100d74458f8d520d38fb84f6910a7e1c3e4aa0da [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>FortranCInterface &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="GenerateExportHeader" href="GenerateExportHeader.html" />
<link rel="prev" title="FindZLIB" href="FindZLIB.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="GenerateExportHeader.html" title="GenerateExportHeader"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="FindZLIB.html" title="FindZLIB"
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-modules.7.html" accesskey="U">cmake-modules(7)</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="fortrancinterface">
<span id="module:FortranCInterface"></span><h1>FortranCInterface<a class="headerlink" href="#fortrancinterface" title="Permalink to this headline"></a></h1>
<p>Fortran/C Interface Detection</p>
<p>This module automatically detects the API by which C and Fortran
languages interact.</p>
<div class="section" id="module-variables">
<h2>Module Variables<a class="headerlink" href="#module-variables" title="Permalink to this headline"></a></h2>
<p>Variables that indicate if the mangling is found:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">FortranCInterface_GLOBAL_FOUND</span></code></dt>
<dd>Global subroutines and functions.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_MODULE_FOUND</span></code></dt>
<dd>Module subroutines and functions (declared by &#8220;MODULE PROCEDURE&#8221;).</dd>
</dl>
<p>This module also provides the following variables to specify
the detected mangling, though a typical use case does not need
to reference them and can use the <a class="reference internal" href="#module-functions">Module Functions</a> below.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">FortranCInterface_GLOBAL_PREFIX</span></code></dt>
<dd>Prefix for a global symbol without an underscore.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_GLOBAL_SUFFIX</span></code></dt>
<dd>Suffix for a global symbol without an underscore.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_GLOBAL_CASE</span></code></dt>
<dd>The case for a global symbol without an underscore,
either <code class="docutils literal"><span class="pre">UPPER</span></code> or <code class="docutils literal"><span class="pre">LOWER</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_GLOBAL__PREFIX</span></code></dt>
<dd>Prefix for a global symbol with an underscore.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_GLOBAL__SUFFIX</span></code></dt>
<dd>Suffix for a global symbol with an underscore.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_GLOBAL__CASE</span></code></dt>
<dd>The case for a global symbol with an underscore,
either <code class="docutils literal"><span class="pre">UPPER</span></code> or <code class="docutils literal"><span class="pre">LOWER</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_MODULE_PREFIX</span></code></dt>
<dd>Prefix for a module symbol without an underscore.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_MODULE_MIDDLE</span></code></dt>
<dd>Middle of a module symbol without an underscore that appears
between the name of the module and the name of the symbol.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_MODULE_SUFFIX</span></code></dt>
<dd>Suffix for a module symbol without an underscore.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_MODULE_CASE</span></code></dt>
<dd>The case for a module symbol without an underscore,
either <code class="docutils literal"><span class="pre">UPPER</span></code> or <code class="docutils literal"><span class="pre">LOWER</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_MODULE__PREFIX</span></code></dt>
<dd>Prefix for a module symbol with an underscore.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_MODULE__MIDDLE</span></code></dt>
<dd>Middle of a module symbol with an underscore that appears
between the name of the module and the name of the symbol.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_MODULE__SUFFIX</span></code></dt>
<dd>Suffix for a module symbol with an underscore.</dd>
<dt><code class="docutils literal"><span class="pre">FortranCInterface_MODULE__CASE</span></code></dt>
<dd>The case for a module symbol with an underscore,
either <code class="docutils literal"><span class="pre">UPPER</span></code> or <code class="docutils literal"><span class="pre">LOWER</span></code>.</dd>
</dl>
</div>
<div class="section" id="module-functions">
<h2>Module Functions<a class="headerlink" href="#module-functions" title="Permalink to this headline"></a></h2>
<dl class="command">
<dt id="command:fortrancinterface_header">
<code class="descname">FortranCInterface_HEADER</code><a class="headerlink" href="#command:fortrancinterface_header" title="Permalink to this definition"></a></dt>
<dd><p>The <code class="docutils literal"><span class="pre">FortranCInterface_HEADER</span></code> function is provided to generate a
C header file containing macros to mangle symbol names:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">FortranCInterface_HEADER</span><span class="p">(</span><span class="o">&lt;</span><span class="n">file</span><span class="o">&gt;</span>
<span class="p">[</span><span class="n">MACRO_NAMESPACE</span> <span class="o">&lt;</span><span class="n">macro</span><span class="o">-</span><span class="n">ns</span><span class="o">&gt;</span><span class="p">]</span>
<span class="p">[</span><span class="n">SYMBOL_NAMESPACE</span> <span class="o">&lt;</span><span class="n">ns</span><span class="o">&gt;</span><span class="p">]</span>
<span class="p">[</span><span class="n">SYMBOLS</span> <span class="p">[</span><span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span><span class="p">:]</span><span class="o">&lt;</span><span class="n">function</span><span class="o">&gt;</span> <span class="o">...</span><span class="p">])</span>
</pre></div>
</div>
<p>It generates in <code class="docutils literal"><span class="pre">&lt;file&gt;</span></code> definitions of the following macros:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1">#define FortranCInterface_GLOBAL (name,NAME) ...</span>
<span class="c1">#define FortranCInterface_GLOBAL_(name,NAME) ...</span>
<span class="c1">#define FortranCInterface_MODULE (mod,name, MOD,NAME) ...</span>
<span class="c1">#define FortranCInterface_MODULE_(mod,name, MOD,NAME) ...</span>
</pre></div>
</div>
<p>These macros mangle four categories of Fortran symbols, respectively:</p>
<ul class="simple">
<li>Global symbols without &#8216;_&#8217;: <code class="docutils literal"><span class="pre">call</span> <span class="pre">mysub()</span></code></li>
<li>Global symbols with &#8216;_&#8217; : <code class="docutils literal"><span class="pre">call</span> <span class="pre">my_sub()</span></code></li>
<li>Module symbols without &#8216;_&#8217;: <code class="docutils literal"><span class="pre">use</span> <span class="pre">mymod;</span> <span class="pre">call</span> <span class="pre">mysub()</span></code></li>
<li>Module symbols with &#8216;_&#8217; : <code class="docutils literal"><span class="pre">use</span> <span class="pre">mymod;</span> <span class="pre">call</span> <span class="pre">my_sub()</span></code></li>
</ul>
<p>If mangling for a category is not known, its macro is left undefined.
All macros require raw names in both lower case and upper case.</p>
<p>The options are:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">MACRO_NAMESPACE</span></code></dt>
<dd>Replace the default <code class="docutils literal"><span class="pre">FortranCInterface_</span></code> prefix with a given
namespace <code class="docutils literal"><span class="pre">&lt;macro-ns&gt;</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">SYMBOLS</span></code></dt>
<dd><p class="first">List symbols to mangle automatically with C preprocessor definitions:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">function</span><span class="o">&gt;</span> <span class="o">==&gt;</span> <span class="c1">#define &lt;ns&gt;&lt;function&gt; ...</span>
<span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span><span class="p">:</span><span class="o">&lt;</span><span class="n">function</span><span class="o">&gt;</span> <span class="o">==&gt;</span> <span class="c1">#define &lt;ns&gt;&lt;module&gt;_&lt;function&gt; ...</span>
</pre></div>
</div>
<p class="last">If the mangling for some symbol is not known then no preprocessor
definition is created, and a warning is displayed.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">SYMBOL_NAMESPACE</span></code></dt>
<dd>Prefix all preprocessor definitions generated by the <code class="docutils literal"><span class="pre">SYMBOLS</span></code>
option with a given namespace <code class="docutils literal"><span class="pre">&lt;ns&gt;</span></code>.</dd>
</dl>
</dd></dl>
<dl class="command">
<dt id="command:fortrancinterface_verify">
<code class="descname">FortranCInterface_VERIFY</code><a class="headerlink" href="#command:fortrancinterface_verify" title="Permalink to this definition"></a></dt>
<dd><p>The <code class="docutils literal"><span class="pre">FortranCInterface_VERIFY</span></code> function is provided to verify
that the Fortran and C/C++ compilers work together:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">FortranCInterface_VERIFY</span><span class="p">([</span><span class="n">CXX</span><span class="p">]</span> <span class="p">[</span><span class="n">QUIET</span><span class="p">])</span>
</pre></div>
</div>
<p>It tests whether a simple test executable using Fortran and C (and C++
when the CXX option is given) compiles and links successfully. The
result is stored in the cache entry <code class="docutils literal"><span class="pre">FortranCInterface_VERIFIED_C</span></code>
(or <code class="docutils literal"><span class="pre">FortranCInterface_VERIFIED_CXX</span></code> if <code class="docutils literal"><span class="pre">CXX</span></code> is given) as a boolean.
If the check fails and <code class="docutils literal"><span class="pre">QUIET</span></code> is not given the function terminates with a
fatal error message describing the problem. The purpose of this check
is to stop a build early for incompatible compiler combinations. The
test is built in the <code class="docutils literal"><span class="pre">Release</span></code> configuration.</p>
</dd></dl>
</div>
<div class="section" id="example-usage">
<h2>Example Usage<a class="headerlink" href="#example-usage" title="Permalink to this headline"></a></h2>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">include</span><span class="p">(</span><span class="s">FortranCInterface</span><span class="p">)</span>
<span class="nb">FortranCInterface_HEADER</span><span class="p">(</span><span class="s">FC.h</span> <span class="s">MACRO_NAMESPACE</span> <span class="s2">&quot;FC_&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>This creates a &#8220;FC.h&#8221; header that defines mangling macros <code class="docutils literal"><span class="pre">FC_GLOBAL()</span></code>,
<code class="docutils literal"><span class="pre">FC_GLOBAL_()</span></code>, <code class="docutils literal"><span class="pre">FC_MODULE()</span></code>, and <code class="docutils literal"><span class="pre">FC_MODULE_()</span></code>.</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">include</span><span class="p">(</span><span class="s">FortranCInterface</span><span class="p">)</span>
<span class="nb">FortranCInterface_HEADER</span><span class="p">(</span><span class="s">FCMangle.h</span>
<span class="s">MACRO_NAMESPACE</span> <span class="s2">&quot;FC_&quot;</span>
<span class="s">SYMBOL_NAMESPACE</span> <span class="s2">&quot;FC_&quot;</span>
<span class="s">SYMBOLS</span> <span class="s">mysub</span> <span class="s">mymod:my_sub</span><span class="p">)</span>
</pre></div>
</div>
<p>This creates a &#8220;FCMangle.h&#8221; header that defines the same <code class="docutils literal"><span class="pre">FC_*()</span></code>
mangling macros as the previous example plus preprocessor symbols
<code class="docutils literal"><span class="pre">FC_mysub</span></code> and <code class="docutils literal"><span class="pre">FC_mymod_my_sub</span></code>.</p>
</div>
<div class="section" id="additional-manglings">
<h2>Additional Manglings<a class="headerlink" href="#additional-manglings" title="Permalink to this headline"></a></h2>
<p>FortranCInterface is aware of possible <code class="docutils literal"><span class="pre">GLOBAL</span></code> and <code class="docutils literal"><span class="pre">MODULE</span></code> manglings
for many Fortran compilers, but it also provides an interface to specify
new possible manglings. Set the variables:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">FortranCInterface_GLOBAL_SYMBOLS</span>
<span class="n">FortranCInterface_MODULE_SYMBOLS</span>
</pre></div>
</div>
<p>before including FortranCInterface to specify manglings of the symbols
<code class="docutils literal"><span class="pre">MySub</span></code>, <code class="docutils literal"><span class="pre">My_Sub</span></code>, <code class="docutils literal"><span class="pre">MyModule:MySub</span></code>, and <code class="docutils literal"><span class="pre">My_Module:My_Sub</span></code>.
For example, the code:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">set</span><span class="p">(</span><span class="s">FortranCInterface_GLOBAL_SYMBOLS</span> <span class="s">mysub_</span> <span class="s">my_sub__</span> <span class="s">MYSUB_</span><span class="p">)</span>
<span class="c"># ^^^^^ ^^^^^^ ^^^^^</span>
<span class="nb">set</span><span class="p">(</span><span class="s">FortranCInterface_MODULE_SYMBOLS</span>
<span class="s">__mymodule_MOD_mysub</span> <span class="s">__my_module_MOD_my_sub</span><span class="p">)</span>
<span class="c"># ^^^^^^^^ ^^^^^ ^^^^^^^^^ ^^^^^^</span>
<span class="nb">include</span><span class="p">(</span><span class="s">FortranCInterface</span><span class="p">)</span>
</pre></div>
</div>
<p>tells FortranCInterface to try given <code class="docutils literal"><span class="pre">GLOBAL</span></code> and <code class="docutils literal"><span class="pre">MODULE</span></code> manglings.
(The carets point at raw symbol names for clarity in this example but
are not needed.)</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="#">FortranCInterface</a><ul>
<li><a class="reference internal" href="#module-variables">Module Variables</a></li>
<li><a class="reference internal" href="#module-functions">Module Functions</a></li>
<li><a class="reference internal" href="#example-usage">Example Usage</a></li>
<li><a class="reference internal" href="#additional-manglings">Additional Manglings</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="FindZLIB.html"
title="previous chapter">FindZLIB</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="GenerateExportHeader.html"
title="next chapter">GenerateExportHeader</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/module/FortranCInterface.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="GenerateExportHeader.html" title="GenerateExportHeader"
>next</a> |</li>
<li class="right" >
<a href="FindZLIB.html" title="FindZLIB"
>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-modules.7.html" >cmake-modules(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>