{"id":13,"date":"2013-03-28T19:28:39","date_gmt":"2013-03-29T00:28:39","guid":{"rendered":"https:\/\/104.236.124.184\/cmake-tutorial-1-getting-started.html"},"modified":"2013-03-28T19:28:39","modified_gmt":"2013-03-29T00:28:39","slug":"cmake-tutorial-1-getting-started","status":"publish","type":"post","link":"https:\/\/www.johnlamp.net\/?p=13","title":{"rendered":"CMake Tutorial &#8211; Chapter&#160;1: Getting Started"},"content":{"rendered":"<nav class=\"contents\">\n<h1>Contents<\/h1>\n<ol>\n<li><a href=\"#section-Introduction\">Introduction<\/a><\/li>\n<li><a href=\"#section-Installation\">Installation<\/a><\/li>\n<li>\n<ol>\n<li><a href=\"#section-Windows\">Windows<\/a><\/li>\n<li>\n<ol>\n<li><a href=\"#section-DownloadAndInstall\">Download and Install<\/a><\/li>\n<li><a href=\"#section-Cygwin\">Cygwin<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"#section-MacOsX\">Mac OS X<\/a><\/li>\n<li>\n<ol>\n<li><a href=\"#DownloadAndInstall1\">Download and Install<\/a><\/li>\n<li><a href=\"#section-Homebrew\">Homebrew<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"#section-Linux\">Linux<\/a><\/li>\n<li>\n<ol>\n<li><a href=\"#section-Ubuntu(Debian)\">Ubuntu (Debian)<\/a><\/li>\n<li><a href=\"#section-RedHat\/Centos\">Red Hat<span class=\"subtle\">\/<\/span>CentOS<\/a><\/li>\n<li><a href=\"#section-Fedora\">Fedora<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"#section-Source\">Source<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"#section-HandsOn\">Hands On<\/a><\/li>\n<li>\n<ol>\n<li><a href=\"#section-DivingIn\">Diving In<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"#section-SimpleImprovements\">Simple Improvements<\/a><\/li>\n<\/ol>\n<\/nav>\n<section>\n<h1 id=\"section-Introduction\">Introduction<\/h1>\n<p>\n    In this chapter we start by installing CMake. Like most open source software<br \/>\n    the best way to do this depends on your platform and how you usually do<br \/>\n    things. Once we have CMake installed we create a simple project. Perhaps<br \/>\n    it&#8217;s a little fancier than &#8220;hello world&#8221; but not much. We finish up with the<br \/>\n    test support built into CMake.\n  <\/p>\n<p>\n    I won&#8217;t cover any particular aspect of CMake in great detail yet. That will<br \/>\n    be left for future chapters. However, after this chapter you will know<br \/>\n    enough to build simple programs with CMake and run simple tests with CTest.\n  <\/p>\n<\/section>\n<section>\n<h1 id=\"section-Installation\">Installation<\/h1>\n<h2 id=\"section-Windows\">Windows<\/h2>\n<section>\n<h3 id=\"section-DownloadAndInstall\">Download and Install<\/h3>\n<p>\n      Download the installer from the CMake<br \/>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/resources\/software.html\">website<\/a>      <time class=\"access\">(2012-06-02)<\/time>. Run the installer and follow its<br \/>\n      steps. Be sure to add CMake to the system <code>PATH<\/code> so that you<br \/>\n      can use it from the command line. Add it for the current or all users as<br \/>\n      appropriate.\n    <\/p>\n<p>\n      This provides both the <code>cmake<\/code> command and the CMake GUI<br \/>\n      <span class=\"subtle\">(<code>cmake-gui<\/code>)<\/span> but not the curses<br \/>\n      interface<br \/>\n      <span class=\"subtle\">(<code>ccmake<\/code>)<\/span>.\n    <\/p>\n<h3 id=\"section-Cygwin\">Cygwin<\/h3>\n<p>\n      CMake can, of course, be installed as part of Cygwin. Even if you don&#8217;t<br \/>\n      already have Cygwin installed you may want to as it provides a Linux-like<br \/>\n      environment natively in Windows. This way common Linux tools and utilities<br \/>\n      can be available. Also most of this tutorial is done in a Linux-like<br \/>\n      environment, so with Cygwin installed it will be easier to follow along.\n    <\/p>\n<p>\n      Download Cygwin&#8217;s <code>setup.exe<\/code> from<br \/>\n      <a href=\"http:\/\/www.cygwin.com\/install.html\">their website<\/a>      <time class=\"access\">(2012-06-02)<\/time>. Run<br \/>\n      <code>setup.exe<\/code>. Follow its steps until you can select packages,<br \/>\n      then either chose to install all packages or just CMake. To install all<br \/>\n      packages click the word &#8220;Default&#8221; next to &#8220;All&#8221; until it reads<br \/>\n      &#8220;Install&#8221;. If you don&#8217;t want to install everything click the word<br \/>\n      &#8220;Default&#8221; next to &#8220;Devel&#8221; until it reads &#8220;Install&#8221;; this will install just<br \/>\n      the development tools. If you chose to install all packages the install<br \/>\n      will take a a few hours, but even just installing the development tools<br \/>\n      will take at least half an hour. After the installer has finished the<br \/>\n      Cygwin environment can then be accessed via the <code>Cygwin<br \/>\n      Terminal<\/code> which can be found in the Start Menu.\n    <\/p>\n<p>\n      This provides the <code>cmake<\/code> command and the curses<br \/>\n      interface <span class=\"subtle\">(<code>ccmake<\/code>)<\/span> but not the<br \/>\n      CMake GUI.\n    <\/p>\n<\/section>\n<h2 id=\"section-MacOsX\">Mac OS X<\/h2>\n<section>\n<h3 id=\"DownloadAndInstall1\">Download and Install<\/h3>\n<p>\n      Download the disk image from the CMake<br \/>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/resources\/software.html\">website<\/a>      <time class=\"access\">(2012-06-02)<\/time>. Pick the correct download for<br \/>\n      whichever version of OS X you are using. Use the installer and follow its<br \/>\n      directions. It will ask if you want it to make the command line tools<br \/>\n      available in your path by creating symbolic links, have it do so.\n    <\/p>\n<p>\n      This provides the <code>cmake<\/code> command, the CMake GUI<br \/>\n      <span class=\"subtle\">(<code>CMake.app<\/code>)<\/span>, and the curses<br \/>\n      interface<br \/>\n      <span class=\"subtle\">(<code>ccmake<\/code>)<\/span>.\n    <\/p>\n<h3 id=\"section-Homebrew\">Homebrew<\/h3>\n<p>\n      If you already have homebrew installed you can simply install CMake with<br \/>\n      the command <kbd>brew install cmake<\/kbd>.\n    <\/p>\n<p>\n      This provides the <code>cmake<\/code> command and the curses interface<br \/>\n      <span class=\"subtle\">(<code>ccmake<\/code>)<\/span> but <b>not<\/b> the<br \/>\n      CMake GUI.\n    <\/p>\n<\/section>\n<h2 id=\"section-Linux\">Linux<\/h2>\n<section>\n<h3 id=\"section-Ubuntu(Debian)\">Ubuntu (Debian)<\/h3>\n<p>\n      The simplest way to install CMake is via the command line: <kbd>sudo<br \/>\n        apt-get install cmake<\/kbd>. However, searching for CMake in the Ubuntu<br \/>\n        Software Center or in the Synaptic Package Manager, depending upon your<br \/>\n        Ubuntu version, will find the <code>cmake<\/code> package. If your Ubuntu<br \/>\n        install doesn&#8217;t include X or you primarily use ssh sessions you will<br \/>\n        also want to install the <code>cmake-curses-gui<\/code> package. Again<br \/>\n        this is simplest with the command <kbd>sudo apt-get install<br \/>\n        cmake-curses-gui<\/kbd>, but either GUI interface can be used instead.\n    <\/p>\n<p>\n      This provides the <code>cmake<\/code> command and the CMake GUI<br \/>\n      <span class=\"subtle\">(<code>cmake-gui<\/code>)<\/span>. The second,<br \/>\n      optional, package provides the curses<br \/>\n      interface <span class=\"subtle\">(<code>ccmake<\/code>)<\/span>.\n    <\/p>\n<h3 id=\"section-RedHat\/Centos\">Red Hat<span class=\"subtle\">\/<\/span>CentOS<\/h3>\n<p>\n      To install CMake via the command line is straightforward. First<br \/>\n      use <kbd>yum search cmake<\/kbd> to find the correct package to install. On<br \/>\n      a 64 bit install it would be <code>cmake.x86_64<\/code>. Use whichever<br \/>\n      package your search found when installing: <kbd>sudo yum<br \/>\n      install <span class=\"arg\">cmake.x86_64<\/span><\/kbd>. If <code>sudo<\/code><br \/>\n      is not setup use <kbd>su<\/kbd> first and then run <kbd>yum<br \/>\n      install <span class=\"arg\">cmake.x86_64<\/span><\/kbd>.\n    <\/p>\n<p>\n      This provides the <code>cmake<\/code> command and the curses<br \/>\n      interface <span class=\"subtle\">(<code>ccmake<\/code>)<\/span>, but not the<br \/>\n      CMake GUI.\n    <\/p>\n<h3 id=\"section-Fedora\">Fedora<\/h3>\n<p>\n      Either the command line or the Add\/Remove Software GUI can be used. In the<br \/>\n      GUI simply search for cmake and install at least the <code>cmake<\/code><br \/>\n      module. If you desire the CMake GUI as well install<br \/>\n      the <code>cmake-gui<\/code> module. From the command line use <kbd>sudo yum<br \/>\n      install cmake<\/kbd> and <kbd>sudo yum install cmake-gui<\/kbd>, if you<br \/>\n      desire the GUI as well.\n    <\/p>\n<p>\n      This provides the <code>cmake<\/code> command and the curses<br \/>\n      interface <span class=\"subtle\">(<code>ccmake<\/code>)<\/span>. The second,<br \/>\n      optional, package provides the CMake<br \/>\n      GUI <span class=\"subtle\">(<code>cmake-gui<\/code>)<\/span>.\n    <\/p>\n<\/section>\n<h2 id=\"section-Source\">Source<\/h2>\n<section>\n<p>\n      As CMake is an open source tool you can, of course, download the source<br \/>\n      code and build it yourself. However, that is outside the scope of this<br \/>\n      tutorial.\n    <\/p>\n<\/section>\n<\/section>\n<section>\n<h1 id=\"section-HandsOn\">Hands On<\/h1>\n<p>\n    For this tutorial we will create a To Do List program. Naturally our focus<br \/>\n    will be on CMake more than the actual code and its functionality. Most<br \/>\n    examples will be done using the command line generating Makefiles. CMake can<br \/>\n    be used with a GUI<br \/>\n    (<a href=\"https:\/\/www.johnlamp.net\/cmake-tutorial-3-gui-tool.html\">chapter 3<\/a>)    and also generate projects for many IDEs<br \/>\n    (<a href=\"https:\/\/www.johnlamp.net\/cmake-tutorial-2-ide-integration.html\">chapter 2<\/a>).  <\/p>\n<h2 id=\"section-DivingIn\">Diving In<\/h2>\n<p>\n    Just as any IDE has project files or Make has Makefiles CMake<br \/>\n    has <code>CmakeLists.txt<\/code> files. These describe your project to CMake<br \/>\n    and affect its output. They are fairly simple especially compared to<br \/>\n    Makefiles. Here&#8217;s our first <code>CMakelists.txt<\/code>:\n  <\/p>\n<section class=\"code cmake\">\n<header class=\"clear-after\">\n<h1>CMakeLists.txt<\/h1>\n<\/header>\n<div class=\"highlight\">\n<pre><a id=\"CMakeLists.txt-1\" class=\"line-number\" href=\"#CMakeLists.txt-1\"><\/a><span class=\"nb\">project<\/span><span class=\"p\">(<\/span><span class=\"s2\">&quot;To Do List&quot;<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-2\" class=\"line-number\" href=\"#CMakeLists.txt-2\"><\/a>\n<a id=\"CMakeLists.txt-3\" class=\"line-number\" href=\"#CMakeLists.txt-3\"><\/a>\n<a id=\"CMakeLists.txt-4\" class=\"line-number\" href=\"#CMakeLists.txt-4\"><\/a><span class=\"nb\">add_executable<\/span><span class=\"p\">(<\/span><span class=\"s\">toDo<\/span> <span class=\"s\">main.cc<\/span>\n<a id=\"CMakeLists.txt-5\" class=\"line-number\" href=\"#CMakeLists.txt-5\"><\/a>                    <span class=\"s\">ToDo.cc<\/span><span class=\"p\">)<\/span>\n<\/pre>\n<\/div>\n<\/section>\n<dl>\n<dt class=\"code\">project(<span class=\"arg\">name<\/span>)<\/dt>\n<dd>\n      The <code>project<\/code> command names your project. Optionally you can<br \/>\n      specify what language the project supports, any<br \/>\n      of <code>CXX<\/code>, <code>C<\/code>, <code>JAVA<\/code>,<br \/>\n      or <code>FORTRAN<\/code>. CMake defaults to <code>C<\/code><br \/>\n      and <code>CXX<\/code> so if you do not have compilers for C++ installed you<br \/>\n      may need to specify the language supported so that CMake doesn&#8217;t search<br \/>\n      for it.\n    <\/dd>\n<dd class=\"note\">\n      <em class=\"call-out\">Note:<\/em> If your project name contains spaces it<br \/>\n      must be surrounded by quotes.\n    <\/dd>\n<dd>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#command:project\">project() documentation<\/a>      <time class=\"access\">(2013-03-26)<\/time>\n    <\/dd>\n<dt class=\"code\">\n      add_executable(<span class=\"arg\">target<\/span><br \/>\n      <span class=\"arg\">sources&hellip;<\/span>)\n    <\/dt>\n<dd>\n      This command tells CMake you want to make an executable and adds it as a<br \/>\n      target. The first argument is the name of the executable and the rest are<br \/>\n      the source files. You may notice that header files aren&#8217;t listed. CMake<br \/>\n      handles dependencies automatically so headers don&#8217;t need to be listed.\n    <\/dd>\n<dd>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#command:add_executable\">add_executable() documentation<\/a>      <time class=\"access\">(2013-03-26)<\/time>\n    <\/dd>\n<\/dl>\n<p>\n    Of course we need some source code to build, so we will start with the<br \/>\n    simplest skeleton possible:\n  <\/p>\n<section class=\"code\">\n<header class=\"clear-after\">\n<h1>main.cc<\/h1>\n<\/header>\n<div class=\"highlight\">\n<pre><a id=\"main.cc-1\" class=\"line-number\" href=\"#main.cc-1\"><\/a><span class=\"cp\">#include &quot;ToDo.h&quot;<\/span>\n<a id=\"main.cc-2\" class=\"line-number\" href=\"#main.cc-2\"><\/a>\n<a id=\"main.cc-3\" class=\"line-number\" href=\"#main.cc-3\"><\/a><span class=\"kt\">int<\/span> <span class=\"nf\">main<\/span><span class=\"p\">(<\/span>\n<a id=\"main.cc-4\" class=\"line-number\" href=\"#main.cc-4\"><\/a>    <span class=\"kt\">int<\/span>    <span class=\"n\">argc<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-5\" class=\"line-number\" href=\"#main.cc-5\"><\/a>    <span class=\"kt\">char<\/span><span class=\"o\">**<\/span> <span class=\"n\">argv<\/span>\n<a id=\"main.cc-6\" class=\"line-number\" href=\"#main.cc-6\"><\/a><span class=\"p\">)<\/span>\n<a id=\"main.cc-7\" class=\"line-number\" href=\"#main.cc-7\"><\/a><span class=\"p\">{<\/span>\n<a id=\"main.cc-8\" class=\"line-number\" href=\"#main.cc-8\"><\/a>    <span class=\"n\">ToDo<\/span> <span class=\"n\">list<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-9\" class=\"line-number\" href=\"#main.cc-9\"><\/a>\n<a id=\"main.cc-10\" class=\"line-number\" href=\"#main.cc-10\"><\/a>    <span class=\"k\">return<\/span> <span class=\"mi\">0<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-11\" class=\"line-number\" href=\"#main.cc-11\"><\/a><span class=\"p\">}<\/span>\n<\/pre>\n<\/div>\n<\/section>\n<section class=\"code\">\n<header class=\"clear-after\">\n<h1>ToDo.h<\/h1>\n<\/header>\n<div class=\"highlight\">\n<pre><a id=\"ToDo.h-1\" class=\"line-number\" href=\"#ToDo.h-1\"><\/a><span class=\"cp\">#ifndef TODO_H<\/span>\n<a id=\"ToDo.h-2\" class=\"line-number\" href=\"#ToDo.h-2\"><\/a><span class=\"cp\">#define TODO_H<\/span>\n<a id=\"ToDo.h-3\" class=\"line-number\" href=\"#ToDo.h-3\"><\/a>\n<a id=\"ToDo.h-4\" class=\"line-number\" href=\"#ToDo.h-4\"><\/a><span class=\"n\">class<\/span> <span class=\"n\">ToDo<\/span>\n<a id=\"ToDo.h-5\" class=\"line-number\" href=\"#ToDo.h-5\"><\/a><span class=\"p\">{<\/span>\n<a id=\"ToDo.h-6\" class=\"line-number\" href=\"#ToDo.h-6\"><\/a><span class=\"nl\">public:<\/span>\n<a id=\"ToDo.h-7\" class=\"line-number\" href=\"#ToDo.h-7\"><\/a>    <span class=\"n\">ToDo<\/span><span class=\"p\">();<\/span>\n<a id=\"ToDo.h-8\" class=\"line-number\" href=\"#ToDo.h-8\"><\/a>    <span class=\"o\">~<\/span><span class=\"n\">ToDo<\/span><span class=\"p\">();<\/span>\n<a id=\"ToDo.h-9\" class=\"line-number\" href=\"#ToDo.h-9\"><\/a><span class=\"p\">};<\/span>\n<a id=\"ToDo.h-10\" class=\"line-number\" href=\"#ToDo.h-10\"><\/a>\n<a id=\"ToDo.h-11\" class=\"line-number\" href=\"#ToDo.h-11\"><\/a><span class=\"cp\">#endif <\/span><span class=\"c1\">\/\/ TODO_H<\/span>\n<\/pre>\n<\/div>\n<\/section>\n<section class=\"code\">\n<header class=\"clear-after\">\n<h1>ToDo.cc<\/h1>\n<\/header>\n<div class=\"highlight\">\n<pre><a id=\"ToDo.cc-1\" class=\"line-number\" href=\"#ToDo.cc-1\"><\/a><span class=\"cp\">#include &quot;ToDo.h&quot;<\/span>\n<a id=\"ToDo.cc-2\" class=\"line-number\" href=\"#ToDo.cc-2\"><\/a>\n<a id=\"ToDo.cc-3\" class=\"line-number\" href=\"#ToDo.cc-3\"><\/a>\n<a id=\"ToDo.cc-4\" class=\"line-number\" href=\"#ToDo.cc-4\"><\/a><span class=\"n\">ToDo<\/span><span class=\"o\">::<\/span><span class=\"n\">ToDo<\/span><span class=\"p\">()<\/span>\n<a id=\"ToDo.cc-5\" class=\"line-number\" href=\"#ToDo.cc-5\"><\/a><span class=\"p\">{<\/span>\n<a id=\"ToDo.cc-6\" class=\"line-number\" href=\"#ToDo.cc-6\"><\/a><span class=\"p\">}<\/span>\n<a id=\"ToDo.cc-7\" class=\"line-number\" href=\"#ToDo.cc-7\"><\/a>\n<a id=\"ToDo.cc-8\" class=\"line-number\" href=\"#ToDo.cc-8\"><\/a><span class=\"n\">ToDo<\/span><span class=\"o\">::~<\/span><span class=\"n\">ToDo<\/span><span class=\"p\">()<\/span>\n<a id=\"ToDo.cc-9\" class=\"line-number\" href=\"#ToDo.cc-9\"><\/a><span class=\"p\">{<\/span>\n<a id=\"ToDo.cc-10\" class=\"line-number\" href=\"#ToDo.cc-10\"><\/a><span class=\"p\">}<\/span>\n<\/pre>\n<\/div>\n<\/section>\n<p>\n    <a class=\"sources\" href=\"https:\/\/www.johnlamp.net\/sources\/chapter1-1.zip\"><img src=\"https:\/\/www.johnlamp.net\/images\/zip.png\" alt=\"[zip file] \" \/>Source<\/a>  <\/p>\n<p>\n    CMake&#8217;s documentation strongly suggests that out-of-source builds be done<br \/>\n    rather than in-source builds. I agree as it makes it much easier to convince<br \/>\n    yourself that your build has really been cleaned since you can simply delete<br \/>\n    the build folder and start over. Building with CMake is actually rather<br \/>\n    simple, so we will charge ahead:\n  <\/p>\n<section id=\"Step1Output\" class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> mkdir build\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd build\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cmake -G &quot;Unix Makefiles&quot; ..\n-- The C compiler identification is GNU 4.2.1\n-- The CXX compiler identification is GNU 4.2.1\n-- Checking whether C compiler has -isysroot\n-- Checking whether C compiler has -isysroot - yes\n-- Checking whether C compiler supports OSX deployment target flag\n-- Checking whether C compiler supports OSX deployment target flag - yes\n-- Check for working C compiler: \/usr\/bin\/gcc\n-- Check for working C compiler: \/usr\/bin\/gcc -- works\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - done\n-- Checking whether CXX compiler has -isysroot\n-- Checking whether CXX compiler has -isysroot - yes\n-- Checking whether CXX compiler supports OSX deployment target flag\n-- Checking whether CXX compiler supports OSX deployment target flag - yes\n-- Check for working CXX compiler: \/usr\/bin\/c++\n-- Check for working CXX compiler: \/usr\/bin\/c++ -- works\n-- Detecting CXX compiler ABI info\n-- Detecting CXX compiler ABI info - done\n-- Configuring done\n-- Generating done\n-- Build files have been written to: \/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> ls\nCMakeCache.txt\t\tMakefile\nCMakeFiles\t\tcmake_install.cmake\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> make\n<span class=\"ansiBold ansiForeground-magenta\">Scanning dependencies of target toDo\n<\/span>[ 50%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/main.cc.o\n<\/span>[100%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/ToDo.cc.o\n<\/span><span class=\"ansiBold ansiForeground-red\">Linking CXX executable toDo\n<\/span>[100%] Built target toDo\n<\/pre>\n<\/section>\n<p>\n    <em>Note:<\/em> If you are using Cygwin you may see a warning. Don&#8217;t worry<br \/>\n    about it, we will take care of that shortly.\n  <\/p>\n<dl>\n<dt><kbd>mkdir build<\/kbd><\/dt>\n<dd>\n      Create the directory in which to build our application. In this example it<br \/>\n      is a subdirectory of our source directory, but it could be anywhere. With<br \/>\n      our build happening outside of the source tree we can easily clean up by<br \/>\n      simply removing the build directory.\n    <\/dd>\n<dt><kbd>cd build<\/kbd><\/dt>\n<dd>\n      Change into the build directory to work from there.\n    <\/dd>\n<dt><kbd>cmake -G \"Unix Makefiles\" ..<\/kbd><\/dt>\n<dd>\n      Use CMake to setup a build using Unix Makefiles.<\/p>\n<dl>\n<dt class=\"code\">\n          -G <span class=\"arg\">&lt;generator name&gt;<\/span>\n        <\/dt>\n<dd>\n          This allows us to tell CMake what kind of project file it should<br \/>\n          generate. In this example I wanted to use a Makefile.  Which<br \/>\n          generators are available depends on your platform, use <kbd>cmake<br \/>\n          --help<\/kbd> to list them. Other generators will be covered in the<br \/>\n          <a href=\"https:\/\/www.johnlamp.net\/cmake-tutorial-2-ide-integration.html\">next chapter<\/a>.        <\/dd>\n<dt class=\"code arg\">&lt;path to source&gt;<\/dt>\n<dd>\n          The path to the source code. When doing out-of-source builds as is<br \/>\n          recommended the source code could be anywhere relative to the build<br \/>\n          directory. This path should be to the directory containing your top<br \/>\n          level <code>CMakeLists.txt<\/code>. In this example the source is in<br \/>\n          the parent directory so the path is &#8216;<code>..<\/code>&#8216;.\n        <\/dd>\n<\/dl>\n<\/dd>\n<dt><kbd>ls<\/kbd><\/dt>\n<dd>\n      CMake generates several files which should not be edited by<br \/>\n      hand. <code>Makefile<\/code> is the most important one to us as we use it<br \/>\n      to build our project. <code>CMakeCache.txt<\/code> is important to CMake as<br \/>\n      it stores a variety of information and settings for the project. Again you<br \/>\n      shouldn&#8217;t touch this, however if unexpected problems arise this file<br \/>\n      probably is the cause; the best option then is to delete your build folder<br \/>\n      and have CMake regenerate.\n    <\/dd>\n<dt><kbd>make<\/kbd><\/dt>\n<dd>\n      Run <code>make<\/code> to build our target executable. Since we chose &#8220;Unix<br \/>\n      Makefiles&#8221; as our generator CMake created a Makefile for us.\n    <\/dd>\n<\/dl>\n<p>\n    CMake does all the hard work of making sure your environment has everything<br \/>\n    you need and sets up a project file, in this case a Makefile. You will<br \/>\n    notice that the Makefile created by CMake is quite fancy and has nice color<br \/>\n    output. If you are used to Make you will notice that this Makefile<br \/>\n    suppresses the standard output. While this provides a neater and cleaner<br \/>\n    experience it can make debugging more difficult as you can&#8217;t check the flags<br \/>\n    passed to the compiler, etc. Before you start worrying you can get all of<br \/>\n    that output by running <kbd>make VERBOSE=1<\/kbd>.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd build\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> make VERBOSE=1\n\/usr\/local\/Cellar\/cmake\/2.8.8\/bin\/cmake -H&quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1&quot; -B&quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build&quot; --check-build-system CMakeFiles\/Makefile.cmake 0\n\/usr\/local\/Cellar\/cmake\/2.8.8\/bin\/cmake -E cmake_progress_start &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles&quot; &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles\/progress.marks&quot;\nmake -f CMakeFiles\/Makefile2 all\nmake -f CMakeFiles\/toDo.dir\/build.make CMakeFiles\/toDo.dir\/depend\ncd &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build&quot; &amp;&amp; \/usr\/local\/Cellar\/cmake\/2.8.8\/bin\/cmake -E cmake_depends &quot;Unix Makefiles&quot; &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1&quot; &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1&quot; &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build&quot; &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build&quot; &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles\/toDo.dir\/DependInfo.cmake&quot; --color=\nDependee &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles\/toDo.dir\/DependInfo.cmake&quot; is newer than depender &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles\/toDo.dir\/depend.internal&quot;.\nDependee &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles\/CMakeDirectoryInformation.cmake&quot; is newer than depender &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles\/toDo.dir\/depend.internal&quot;.\n<span class=\"ansiBold ansiForeground-magenta\">Scanning dependencies of target toDo\n<\/span>make -f CMakeFiles\/toDo.dir\/build.make CMakeFiles\/toDo.dir\/build\n\/usr\/local\/Cellar\/cmake\/2.8.8\/bin\/cmake -E cmake_progress_report &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles&quot; 1\n[ 50%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/main.cc.o\n<\/span>\/usr\/bin\/c++     -o CMakeFiles\/toDo.dir\/main.cc.o -c &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/main.cc&quot;\n\/usr\/local\/Cellar\/cmake\/2.8.8\/bin\/cmake -E cmake_progress_report &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles&quot; 2\n[100%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/ToDo.cc.o\n<\/span>\/usr\/bin\/c++     -o CMakeFiles\/toDo.dir\/ToDo.cc.o -c &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/ToDo.cc&quot;\n<span class=\"ansiBold ansiForeground-red\">Linking CXX executable toDo\n<\/span>\/usr\/local\/Cellar\/cmake\/2.8.8\/bin\/cmake -E cmake_link_script CMakeFiles\/toDo.dir\/link.txt --verbose=1\n\/usr\/bin\/c++    -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles\/toDo.dir\/main.cc.o CMakeFiles\/toDo.dir\/ToDo.cc.o  -o toDo\n\/usr\/local\/Cellar\/cmake\/2.8.8\/bin\/cmake -E cmake_progress_report &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles&quot;  1 2\n[100%] Built target toDo\n\/usr\/local\/Cellar\/cmake\/2.8.8\/bin\/cmake -E cmake_progress_start &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step1\/build\/CMakeFiles&quot; 0\n<\/pre>\n<\/section>\n<p>\n    You can see that the makefile created by CMake is very precise and<br \/>\n    detailed. As such if anything moves you will have to run <code>cmake<\/code><br \/>\n    again.\n  <\/p>\n<\/section>\n<section>\n<h1 id=\"section-SimpleImprovements\">Simple Improvements<\/h1>\n<section class=\"code cmake\">\n<header class=\"clear-after\">\n<h1>CMakeLists.txt<\/h1>\n<div class=\"hll legend\">New or modified lines in bold.<\/div>\n<\/header>\n<div class=\"highlight\">\n<pre><a id=\"CMakeLists.txt-1-1\" class=\"line-number\" href=\"#CMakeLists.txt-1-1\"><\/a><span class=\"hll\"><span class=\"nb\">cmake_minimum_required<\/span><span class=\"p\">(<\/span><span class=\"s\">VERSION<\/span> <span class=\"s\">2.8<\/span> <span class=\"s\">FATAL_ERROR<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-1-2\" class=\"line-number\" href=\"#CMakeLists.txt-1-2\"><\/a><span class=\"hll\"><span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">CMAKE_LEGACY_CYGWIN_WIN32<\/span> <span class=\"s\">0<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-1-3\" class=\"line-number\" href=\"#CMakeLists.txt-1-3\"><\/a><span class=\"hll\">\n<\/span><a id=\"CMakeLists.txt-1-4\" class=\"line-number\" href=\"#CMakeLists.txt-1-4\"><\/a><span class=\"nb\">project<\/span><span class=\"p\">(<\/span><span class=\"s2\">&quot;To Do List&quot;<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-1-5\" class=\"line-number\" href=\"#CMakeLists.txt-1-5\"><\/a>\n<a id=\"CMakeLists.txt-1-6\" class=\"line-number\" href=\"#CMakeLists.txt-1-6\"><\/a><span class=\"hll\"><span class=\"nb\">enable_testing<\/span><span class=\"p\">()<\/span>\n<\/span><a id=\"CMakeLists.txt-1-7\" class=\"line-number\" href=\"#CMakeLists.txt-1-7\"><\/a><span class=\"hll\">\n<\/span><a id=\"CMakeLists.txt-1-8\" class=\"line-number\" href=\"#CMakeLists.txt-1-8\"><\/a>\n<a id=\"CMakeLists.txt-1-9\" class=\"line-number\" href=\"#CMakeLists.txt-1-9\"><\/a><span class=\"nb\">add_executable<\/span><span class=\"p\">(<\/span><span class=\"s\">toDo<\/span> <span class=\"s\">main.cc<\/span>\n<a id=\"CMakeLists.txt-1-10\" class=\"line-number\" href=\"#CMakeLists.txt-1-10\"><\/a>                    <span class=\"s\">ToDo.cc<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-1-11\" class=\"line-number\" href=\"#CMakeLists.txt-1-11\"><\/a><span class=\"hll\">\n<\/span><a id=\"CMakeLists.txt-1-12\" class=\"line-number\" href=\"#CMakeLists.txt-1-12\"><\/a><span class=\"hll\"><span class=\"nb\">add_test<\/span><span class=\"p\">(<\/span><span class=\"s\">toDoTest<\/span> <span class=\"s\">toDo<\/span><span class=\"p\">)<\/span>\n<\/span><\/pre>\n<\/div>\n<\/section>\n<dl>\n<dt class=\"code\">\n      cmake_minimum_required(VERSION<br \/>\n      <span class=\"arg\">version<\/span><br \/>\n      <span class=\"optional\">FATAL_ERROR<\/span>)\n    <\/dt>\n<dd>\n      This command specifies the minimum version of CMake that can be used<br \/>\n      with <code>CMakeLists.txt<\/code> file. The first argument must<br \/>\n      be <code>VERSION<\/code> verbatim. The next is the minimum version of CMake<br \/>\n      that can be used. The last is optional, but should be included, it must<br \/>\n      be <code>FATAL_ERROR<\/code> verbatim. It is recommended that this command<br \/>\n      be used in all top level <code>CMakeLists.txt<\/code>. If you aren&#8217;t sure<br \/>\n      what version to set use the version of CMake you have installed.\n    <\/dd>\n<dd>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#command:cmake_minimum_required\">cmake_minimum_required() documentation<\/a>      <time class=\"access\">(2013-03-26)<\/time>\n    <\/dd>\n<dt class=\"code\">\n      set(CMAKE_LEGACY_CYGWIN_WIN32 0)\n    <\/dt>\n<dd>\n      This gets rid of the warning you would have seen earlier if you were using<br \/>\n      Cygwin. If you aren&#8217;t using Cygwin then it has no effect at all.\n    <\/dd>\n<dd>\n      This tells CMake not to define <code>WIN32<\/code> when building with<br \/>\n      Cygwin. This is the preferred option and for us it doesn&#8217;t make a<br \/>\n      difference either way so we will use the recommended setting.\n    <\/dd>\n<dt class=\"code\">\n      enable_testing()\n    <\/dt>\n<dd>\n      Enables testing for this CMake project. This should only be used in top<br \/>\n      level <code>CMakeLists.txt<\/code>. The main thing this does is enable<br \/>\n      the <code>add_test()<\/code> command.\n    <\/dd>\n<dd>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#command:enable_testing\">enable_testing() documentation<\/a>      <time class=\"access\">(2013-03-26)<\/time>\n    <\/dd>\n<dt class=\"code\">\n      add_test(<span class=\"arg\">testname<\/span><br \/>\n      <span class=\"arg\">executable<\/span><br \/>\n      <span class=\"arg optional\">arg1 &#8230;<\/span>)\n    <\/dt>\n<dd>\n      This command only does something if the <code>enable_testing()<\/code> has<br \/>\n      already been run, otherwise it does nothing. This adds a test to the<br \/>\n      current directory that will be run by CTest. The executable can be<br \/>\n      anything, so it could be a test program, e.g. a unit test created with<br \/>\n      something like Google Test, a script, or any other test<br \/>\n      imaginable. <em>Note:<\/em> Tests are not run automatically and if your<br \/>\n      test program is built as part of your project the test target will not<br \/>\n      ensure it is up to date. It is best to build all other targets before<br \/>\n      running the test target.\n    <\/dd>\n<dd>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#command:add_test\">add_test() documentation<\/a>      <time class=\"access\">(2013-03-26)<\/time>\n    <\/dd>\n<\/dl>\n<p>\n    Perhaps I lied. One can easily argue that introducing<br \/>\n    the <code>add_test()<\/code> command is not a simple improvement. And they<br \/>\n    would probably be right, however, it is an important improvement. Testing<br \/>\n    will be explored further later in this tutorial.\n  <\/p>\n<p>\n    Naturally we need some more code to go with this, so here goes:\n  <\/p>\n<section class=\"code\">\n<header class=\"clear-after\">\n<h1>main.cc<\/h1>\n<div class=\"hll legend\">New or modified lines in bold.<\/div>\n<\/header>\n<div class=\"highlight\">\n<pre><a id=\"main.cc-1-1\" class=\"line-number\" href=\"#main.cc-1-1\"><\/a><span class=\"hll\"><span class=\"cp\">#include &lt;iostream&gt;<\/span>\n<\/span><a id=\"main.cc-1-2\" class=\"line-number\" href=\"#main.cc-1-2\"><\/a><span class=\"hll\">  <span class=\"k\">using<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">cerr<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"main.cc-1-3\" class=\"line-number\" href=\"#main.cc-1-3\"><\/a><span class=\"hll\">  <span class=\"k\">using<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">cout<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"main.cc-1-4\" class=\"line-number\" href=\"#main.cc-1-4\"><\/a><span class=\"hll\">  <span class=\"k\">using<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">endl<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"main.cc-1-5\" class=\"line-number\" href=\"#main.cc-1-5\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-6\" class=\"line-number\" href=\"#main.cc-1-6\"><\/a><span class=\"cp\">#include &quot;ToDo.h&quot;<\/span>\n<a id=\"main.cc-1-7\" class=\"line-number\" href=\"#main.cc-1-7\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-8\" class=\"line-number\" href=\"#main.cc-1-8\"><\/a><span class=\"hll\"><span class=\"cp\">#define EXPECT_EQUAL(test, expect) equalityTest( test,  expect, \\<\/span>\n<\/span><a id=\"main.cc-1-9\" class=\"line-number\" href=\"#main.cc-1-9\"><\/a><span class=\"hll\"><span class=\"cp\">                                                #test, #expect, \\<\/span>\n<\/span><a id=\"main.cc-1-10\" class=\"line-number\" href=\"#main.cc-1-10\"><\/a><span class=\"hll\"><span class=\"cp\">                                                __FILE__, __LINE__)<\/span>\n<\/span><a id=\"main.cc-1-11\" class=\"line-number\" href=\"#main.cc-1-11\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-12\" class=\"line-number\" href=\"#main.cc-1-12\"><\/a><span class=\"hll\"><span class=\"k\">template<\/span> <span class=\"o\">&lt;<\/span> <span class=\"k\">typename<\/span> <span class=\"n\">T1<\/span><span class=\"p\">,<\/span> <span class=\"k\">typename<\/span> <span class=\"n\">T2<\/span> <span class=\"o\">&gt;<\/span>\n<\/span><a id=\"main.cc-1-13\" class=\"line-number\" href=\"#main.cc-1-13\"><\/a><span class=\"hll\"><span class=\"kt\">int<\/span> <span class=\"n\">equalityTest<\/span><span class=\"p\">(<\/span><span class=\"k\">const<\/span> <span class=\"n\">T1<\/span>    <span class=\"n\">testValue<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-1-14\" class=\"line-number\" href=\"#main.cc-1-14\"><\/a><span class=\"hll\">                 <span class=\"k\">const<\/span> <span class=\"n\">T2<\/span>    <span class=\"n\">expectedValue<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-1-15\" class=\"line-number\" href=\"#main.cc-1-15\"><\/a><span class=\"hll\">                 <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">testName<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-1-16\" class=\"line-number\" href=\"#main.cc-1-16\"><\/a><span class=\"hll\">                 <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">expectedName<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-1-17\" class=\"line-number\" href=\"#main.cc-1-17\"><\/a><span class=\"hll\">                 <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">fileName<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-1-18\" class=\"line-number\" href=\"#main.cc-1-18\"><\/a><span class=\"hll\">                 <span class=\"k\">const<\/span> <span class=\"kt\">int<\/span>   <span class=\"n\">lineNumber<\/span><span class=\"p\">);<\/span>\n<\/span><a id=\"main.cc-1-19\" class=\"line-number\" href=\"#main.cc-1-19\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-20\" class=\"line-number\" href=\"#main.cc-1-20\"><\/a>\n<a id=\"main.cc-1-21\" class=\"line-number\" href=\"#main.cc-1-21\"><\/a><span class=\"kt\">int<\/span> <span class=\"nf\">main<\/span><span class=\"p\">(<\/span>\n<a id=\"main.cc-1-22\" class=\"line-number\" href=\"#main.cc-1-22\"><\/a>    <span class=\"kt\">int<\/span>    <span class=\"n\">argc<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-1-23\" class=\"line-number\" href=\"#main.cc-1-23\"><\/a>    <span class=\"kt\">char<\/span><span class=\"o\">**<\/span> <span class=\"n\">argv<\/span>\n<a id=\"main.cc-1-24\" class=\"line-number\" href=\"#main.cc-1-24\"><\/a><span class=\"p\">)<\/span>\n<a id=\"main.cc-1-25\" class=\"line-number\" href=\"#main.cc-1-25\"><\/a><span class=\"p\">{<\/span>\n<a id=\"main.cc-1-26\" class=\"line-number\" href=\"#main.cc-1-26\"><\/a><span class=\"hll\">    <span class=\"kt\">int<\/span> <span class=\"n\">result<\/span> <span class=\"o\">=<\/span> <span class=\"mi\">0<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"main.cc-1-27\" class=\"line-number\" href=\"#main.cc-1-27\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-28\" class=\"line-number\" href=\"#main.cc-1-28\"><\/a>    <span class=\"n\">ToDo<\/span> <span class=\"n\">list<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-1-29\" class=\"line-number\" href=\"#main.cc-1-29\"><\/a>\n<a id=\"main.cc-1-30\" class=\"line-number\" href=\"#main.cc-1-30\"><\/a><span class=\"hll\">    <span class=\"n\">list<\/span><span class=\"p\">.<\/span><span class=\"n\">addTask<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;write code&quot;<\/span><span class=\"p\">);<\/span>\n<\/span><a id=\"main.cc-1-31\" class=\"line-number\" href=\"#main.cc-1-31\"><\/a><span class=\"hll\">    <span class=\"n\">list<\/span><span class=\"p\">.<\/span><span class=\"n\">addTask<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;compile&quot;<\/span><span class=\"p\">);<\/span>\n<\/span><a id=\"main.cc-1-32\" class=\"line-number\" href=\"#main.cc-1-32\"><\/a><span class=\"hll\">    <span class=\"n\">list<\/span><span class=\"p\">.<\/span><span class=\"n\">addTask<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;test&quot;<\/span><span class=\"p\">);<\/span>\n<\/span><a id=\"main.cc-1-33\" class=\"line-number\" href=\"#main.cc-1-33\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-34\" class=\"line-number\" href=\"#main.cc-1-34\"><\/a><span class=\"hll\">    <span class=\"n\">result<\/span> <span class=\"o\">|=<\/span> <span class=\"n\">EXPECT_EQUAL<\/span><span class=\"p\">(<\/span><span class=\"n\">list<\/span><span class=\"p\">.<\/span><span class=\"n\">size<\/span><span class=\"p\">(),<\/span>     <span class=\"mi\">3<\/span><span class=\"p\">);<\/span>\n<\/span><a id=\"main.cc-1-35\" class=\"line-number\" href=\"#main.cc-1-35\"><\/a><span class=\"hll\">    <span class=\"n\">result<\/span> <span class=\"o\">|=<\/span> <span class=\"n\">EXPECT_EQUAL<\/span><span class=\"p\">(<\/span><span class=\"n\">list<\/span><span class=\"p\">.<\/span><span class=\"n\">getTask<\/span><span class=\"p\">(<\/span><span class=\"mi\">0<\/span><span class=\"p\">),<\/span> <span class=\"s\">&quot;write code&quot;<\/span><span class=\"p\">);<\/span>\n<\/span><a id=\"main.cc-1-36\" class=\"line-number\" href=\"#main.cc-1-36\"><\/a><span class=\"hll\">    <span class=\"n\">result<\/span> <span class=\"o\">|=<\/span> <span class=\"n\">EXPECT_EQUAL<\/span><span class=\"p\">(<\/span><span class=\"n\">list<\/span><span class=\"p\">.<\/span><span class=\"n\">getTask<\/span><span class=\"p\">(<\/span><span class=\"mi\">1<\/span><span class=\"p\">),<\/span> <span class=\"s\">&quot;compile&quot;<\/span><span class=\"p\">);<\/span>\n<\/span><a id=\"main.cc-1-37\" class=\"line-number\" href=\"#main.cc-1-37\"><\/a><span class=\"hll\">    <span class=\"n\">result<\/span> <span class=\"o\">|=<\/span> <span class=\"n\">EXPECT_EQUAL<\/span><span class=\"p\">(<\/span><span class=\"n\">list<\/span><span class=\"p\">.<\/span><span class=\"n\">getTask<\/span><span class=\"p\">(<\/span><span class=\"mi\">2<\/span><span class=\"p\">),<\/span> <span class=\"s\">&quot;test&quot;<\/span><span class=\"p\">);<\/span>\n<\/span><a id=\"main.cc-1-38\" class=\"line-number\" href=\"#main.cc-1-38\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-39\" class=\"line-number\" href=\"#main.cc-1-39\"><\/a><span class=\"hll\">    <span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"n\">result<\/span> <span class=\"o\">==<\/span> <span class=\"mi\">0<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"main.cc-1-40\" class=\"line-number\" href=\"#main.cc-1-40\"><\/a><span class=\"hll\">    <span class=\"p\">{<\/span>\n<\/span><a id=\"main.cc-1-41\" class=\"line-number\" href=\"#main.cc-1-41\"><\/a><span class=\"hll\">        <span class=\"n\">cout<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;Test passed&quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">endl<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"main.cc-1-42\" class=\"line-number\" href=\"#main.cc-1-42\"><\/a><span class=\"hll\">    <span class=\"p\">}<\/span>\n<\/span><a id=\"main.cc-1-43\" class=\"line-number\" href=\"#main.cc-1-43\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-44\" class=\"line-number\" href=\"#main.cc-1-44\"><\/a><span class=\"hll\">    <span class=\"k\">return<\/span> <span class=\"n\">result<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"main.cc-1-45\" class=\"line-number\" href=\"#main.cc-1-45\"><\/a><span class=\"p\">}<\/span>\n<a id=\"main.cc-1-46\" class=\"line-number\" href=\"#main.cc-1-46\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-47\" class=\"line-number\" href=\"#main.cc-1-47\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-48\" class=\"line-number\" href=\"#main.cc-1-48\"><\/a><span class=\"hll\"><span class=\"k\">template<\/span> <span class=\"o\">&lt;<\/span> <span class=\"k\">typename<\/span> <span class=\"n\">T1<\/span><span class=\"p\">,<\/span> <span class=\"k\">typename<\/span> <span class=\"n\">T2<\/span> <span class=\"o\">&gt;<\/span>\n<\/span><a id=\"main.cc-1-49\" class=\"line-number\" href=\"#main.cc-1-49\"><\/a><span class=\"hll\"><span class=\"kt\">int<\/span> <span class=\"n\">equalityTest<\/span><span class=\"p\">(<\/span>\n<\/span><a id=\"main.cc-1-50\" class=\"line-number\" href=\"#main.cc-1-50\"><\/a><span class=\"hll\">    <span class=\"k\">const<\/span> <span class=\"n\">T1<\/span>    <span class=\"n\">testValue<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-1-51\" class=\"line-number\" href=\"#main.cc-1-51\"><\/a><span class=\"hll\">    <span class=\"k\">const<\/span> <span class=\"n\">T2<\/span>    <span class=\"n\">expectedValue<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-1-52\" class=\"line-number\" href=\"#main.cc-1-52\"><\/a><span class=\"hll\">    <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">testName<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-1-53\" class=\"line-number\" href=\"#main.cc-1-53\"><\/a><span class=\"hll\">    <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">expectedName<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-1-54\" class=\"line-number\" href=\"#main.cc-1-54\"><\/a><span class=\"hll\">    <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">fileName<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-1-55\" class=\"line-number\" href=\"#main.cc-1-55\"><\/a><span class=\"hll\">    <span class=\"k\">const<\/span> <span class=\"kt\">int<\/span>   <span class=\"n\">lineNumber<\/span>\n<\/span><a id=\"main.cc-1-56\" class=\"line-number\" href=\"#main.cc-1-56\"><\/a><span class=\"hll\"><span class=\"p\">)<\/span>\n<\/span><a id=\"main.cc-1-57\" class=\"line-number\" href=\"#main.cc-1-57\"><\/a><span class=\"hll\"><span class=\"p\">{<\/span>\n<\/span><a id=\"main.cc-1-58\" class=\"line-number\" href=\"#main.cc-1-58\"><\/a><span class=\"hll\">    <span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"n\">testValue<\/span> <span class=\"o\">!=<\/span> <span class=\"n\">expectedValue<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"main.cc-1-59\" class=\"line-number\" href=\"#main.cc-1-59\"><\/a><span class=\"hll\">    <span class=\"p\">{<\/span>\n<\/span><a id=\"main.cc-1-60\" class=\"line-number\" href=\"#main.cc-1-60\"><\/a><span class=\"hll\">        <span class=\"n\">cerr<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">fileName<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;:&quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">lineNumber<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;: &quot;<\/span>\n<\/span><a id=\"main.cc-1-61\" class=\"line-number\" href=\"#main.cc-1-61\"><\/a><span class=\"hll\">             <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;Expected &quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">testName<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot; &quot;<\/span>\n<\/span><a id=\"main.cc-1-62\" class=\"line-number\" href=\"#main.cc-1-62\"><\/a><span class=\"hll\">             <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;to equal &quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">expectedName<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot; (&quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">expectedValue<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;) &quot;<\/span>\n<\/span><a id=\"main.cc-1-63\" class=\"line-number\" href=\"#main.cc-1-63\"><\/a><span class=\"hll\">             <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;but it was (&quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">testValue<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;)&quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">endl<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"main.cc-1-64\" class=\"line-number\" href=\"#main.cc-1-64\"><\/a><span class=\"hll\">\n<\/span><a id=\"main.cc-1-65\" class=\"line-number\" href=\"#main.cc-1-65\"><\/a><span class=\"hll\">        <span class=\"k\">return<\/span> <span class=\"mi\">1<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"main.cc-1-66\" class=\"line-number\" href=\"#main.cc-1-66\"><\/a><span class=\"hll\">    <span class=\"p\">}<\/span>\n<\/span><a id=\"main.cc-1-67\" class=\"line-number\" href=\"#main.cc-1-67\"><\/a><span class=\"hll\">    <span class=\"k\">else<\/span>\n<\/span><a id=\"main.cc-1-68\" class=\"line-number\" href=\"#main.cc-1-68\"><\/a><span class=\"hll\">    <span class=\"p\">{<\/span>\n<\/span><a id=\"main.cc-1-69\" class=\"line-number\" href=\"#main.cc-1-69\"><\/a><span class=\"hll\">        <span class=\"k\">return<\/span> <span class=\"mi\">0<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"main.cc-1-70\" class=\"line-number\" href=\"#main.cc-1-70\"><\/a><span class=\"hll\">    <span class=\"p\">}<\/span>\n<\/span><a id=\"main.cc-1-71\" class=\"line-number\" href=\"#main.cc-1-71\"><\/a><span class=\"hll\"><span class=\"p\">}<\/span>\n<\/span><\/pre>\n<\/div>\n<\/section>\n<section class=\"code\">\n<header class=\"clear-after\">\n<h1>ToDo.h<\/h1>\n<div class=\"hll legend\">New or modified lines in bold.<\/div>\n<\/header>\n<div class=\"highlight\">\n<pre><a id=\"ToDo.h-1-1\" class=\"line-number\" href=\"#ToDo.h-1-1\"><\/a><span class=\"cp\">#ifndef TODO_H<\/span>\n<a id=\"ToDo.h-1-2\" class=\"line-number\" href=\"#ToDo.h-1-2\"><\/a><span class=\"cp\">#define TODO_H<\/span>\n<a id=\"ToDo.h-1-3\" class=\"line-number\" href=\"#ToDo.h-1-3\"><\/a>\n<a id=\"ToDo.h-1-4\" class=\"line-number\" href=\"#ToDo.h-1-4\"><\/a><span class=\"hll\"><span class=\"cp\">#include &lt;string&gt;<\/span>\n<\/span><a id=\"ToDo.h-1-5\" class=\"line-number\" href=\"#ToDo.h-1-5\"><\/a><span class=\"hll\"><span class=\"cp\">#include &lt;vector&gt;<\/span>\n<\/span><a id=\"ToDo.h-1-6\" class=\"line-number\" href=\"#ToDo.h-1-6\"><\/a><span class=\"hll\">\n<\/span><a id=\"ToDo.h-1-7\" class=\"line-number\" href=\"#ToDo.h-1-7\"><\/a><span class=\"hll\">\n<\/span><a id=\"ToDo.h-1-8\" class=\"line-number\" href=\"#ToDo.h-1-8\"><\/a><span class=\"n\">class<\/span> <span class=\"n\">ToDo<\/span>\n<a id=\"ToDo.h-1-9\" class=\"line-number\" href=\"#ToDo.h-1-9\"><\/a><span class=\"p\">{<\/span>\n<a id=\"ToDo.h-1-10\" class=\"line-number\" href=\"#ToDo.h-1-10\"><\/a><span class=\"nl\">public:<\/span>\n<a id=\"ToDo.h-1-11\" class=\"line-number\" href=\"#ToDo.h-1-11\"><\/a>    <span class=\"n\">ToDo<\/span><span class=\"p\">();<\/span>\n<a id=\"ToDo.h-1-12\" class=\"line-number\" href=\"#ToDo.h-1-12\"><\/a>    <span class=\"o\">~<\/span><span class=\"n\">ToDo<\/span><span class=\"p\">();<\/span>\n<a id=\"ToDo.h-1-13\" class=\"line-number\" href=\"#ToDo.h-1-13\"><\/a><span class=\"hll\">\n<\/span><a id=\"ToDo.h-1-14\" class=\"line-number\" href=\"#ToDo.h-1-14\"><\/a><span class=\"hll\">    <span class=\"kt\">size_t<\/span> <span class=\"n\">size<\/span><span class=\"p\">()<\/span> <span class=\"k\">const<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"ToDo.h-1-15\" class=\"line-number\" href=\"#ToDo.h-1-15\"><\/a><span class=\"hll\">\n<\/span><a id=\"ToDo.h-1-16\" class=\"line-number\" href=\"#ToDo.h-1-16\"><\/a><span class=\"hll\">    <span class=\"kt\">void<\/span> <span class=\"nf\">addTask<\/span><span class=\"p\">(<\/span><span class=\"k\">const<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">string<\/span><span class=\"o\">&amp;<\/span> <span class=\"n\">task<\/span><span class=\"p\">);<\/span>\n<\/span><a id=\"ToDo.h-1-17\" class=\"line-number\" href=\"#ToDo.h-1-17\"><\/a><span class=\"hll\">    <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">string<\/span> <span class=\"n\">getTask<\/span><span class=\"p\">(<\/span><span class=\"kt\">size_t<\/span> <span class=\"n\">index<\/span><span class=\"p\">)<\/span> <span class=\"k\">const<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"ToDo.h-1-18\" class=\"line-number\" href=\"#ToDo.h-1-18\"><\/a><span class=\"hll\">\n<\/span><a id=\"ToDo.h-1-19\" class=\"line-number\" href=\"#ToDo.h-1-19\"><\/a><span class=\"hll\"><span class=\"nl\">private:<\/span>\n<\/span><a id=\"ToDo.h-1-20\" class=\"line-number\" href=\"#ToDo.h-1-20\"><\/a><span class=\"hll\">    <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">vector<\/span><span class=\"o\">&lt;<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">string<\/span> <span class=\"o\">&gt;<\/span> <span class=\"n\">this_tasks<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"ToDo.h-1-21\" class=\"line-number\" href=\"#ToDo.h-1-21\"><\/a><span class=\"p\">};<\/span>\n<a id=\"ToDo.h-1-22\" class=\"line-number\" href=\"#ToDo.h-1-22\"><\/a>\n<a id=\"ToDo.h-1-23\" class=\"line-number\" href=\"#ToDo.h-1-23\"><\/a><span class=\"cp\">#endif <\/span><span class=\"c1\">\/\/ TODO_H<\/span>\n<\/pre>\n<\/div>\n<\/section>\n<section class=\"code\">\n<header class=\"clear-after\">\n<h1>ToDo.cc<\/h1>\n<div class=\"hll legend\">New or modified lines in bold.<\/div>\n<\/header>\n<div class=\"highlight\">\n<pre><a id=\"ToDo.cc-1-1\" class=\"line-number\" href=\"#ToDo.cc-1-1\"><\/a><span class=\"cp\">#include &quot;ToDo.h&quot;<\/span>\n<a id=\"ToDo.cc-1-2\" class=\"line-number\" href=\"#ToDo.cc-1-2\"><\/a>\n<a id=\"ToDo.cc-1-3\" class=\"line-number\" href=\"#ToDo.cc-1-3\"><\/a>\n<a id=\"ToDo.cc-1-4\" class=\"line-number\" href=\"#ToDo.cc-1-4\"><\/a><span class=\"n\">ToDo<\/span><span class=\"o\">::<\/span><span class=\"n\">ToDo<\/span><span class=\"p\">()<\/span>\n<a id=\"ToDo.cc-1-5\" class=\"line-number\" href=\"#ToDo.cc-1-5\"><\/a><span class=\"p\">{<\/span>\n<a id=\"ToDo.cc-1-6\" class=\"line-number\" href=\"#ToDo.cc-1-6\"><\/a><span class=\"p\">}<\/span>\n<a id=\"ToDo.cc-1-7\" class=\"line-number\" href=\"#ToDo.cc-1-7\"><\/a>\n<a id=\"ToDo.cc-1-8\" class=\"line-number\" href=\"#ToDo.cc-1-8\"><\/a><span class=\"n\">ToDo<\/span><span class=\"o\">::~<\/span><span class=\"n\">ToDo<\/span><span class=\"p\">()<\/span>\n<a id=\"ToDo.cc-1-9\" class=\"line-number\" href=\"#ToDo.cc-1-9\"><\/a><span class=\"p\">{<\/span>\n<a id=\"ToDo.cc-1-10\" class=\"line-number\" href=\"#ToDo.cc-1-10\"><\/a><span class=\"p\">}<\/span>\n<a id=\"ToDo.cc-1-11\" class=\"line-number\" href=\"#ToDo.cc-1-11\"><\/a><span class=\"hll\">\n<\/span><a id=\"ToDo.cc-1-12\" class=\"line-number\" href=\"#ToDo.cc-1-12\"><\/a><span class=\"hll\">\n<\/span><a id=\"ToDo.cc-1-13\" class=\"line-number\" href=\"#ToDo.cc-1-13\"><\/a><span class=\"hll\"><span class=\"kt\">size_t<\/span> <span class=\"n\">ToDo<\/span><span class=\"o\">::<\/span><span class=\"n\">size<\/span><span class=\"p\">()<\/span> <span class=\"k\">const<\/span>\n<\/span><a id=\"ToDo.cc-1-14\" class=\"line-number\" href=\"#ToDo.cc-1-14\"><\/a><span class=\"hll\"><span class=\"p\">{<\/span>\n<\/span><a id=\"ToDo.cc-1-15\" class=\"line-number\" href=\"#ToDo.cc-1-15\"><\/a><span class=\"hll\">    <span class=\"k\">return<\/span> <span class=\"n\">this_tasks<\/span><span class=\"p\">.<\/span><span class=\"n\">size<\/span><span class=\"p\">();<\/span>\n<\/span><a id=\"ToDo.cc-1-16\" class=\"line-number\" href=\"#ToDo.cc-1-16\"><\/a><span class=\"hll\"><span class=\"p\">}<\/span>\n<\/span><a id=\"ToDo.cc-1-17\" class=\"line-number\" href=\"#ToDo.cc-1-17\"><\/a><span class=\"hll\">\n<\/span><a id=\"ToDo.cc-1-18\" class=\"line-number\" href=\"#ToDo.cc-1-18\"><\/a><span class=\"hll\">\n<\/span><a id=\"ToDo.cc-1-19\" class=\"line-number\" href=\"#ToDo.cc-1-19\"><\/a><span class=\"hll\"><span class=\"kt\">void<\/span> <span class=\"n\">ToDo<\/span><span class=\"o\">::<\/span><span class=\"n\">addTask<\/span><span class=\"p\">(<\/span>\n<\/span><a id=\"ToDo.cc-1-20\" class=\"line-number\" href=\"#ToDo.cc-1-20\"><\/a><span class=\"hll\">    <span class=\"k\">const<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">string<\/span><span class=\"o\">&amp;<\/span> <span class=\"n\">task<\/span>\n<\/span><a id=\"ToDo.cc-1-21\" class=\"line-number\" href=\"#ToDo.cc-1-21\"><\/a><span class=\"hll\"><span class=\"p\">)<\/span>\n<\/span><a id=\"ToDo.cc-1-22\" class=\"line-number\" href=\"#ToDo.cc-1-22\"><\/a><span class=\"hll\"><span class=\"p\">{<\/span>\n<\/span><a id=\"ToDo.cc-1-23\" class=\"line-number\" href=\"#ToDo.cc-1-23\"><\/a><span class=\"hll\">    <span class=\"n\">this_tasks<\/span><span class=\"p\">.<\/span><span class=\"n\">push_back<\/span><span class=\"p\">(<\/span><span class=\"n\">task<\/span><span class=\"p\">);<\/span>\n<\/span><a id=\"ToDo.cc-1-24\" class=\"line-number\" href=\"#ToDo.cc-1-24\"><\/a><span class=\"hll\"><span class=\"p\">}<\/span>\n<\/span><a id=\"ToDo.cc-1-25\" class=\"line-number\" href=\"#ToDo.cc-1-25\"><\/a><span class=\"hll\">\n<\/span><a id=\"ToDo.cc-1-26\" class=\"line-number\" href=\"#ToDo.cc-1-26\"><\/a><span class=\"hll\"><span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">string<\/span> <span class=\"n\">ToDo<\/span><span class=\"o\">::<\/span><span class=\"n\">getTask<\/span><span class=\"p\">(<\/span>\n<\/span><a id=\"ToDo.cc-1-27\" class=\"line-number\" href=\"#ToDo.cc-1-27\"><\/a><span class=\"hll\">    <span class=\"kt\">size_t<\/span> <span class=\"n\">index<\/span>\n<\/span><a id=\"ToDo.cc-1-28\" class=\"line-number\" href=\"#ToDo.cc-1-28\"><\/a><span class=\"hll\"><span class=\"p\">)<\/span> <span class=\"k\">const<\/span>\n<\/span><a id=\"ToDo.cc-1-29\" class=\"line-number\" href=\"#ToDo.cc-1-29\"><\/a><span class=\"hll\"><span class=\"p\">{<\/span>\n<\/span><a id=\"ToDo.cc-1-30\" class=\"line-number\" href=\"#ToDo.cc-1-30\"><\/a><span class=\"hll\">    <span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"n\">index<\/span> <span class=\"o\">&lt;<\/span> <span class=\"n\">this_tasks<\/span><span class=\"p\">.<\/span><span class=\"n\">size<\/span><span class=\"p\">())<\/span>\n<\/span><a id=\"ToDo.cc-1-31\" class=\"line-number\" href=\"#ToDo.cc-1-31\"><\/a><span class=\"hll\">    <span class=\"p\">{<\/span>\n<\/span><a id=\"ToDo.cc-1-32\" class=\"line-number\" href=\"#ToDo.cc-1-32\"><\/a><span class=\"hll\">        <span class=\"k\">return<\/span> <span class=\"n\">this_tasks<\/span><span class=\"p\">[<\/span><span class=\"n\">index<\/span><span class=\"p\">];<\/span>\n<\/span><a id=\"ToDo.cc-1-33\" class=\"line-number\" href=\"#ToDo.cc-1-33\"><\/a><span class=\"hll\">    <span class=\"p\">}<\/span>\n<\/span><a id=\"ToDo.cc-1-34\" class=\"line-number\" href=\"#ToDo.cc-1-34\"><\/a><span class=\"hll\">    <span class=\"k\">else<\/span>\n<\/span><a id=\"ToDo.cc-1-35\" class=\"line-number\" href=\"#ToDo.cc-1-35\"><\/a><span class=\"hll\">    <span class=\"p\">{<\/span>\n<\/span><a id=\"ToDo.cc-1-36\" class=\"line-number\" href=\"#ToDo.cc-1-36\"><\/a><span class=\"hll\">        <span class=\"k\">return<\/span> <span class=\"s\">&quot;&quot;<\/span><span class=\"p\">;<\/span>\n<\/span><a id=\"ToDo.cc-1-37\" class=\"line-number\" href=\"#ToDo.cc-1-37\"><\/a><span class=\"hll\">    <span class=\"p\">}<\/span>\n<\/span><a id=\"ToDo.cc-1-38\" class=\"line-number\" href=\"#ToDo.cc-1-38\"><\/a><span class=\"hll\"><span class=\"p\">}<\/span>\n<\/span><\/pre>\n<\/div>\n<\/section>\n<p>\n    <a class=\"sources\" href=\"https:\/\/www.johnlamp.net\/sources\/chapter1-2.zip\"><img src=\"https:\/\/www.johnlamp.net\/images\/zip.png\" alt=\"[zip file] \" \/>Source<\/a>  <\/p>\n<p>\n    Whew! That was not simple at all. Hopefully some of you are wondering why I<br \/>\n    didn&#8217;t use a test framework. Later we will, but had we done so now we would<br \/>\n    have gotten further ahead of ourselves than we already have.\n  <\/p>\n<p>\n    Building is exactly the same as before. In fact if you modified the files<br \/>\n    you had used before you simply need to run <kbd>make<\/kbd> again. The<br \/>\n    Makefile created by CMake will automatically run <code>cmake<\/code> again if<br \/>\n    you modify your <code>CMakeLists.txt<\/code>. So let&#8217;s run our test:\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> mkdir build\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd build\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cmake -G &quot;Unix Makefiles&quot; ..\n-- The C compiler identification is GNU 4.2.1\n-- The CXX compiler identification is GNU 4.2.1\n-- Checking whether C compiler has -isysroot\n-- Checking whether C compiler has -isysroot - yes\n-- Checking whether C compiler supports OSX deployment target flag\n-- Checking whether C compiler supports OSX deployment target flag - yes\n-- Check for working C compiler: \/usr\/bin\/gcc\n-- Check for working C compiler: \/usr\/bin\/gcc -- works\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - done\n-- Checking whether CXX compiler has -isysroot\n-- Checking whether CXX compiler has -isysroot - yes\n-- Checking whether CXX compiler supports OSX deployment target flag\n-- Checking whether CXX compiler supports OSX deployment target flag - yes\n-- Check for working CXX compiler: \/usr\/bin\/c++\n-- Check for working CXX compiler: \/usr\/bin\/c++ -- works\n-- Detecting CXX compiler ABI info\n-- Detecting CXX compiler ABI info - done\n-- Configuring done\n-- Generating done\n-- Build files have been written to: \/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/build\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> make\n<span class=\"ansiBold ansiForeground-magenta\">Scanning dependencies of target toDo\n<\/span>[ 50%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/main.cc.o\n<\/span>[100%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/ToDo.cc.o\n<\/span><span class=\"ansiBold ansiForeground-red\">Linking CXX executable toDo\n<\/span>[100%] Built target toDo\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> make test\n<span class=\"ansiForeground-cyan\">Running tests...\n<\/span>Test project \/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/build\n    Start 1: toDoTest\n1\/1 Test #1: toDoTest .........................   Passed    0.01 sec\n100% tests passed, 0 tests failed out of 1\nTotal Test time (real) =   0.03 sec\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> ls Testing\nTemporary\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> ls Testing\/Temporary\nCTestCostData.txt\tLastTest.log\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cat Testing\/Temporary\/LastTest.log\nStart testing: Jul 16 22:00 EDT\n----------------------------------------------------------\n1\/1 Testing: toDoTest\n1\/1 Test: toDoTest\nCommand: &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/build\/toDo&quot;\nDirectory: \/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/build\n&quot;toDoTest&quot; start time: Jul 16 22:00 EDT\nOutput:\n----------------------------------------------------------\nTest passed\n&lt;end of output&gt;\nTest time =   0.01 sec\n----------------------------------------------------------\nTest Passed.\n&quot;toDoTest&quot; end time: Jul 16 22:00 EDT\n&quot;toDoTest&quot; time elapsed: 00:00:00\n----------------------------------------------------------\nEnd testing: Jul 16 22:00 EDT\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cat Testing\/Temporary\/CTestCostData.txt\ntoDoTest 1 0.00976491\n---\n<\/pre>\n<\/section>\n<dl>\n<dd>\n      As mentioned earlier building with CMake is the same as it was<br \/>\n      before.\n    <\/dd>\n<dt><kbd>make test<\/kbd><\/dt>\n<dd>\n      The <code>enable_testing()<\/code> function we added to<br \/>\n      our <code>CMakeLists.txt<\/code> adds the &#8220;test&#8221; target to our<br \/>\n      Makefile. Making the &#8220;test&#8221; target will run CTest which will, in turn, run<br \/>\n      all of our tests. In our case just the one.\n    <\/dd>\n<dd>\n      When CTest runs our tests it prints an abbreviated output that just<br \/>\n      provides the status of each of our tests. It then finishes up with a<br \/>\n      summary of all tests.\n    <\/dd>\n<dt class=\"code\">Testing\/Temporary\/LastTest.log<\/dt>\n<dd>\n      This file is created by CTest whenever it is run. It contains much more<br \/>\n      detail than the terminal output of CTest shows. Most importantly it<br \/>\n      contains the output of the tests. This is where you will want to look<br \/>\n      whenever a test fails.\n    <\/dd>\n<dt class=\"code\">Testing\/Temporary\/CTestCostData.txt<\/dt>\n<dd>\n      This file contains the time, in seconds, taken to run each test.\n    <\/dd>\n<\/dl>\n<p>\n    CMake along with CTest makes it easy to run our tests. CTest has many other<br \/>\n    features which will be presented later in this tutorial. There are, however,<br \/>\n    a few drawbacks to running our tests this way but we will leave those for<br \/>\n    later, too.\n  <\/p>\n<\/section>\n<section id=\"revision-history\"><span class=\"heading\">Revision History<\/span><\/p>\n<table summary=\"Revision History\">\n<thead>\n<tr>\n<td>Version<\/td>\n<td>Date<\/td>\n<td>Comment<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>2013-03-28<\/td>\n<td>Original version.<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>2013-07-14<\/td>\n<td>Added line numbers and indication of changes to code sample.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>In this chapter we start by installing CMake. Like most open source software<br \/>\n    the best way to do this depends on your platform and how you usually do<br \/>\n    things. Once we have CMake installed we create a simple project. Perhaps<br \/>\n    it&#8217;s a little fancier than &#8220;hello world&#8221; but not much. We finish up with the<br \/>\n    &hellip;<br \/><a href=\"https:\/\/www.johnlamp.net\/?p=13\" rel=\"bookmark\">Continue reading &quot;CMake Tutorial &#8211; Chapter&#160;1: Getting Started&quot;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[3,4,5],"_links":{"self":[{"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=\/wp\/v2\/posts\/13"}],"collection":[{"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":0,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}