{"id":54,"date":"2015-03-03T21:38:21","date_gmt":"2015-03-04T02:38:21","guid":{"rendered":"https:\/\/www.johnlamp.net\/cmake-tutorial-6-realistically-getting-a-boost.html"},"modified":"2015-03-03T21:38:21","modified_gmt":"2015-03-04T02:38:21","slug":"cmake-tutorial-6-realistically-getting-a-boost","status":"publish","type":"post","link":"https:\/\/www.johnlamp.net\/?p=54","title":{"rendered":"CMake Tutorial &#8211; Chapter&#160;6: Realistically Getting a Boost"},"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-BoostingTheCommandLine\">Boosting the Command Line<\/a><\/li>\n<li><a href=\"#section-HowToUseFindboost\">How to Use FindBoost<\/a><\/li>\n<li>\n<ol>\n<li><a href=\"#section-ChoosingARoot\">Choosing a Root<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"#section-FindingPackages\">Finding Packages<\/a><\/li>\n<li><a href=\"#section-DocumentationFound\">Documentation Found<\/a><\/li>\n<\/ol>\n<\/nav>\n<section>\n<h1 id=\"section-Introduction\">Introduction<\/h1>\n<p>\n    Now that we have our testing simplified and automated we have a great<br \/>\n    foundation upon which to build our amazing command line To Do list app.<br \/>\n    What&#8217;s that? You say that an awesome To Do app allows you to add items to<br \/>\n    your list? Indeed it does, and more! But wait, let&#8217;s not get ahead of<br \/>\n    ourselves. We need to be able to accept and parse command line options if<br \/>\n    this app is to be of any use at all.\n  <\/p>\n<p>\n    I know what you are thinking now: parsing command line options is a drag and<br \/>\n    who likes parsing stuff anyway? Well we are in luck as the Boost<br \/>\n    <a href=\"http:\/\/www.boost.org\/doc\/libs\/1_54_0\/doc\/html\/program_options.html\">Program Options<\/a>    library will do all the hard work for us. All we need to do is rewrite our<br \/>\n    main function to be something useful, let the library do the parsing and our<br \/>\n    app will be on it&#8217;s way to the top 10 list. Okay, I might be exaggerating<br \/>\n    that last one.\n  <\/p>\n<\/section>\n<section>\n<h1 id=\"section-BoostingTheCommandLine\">Boosting the Command Line<\/h1>\n<p>\n    Okay, that section title may be a little over the top. Our main function has<br \/>\n    languished while we set up testing and streamlined our CMake. Now it&#8217;s time<br \/>\n    to turn attention back to it and what we find is that it needs to be gutted<br \/>\n    and re-done, much like an old kitchen. Since we have better tests we don&#8217;t<br \/>\n    need the one in main anymore. We will update main to have two command line<br \/>\n    options: <kbd>--add<\/kbd>, which will add a new entry to the to do list, and<br \/>\n    <kbd>--help<\/kbd>, which will do what you&#8217;d expect.\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 &lt;iostream&gt;<\/span>\n<a id=\"main.cc-2\" class=\"line-number\" href=\"#main.cc-2\"><\/a>  <span class=\"k\">using<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">cerr<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-3\" class=\"line-number\" href=\"#main.cc-3\"><\/a>  <span class=\"k\">using<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">cout<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-4\" class=\"line-number\" href=\"#main.cc-4\"><\/a>  <span class=\"k\">using<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">endl<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-5\" class=\"line-number\" href=\"#main.cc-5\"><\/a><span class=\"cp\">#include &lt;string&gt;<\/span>\n<a id=\"main.cc-6\" class=\"line-number\" href=\"#main.cc-6\"><\/a>  <span class=\"k\">using<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">string<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-7\" class=\"line-number\" href=\"#main.cc-7\"><\/a>\n<a id=\"main.cc-8\" class=\"line-number\" href=\"#main.cc-8\"><\/a><span class=\"cp\">#include &lt;boost\/program_options.hpp&gt;<\/span>\n<a id=\"main.cc-9\" class=\"line-number\" href=\"#main.cc-9\"><\/a>  <span class=\"k\">namespace<\/span> <span class=\"n\">po<\/span> <span class=\"o\">=<\/span> <span class=\"n\">boost<\/span><span class=\"o\">::<\/span><span class=\"n\">program_options<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-10\" class=\"line-number\" href=\"#main.cc-10\"><\/a>\n<a id=\"main.cc-11\" class=\"line-number\" href=\"#main.cc-11\"><\/a><span class=\"cp\">#include &quot;ToDoCore\/ToDo.h&quot;<\/span>\n<a id=\"main.cc-12\" class=\"line-number\" href=\"#main.cc-12\"><\/a>  <span class=\"k\">using<\/span> <span class=\"n\">ToDoCore<\/span><span class=\"o\">::<\/span><span class=\"n\">ToDo<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-13\" class=\"line-number\" href=\"#main.cc-13\"><\/a>\n<a id=\"main.cc-14\" class=\"line-number\" href=\"#main.cc-14\"><\/a><span class=\"kt\">int<\/span> <span class=\"nf\">main<\/span><span class=\"p\">(<\/span>\n<a id=\"main.cc-15\" class=\"line-number\" href=\"#main.cc-15\"><\/a>    <span class=\"kt\">int<\/span>    <span class=\"n\">argc<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-16\" class=\"line-number\" href=\"#main.cc-16\"><\/a>    <span class=\"kt\">char<\/span><span class=\"o\">**<\/span> <span class=\"n\">argv<\/span>\n<a id=\"main.cc-17\" class=\"line-number\" href=\"#main.cc-17\"><\/a><span class=\"p\">)<\/span>\n<a id=\"main.cc-18\" class=\"line-number\" href=\"#main.cc-18\"><\/a><span class=\"p\">{<\/span>\n<a id=\"main.cc-19\" class=\"line-number\" href=\"#main.cc-19\"><\/a>    <span class=\"n\">po<\/span><span class=\"o\">::<\/span><span class=\"n\">options_description<\/span> <span class=\"n\">desc<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;Options&quot;<\/span><span class=\"p\">);<\/span>\n<a id=\"main.cc-20\" class=\"line-number\" href=\"#main.cc-20\"><\/a>    <span class=\"n\">desc<\/span><span class=\"p\">.<\/span><span class=\"n\">add_options<\/span><span class=\"p\">()<\/span>\n<a id=\"main.cc-21\" class=\"line-number\" href=\"#main.cc-21\"><\/a>        <span class=\"p\">(<\/span><span class=\"s\">&quot;help,h&quot;<\/span><span class=\"p\">,<\/span> <span class=\"s\">&quot;display this help&quot;<\/span><span class=\"p\">)<\/span>\n<a id=\"main.cc-22\" class=\"line-number\" href=\"#main.cc-22\"><\/a>        <span class=\"p\">(<\/span><span class=\"s\">&quot;add,a&quot;<\/span><span class=\"p\">,<\/span> <span class=\"n\">po<\/span><span class=\"o\">::<\/span><span class=\"n\">value<\/span><span class=\"o\">&lt;<\/span> <span class=\"n\">string<\/span> <span class=\"o\">&gt;<\/span><span class=\"p\">(),<\/span> <span class=\"s\">&quot;add a new entry to the To Do list&quot;<\/span><span class=\"p\">)<\/span>\n<a id=\"main.cc-23\" class=\"line-number\" href=\"#main.cc-23\"><\/a>        <span class=\"p\">;<\/span>\n<a id=\"main.cc-24\" class=\"line-number\" href=\"#main.cc-24\"><\/a>\n<a id=\"main.cc-25\" class=\"line-number\" href=\"#main.cc-25\"><\/a>    <span class=\"kt\">bool<\/span> <span class=\"n\">parseError<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">false<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-26\" class=\"line-number\" href=\"#main.cc-26\"><\/a>    <span class=\"n\">po<\/span><span class=\"o\">::<\/span><span class=\"n\">variables_map<\/span> <span class=\"n\">vm<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-27\" class=\"line-number\" href=\"#main.cc-27\"><\/a>    <span class=\"n\">try<\/span>\n<a id=\"main.cc-28\" class=\"line-number\" href=\"#main.cc-28\"><\/a>    <span class=\"p\">{<\/span>\n<a id=\"main.cc-29\" class=\"line-number\" href=\"#main.cc-29\"><\/a>        <span class=\"n\">po<\/span><span class=\"o\">::<\/span><span class=\"n\">store<\/span><span class=\"p\">(<\/span><span class=\"n\">po<\/span><span class=\"o\">::<\/span><span class=\"n\">parse_command_line<\/span><span class=\"p\">(<\/span><span class=\"n\">argc<\/span><span class=\"p\">,<\/span> <span class=\"n\">argv<\/span><span class=\"p\">,<\/span> <span class=\"n\">desc<\/span><span class=\"p\">),<\/span> <span class=\"n\">vm<\/span><span class=\"p\">);<\/span>\n<a id=\"main.cc-30\" class=\"line-number\" href=\"#main.cc-30\"><\/a>        <span class=\"n\">po<\/span><span class=\"o\">::<\/span><span class=\"n\">notify<\/span><span class=\"p\">(<\/span><span class=\"n\">vm<\/span><span class=\"p\">);<\/span>\n<a id=\"main.cc-31\" class=\"line-number\" href=\"#main.cc-31\"><\/a>    <span class=\"p\">}<\/span>\n<a id=\"main.cc-32\" class=\"line-number\" href=\"#main.cc-32\"><\/a>    <span class=\"k\">catch<\/span> <span class=\"p\">(<\/span><span class=\"n\">po<\/span><span class=\"o\">::<\/span><span class=\"n\">error<\/span><span class=\"o\">&amp;<\/span> <span class=\"n\">error<\/span><span class=\"p\">)<\/span>\n<a id=\"main.cc-33\" class=\"line-number\" href=\"#main.cc-33\"><\/a>    <span class=\"p\">{<\/span>\n<a id=\"main.cc-34\" class=\"line-number\" href=\"#main.cc-34\"><\/a>        <span class=\"n\">cerr<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;Error: &quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">error<\/span><span class=\"p\">.<\/span><span class=\"n\">what<\/span><span class=\"p\">()<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">endl<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-35\" class=\"line-number\" href=\"#main.cc-35\"><\/a>        <span class=\"n\">parseError<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">true<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-36\" class=\"line-number\" href=\"#main.cc-36\"><\/a>    <span class=\"p\">}<\/span>\n<a id=\"main.cc-37\" class=\"line-number\" href=\"#main.cc-37\"><\/a>\n<a id=\"main.cc-38\" class=\"line-number\" href=\"#main.cc-38\"><\/a>    <span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"n\">parseError<\/span> <span class=\"o\">||<\/span> <span class=\"n\">vm<\/span><span class=\"p\">.<\/span><span class=\"n\">count<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;help&quot;<\/span><span class=\"p\">))<\/span>\n<a id=\"main.cc-39\" class=\"line-number\" href=\"#main.cc-39\"><\/a>    <span class=\"p\">{<\/span>\n<a id=\"main.cc-40\" class=\"line-number\" href=\"#main.cc-40\"><\/a>        <span class=\"n\">cout<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;todo:  A simple To Do list program&quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-41\" class=\"line-number\" href=\"#main.cc-41\"><\/a>        <span class=\"n\">cout<\/span>                                         <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-42\" class=\"line-number\" href=\"#main.cc-42\"><\/a>        <span class=\"n\">cout<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;Usage:&quot;<\/span>                             <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-43\" class=\"line-number\" href=\"#main.cc-43\"><\/a>        <span class=\"n\">cout<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;  &quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">argv<\/span><span class=\"p\">[<\/span><span class=\"mi\">0<\/span><span class=\"p\">]<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot; [options]&quot;<\/span>      <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-44\" class=\"line-number\" href=\"#main.cc-44\"><\/a>        <span class=\"n\">cout<\/span>                                         <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-45\" class=\"line-number\" href=\"#main.cc-45\"><\/a>        <span class=\"n\">cout<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">desc<\/span>                                 <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-46\" class=\"line-number\" href=\"#main.cc-46\"><\/a>\n<a id=\"main.cc-47\" class=\"line-number\" href=\"#main.cc-47\"><\/a>        <span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"n\">parseError<\/span><span class=\"p\">)<\/span>\n<a id=\"main.cc-48\" class=\"line-number\" href=\"#main.cc-48\"><\/a>        <span class=\"p\">{<\/span>\n<a id=\"main.cc-49\" class=\"line-number\" href=\"#main.cc-49\"><\/a>            <span class=\"k\">return<\/span> <span class=\"mi\">64<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-50\" class=\"line-number\" href=\"#main.cc-50\"><\/a>        <span class=\"p\">}<\/span>\n<a id=\"main.cc-51\" class=\"line-number\" href=\"#main.cc-51\"><\/a>        <span class=\"k\">else<\/span>\n<a id=\"main.cc-52\" class=\"line-number\" href=\"#main.cc-52\"><\/a>        <span class=\"p\">{<\/span>\n<a id=\"main.cc-53\" class=\"line-number\" href=\"#main.cc-53\"><\/a>            <span class=\"k\">return<\/span> <span class=\"mi\">0<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-54\" class=\"line-number\" href=\"#main.cc-54\"><\/a>        <span class=\"p\">}<\/span>\n<a id=\"main.cc-55\" class=\"line-number\" href=\"#main.cc-55\"><\/a>    <span class=\"p\">}<\/span>\n<a id=\"main.cc-56\" class=\"line-number\" href=\"#main.cc-56\"><\/a>\n<a id=\"main.cc-57\" class=\"line-number\" href=\"#main.cc-57\"><\/a>\n<a id=\"main.cc-58\" class=\"line-number\" href=\"#main.cc-58\"><\/a>    <span class=\"n\">ToDo<\/span> <span class=\"n\">list<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-59\" class=\"line-number\" href=\"#main.cc-59\"><\/a>\n<a id=\"main.cc-60\" class=\"line-number\" href=\"#main.cc-60\"><\/a>    <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<a id=\"main.cc-61\" class=\"line-number\" href=\"#main.cc-61\"><\/a>    <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<a id=\"main.cc-62\" class=\"line-number\" href=\"#main.cc-62\"><\/a>    <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<a id=\"main.cc-63\" class=\"line-number\" href=\"#main.cc-63\"><\/a>\n<a id=\"main.cc-64\" class=\"line-number\" href=\"#main.cc-64\"><\/a>    <span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"n\">vm<\/span><span class=\"p\">.<\/span><span class=\"n\">count<\/span><span class=\"p\">(<\/span><span class=\"s\">&quot;add&quot;<\/span><span class=\"p\">))<\/span>\n<a id=\"main.cc-65\" class=\"line-number\" href=\"#main.cc-65\"><\/a>    <span class=\"p\">{<\/span>\n<a id=\"main.cc-66\" class=\"line-number\" href=\"#main.cc-66\"><\/a>        <span class=\"n\">list<\/span><span class=\"p\">.<\/span><span class=\"n\">addTask<\/span><span class=\"p\">(<\/span><span class=\"n\">vm<\/span><span class=\"p\">[<\/span><span class=\"s\">&quot;add&quot;<\/span><span class=\"p\">].<\/span><span class=\"n\">as<\/span><span class=\"o\">&lt;<\/span> <span class=\"n\">string<\/span> <span class=\"o\">&gt;<\/span><span class=\"p\">());<\/span>\n<a id=\"main.cc-67\" class=\"line-number\" href=\"#main.cc-67\"><\/a>    <span class=\"p\">}<\/span>\n<a id=\"main.cc-68\" class=\"line-number\" href=\"#main.cc-68\"><\/a>\n<a id=\"main.cc-69\" class=\"line-number\" href=\"#main.cc-69\"><\/a>    <span class=\"k\">for<\/span> <span class=\"p\">(<\/span><span class=\"kt\">size_t<\/span> <span class=\"n\">i<\/span> <span class=\"o\">=<\/span> <span class=\"mi\">0<\/span><span class=\"p\">;<\/span> <span class=\"n\">i<\/span> <span class=\"o\">&lt;<\/span> <span class=\"n\">list<\/span><span class=\"p\">.<\/span><span class=\"n\">size<\/span><span class=\"p\">();<\/span> <span class=\"o\">++<\/span><span class=\"n\">i<\/span><span class=\"p\">)<\/span>\n<a id=\"main.cc-70\" class=\"line-number\" href=\"#main.cc-70\"><\/a>    <span class=\"p\">{<\/span>\n<a id=\"main.cc-71\" class=\"line-number\" href=\"#main.cc-71\"><\/a>        <span class=\"n\">cout<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">list<\/span><span class=\"p\">.<\/span><span class=\"n\">getTask<\/span><span class=\"p\">(<\/span><span class=\"n\">i<\/span><span class=\"p\">)<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">&quot;<\/span><span class=\"se\">\\n<\/span><span class=\"s\">&quot;<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-72\" class=\"line-number\" href=\"#main.cc-72\"><\/a>    <span class=\"p\">}<\/span>\n<a id=\"main.cc-73\" class=\"line-number\" href=\"#main.cc-73\"><\/a>    <span class=\"k\">return<\/span> <span class=\"mi\">0<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-74\" class=\"line-number\" href=\"#main.cc-74\"><\/a><span class=\"p\">}<\/span>\n<\/pre>\n<\/div>\n<\/section>\n<p>\n    <a href=\"http:\/\/www.boost.org\/doc\/libs\/1_53_0\/doc\/html\/program_options.html\">Boost Program Options<\/a>    makes it easier to parse command line options than it would be to do it by<br \/>\n    hand. Now that we have the required <kbd>--help<\/kbd> option and the<br \/>\n    <kbd>--add<\/kbd> our app is a bit more useful.\n  <\/p>\n<p>\n    There&#8217;s a new problem now. How will we link our app against Boost? As it<br \/>\n    turns out CMake has a command for finding things like Boost: the<br \/>\n    <code>find_package()<\/code> command. Let&#8217;s see how it works.\n  <\/p>\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\" class=\"line-number\" href=\"#CMakeLists.txt-1\"><\/a><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<a id=\"CMakeLists.txt-2\" class=\"line-number\" href=\"#CMakeLists.txt-2\"><\/a><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<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\">project<\/span><span class=\"p\">(<\/span><span class=\"s2\">&quot;To Do List&quot;<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-5\" class=\"line-number\" href=\"#CMakeLists.txt-5\"><\/a>\n<a id=\"CMakeLists.txt-6\" class=\"line-number\" href=\"#CMakeLists.txt-6\"><\/a><span class=\"nb\">list<\/span><span class=\"p\">(<\/span><span class=\"s\">APPEND<\/span> <span class=\"s\">CMAKE_MODULE_PATH<\/span> <span class=\"o\">${<\/span><span class=\"nv\">CMAKE_SOURCE_DIR<\/span><span class=\"o\">}<\/span><span class=\"s\">\/cmake\/Modules<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-7\" class=\"line-number\" href=\"#CMakeLists.txt-7\"><\/a>\n<a id=\"CMakeLists.txt-8\" class=\"line-number\" href=\"#CMakeLists.txt-8\"><\/a><span class=\"nb\">enable_testing<\/span><span class=\"p\">()<\/span>\n<a id=\"CMakeLists.txt-9\" class=\"line-number\" href=\"#CMakeLists.txt-9\"><\/a><span class=\"nb\">include<\/span><span class=\"p\">(<\/span><span class=\"s\">gmock<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-10\" class=\"line-number\" href=\"#CMakeLists.txt-10\"><\/a>\n<a id=\"CMakeLists.txt-11\" class=\"line-number\" href=\"#CMakeLists.txt-11\"><\/a>\n<a id=\"CMakeLists.txt-12\" class=\"line-number\" href=\"#CMakeLists.txt-12\"><\/a><span class=\"hll\"><span class=\"nb\">if<\/span> <span class=\"p\">(<\/span><span class=\"s\">NOT<\/span> <span class=\"s\">DEFINED<\/span>     <span class=\"s\">BOOST_ROOT<\/span>        <span class=\"s\">AND<\/span>\n<\/span><a id=\"CMakeLists.txt-13\" class=\"line-number\" href=\"#CMakeLists.txt-13\"><\/a><span class=\"hll\">    <span class=\"s\">NOT<\/span> <span class=\"s\">DEFINED<\/span> <span class=\"s\">ENV{BOOST_ROOT}<\/span>       <span class=\"s\">AND<\/span>\n<\/span><a id=\"CMakeLists.txt-14\" class=\"line-number\" href=\"#CMakeLists.txt-14\"><\/a><span class=\"hll\">    <span class=\"s\">NOT<\/span> <span class=\"s\">DEFINED<\/span>     <span class=\"s\">BOOST_INCLUDEDIR<\/span>  <span class=\"s\">AND<\/span>\n<\/span><a id=\"CMakeLists.txt-15\" class=\"line-number\" href=\"#CMakeLists.txt-15\"><\/a><span class=\"hll\">    <span class=\"s\">NOT<\/span> <span class=\"s\">DEFINED<\/span> <span class=\"s\">ENV{BOOST_INCLUDEDIR}<\/span> <span class=\"s\">AND<\/span>\n<\/span><a id=\"CMakeLists.txt-16\" class=\"line-number\" href=\"#CMakeLists.txt-16\"><\/a><span class=\"hll\">    <span class=\"s\">NOT<\/span> <span class=\"s\">DEFINED<\/span>     <span class=\"s\">BOOST_LIBRARYDIR<\/span>  <span class=\"s\">AND<\/span>\n<\/span><a id=\"CMakeLists.txt-17\" class=\"line-number\" href=\"#CMakeLists.txt-17\"><\/a><span class=\"hll\">    <span class=\"s\">NOT<\/span> <span class=\"s\">DEFINED<\/span> <span class=\"s\">ENV{BOOST_LIBRARYDIR}<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-18\" class=\"line-number\" href=\"#CMakeLists.txt-18\"><\/a><span class=\"hll\">    <span class=\"nb\">if<\/span> <span class=\"p\">(<\/span><span class=\"s\">APPLE<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-19\" class=\"line-number\" href=\"#CMakeLists.txt-19\"><\/a><span class=\"hll\">        <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">BOOST_ROOT<\/span> <span class=\"s2\">&quot;..\/..\/..\/boost\/boost_1_54_0\/mac&quot;<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-20\" class=\"line-number\" href=\"#CMakeLists.txt-20\"><\/a><span class=\"hll\">    <span class=\"nb\">elseif<\/span> <span class=\"p\">(<\/span><span class=\"s\">WIN32<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-21\" class=\"line-number\" href=\"#CMakeLists.txt-21\"><\/a><span class=\"hll\">        <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">BOOST_INCLUDEDIR<\/span> <span class=\"s2\">&quot;C:\/local\/boost_1_55_0&quot;<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-22\" class=\"line-number\" href=\"#CMakeLists.txt-22\"><\/a><span class=\"hll\">        <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">BOOST_LIBRARYDIR<\/span> <span class=\"s2\">&quot;C:\/local\/boost_1_55_0\/lib32-msvc-10.0&quot;<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-23\" class=\"line-number\" href=\"#CMakeLists.txt-23\"><\/a><span class=\"hll\">    <span class=\"nb\">endif<\/span><span class=\"p\">()<\/span>\n<\/span><a id=\"CMakeLists.txt-24\" class=\"line-number\" href=\"#CMakeLists.txt-24\"><\/a><span class=\"hll\"><span class=\"nb\">endif<\/span><span class=\"p\">()<\/span>\n<\/span><a id=\"CMakeLists.txt-25\" class=\"line-number\" href=\"#CMakeLists.txt-25\"><\/a><span class=\"hll\"><span class=\"nb\">if<\/span> <span class=\"p\">(<\/span><span class=\"s\">APPLE<\/span> <span class=\"s\">OR<\/span> <span class=\"s\">WIN32<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-26\" class=\"line-number\" href=\"#CMakeLists.txt-26\"><\/a><span class=\"hll\">    <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">Boost_USE_STATIC_LIBS<\/span> <span class=\"s\">TRUE<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-27\" class=\"line-number\" href=\"#CMakeLists.txt-27\"><\/a><span class=\"hll\"><span class=\"nb\">endif<\/span><span class=\"p\">()<\/span>\n<\/span><a id=\"CMakeLists.txt-28\" class=\"line-number\" href=\"#CMakeLists.txt-28\"><\/a><span class=\"hll\"><span class=\"nb\">find_package<\/span><span class=\"p\">(<\/span><span class=\"s\">Boost<\/span> <span class=\"s\">1.32<\/span> <span class=\"s\">REQUIRED<\/span> <span class=\"s\">COMPONENTS<\/span> <span class=\"s\">program_options<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-29\" class=\"line-number\" href=\"#CMakeLists.txt-29\"><\/a><span class=\"hll\"><span class=\"nb\">include_directories<\/span><span class=\"p\">(<\/span><span class=\"s\">SYSTEM<\/span> <span class=\"o\">${<\/span><span class=\"nv\">Boost_INCLUDE_DIRS<\/span><span class=\"o\">}<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-30\" class=\"line-number\" href=\"#CMakeLists.txt-30\"><\/a><span class=\"hll\">\n<\/span><a id=\"CMakeLists.txt-31\" class=\"line-number\" href=\"#CMakeLists.txt-31\"><\/a><span class=\"nb\">if<\/span> <span class=\"p\">(<\/span><span class=\"s2\">&quot;${CMAKE_CXX_COMPILER_ID}&quot;<\/span> <span class=\"s\">STREQUAL<\/span> <span class=\"s2\">&quot;GNU&quot;<\/span> <span class=\"s\">OR<\/span>\n<a id=\"CMakeLists.txt-32\" class=\"line-number\" href=\"#CMakeLists.txt-32\"><\/a>    <span class=\"s2\">&quot;${CMAKE_CXX_COMPILER_ID}&quot;<\/span> <span class=\"s\">STREQUAL<\/span> <span class=\"s2\">&quot;Clang&quot;<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-33\" class=\"line-number\" href=\"#CMakeLists.txt-33\"><\/a>    <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">warnings<\/span> <span class=\"s2\">&quot;-Wall -Wextra -Werror&quot;<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-34\" class=\"line-number\" href=\"#CMakeLists.txt-34\"><\/a><span class=\"nb\">elseif<\/span> <span class=\"p\">(<\/span><span class=\"s2\">&quot;${CMAKE_CXX_COMPILER_ID}&quot;<\/span> <span class=\"s\">STREQUAL<\/span> <span class=\"s2\">&quot;MSVC&quot;<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-35\" class=\"line-number\" href=\"#CMakeLists.txt-35\"><\/a><span class=\"hll\">    <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">warnings<\/span> <span class=\"s2\">&quot;\/W4 \/wd4512 \/WX \/EHsc&quot;<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-36\" class=\"line-number\" href=\"#CMakeLists.txt-36\"><\/a><span class=\"hll\">        <span class=\"c\"># Disabled Warnings:<\/span>\n<\/span><a id=\"CMakeLists.txt-37\" class=\"line-number\" href=\"#CMakeLists.txt-37\"><\/a><span class=\"hll\">        <span class=\"c\">#   4512 &quot;assignment operator could not be generated&quot;<\/span>\n<\/span><a id=\"CMakeLists.txt-38\" class=\"line-number\" href=\"#CMakeLists.txt-38\"><\/a><span class=\"hll\">        <span class=\"c\">#        This warning provides no useful information and will occur in<\/span>\n<\/span><a id=\"CMakeLists.txt-39\" class=\"line-number\" href=\"#CMakeLists.txt-39\"><\/a><span class=\"hll\">        <span class=\"c\">#        well formed programs.<\/span>\n<\/span><a id=\"CMakeLists.txt-40\" class=\"line-number\" href=\"#CMakeLists.txt-40\"><\/a><span class=\"hll\">        <span class=\"c\">#        &lt;http:\/\/msdn.microsoft.com\/en-us\/library\/hsyx7kbz.aspx&gt;<\/span>\n<\/span><a id=\"CMakeLists.txt-41\" class=\"line-number\" href=\"#CMakeLists.txt-41\"><\/a><span class=\"nb\">endif<\/span><span class=\"p\">()<\/span>\n<a id=\"CMakeLists.txt-42\" class=\"line-number\" href=\"#CMakeLists.txt-42\"><\/a><span class=\"nb\">if<\/span> <span class=\"p\">(<\/span><span class=\"s\">NOT<\/span> <span class=\"s\">CONFIGURED_ONCE<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-43\" class=\"line-number\" href=\"#CMakeLists.txt-43\"><\/a>    <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">CMAKE_CXX_FLAGS<\/span> <span class=\"s2\">&quot;${warnings}&quot;<\/span>\n<a id=\"CMakeLists.txt-44\" class=\"line-number\" href=\"#CMakeLists.txt-44\"><\/a>        <span class=\"s\">CACHE<\/span> <span class=\"s\">STRING<\/span> <span class=\"s2\">&quot;Flags used by the compiler during all build types.&quot;<\/span> <span class=\"s\">FORCE<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-45\" class=\"line-number\" href=\"#CMakeLists.txt-45\"><\/a>    <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">CMAKE_C_FLAGS<\/span>   <span class=\"s2\">&quot;${warnings}&quot;<\/span>\n<a id=\"CMakeLists.txt-46\" class=\"line-number\" href=\"#CMakeLists.txt-46\"><\/a>        <span class=\"s\">CACHE<\/span> <span class=\"s\">STRING<\/span> <span class=\"s2\">&quot;Flags used by the compiler during all build types.&quot;<\/span> <span class=\"s\">FORCE<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-47\" class=\"line-number\" href=\"#CMakeLists.txt-47\"><\/a><span class=\"nb\">endif<\/span><span class=\"p\">()<\/span>\n<a id=\"CMakeLists.txt-48\" class=\"line-number\" href=\"#CMakeLists.txt-48\"><\/a>\n<a id=\"CMakeLists.txt-49\" class=\"line-number\" href=\"#CMakeLists.txt-49\"><\/a>\n<a id=\"CMakeLists.txt-50\" class=\"line-number\" href=\"#CMakeLists.txt-50\"><\/a><span class=\"nb\">include_directories<\/span><span class=\"p\">(<\/span><span class=\"o\">${<\/span><span class=\"nv\">CMAKE_CURRENT_SOURCE_DIR<\/span><span class=\"o\">}<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-51\" class=\"line-number\" href=\"#CMakeLists.txt-51\"><\/a>\n<a id=\"CMakeLists.txt-52\" class=\"line-number\" href=\"#CMakeLists.txt-52\"><\/a><span class=\"nb\">add_subdirectory<\/span><span class=\"p\">(<\/span><span class=\"s\">ToDoCore<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-53\" class=\"line-number\" href=\"#CMakeLists.txt-53\"><\/a>\n<a id=\"CMakeLists.txt-54\" class=\"line-number\" href=\"#CMakeLists.txt-54\"><\/a><span class=\"nb\">add_executable<\/span><span class=\"p\">(<\/span><span class=\"s\">toDo<\/span> <span class=\"s\">main.cc<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-55\" class=\"line-number\" href=\"#CMakeLists.txt-55\"><\/a><span class=\"hll\"><span class=\"nb\">target_link_libraries<\/span><span class=\"p\">(<\/span><span class=\"s\">toDo<\/span> <span class=\"s\">toDoCore<\/span> <span class=\"o\">${<\/span><span class=\"nv\">Boost_LIBRARIES<\/span><span class=\"o\">}<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-56\" class=\"line-number\" href=\"#CMakeLists.txt-56\"><\/a>\n<a id=\"CMakeLists.txt-57\" class=\"line-number\" href=\"#CMakeLists.txt-57\"><\/a>\n<a id=\"CMakeLists.txt-58\" class=\"line-number\" href=\"#CMakeLists.txt-58\"><\/a><span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">CONFIGURED_ONCE<\/span> <span class=\"s\">TRUE<\/span> <span class=\"s\">CACHE<\/span> <span class=\"s\">INTERNAL<\/span>\n<a id=\"CMakeLists.txt-59\" class=\"line-number\" href=\"#CMakeLists.txt-59\"><\/a>    <span class=\"s2\">&quot;A flag showing that CMake has configured at least once.&quot;<\/span><span class=\"p\">)<\/span>\n<\/pre>\n<\/div>\n<\/section>\n<p>  <a class=\"sources\" href=\"https:\/\/www.johnlamp.net\/sources\/chapter6.zip\"><img src=\"https:\/\/www.johnlamp.net\/images\/zip.png\" alt=\"[zip file] \" \/>Source<\/a><\/p>\n<dl>\n<dt class=\"code\">\n      find_package(Boost 1.32 REQUIRED COMPONENTS program_options)\n    <\/dt>\n<dd>\n      This command searches for Boost, both the headers and the<br \/>\n      boost_program_options library, and then defines variables that indicate<br \/>\n      whether or not Boost has been found and if so describe the locations of<br \/>\n      the libraries and header files.\n    <\/dd>\n<dt class=\"code\">\n      include_directories(SYSTEM ${Boost_INCLUDE_DIRS})\n    <\/dt>\n<dd>\n      Add the paths to Boost&#8217;s include files to the compiler&#8217;s include search<br \/>\n      paths.\n    <\/dd>\n<dd>\n      By using the <code>SYSTEM<\/code> argument CMake will tell the compiler, if<br \/>\n      possible, that these paths contain system include files. Oftentimes the<br \/>\n      compiler will ignore warnings from files found in system include paths.\n    <\/dd>\n<dd class=\"note\">\n      The <code>SYSTEM<\/code> option does not have an effect with all<br \/>\n      generators. When using the Visual Studio 10 or the Xcode generators<br \/>\n      neither Visual Studio nor Xcode appear to treat system include paths any<br \/>\n      differently than regular include paths. This can make a big difference<br \/>\n      when compiler flags are set to treat warnings as errors.\n    <\/dd>\n<dt class=\"code\">\n      target_link_libraries(toDo ${Boost_LIBRARIES} toDoCore)\n    <\/dt>\n<dd>\n      This links our little app, toDo, with the Boost libraries. In this case<br \/>\n      just <code>boost_program_options<\/code> since that&#8217;s the only compiled<br \/>\n      library we requested. It also links toDo with our toDoCore<br \/>\n      library. Naturally we need this as that library implements all of our to<br \/>\n      do list functionality.\n    <\/dd>\n<\/dl>\n<dl>\n<dt class=\"code\">\n      find_package(<span class=\"arg\">package<\/span><br \/>\n                   <span class=\"optional\"><span class=\"arg\">version<\/span><br \/>\n                     <span class=\"optional\">EXACT<\/span><\/span><br \/>\n                   <span class=\"optional\">REQUIRED<\/span><br \/>\n                   <span class=\"optional\">COMPONENTS<br \/>\n                     <span class=\"arg\">components&hellip;<\/span><\/span>)\n    <\/dt>\n<dd>\n<dl>\n<dt class=\"code arg\">\n          package\n        <\/dt>\n<dd>\n          The name of the package to find, e.g. <code>Boost<\/code>. This name is case<br \/>\n          sensitive.\n        <\/dd>\n<dt class=\"arg\">\n          <span class=\"optional\">version<\/span>\n        <\/dt>\n<dd>\n          The desired version of the package.\n        <\/dd>\n<dt class=\"code\">\n          <span class=\"optional\">EXACT<\/span>\n        <\/dt>\n<dd>\n          Match the version of the package exactly instead of accepting a newer version.\n        <\/dd>\n<dt class=\"code\">\n          <span class=\"optional\">REQUIRED<\/span>\n        <\/dt>\n<dd>\n          Specifying this option causes CMake&#8217;s configure step to fail if the<br \/>\n          package cannot be found.\n        <\/dd>\n<dt class=\"code\">\n          <span class=\"optional\">COMPONENTS<br \/>\n            <span class=\"arg\">components&hellip;<\/span><\/span>\n        <\/dt>\n<dd>\n          Some libraries, like Boost, have optional components. The<br \/>\n          <code>find_package()<\/code> command will only search for these<br \/>\n          components if they have been listed as arguments when the command is<br \/>\n          called.\n        <\/dd>\n<\/dl>\n<\/dd>\n<dd>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#command:find_package\"><code>find_package()<\/code> documentation<\/a>      <time class=\"access\" datetime=\"2014-11-14\">(2014-11-14)<\/time>    <\/dd>\n<\/dl>\n<\/section>\n<section>\n<h1 id=\"section-HowToUseFindboost\">How to Use FindBoost<\/h1>\n<p>\n    We glossed over how to use FindBoost before and actually we<br \/>\n    glossed over how <code>find_package()<\/code> really works. Naturally CMake<br \/>\n    can&#8217;t know how to find any arbitrary package. So<br \/>\n    <code>find_package()<\/code>, as invoked above, actually loads a CMake Module<br \/>\n    file called <code>FindBoost.cmake<\/code> which does the actual work of<br \/>\n    finding Boost. CMake installations come with a good complement of Find<br \/>\n    Modules. CMake searches for <code>FindBoost.cmake<\/code> just as it would<br \/>\n    any module included using the <code>include()<\/code> command.\n  <\/p>\n<p>\n    The documentation for it can be obtained using the command <kbd>cmake<br \/>\n    --help-module FindBoost<\/kbd>.\n  <\/p>\n<dl>\n<dt class=\"code\">\n      set(BOOST_ROOT &#8220;..\/..\/..\/boost\/boost_1_54_0\/mac&#8221;)\n    <\/dt>\n<dd>\n      FindBoost uses the value of <code>BOOST_ROOT<\/code> as a hint for where to<br \/>\n      look. It will search in <code>BOOST_ROOT<\/code> as well as the standard<br \/>\n      places to look for libraries. In this example I did not install Boost in a<br \/>\n      standard location on my Mac so I needed to tell FindBoost where to look.\n    <\/dd>\n<dt class=\"code\">\n      set(BOOST_INCLUDEDIR &#8220;C:\/local\/boost_1_55_0&#8221;)\n    <\/dt>\n<dd>\n      If your installation of boost is not stored in the &ldquo;normal&rdquo;<br \/>\n      folders, i.e. <code>include<\/code> and <code>lib<\/code>, you will need to<br \/>\n      specify the directory that contains the include files separately. Since<br \/>\n      libraries don&#8217;t seem to have a standard installation location on Windows<br \/>\n      as they do on Linux we needed to tell FindBoost where Boost&#8217;s header files<br \/>\n      are. Usually when providing <code>BOOST_INCLUDEDIR<\/code><br \/>\n      <code>BOOST_ROOT<\/code> isn&#8217;t needed. If you are using any of Boost&#8217;s<br \/>\n      compiled libraries you will also need <code>BOOST_LIBRARYDIR<\/code>.\n    <\/dd>\n<dt class=\"code\">\n      set(BOOST_LIBRARYDIR &#8220;C:\/local\/boost_1_55_0\/lib32-msvc-10.0&#8221;)\n    <\/dt>\n<dd>\n      The same as <code>BOOST_INCLUDEDIR<\/code>, if specifying<br \/>\n      <code>BOOST_ROOT<\/code> doesn&#8217;t find the libraries then you will have to<br \/>\n      specify the <code>BOOST_LIBRARYDIR<\/code>.\n    <\/dd>\n<dt class=\"code\">\n      set(Boost_USE_STATIC_LIBS TRUE)\n    <\/dt>\n<dd>\n      By default FindBoost provides the paths to dynamic libraries, however you<br \/>\n      can set <code>Boost_USE_STATIC_LIBS<\/code> to true so that FindBoost will<br \/>\n      provide the paths to the static libraries instead.\n    <\/dd>\n<dd>\n      We want to use the static libraries on Mac OS X (<code>APPLE<\/code>)<br \/>\n      because when Boost is installed on the Mac the dynamic libraries are not<br \/>\n      configured properly and our app would not run if we were to link against<br \/>\n      them.\n    <\/dd>\n<dd>\n      On Windows we are linking with static libraries so Visual Studio will look<br \/>\n      for the static Boost libraries. Since FindBoost normally provides the<br \/>\n      paths to Boost&#8217;s dynamic libraries linking would fail. By specifying that<br \/>\n      we want the static libraries linking will succeed and we can use our new<br \/>\n      command line arguments.\n    <\/dd>\n<\/dl>\n<p>\n    There are several other variables that affect how FindBoost works, but they<br \/>\n    aren&#8217;t needed as often. Consult the documentation for more information.\n  <\/p>\n<p>\n    <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#module:FindBoost\">FindBoost documentation<\/a>    <time class=\"access\" datetime=\"2015-03-02\">(2015-03-02)<\/time>  <\/p>\n<dl>\n<dt class=\"code\">\n      include_directories(SYSTEM ${Boost_INCLUDE_DIRS})\n    <\/dt>\n<dd>\n      We add the paths to where the Boost header files are. These assume that<br \/>\n      your include directives are of the canonical form<br \/>\n      <code>#include &lt;boost\/&hellip;&gt;<\/code>.<br \/>\n      <code>Boost_INCLUDE_DIRS<\/code> is set for us by FindBoost.\n    <\/dd>\n<dt class=\"code\">\n      target_link_libraries(toDo ${Boost_LIBRARIES} toDoCore)\n    <\/dt>\n<dd>\n      The paths to all of the boost libraries we requested,<br \/>\n      i.e. <code>program_options<\/code>, are provided by FindBoost in the<br \/>\n      variable <code>Boost_LIBRARIES<\/code>. We simply link against the list of<br \/>\n      libraries provided.\n    <\/dd>\n<\/dl>\n<p>\n    FindBoost defines several other variables, which are listed in its<br \/>\n    documentation. The most important one, not used here, is<br \/>\n    <code>Boost_FOUND<\/code>. If Boost has been found then<br \/>\n    <code>Boost_FOUND<\/code> will be true, otherwise it will be false. Since we<br \/>\n    specified that Boost was <code>REQUIRED<\/code> we know that<br \/>\n    <code>Boost_FOUND<\/code> must be true otherwise CMake&#8217;s configuration step<br \/>\n    would have failed. If Boost were not <code>REQUIRED<\/code> then<br \/>\n    <code>Boost_FOUND<\/code> would be an extremely important variable.\n  <\/p>\n<p>\n    If we had chosen not to require Boost but not changed anything else in our<br \/>\n    <code>CMakeLists.txt<\/code> we would run into trouble if Boost had not been<br \/>\n    found. You would expect that our code wouldn&#8217;t compile because an include<br \/>\n    file could not be found. As it turns out you won&#8217;t actually get that<br \/>\n    far. FindBoost will set <code>Boost_INCLUDE_DIRS<\/code> to a value<br \/>\n    indicating that Boost was not found. Because of this the CMake configure<br \/>\n    step will fail because we use that variable as an include directory. Since<br \/>\n    CMake checks this for us we need to remember to be careful when using<br \/>\n    optional packages.\n  <\/p>\n<h2 id=\"section-ChoosingARoot\">Choosing a Root<\/h2>\n<p>\n    Typically <code>BOOST_ROOT<\/code> should be the directory that contains the<br \/>\n    <code>include<\/code> and <code>lib<\/code> directories in which you will find<br \/>\n    boost. Remember the boost headers will be inside a <code>boost<\/code><br \/>\n    directory. As you might notice this is the standard layout used on Unix and<br \/>\n    Linux. When the headers and libraries are not arranged this way, as is<br \/>\n    likely on Windows, the <code>BOOST_INCLUDEDIR<\/code> and<br \/>\n    <code>BOOST_LIBRARYDIR<\/code> should be used instead.\n  <\/p>\n<p>\n    So right now you are probably wondering what use FindBoost really is if I<br \/>\n    had to specify the root, or worse the include and library directories. Well<br \/>\n    there are a few reasons:\n  <\/p>\n<ul>\n<li>\n      Most importantly if Boost has been installed in a standard location it<br \/>\n      would have been found without any information being provided.\n    <\/li>\n<li>\n      It will check that the Boost it finds is the desired version, 1.32 or<br \/>\n      greater in this case. Not all finders actually check version, but when<br \/>\n      available this feature is very useful as incorrect library versions are<br \/>\n      caught immediately rather than later through potentially confusing compile<br \/>\n      errors.\n    <\/li>\n<li>\n      In the case of Boost the finder will ensure the desired libraries are<br \/>\n      found. Since approximately 90% of the Boost libraries are header only some<br \/>\n      installs only include the headers and none of the compiled libraries.\n    <\/li>\n<li>\n      Lastly even though I specified my non-standard install locations for<br \/>\n      Boost in the <code>CMakeLists.txt<\/code> you needn&#8217;t install it<br \/>\n      there. Regardless FindBoost will still find Boost if you have it<br \/>\n      installed in a standard location. Additionally you can set your own<br \/>\n      location using by setting the <code>BOOST_ROOT<\/code> variable using the<br \/>\n      <code>-D<\/code> command line option of <code>cmake<\/code> or by setting<br \/>\n      it using the GUI or curses interface. Perhaps most conveniently you can<br \/>\n      set the <code>BOOST_ROOT<\/code> environment variable and not need to<br \/>\n      tell CMake separately. This, of course, applies to the<br \/>\n      <code>BOOST_INCLUDEDIR<\/code> and <code>BOOST_LIBRARYDIR<\/code><br \/>\n      variables, too.\n    <\/li>\n<\/ul>\n<p>\n    So this leaves one question: does it make sense to set<br \/>\n    <code>BOOST_ROOT<\/code> in the <code>CMakeLists.txt<\/code>?\n  <\/p>\n<p>\n    If you are the only one working on the project then it will certainly be<br \/>\n    easier to set it in the <code>CMakeLists.txt<\/code>, although you will have<br \/>\n    to do this for every project. Setting the environmental variable might be<br \/>\n    easier.\n  <\/p>\n<p>\n    If you work on a team whose development machines are all configured<br \/>\n    similarly, or should be, then setting <code>BOOST_ROOT<\/code> in the<br \/>\n    <code>CMakeLists.txt<\/code> is a good idea because it simplifies things for<br \/>\n    most developers and therefore provides and incentive for all developers to<br \/>\n    use the standard configuration.\n  <\/p>\n<p>\n    Now if you work with a disparate group of people, say on an free\/open source<br \/>\n    project, it makes less sense to set <code>BOOST_ROOT<\/code> in the<br \/>\n    <code>CMakeLists.txt<\/code> as there is likely no notion of a standard<br \/>\n    development environment.\n  <\/p>\n<\/section>\n<section>\n<h1 id=\"section-FindingPackages\">Finding Packages<\/h1>\n<p>\n    Since CMake ships with a reasonable number of Find modules there&#8217;s a good<br \/>\n    chance that whatever you want to find can be found by simply using the<br \/>\n    <code>find_package<\/code> command. While you should review the documentation<br \/>\n    for that particular module there are some variables that you can expect to<br \/>\n    be defined.\n  <\/p>\n<dl>\n<dt class=\"code\">\n      <span class=\"arg\">Package<\/span>_FOUND\n    <\/dt>\n<dd>\n      This variable indicates whether or not the package has been found.\n    <\/dd>\n<dt class=\"code\">\n      <span class=\"arg\">Package<\/span>_INCLUDE_DIRS\n    <\/dt>\n<dd>\n      The include directories for that particular package. This variable should<br \/>\n      be passed to the <code>include_directories()<\/code> command.\n    <\/dd>\n<dt class=\"code\">\n      <span class=\"arg\">Package<\/span>_LIBRARIES\n    <\/dt>\n<dd>\n      The full paths to this package&#8217;s libraries. This variable should be passed<br \/>\n      to the <code>target_link_libraries()<\/code> command.\n    <\/dd>\n<dt class=\"code\">\n      <span class=\"arg\">Package<\/span>_DEFINITIONS\n    <\/dt>\n<dd>\n      Definitions required to compile code that uses this package. This should<br \/>\n      be passed to the <code>add_definitions()<\/code> command.\n    <\/dd>\n<\/dl>\n<\/section>\n<section>\n<h1 id=\"section-DocumentationFound\">Documentation Found<\/h1>\n<p>\n    As mentioned above you can get the documentation for FindBoost by using the<br \/>\n    <kbd>cmake<\/kbd> command. While this is somewhat convenient the terminal is<br \/>\n    not always the best tool for reading documentation. There is a slightly more<br \/>\n    useful variant of the command:<br \/>\n    <kbd>cmake --help-module FindBoost <span class=\"arg\">file<\/span><\/kbd>.<br \/>\n    This allows you to read the documentation however you please.\n  <\/p>\n<p>\n    There&#8217;s another convenient command that will list all of the available<br \/>\n    modules: <kbd>cmake --help-modules<\/kbd>. This will also provide some<br \/>\n    documentation for each. Again you can easily save this to a file with the<br \/>\n    command <kbd>cmake --help-modules <span class=\"arg\">file<\/span><\/kbd>.\n  <\/p>\n<p>\n    If you have a Unix\/Linux-like shell then you can easily get a list of all<br \/>\n    available Find modules.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n <span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cmake --version\ncmake version 2.8.12.1\n <span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cmake --help-modules | grep -E &quot;^  Find&quot;\n  FindALSA\n  FindASPELL\n  FindAVIFile\n  FindArmadillo\n  FindBISON\n  FindBLAS\n  FindBZip2\n  FindBoost\n  FindBullet\n  FindCABLE\n  FindCUDA\n  FindCURL\n  FindCVS\n  FindCoin3D\n  FindCups\n  FindCurses\n  FindCxxTest\n  FindCygwin\n  FindDCMTK\n  FindDart\n  FindDevIL\n  FindDoxygen\n  FindEXPAT\n  FindFLEX\n  FindFLTK\n  FindFLTK2\n  FindFreetype\n  FindGCCXML\n  FindGDAL\n  FindGIF\n  FindGLEW\n  FindGLUT\n  FindGTK\n  FindGTK2\n  FindGTest\n  FindGettext\n  FindGit\n  FindGnuTLS\n  FindGnuplot\n  FindHDF5\n  FindHSPELL\n  FindHTMLHelp\n  FindHg\n  FindITK\n  FindIcotool\n  FindImageMagick\n  FindJNI\n  FindJPEG\n  FindJasper\n  FindJava\n  FindKDE3\n  FindKDE4\n  FindLAPACK\n  FindLATEX\n  FindLibArchive\n  FindLibLZMA\n  FindLibXml2\n  FindLibXslt\n  FindLua50\n  FindLua51\n  FindMFC\n  FindMPEG\n  FindMPEG2\n  FindMPI\n  FindMatlab\n  FindMotif\n  FindOpenAL\n  FindOpenGL\n  FindOpenMP\n  FindOpenSSL\n  FindOpenSceneGraph\n  FindOpenThreads\n  FindPHP4\n  FindPNG\n  FindPackageHandleStandardArgs\n  FindPackageMessage\n  FindPerl\n  FindPerlLibs\n  FindPhysFS\n  FindPike\n  FindPkgConfig\n  FindPostgreSQL\n  FindProducer\n  FindProtobuf\n  FindPythonInterp\n  FindPythonLibs\n  FindQt\n  FindQt3\n  FindQt4\n  FindQuickTime\n  FindRTI\n  FindRuby\n  FindSDL\n  FindSDL_image\n  FindSDL_mixer\n  FindSDL_net\n  FindSDL_sound\n  FindSDL_ttf\n  FindSWIG\n  FindSelfPackers\n  FindSquish\n  FindSubversion\n  FindTCL\n  FindTIFF\n  FindTclStub\n  FindTclsh\n  FindThreads\n  FindUnixCommands\n  FindVTK\n  FindWget\n  FindWish\n  FindX11\n  FindXMLRPC\n  FindZLIB\n  Findosg\n  FindosgAnimation\n  FindosgDB\n  FindosgFX\n  FindosgGA\n  FindosgIntrospection\n  FindosgManipulator\n  FindosgParticle\n  FindosgPresentation\n  FindosgProducer\n  FindosgQt\n  FindosgShadow\n  FindosgSim\n  FindosgTerrain\n  FindosgText\n  FindosgUtil\n  FindosgViewer\n  FindosgVolume\n  FindosgWidget\n  Findosg_functions\n  FindwxWidgets\n  FindwxWindows\n<\/pre>\n<\/section>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Now that we have our testing simplified and automated we have a great<br \/>\n    foundation upon which to build our amazing command line To Do list app.<br \/>\n    What&#8217;s that? You say that an awesome To Do app allows you to add items to<br \/>\n    your list? Indeed it does, and more! But wait, let&#8217;s not get ahead &hellip;<br \/><a href=\"https:\/\/www.johnlamp.net\/?p=54\" rel=\"bookmark\">Continue reading &quot;CMake Tutorial &#8211; Chapter&#160;6: Realistically Getting a Boost&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\/54"}],"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=54"}],"version-history":[{"count":0,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}