blob: 507c1419b54994e2faa5c12abd8ed10a4e61337f [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>FindGTest &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="FindGTK2" href="FindGTK2.html" />
<link rel="prev" title="FindGSL" href="FindGSL.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="FindGTK2.html" title="FindGTK2"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="FindGSL.html" title="FindGSL"
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="findgtest">
<span id="module:FindGTest"></span><h1>FindGTest<a class="headerlink" href="#findgtest" title="Permalink to this headline"></a></h1>
<p>Locate the Google C++ Testing Framework.</p>
<div class="section" id="imported-targets">
<h2>Imported targets<a class="headerlink" href="#imported-targets" title="Permalink to this headline"></a></h2>
<p>This module defines the following <span class="target" id="index-0-prop_tgt:IMPORTED"></span><a class="reference internal" href="../prop_tgt/IMPORTED.html#prop_tgt:IMPORTED" title="IMPORTED"><code class="xref cmake cmake-prop_tgt docutils literal"><span class="pre">IMPORTED</span></code></a> targets:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">GTest::GTest</span></code></dt>
<dd>The Google Test <code class="docutils literal"><span class="pre">gtest</span></code> library, if found; adds Thread::Thread
automatically</dd>
<dt><code class="docutils literal"><span class="pre">GTest::Main</span></code></dt>
<dd>The Google Test <code class="docutils literal"><span class="pre">gtest_main</span></code> library, if found</dd>
</dl>
</div>
<div class="section" id="result-variables">
<h2>Result variables<a class="headerlink" href="#result-variables" title="Permalink to this headline"></a></h2>
<p>This module will set the following variables in your project:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">GTEST_FOUND</span></code></dt>
<dd>Found the Google Testing framework</dd>
<dt><code class="docutils literal"><span class="pre">GTEST_INCLUDE_DIRS</span></code></dt>
<dd>the directory containing the Google Test headers</dd>
</dl>
<p>The library variables below are set as normal variables. These
contain debug/optimized keywords when a debugging library is found.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">GTEST_LIBRARIES</span></code></dt>
<dd>The Google Test <code class="docutils literal"><span class="pre">gtest</span></code> library; note it also requires linking
with an appropriate thread library</dd>
<dt><code class="docutils literal"><span class="pre">GTEST_MAIN_LIBRARIES</span></code></dt>
<dd>The Google Test <code class="docutils literal"><span class="pre">gtest_main</span></code> library</dd>
<dt><code class="docutils literal"><span class="pre">GTEST_BOTH_LIBRARIES</span></code></dt>
<dd>Both <code class="docutils literal"><span class="pre">gtest</span></code> and <code class="docutils literal"><span class="pre">gtest_main</span></code></dd>
</dl>
</div>
<div class="section" id="cache-variables">
<h2>Cache variables<a class="headerlink" href="#cache-variables" title="Permalink to this headline"></a></h2>
<p>The following cache variables may also be set:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">GTEST_ROOT</span></code></dt>
<dd>The root directory of the Google Test installation (may also be
set as an environment variable)</dd>
<dt><code class="docutils literal"><span class="pre">GTEST_MSVC_SEARCH</span></code></dt>
<dd>If compiling with MSVC, this variable can be set to <code class="docutils literal"><span class="pre">MT</span></code> or
<code class="docutils literal"><span class="pre">MD</span></code> (the default) to enable searching a GTest build tree</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-default"><div class="highlight"><pre><span></span><span class="n">enable_testing</span><span class="p">()</span>
<span class="n">find_package</span><span class="p">(</span><span class="n">GTest</span> <span class="n">REQUIRED</span><span class="p">)</span>
<span class="n">add_executable</span><span class="p">(</span><span class="n">foo</span> <span class="n">foo</span><span class="o">.</span><span class="n">cc</span><span class="p">)</span>
<span class="n">target_link_libraries</span><span class="p">(</span><span class="n">foo</span> <span class="n">GTest</span><span class="p">::</span><span class="n">GTest</span> <span class="n">GTest</span><span class="p">::</span><span class="n">Main</span><span class="p">)</span>
<span class="n">add_test</span><span class="p">(</span><span class="n">AllTestsInFoo</span> <span class="n">foo</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="deeper-integration-with-ctest">
<h2>Deeper integration with CTest<a class="headerlink" href="#deeper-integration-with-ctest" title="Permalink to this headline"></a></h2>
<p>If you would like each Google test to show up in CTest as a test you
may use the following macro:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">GTEST_ADD_TESTS</span><span class="p">(</span><span class="n">executable</span> <span class="n">extra_args</span> <span class="n">files</span><span class="o">...</span><span class="p">)</span>
</pre></div>
</div>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">executable</span></code></dt>
<dd>the path to the test executable</dd>
<dt><code class="docutils literal"><span class="pre">extra_args</span></code></dt>
<dd>a list of extra arguments to be passed to executable enclosed in
quotes (or <code class="docutils literal"><span class="pre">&quot;&quot;</span></code> for none)</dd>
<dt><code class="docutils literal"><span class="pre">files...</span></code></dt>
<dd>a list of source files to search for tests and test fixtures. Or
<code class="docutils literal"><span class="pre">AUTO</span></code> to find them from executable target</dd>
</dl>
<p>However, note that this macro will slow down your tests by running
an executable for each test and test fixture.</p>
<p>Example usage:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nb">set</span><span class="p">(</span><span class="n">FooTestArgs</span> <span class="o">--</span><span class="n">foo</span> <span class="mi">1</span> <span class="o">--</span><span class="n">bar</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">add_executable</span><span class="p">(</span><span class="n">FooTest</span> <span class="n">FooUnitTest</span><span class="o">.</span><span class="n">cc</span><span class="p">)</span>
<span class="n">GTEST_ADD_TESTS</span><span class="p">(</span><span class="n">FooTest</span> <span class="s2">&quot;$</span><span class="si">{FooTestArgs}</span><span class="s2">&quot;</span> <span class="n">AUTO</span><span class="p">)</span>
</pre></div>
</div>
</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="#">FindGTest</a><ul>
<li><a class="reference internal" href="#imported-targets">Imported targets</a></li>
<li><a class="reference internal" href="#result-variables">Result variables</a></li>
<li><a class="reference internal" href="#cache-variables">Cache variables</a></li>
<li><a class="reference internal" href="#example-usage">Example usage</a></li>
<li><a class="reference internal" href="#deeper-integration-with-ctest">Deeper integration with CTest</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="FindGSL.html"
title="previous chapter">FindGSL</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="FindGTK2.html"
title="next chapter">FindGTK2</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/module/FindGTest.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="FindGTK2.html" title="FindGTK2"
>next</a> |</li>
<li class="right" >
<a href="FindGSL.html" title="FindGSL"
>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>