{"id":18,"date":"2013-03-28T19:34:23","date_gmt":"2013-03-29T00:34:23","guid":{"rendered":"https:\/\/104.236.124.184\/cmake-tutorial-3-gui-tool.html"},"modified":"2013-03-28T19:34:23","modified_gmt":"2013-03-29T00:34:23","slug":"cmake-tutorial-3-gui-tool","status":"publish","type":"post","link":"https:\/\/www.johnlamp.net\/?p=18","title":{"rendered":"CMake Tutorial &#8211; Chapter&#160;3: GUI Tool"},"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-FirstFixAWarning\">First Fix a Warning<\/a><\/li>\n<li><a href=\"#section-CmakeGui\">CMake GUI<\/a><\/li>\n<li>\n<ol>\n<li><a href=\"#section-GeneratingOurProject\">Generating Our Project<\/a><\/li>\n<li><a href=\"#section-CmakeCache\">CMake Cache<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"#section-CmakeCursesInterface\">CMake Curses Interface<\/a><\/li>\n<li>\n<ol>\n<li><a href=\"#section-IntroducingCcmake\">Introducing <code>ccmake<\/code><\/a><\/li>\n<li><a href=\"#section-UsefulMakefileTargets\">Useful Makefile Targets<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/nav>\n<section>\n<h1 id=\"section-Introduction\">Introduction<\/h1>\n<p>\n    Although when we looked at IDE projects generated by CMake we still used the<br \/>\n    command line. You can also use the CMake GUI to generate and configure<br \/>\n    projects. This can be convenient if you don&#8217;t like the command line, however<br \/>\n    it can be even more useful than that.\n  <\/p>\n<p>\n    CMake stores a lot of configuration settings in the project&#8217;s cache. This<br \/>\n    cache can be viewed and edited using the CMake GUI. This can be quite useful<br \/>\n    for seeing how a project is configured as the settings are presented in a<br \/>\n    nice list. You can also change these values so you can set your build type<br \/>\n    to &#8220;Release&#8221; to make a release build or you can add specific compiler flags.\n  <\/p>\n<\/section>\n<section>\n<h1 id=\"section-FirstFixAWarning\">First Fix a Warning<\/h1>\n<p>\n    In <a href=\"https:\/\/www.johnlamp.net\/cmake-tutorial-2-ide-integration.html#section-Xcode\">chapter 2<\/a>    when covering the Xcode generator I said that I&#8217;d fix the warning we saw<br \/>\n    later. Well it looks like later has come. The first thing we need to do<br \/>\n    is give the compiler some more flags so that we can reproduce the warning.\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\">enable_testing<\/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>\n<a id=\"CMakeLists.txt-9\" class=\"line-number\" href=\"#CMakeLists.txt-9\"><\/a><span class=\"hll\"><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<\/span><a id=\"CMakeLists.txt-10\" class=\"line-number\" href=\"#CMakeLists.txt-10\"><\/a><span class=\"hll\">    <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<\/span><a id=\"CMakeLists.txt-11\" class=\"line-number\" href=\"#CMakeLists.txt-11\"><\/a><span class=\"hll\">    <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<\/span><a id=\"CMakeLists.txt-12\" class=\"line-number\" href=\"#CMakeLists.txt-12\"><\/a><span class=\"hll\"><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<\/span><a id=\"CMakeLists.txt-13\" class=\"line-number\" href=\"#CMakeLists.txt-13\"><\/a><span class=\"hll\">    <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">warnings<\/span> <span class=\"s2\">&quot;\/W4 \/WX \/EHsc&quot;<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-14\" class=\"line-number\" href=\"#CMakeLists.txt-14\"><\/a><span class=\"hll\"><span class=\"nb\">endif<\/span><span class=\"p\">()<\/span>\n<\/span><a id=\"CMakeLists.txt-15\" class=\"line-number\" href=\"#CMakeLists.txt-15\"><\/a><span class=\"hll\"><span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">CMAKE_C_FLAGS<\/span>   <span class=\"s2\">&quot;${CMAKE_C_FLAGS} ${warnings}&quot;<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-16\" class=\"line-number\" href=\"#CMakeLists.txt-16\"><\/a><span class=\"hll\"><span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">CMAKE_CXX_FLAGS<\/span> <span class=\"s2\">&quot;${CMAKE_CXX_FLAGS} ${warnings}&quot;<\/span><span class=\"p\">)<\/span>\n<\/span><a id=\"CMakeLists.txt-17\" class=\"line-number\" href=\"#CMakeLists.txt-17\"><\/a><span class=\"hll\">\n<\/span><a id=\"CMakeLists.txt-18\" class=\"line-number\" href=\"#CMakeLists.txt-18\"><\/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-19\" class=\"line-number\" href=\"#CMakeLists.txt-19\"><\/a>                    <span class=\"s\">ToDo.cc<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-20\" class=\"line-number\" href=\"#CMakeLists.txt-20\"><\/a>\n<a id=\"CMakeLists.txt-21\" class=\"line-number\" href=\"#CMakeLists.txt-21\"><\/a><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<\/pre>\n<\/div>\n<\/section>\n<dl>\n<dt>\n      <code>if(<span class=\"subtle\">...<\/span>)<\/code>,<br \/>\n      <code>elseif(<span class=\"subtle\">...<\/span>)<\/code>,<br \/>\n      <code>else()<\/code>,<br \/>\n      <code>endif()<\/code>\n    <\/dt>\n<dd>\n      While everything in CMake looks like a function call control flow is<br \/>\n      available. Its <code>if<\/code> syntax is rather strange so be sure to keep<br \/>\n      the<br \/>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#command:if\">documentation<\/a>      <time class=\"access\">(2013-01-07)<\/time> handy. The arguments passed<br \/>\n      to <code>else()<\/code> and <code>endif()<\/code> are ignored, but they can<br \/>\n      be useful for documentation purposes.\n    <\/dd>\n<dt class=\"code\">\n      CMAKE_<i>&lt;LANG&gt;<\/i>_COMPILER_ID\n    <\/dt>\n<dd>\n      These variables identify the type of compiler being used. Here we are<br \/>\n      using it to be able to pass different flags to different compilers as<br \/>\n      needed. Since Clang accepts the same arguments as GCC I grouped them<br \/>\n      together.  A list of possible values is provided by the<br \/>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#variable:CMAKE_LANG_COMPILER_ID\">documentation<\/a>      <time class=\"access\">(2013-01-07)<\/time>.  Obviously my if statement is<br \/>\n      not exhaustive as it only covers the 3 compilers I have readily available.\n    <\/dd>\n<dt class=\"code\">\n      set(<span class=\"arg\">variableName<\/span><br \/>\n      <span class=\"arg\">value&#8230;<\/span>)\n    <\/dt>\n<dd>\n      Set a variable with the given name to a particular value or list of<br \/>\n      values. <span class=\"subtle\">(Lists will be covered<br \/>\n      <a href=\"https:\/\/www.johnlamp.net\/cmake-tutorial-5-functionally-improved-testing.html#section-Lists!\">later<\/a>)<\/span>    <\/dd>\n<dd>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#command:set\">set() documentation<\/a>      <time class=\"access\">(2013-03-26)<\/time>\n    <\/dd>\n<dt class=\"code\">\n      CMAKE_<i>&lt;LANG&gt;<\/i>_FLAGS\n    <\/dt>\n<dd>\n      These variables store the flags that will be passed to the compiler for<br \/>\n      all build types. In this particular case we wanted to add some flags that<br \/>\n      control warnings. (Build types will be covered later in this chapter.)\n    <\/dd>\n<dd class=\"note\">\n      <em class=\"call-out\">Note:<\/em> This variable is a string containing all<br \/>\n      of the flags separated by spaces; it is <b>not<\/b> a list.\n    <\/dd>\n<dd>\n      In this case we are turning on most warnings and having the compiler treat<br \/>\n      them as errors. <span class=\"subtle\">(This is, in fact,<br \/>\n      <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/thxezb7y.aspx\">Microsoft&#8217;s<\/a>      suggestion for all new projects.)<\/span> Since we only want to add these<br \/>\n      options we append them to the end of the existing flags string.\n    <\/dd>\n<dd>\n      CMake does offer some string functions, but not for something as simple as<br \/>\n      appending to an existing string.\n    <\/dd>\n<dd>\n      A few notes about MSVC: The <code>\/EHsc<\/code> flag enables complete C++<br \/>\n      exception handling which is required by <code>iostream<\/code>.<br \/>\n      (<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/vstudio\/1deeycx5.aspx\"><code>\/EH<\/code> documentation<\/a>      <time class=\"access\">2013-04-13<\/time>)<br \/>\n      More importantly is that CMake will convert Unix-style flags to<br \/>\n      Microsoft-style flags automatically for you. So we could have used<br \/>\n      <code>\"-W4 -WX -EHsc\"<\/code> instead and it would have worked. This means<br \/>\n      that any common flags do not need to be defined separately for MSVC. I<br \/>\n      would, however, recommend always using Microsoft-style flags for MSVC<br \/>\n      specific flags. Then not only is it obvious that they are MSVC flags, but<br \/>\n      they are also easier to look up since you won&#8217;t have to remember to<br \/>\n      translate them yourself.\n    <\/dd>\n<\/dl>\n<p>\n    Now if we build not only should we see more warnings and since they are<br \/>\n    being treated as errors they should also prevent the build from<br \/>\n    completing. Since warnings usually point to potential problems I always set<br \/>\n    up my <code>CMakeLists.txt<\/code> to enable stricter warnings and treat them<br \/>\n    as errors. Developing this way can be a bit annoying, but in the long run it<br \/>\n    will lead to cleaner code and, in theory, fewer defects.\n  <\/p>\n<section id=\"WarningOutput\" class=\"terminal\">\n<pre>\n <span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> mkdir build\n <span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd build\n <span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cmake -G &quot;Unix Makefiles&quot; ..\n-- The C compiler identification is Clang 4.1.0\n-- The CXX compiler identification is Clang 4.1.0\n-- Check for working C compiler: \/usr\/bin\/cc\n-- Check for working C compiler: \/usr\/bin\/cc -- works\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - done\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\/mac\/part3\/build\n <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><span class=\"ansiBold\">\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/mac\/part3\/main.cc:22:12: <\/span><span class=\"ansiBold ansiForeground-red\">error: <\/span><span class=\"ansiBold\">\n      unused parameter 'argc' [-Werror,-Wunused-parameter]<\/span>\n    int    argc,\n<span class=\"ansiBold ansiForeground-green\">           ^\n<\/span><span class=\"ansiBold\">\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/mac\/part3\/main.cc:23:12: <\/span><span class=\"ansiBold ansiForeground-red\">error: <\/span><span class=\"ansiBold\">\n      unused parameter 'argv' [-Werror,-Wunused-parameter]<\/span>\n    char** argv\n<span class=\"ansiBold ansiForeground-green\">           ^\n<\/span><span class=\"ansiBold\">\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/mac\/part3\/main.cc:58:19: <\/span><span class=\"ansiBold ansiForeground-red\">error: <\/span><span class=\"ansiBold\">\n      comparison of integers of different signs: 'const unsigned long' and\n      'const int' [-Werror,-Wsign-compare]<\/span>\n    if (testValue != expectedValue)\n<span class=\"ansiBold ansiForeground-green\">        ~~~~~~~~~ ^  ~~~~~~~~~~~~~\n<\/span><span class=\"ansiBold\">\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/mac\/part3\/main.cc:34:15: <\/span><span class=\"ansiBold ansiForeground-black\">note: <\/span>\n      in instantiation of function template specialization\n      'equalityTest&lt;unsigned long, int&gt;' requested here\n    result |= EXPECT_EQUAL(list.size(), 3);\n<span class=\"ansiBold ansiForeground-green\">              ^\n<\/span><span class=\"ansiBold\">\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/mac\/part3\/main.cc:8:36: <\/span><span class=\"ansiBold ansiForeground-black\">note: <\/span>\n      expanded from macro 'EXPECT_EQUAL'\n#define EXPECT_EQUAL(test, expect) equalityTest( test,  expect, \\\n<span class=\"ansiBold ansiForeground-green\">                                   ^\n<\/span>3 errors generated.\nmake[2]: *** [CMakeFiles\/toDo.dir\/main.cc.o] Error 1\nmake[1]: *** [CMakeFiles\/toDo.dir\/all] Error 2\nmake: *** [all] Error 2\n<\/pre>\n<\/section>\n<p>\n    This time CMake found Clang and with our new flags we have 3 errors.<br \/>\n    <span class=\"subtle\">(Rather nice errors, actually.)<\/span> These errors are<br \/>\n    actually simple to fix, so lets fix them before we move on.\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\" 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>\n<a id=\"main.cc-6\" class=\"line-number\" href=\"#main.cc-6\"><\/a><span class=\"cp\">#include &quot;ToDo.h&quot;<\/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\">#define EXPECT_EQUAL(test, expect) equalityTest( test,  expect, \\<\/span>\n<a id=\"main.cc-9\" class=\"line-number\" href=\"#main.cc-9\"><\/a><span class=\"cp\">                                                #test, #expect, \\<\/span>\n<a id=\"main.cc-10\" class=\"line-number\" href=\"#main.cc-10\"><\/a><span class=\"cp\">                                                __FILE__, __LINE__)<\/span>\n<a id=\"main.cc-11\" class=\"line-number\" href=\"#main.cc-11\"><\/a>\n<a id=\"main.cc-12\" class=\"line-number\" href=\"#main.cc-12\"><\/a><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<a id=\"main.cc-13\" class=\"line-number\" href=\"#main.cc-13\"><\/a><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<a id=\"main.cc-14\" class=\"line-number\" href=\"#main.cc-14\"><\/a>                 <span class=\"k\">const<\/span> <span class=\"n\">T2<\/span>    <span class=\"n\">expectedValue<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-15\" class=\"line-number\" href=\"#main.cc-15\"><\/a>                 <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">testName<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-16\" class=\"line-number\" href=\"#main.cc-16\"><\/a>                 <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">expectedName<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-17\" class=\"line-number\" href=\"#main.cc-17\"><\/a>                 <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">fileName<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-18\" class=\"line-number\" href=\"#main.cc-18\"><\/a>                 <span class=\"k\">const<\/span> <span class=\"kt\">int<\/span>   <span class=\"n\">lineNumber<\/span><span class=\"p\">);<\/span>\n<a id=\"main.cc-19\" class=\"line-number\" href=\"#main.cc-19\"><\/a>\n<a id=\"main.cc-20\" class=\"line-number\" href=\"#main.cc-20\"><\/a>\n<a id=\"main.cc-21\" class=\"line-number\" href=\"#main.cc-21\"><\/a><span class=\"kt\">int<\/span> <span class=\"nf\">main<\/span><span class=\"p\">(<\/span>\n<a id=\"main.cc-22\" class=\"line-number\" href=\"#main.cc-22\"><\/a><span class=\"hll\">    <span class=\"kt\">int<\/span><span class=\"p\">,<\/span>\n<\/span><a id=\"main.cc-23\" class=\"line-number\" href=\"#main.cc-23\"><\/a><span class=\"hll\">    <span class=\"kt\">char<\/span><span class=\"o\">**<\/span>\n<\/span><a id=\"main.cc-24\" class=\"line-number\" href=\"#main.cc-24\"><\/a><span class=\"p\">)<\/span>\n<a id=\"main.cc-25\" class=\"line-number\" href=\"#main.cc-25\"><\/a><span class=\"p\">{<\/span>\n<a id=\"main.cc-26\" class=\"line-number\" href=\"#main.cc-26\"><\/a>    <span class=\"kt\">int<\/span> <span class=\"n\">result<\/span> <span class=\"o\">=<\/span> <span class=\"mi\">0<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-27\" class=\"line-number\" href=\"#main.cc-27\"><\/a>\n<a id=\"main.cc-28\" class=\"line-number\" href=\"#main.cc-28\"><\/a>    <span class=\"n\">ToDo<\/span> <span class=\"n\">list<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-29\" class=\"line-number\" href=\"#main.cc-29\"><\/a>\n<a id=\"main.cc-30\" class=\"line-number\" href=\"#main.cc-30\"><\/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-31\" class=\"line-number\" href=\"#main.cc-31\"><\/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-32\" class=\"line-number\" href=\"#main.cc-32\"><\/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-33\" class=\"line-number\" href=\"#main.cc-33\"><\/a>\n<a id=\"main.cc-34\" class=\"line-number\" href=\"#main.cc-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=\"kt\">size_t<\/span><span class=\"p\">(<\/span><span class=\"mi\">3<\/span><span class=\"p\">));<\/span>\n<\/span><a id=\"main.cc-35\" class=\"line-number\" href=\"#main.cc-35\"><\/a>    <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<a id=\"main.cc-36\" class=\"line-number\" href=\"#main.cc-36\"><\/a>    <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<a id=\"main.cc-37\" class=\"line-number\" href=\"#main.cc-37\"><\/a>    <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<a id=\"main.cc-38\" class=\"line-number\" href=\"#main.cc-38\"><\/a>\n<a id=\"main.cc-39\" class=\"line-number\" href=\"#main.cc-39\"><\/a>    <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<a id=\"main.cc-40\" class=\"line-number\" href=\"#main.cc-40\"><\/a>    <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;Test passed&quot;<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">endl<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-42\" class=\"line-number\" href=\"#main.cc-42\"><\/a>    <span class=\"p\">}<\/span>\n<a id=\"main.cc-43\" class=\"line-number\" href=\"#main.cc-43\"><\/a>\n<a id=\"main.cc-44\" class=\"line-number\" href=\"#main.cc-44\"><\/a>    <span class=\"k\">return<\/span> <span class=\"n\">result<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-45\" class=\"line-number\" href=\"#main.cc-45\"><\/a><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>\n<a id=\"main.cc-48\" class=\"line-number\" href=\"#main.cc-48\"><\/a><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<a id=\"main.cc-49\" class=\"line-number\" href=\"#main.cc-49\"><\/a><span class=\"kt\">int<\/span> <span class=\"n\">equalityTest<\/span><span class=\"p\">(<\/span>\n<a id=\"main.cc-50\" class=\"line-number\" href=\"#main.cc-50\"><\/a>    <span class=\"k\">const<\/span> <span class=\"n\">T1<\/span>    <span class=\"n\">testValue<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-51\" class=\"line-number\" href=\"#main.cc-51\"><\/a>    <span class=\"k\">const<\/span> <span class=\"n\">T2<\/span>    <span class=\"n\">expectedValue<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-52\" class=\"line-number\" href=\"#main.cc-52\"><\/a>    <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">testName<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-53\" class=\"line-number\" href=\"#main.cc-53\"><\/a>    <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">expectedName<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-54\" class=\"line-number\" href=\"#main.cc-54\"><\/a>    <span class=\"k\">const<\/span> <span class=\"kt\">char<\/span><span class=\"o\">*<\/span> <span class=\"n\">fileName<\/span><span class=\"p\">,<\/span>\n<a id=\"main.cc-55\" class=\"line-number\" href=\"#main.cc-55\"><\/a>    <span class=\"k\">const<\/span> <span class=\"kt\">int<\/span>   <span class=\"n\">lineNumber<\/span>\n<a id=\"main.cc-56\" class=\"line-number\" href=\"#main.cc-56\"><\/a><span class=\"p\">)<\/span>\n<a id=\"main.cc-57\" class=\"line-number\" href=\"#main.cc-57\"><\/a><span class=\"p\">{<\/span>\n<a id=\"main.cc-58\" class=\"line-number\" href=\"#main.cc-58\"><\/a>    <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<a id=\"main.cc-59\" class=\"line-number\" href=\"#main.cc-59\"><\/a>    <span class=\"p\">{<\/span>\n<a id=\"main.cc-60\" class=\"line-number\" href=\"#main.cc-60\"><\/a>        <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<a id=\"main.cc-61\" class=\"line-number\" href=\"#main.cc-61\"><\/a>             <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<a id=\"main.cc-62\" class=\"line-number\" href=\"#main.cc-62\"><\/a>             <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<a id=\"main.cc-63\" class=\"line-number\" href=\"#main.cc-63\"><\/a>             <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<a id=\"main.cc-64\" class=\"line-number\" href=\"#main.cc-64\"><\/a>\n<a id=\"main.cc-65\" class=\"line-number\" href=\"#main.cc-65\"><\/a>        <span class=\"k\">return<\/span> <span class=\"mi\">1<\/span><span class=\"p\">;<\/span>\n<a id=\"main.cc-66\" class=\"line-number\" href=\"#main.cc-66\"><\/a>    <span class=\"p\">}<\/span>\n<a id=\"main.cc-67\" class=\"line-number\" href=\"#main.cc-67\"><\/a>    <span class=\"k\">else<\/span>\n<a id=\"main.cc-68\" class=\"line-number\" href=\"#main.cc-68\"><\/a>    <span class=\"p\">{<\/span>\n<a id=\"main.cc-69\" class=\"line-number\" href=\"#main.cc-69\"><\/a>        <span class=\"k\">return<\/span> <span class=\"mi\">0<\/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=\"p\">}<\/span>\n<\/pre>\n<\/div>\n<\/section>\n<p>\n    <a class=\"sources\" href=\"https:\/\/www.johnlamp.net\/sources\/chapter3-1.zip\"><img src=\"https:\/\/www.johnlamp.net\/images\/zip.png\" alt=\"[zip file] \" \/>Source<\/a>  <\/p>\n<p>\n    They were rather simple errors to fix. The simplest solution to unused<br \/>\n    function parameters is to delete their names leaving only the types, if it&#8217;s<br \/>\n    temporary just comment them out. This documents both for other people and<br \/>\n    the compiler that the parameters aren&#8217;t being used. The last error is caused<br \/>\n    by literal numbers defaulting to being <code>int<\/code>s. If we construct<br \/>\n    a <code>size_t<\/code> the problem is fixed.\n  <\/p>\n<\/section>\n<section>\n<h1 id=\"section-CmakeGui\">CMake GUI<\/h1>\n<h2 id=\"section-GeneratingOurProject\">Generating Our Project<\/h2>\n<p>\n    The CMake GUI allows one to easily run CMake without having to use the<br \/>\n    command line. It also makes it easier to set or change specific options,<br \/>\n    which we will explore.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-3\/blank.png\" alt=\"[blank CMake window]\" \/><\/p>\n<p>\n    The first two entries should be familiar, but more explicit than what we saw<br \/>\n    earlier. To relate to the command line we were<br \/>\n    using: <kbd>cd <span class=\"arg\">&lt;Where to build the binaries&gt;<\/span>;<br \/>\n    cmake <span class=\"arg\">&lt;Where is the source code&gt;<\/span><\/kbd>. That<br \/>\n    command line also configures and generates, which you would do using the<br \/>\n    &#8220;Configure&#8221; and &#8220;Generate&#8221; buttons, of course. The bulk of the window is for<br \/>\n    variables, which are only visible once you have configured.\n  <\/p>\n<p>\n    It isn&#8217;t quite that simple, though. Once you pick your source and build<br \/>\n    directories and then click &#8220;Configure&#8221; CMake will ask you about which<br \/>\n    generator you want to use and more.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-3\/generator.png\" alt=\"[generator window]\" \/><\/p>\n<p>\n    The displayed options are the typical ones used so far during this<br \/>\n    tutorial. Generate Unix Makefiles and use the default native compilers. A<br \/>\n    different generator can be chosen from the list rather than having to<br \/>\n    carefully type it, which can be handy. The other options allow you to<br \/>\n    specify which compiler to use, a topic that will be covered later. Clicking<br \/>\n    &#8220;Finish&#8221; will then actually configure.\n  <\/p>\n<p class=\"note\">\n    <em class=\"call-out\">Note:<\/em> This step can only be done the first time,<br \/>\n    so if you want to use a different generator <span class=\"subtle\">(or<br \/>\n    compiler)<\/span> you will have to start over with an empty build directory.\n  <\/p>\n<p>  <img class=\"screenshot-osX\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-3\/firstConfigure.png\" alt=\"[CMake window after configuring]\" \/><\/p>\n<p>\n    Notice that the bottom section displays the same output<br \/>\n    the <code>cmake<\/code> command displays when configuring. There are also now<br \/>\n    some variables displayed in the central portion of the window. In this<br \/>\n    example most are specific to Mac OS X. The variables&#8217; values can easily be<br \/>\n    changed by double clicking in the &#8220;Value&#8221; field and entering a new value.\n  <\/p>\n<dl>\n<dt class=\"code\">\n      CMAKE_BUILD_TYPE\n    <\/dt>\n<dd>\n      This variable controls the type of build to be done. The possible<br \/>\n      values are empty, <code>Debug<\/code>, <code>Release<\/code>,<br \/>\n      <code>RelWithDebInfo<\/code>, and <code>MinSizeRel<\/code>. The values&#8217;<br \/>\n      meanings are relatively obvious. Based upon the value of this variable<br \/>\n      CMake will set the compiler flags appropriately. This is done by adding<br \/>\n      the value of the<br \/>\n      variable <code>CMAKE_<i>&lt;LANG&gt;<\/i>_FLAGS_<i>&lt;BUILD_TYPE&gt;<\/i><\/code><br \/>\n      to <code>CMAKE_<i>&lt;LANG&gt;<\/i>_FLAGS<\/code>. By setting these<br \/>\n      variables appropriately you can control the compiler flags for the various<br \/>\n      types of builds.\n    <\/dd>\n<dd class=\"note\">\n      <em class=\"call-out\">Note:<\/em> This variable is not available with all<br \/>\n      generators. Some IDE generators create non-Makefile projects, e.g. Visual<br \/>\n      Studio, in which case the build type is handled by the IDE itself.\n    <\/dd>\n<dd>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#variable:CMAKE_BUILD_TYPE\">CMAKE_BUILD_TYPE Documentation<\/a>      <time class=\"access\">2013-01-20<\/time>\n    <\/dd>\n<dt>\n      CMAKE_INSTALL_PREFIX\n    <\/dt>\n<dd>\n      CMake can create an install target which will be covered in a future<br \/>\n      chapter. This prefix can be set to control where things are installed. It<br \/>\n      is similar to the <code>--prefix<\/code> argument<br \/>\n      for <code>configure<\/code> scripts.\n    <\/dd>\n<dd>\n      However if you are curious:<br \/>\n      <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#variable:CMAKE_INSTALL_PREFIX\">CMAKE_INSTALL_PREFIX Documentation<\/a>      <time class=\"access\">2013-01-20<\/time>\n    <\/dd>\n<\/dl>\n<p>\n    Simply click &#8220;Configure&#8221; again as directed. Clicking &#8220;Generate&#8221; will then<br \/>\n    generate our Makefile so we can build.\n  <\/p>\n<h2 id=\"section-CmakeCache\">CMake Cache<\/h2>\n<p>\n    If you check the &#8220;Advanced&#8221; box all cache variables will be listed.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-3\/advanced.png\" alt=\"[advanced variables]\" \/><\/p>\n<p>\n    CMake stores variables that need to be persistent in the cache. These<br \/>\n    include things such as the path to your compiler and the flags for the<br \/>\n    compiler. Naturally one should be careful when editing variables in the<br \/>\n    cache.\n  <\/p>\n<p>\n    You will notice that the compiler flags we added earlier do not appear in<br \/>\n    the cache. While this might be a good idea as it forces those options to<br \/>\n    always be used it really isn&#8217;t correct. We can tell <code>set()<\/code> to<br \/>\n    put the variable in the cache, however it&#8217;s not that simple. Either the<br \/>\n    cache will never be updated or our options will be appended <i>every<\/i><br \/>\n    time CMake configures.\n  <\/p>\n<p>\n    The following should do the trick:\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-1\" class=\"line-number\" href=\"#CMakeLists.txt-1-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-1-2\" class=\"line-number\" href=\"#CMakeLists.txt-1-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-1-3\" class=\"line-number\" href=\"#CMakeLists.txt-1-3\"><\/a>\n<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=\"nb\">enable_testing<\/span><span class=\"p\">()<\/span>\n<a id=\"CMakeLists.txt-1-7\" class=\"line-number\" href=\"#CMakeLists.txt-1-7\"><\/a>\n<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\">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-1-10\" class=\"line-number\" href=\"#CMakeLists.txt-1-10\"><\/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-1-11\" class=\"line-number\" href=\"#CMakeLists.txt-1-11\"><\/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-1-12\" class=\"line-number\" href=\"#CMakeLists.txt-1-12\"><\/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-1-13\" class=\"line-number\" href=\"#CMakeLists.txt-1-13\"><\/a>    <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">warnings<\/span> <span class=\"s2\">&quot;\/W4 \/WX \/EHsc&quot;<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-1-14\" class=\"line-number\" href=\"#CMakeLists.txt-1-14\"><\/a><span class=\"nb\">endif<\/span><span class=\"p\">()<\/span>\n<a id=\"CMakeLists.txt-1-15\" class=\"line-number\" href=\"#CMakeLists.txt-1-15\"><\/a><span class=\"hll\"><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<\/span><a id=\"CMakeLists.txt-1-16\" class=\"line-number\" href=\"#CMakeLists.txt-1-16\"><\/a><span class=\"hll\">    <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">CMAKE_CXX_FLAGS<\/span> <span class=\"s2\">&quot;${warnings}&quot;<\/span>\n<\/span><a id=\"CMakeLists.txt-1-17\" class=\"line-number\" href=\"#CMakeLists.txt-1-17\"><\/a><span class=\"hll\">        <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<\/span><a id=\"CMakeLists.txt-1-18\" class=\"line-number\" href=\"#CMakeLists.txt-1-18\"><\/a><span class=\"hll\">    <span class=\"nb\">set<\/span><span class=\"p\">(<\/span><span class=\"s\">CMAKE_C_FLAGS<\/span>   <span class=\"s2\">&quot;${warnings}&quot;<\/span>\n<\/span><a id=\"CMakeLists.txt-1-19\" class=\"line-number\" href=\"#CMakeLists.txt-1-19\"><\/a><span class=\"hll\">        <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<\/span><a id=\"CMakeLists.txt-1-20\" class=\"line-number\" href=\"#CMakeLists.txt-1-20\"><\/a><span class=\"hll\"><span class=\"nb\">endif<\/span><span class=\"p\">()<\/span>\n<\/span><a id=\"CMakeLists.txt-1-21\" class=\"line-number\" href=\"#CMakeLists.txt-1-21\"><\/a><span class=\"hll\">\n<\/span><a id=\"CMakeLists.txt-1-22\" class=\"line-number\" href=\"#CMakeLists.txt-1-22\"><\/a>\n<a id=\"CMakeLists.txt-1-23\" class=\"line-number\" href=\"#CMakeLists.txt-1-23\"><\/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-24\" class=\"line-number\" href=\"#CMakeLists.txt-1-24\"><\/a>                    <span class=\"s\">ToDo.cc<\/span><span class=\"p\">)<\/span>\n<a id=\"CMakeLists.txt-1-25\" class=\"line-number\" href=\"#CMakeLists.txt-1-25\"><\/a>\n<a id=\"CMakeLists.txt-1-26\" class=\"line-number\" href=\"#CMakeLists.txt-1-26\"><\/a><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<a id=\"CMakeLists.txt-1-27\" class=\"line-number\" href=\"#CMakeLists.txt-1-27\"><\/a><span class=\"hll\">\n<\/span><a id=\"CMakeLists.txt-1-28\" class=\"line-number\" href=\"#CMakeLists.txt-1-28\"><\/a><span class=\"hll\">\n<\/span><a id=\"CMakeLists.txt-1-29\" class=\"line-number\" href=\"#CMakeLists.txt-1-29\"><\/a><span class=\"hll\"><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<\/span><a id=\"CMakeLists.txt-1-30\" class=\"line-number\" href=\"#CMakeLists.txt-1-30\"><\/a><span class=\"hll\">    <span class=\"s2\">&quot;A flag showing that CMake has configured at least once.&quot;<\/span><span class=\"p\">)<\/span>\n<\/span><\/pre>\n<\/div>\n<\/section>\n<p>\n    <a class=\"sources\" href=\"https:\/\/www.johnlamp.net\/sources\/chapter3-2.zip\"><img src=\"https:\/\/www.johnlamp.net\/images\/zip.png\" alt=\"[zip file] \" \/>Source<\/a>  <\/p>\n<dl>\n<dt class=\"code\">\n      if (NOT CONFIGURED_ONCE)\n    <\/dt>\n<dd>\n      In CMake an undefined variable evaluates to false. Because of this we can<br \/>\n      use <code>CONFIGURED_ONCE<\/code> as a flag to determine if CMake has<br \/>\n      configured this project at least once.  <br \/> Defined variables that are<br \/>\n      empty or contain <code>0<\/code>, <code>N<\/code>, <code>NO<\/code>,<br \/>\n      <code>OFF<\/code>, <code>FALSE<\/code>, <code>NOTFOUND<\/code><br \/>\n      or <code><span class=\"arg\">variable<\/span>-NOTFOUND<\/code> are also<br \/>\n      considered false.\n    <\/dd>\n<dt class=\"code\">\n      set(CMAKE_CXX_FLAGS &#8220;${warnings}&#8221;<br \/>\n      CACHE STRING &#8220;Flags used by the compiler during all build types.&#8221;<br \/>\n      FORCE)\n    <\/dt>\n<dd>\n      Initialize the value of <code>CMAKE_CXX_FLAGS<\/code> to be the desired<br \/>\n      warning flags. The syntax for this form of the <code>set<\/code> command is<br \/>\n      explained below. Two things to note:<\/p>\n<ol>\n<li>\n          The docstring is exactly what CMake uses by default. When overriding<br \/>\n          built-in CMake variables be sure to use the same docstring as it does<br \/>\n          to avoid confusion.\n        <\/li>\n<li>\n          We need to force this value to be stored in the cache because the<br \/>\n          built-in variables are present in the cache even before the first time<br \/>\n          our project is configured. This is why we need the<br \/>\n          <code>CONFIGURED_ONCE<\/code> variable.\n        <\/li>\n<\/ol>\n<\/dd>\n<dt class=\"code\">\n      set(CONFIGURED_ONCE TRUE CACHE INTERNAL<br \/>\n      &#8220;A flag showing that CMake has configured at least once.&#8221;)\n    <\/dt>\n<dd>\n      Set <code>CONFIGURED_ONCE<\/code> to true and store it in the cache since<br \/>\n      by now configuration is complete. We don&#8217;t need to force this<br \/>\n      as <code>CONFIGURED_ONCE<\/code> is not present in the cache.\n    <\/dd>\n<\/dl>\n<p>\n    A new form of the <code>set<\/code> command was used this time to store<br \/>\n    variables in the CMake project&#8217;s cache. It is explained here and also in<br \/>\n    CMake&#8217;s<br \/>\n    <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.10\/cmake.html#command:set\">documentation<\/a>    <time class=\"access\">(2013-01-29)<\/time>\n  <\/p>\n<dl>\n<dt class=\"code\">\n      set(<span class=\"arg\">variableName<\/span><br \/>\n      <span class=\"arg\">value &#8230;<\/span><br \/>\n      CACHE <span class=\"arg\">type<\/span> <span class=\"arg\">docstring<\/span><br \/>\n      <span class=\"optional\">FORCE<\/span>)\n    <\/dt>\n<dd>\n      This form of the <code>set<\/code> function allows you to store a variable<br \/>\n      in CMake&#8217;s cache. The cache is both global and persistent. For both of<br \/>\n      these reasons it can be quite useful and should be used carefully. The<br \/>\n      other important thing about the cache is that users can, for the most<br \/>\n      part, edit it.<br \/>\n      The <code>CACHE<\/code> flag is a literal that tells CMake you want to<br \/>\n      store this variable in the cache.<\/p>\n<dl>\n<dt class=\"code arg\">type<\/dt>\n<dd>\n          The type of value being stored in the cache. Possible values:<\/p>\n<dl>\n<dt class=\"code\">FILEPATH<\/dt>\n<dd>\n              A path to a file. In the CMake GUI a file chooser dialog may<br \/>\n              be used.\n            <\/dd>\n<dt class=\"code\">PATH<\/dt>\n<dd>\n              A path to a directory. In the CMake GUI a directory chooser<br \/>\n              dialog may be used.\n            <\/dd>\n<dt class=\"code\">STRING<\/dt>\n<dd>\n              An arbitrary string.\n            <\/dd>\n<dt class=\"code\">BOOL<\/dt>\n<dd>\n              A boolean on\/off value. In the CMake GUI a checkbox will be<br \/>\n              used.\n            <\/dd>\n<dt class=\"code\">INTERNAL<\/dt>\n<dd>\n              A value of any type with no GUI entry. This is useful for<br \/>\n              persistent, global variables.\n            <\/dd>\n<\/dl>\n<\/dd>\n<dt class=\"code arg\">docstring<\/dt>\n<dd>\n          A string that describes the purpose of the variable. If only specific<br \/>\n          values are allowed list them here as the user will see this string in<br \/>\n          the CMake GUI as a tool tip.\n        <\/dd>\n<dt>\n          <span class=\"code\">FORCE<\/span><br \/>\n          <span class=\"subtle\">(optional)<\/span>\n        <\/dt>\n<dd>\n          Force this entry to be set in the cache. Normally if a variable<br \/>\n          already exists in the cache future attempts to set it will be ignored<br \/>\n          unless <code>FORCE<\/code> is the last argument. Please note that<br \/>\n          setting a variable in the cache is dependent on the variable already<br \/>\n          being in the cache not on its emptiness. Because of this and the fact<br \/>\n          that many of the CMake variables exist in the cache before<br \/>\n          your <code>CMakeLists.txt<\/code> is processed you need to test for the<br \/>\n          first configuration as done above.\n        <\/dd>\n<\/dl>\n<\/dd>\n<\/dl>\n<\/section>\n<section>\n<h1 id=\"section-CmakeCursesInterface\">CMake Curses Interface<\/h1>\n<h2 id=\"section-IntroducingCcmake\">Introducing <code>ccmake<\/code><\/h2>\n<p>\n    CMake also includes a command line curses-based<br \/>\n    interface, <code>ccmake<\/code>. It provides equivalent functionality to that<br \/>\n    of the GUI. Most installations include this tool, although not<br \/>\n    all. The <code>ccmake<\/code> tool can be used both to create a CMake build<br \/>\n    or edit the cache of one. To create a new build it is used very similarly<br \/>\n    to <code>cmake<\/code>:<br \/>\n    <br \/>\n    <kbd>ccmake <span class=\"arg\">path-to-source<\/span><\/kbd><br \/>\n    <br \/>\n    Naturally editing a build&#8217;s cache is quite similar:<br \/>\n    <br \/>\n    <kbd>ccmake <span class=\"arg\">path-to-existing-build<\/span><\/kbd><br \/>\n    <br \/>\n    For the most part this tool is very much like the GUI except, of course, its<br \/>\n    interactions are all keyboard based. It can be useful if you often connect<br \/>\n    to your build machine via an ssh session or you don&#8217;t want the dependency of<br \/>\n    Qt, which the GUI requires.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-3\/ccmake.png\" alt=\"[ccmake curses interface]\" \/><\/p>\n<p>\n    The main difference between this tool and the GUI is that it won&#8217;t walk you<br \/>\n    through setting up a build, you have to provide paths on the command<br \/>\n    line. Besides that its features are mostly the same. Of course, instead of<br \/>\n    clicking the &#8220;Configure&#8221; and &#8220;Generate&#8221; buttons you would use<br \/>\n    the <kbd class=\"key\">c<\/kbd> and <kbd class=\"key\">g<\/kbd> keys.\n  <\/p>\n<h2 id=\"section-UsefulMakefileTargets\">Useful Makefile Targets<\/h2>\n<p>\n    There are two built-in make targets that CMake provides that are useful for<br \/>\n    managing the cache. These are especially useful if you work from the command<br \/>\n    line a lot.\n  <\/p>\n<dl>\n<dt>\n      <kbd>make rebuild_cache<\/kbd>\n    <\/dt>\n<dd>\n      This target re-runs CMake for your build having the same effect<br \/>\n      as <kbd>cmake .<\/kbd>, this can be handy, though, if you have multiple<br \/>\n      versions of CMake installed or don&#8217;t have <code>cmake<\/code> in your path<br \/>\n      as this target knows the path to the <code>cmake<\/code> that was<br \/>\n      originally used to generate the build.\n    <\/dd>\n<dt>\n      <kbd>make edit_cache<\/kbd>\n    <\/dt>\n<dd>\n      Very similar to the above target except this one runs the<br \/>\n      appropriate <code>ccmake<\/code>, or <code>cmake-gui<\/code><br \/>\n      if <code>ccmake<\/code> isn&#8217;t installed. The reasons for this being useful<br \/>\n      are the same, too.\n    <\/dd>\n<\/dl>\n<p>\n    Most of the time these targets aren&#8217;t used, but as they can be handy it&#8217;s<br \/>\n    good to know about them.\n  <\/p>\n<p>\n    There is one last Makefile target that is useful, especially on larger<br \/>\n    projects: <kbd>make help<\/kbd>. This prints a list of targets provided by<br \/>\n    the Makefile. This can be convenient if you only want to build specific<br \/>\n    targets but aren&#8217;t sure how they were named.\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-04-14<\/td>\n<td>Updated MSVC compiler flags and added note about automatic flag-style conversion.<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>2013-07-14<\/td>\n<td>Added line numbers and indication of changes to code sample. Added a link to the section on lists.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Although when we looked at IDE projects generated by CMake we still used the<br \/>\n    command line. You can also use the CMake GUI to generate and configure<br \/>\n    projects. This can be convenient if you don&#8217;t like the command line, however<br \/>\n    it can be even more useful than that.<\/p>\n<p>    CMake stores a lot of configuration settings &hellip;<br \/><a href=\"https:\/\/www.johnlamp.net\/?p=18\" rel=\"bookmark\">Continue reading &quot;CMake Tutorial &#8211; Chapter&#160;3: GUI Tool&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\/18"}],"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=18"}],"version-history":[{"count":0,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}