{"id":16,"date":"2013-03-28T19:31:48","date_gmt":"2013-03-29T00:31:48","guid":{"rendered":"https:\/\/104.236.124.184\/cmake-tutorial-2-ide-integration.html"},"modified":"2013-03-28T19:31:48","modified_gmt":"2013-03-29T00:31:48","slug":"cmake-tutorial-2-ide-integration","status":"publish","type":"post","link":"https:\/\/www.johnlamp.net\/?p=16","title":{"rendered":"CMake Tutorial &#8211; Chapter&#160;2: IDE Integration"},"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-VisualStudio\">Visual Studio<\/a><\/li>\n<li><a href=\"#section-Xcode\">Xcode<\/a><\/li>\n<li>\n<ol>\n<li><a href=\"#section-MacOsX\">Mac OS X<\/a><\/li>\n<li><a href=\"#section-Ios\">iOS<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"#section-EclipseCdt4\">Eclipse CDT4<\/a><\/li>\n<li><a href=\"#section-Kdevelop\">KDevelop<\/a><\/li>\n<li>\n<ol>\n<li><a href=\"#section-Generated(Kdevelop3)\">Generated (KDevelop3)<\/a><\/li>\n<li><a href=\"#section-CmakeSupport(Kdevelop4)\">CMake Support (KDevelop4)<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/nav>\n<section>\n<h1 id=\"section-Introduction\">Introduction<\/h1>\n<p>\n    Now that we are familiar with CMake I will make good on CMake&#8217;s promise of<br \/>\n    flexibility. I said before that CMake could create projects for various<br \/>\n    IDE&#8217;s and in this chapter we will do so. This is one of CMake&#8217;s greatest<br \/>\n    strengths as it allows for very diverse development environments while<br \/>\n    working on the same project. It also makes it possible for you to take<br \/>\n    advantage of all available tools. If, for example, you prefer to work in<br \/>\n    Emacs or Vim and build with Make you could still create an IDE project and<br \/>\n    take advantage of its refactoring tools.\n  <\/p>\n<p>\n    By now some of you have looked at the scroll bar and noticed that this<br \/>\n    chapter is rather long. Don&#8217;t worry I don&#8217;t expect you to read all of it and<br \/>\n    there are a lot of pictures. I present several IDEs but assume that you will<br \/>\n    only read the ones that are useful to you.\n  <\/p>\n<p>\n    Please remember that CMake has more generators than those presented here. To<br \/>\n    list all of the available generators for your install use the<br \/>\n    command <kbd>cmake --help<\/kbd>. Most available generators are listed in the<br \/>\n    CMake<br \/>\n    <a href=\"http:\/\/www.cmake.org\/cmake\/help\/v2.8.8\/cmake.html#section_Generators\">documentation<\/a>    <time class=\"access\">(2012-07-08)<\/time>.\n  <\/p>\n<p>\n    We will use the same code as we had at the end of the<br \/>\n    <a href=\"https:\/\/www.johnlamp.net\/cmake-tutorial-1-getting-started.html#section-SimpleImprovements\">first chapter<\/a>.    It can be downloaded again here:<br \/>\n    <a class=\"sources\" href=\"https:\/\/www.johnlamp.net\/sources\/chapter1-2.zip\"><img src=\"https:\/\/www.johnlamp.net\/images\/zip.png\" alt=\"[zip file] \" \/>Source<\/a>  <\/p>\n<\/section>\n<section>\n<h1 id=\"section-VisualStudio\">Visual Studio<\/h1>\n<p class=\"subtle\">\n    Visual Studio 2010 Express Version 10.0.30319.1 RTMTel was used.<br \/>\n    <br \/>\n    Visual Studio 2010 Professional Version 10.0.30319.1 RTMRel was used<br \/>\n    for <code>MSBuild<\/code>\n  <\/p>\n<p>\n    Generating a Visual Studio solution is simple, we just have to use a Visual<br \/>\n    Studio generator when we invoke CMake.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> mkdir visualStudio\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd visualStudio\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cmake -G &quot;Visual Studio 10&quot; ..\n-- Check for working C compiler using: Visual Studio 10\n-- Check for working C compiler using: Visual Studio 10 -- works\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - done\n-- Check for working CXX compiler using: Visual Studio 10\n-- Check for working CXX compiler using: Visual Studio 10 -- 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: M:\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/visualStudio\n<\/pre>\n<\/section>\n<p>\n    It is important to note that there are different generators for different<br \/>\n    versions of Visual Studio, so you will have to make sure that you chose the<br \/>\n    generator most appropriate for your Visual Studio install. CMake&#8217;s output is<br \/>\n    actually a lot shorter than when we<br \/>\n    <a href=\"https:\/\/www.johnlamp.net\/cmake-tutorial-1-getting-started.html#Step1Output\">first<\/a>    ran it. You will notice that CMake uses Visual Studio to compile rather than<br \/>\n    interacting directly with the compiler.\n  <\/p>\n<p>\n    Of course we still did an out-of-source build so the Visual Studio project<br \/>\n    files will not clutter your source tree. This is what CMake created:\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/visualStudio\/files.png\" alt=\"[generated files]\" \/><\/p>\n<p>\n    As you can see CMake created several Visual Studio files. The one we really<br \/>\n    care about is <code>To Do List.sln<\/code>, as you can see this is named<br \/>\n    after our CMake project. If file names containing spaces cause problems for<br \/>\n    you, or are inconvenient, then you will want to make sure your project names<br \/>\n    do not contain spaces. Let&#8217;s see what kind of solution CMake created.\n  <\/p>\n<p class=\"note\">\n    <em class=\"call-out\">Note:<\/em> When you open the solution Visual Studio may<br \/>\n    display a Security Warning because it doesn&#8217;t trust the projects. This seems<br \/>\n    to be caused by CMake creating them not Visual Studio. You can just click<br \/>\n    &#8220;OK&#8221;.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/visualStudio\/project.png\" alt=\"[Visual Studio project window]\" \/><\/p>\n<p>\n    The generated solution is a bit more complicated than what you would have<br \/>\n    created by hand. There are 3 more projects than you would have expected<br \/>\n    since we are only building one executable and nothing else. Each project<br \/>\n    does, however, have a purpose:\n  <\/p>\n<dl>\n<dt>ALL_BUILD<\/dt>\n<dd>\n      This project builds all of the targets that are defined in<br \/>\n      the <code>CMakeLists.txt<\/code>. Since we only have one in ours it is a<br \/>\n      bit redundant.\n    <\/dd>\n<dt>RUN_TESTS<\/dt>\n<dd>\n      Building this project runs CTest in much the same way that <kbd>make<br \/>\n        test<\/kbd> did. It creates the same output files, too. CTest&#8217;s output is<br \/>\n        also displayed in the Output Window. Just as before this does not depend<br \/>\n        on any of your targets, so if your tests depend on any targets be sure<br \/>\n        to build them first.\n    <\/dd>\n<dt>toDo<\/dt>\n<dd>\n      This is the little command line tool we are building. It corresponds to<br \/>\n      the <code>add_executable<\/code> command we have in<br \/>\n      our <code>CMakeLists.txt<\/code>.\n    <\/dd>\n<dt>ZERO_CHECK<\/dt>\n<dd>\n      This is a rather oddly named project. It&#8217;s purpose is to make sure that<br \/>\n      the Visual Studio solution and its projects are all up to date. If you<br \/>\n      modify the <code>CMakeLists.txt<\/code> this project will update your<br \/>\n      Visual Studio solution. All other projects depend on this one so you don&#8217;t<br \/>\n      have to build it manually. Unfortunately when the solution and projects<br \/>\n      are updated by this Visual Studio will, for each one updated, ask you if<br \/>\n      you want to reload it, which can get a bit annoying.\n    <\/dd>\n<\/dl>\n<p>\n    If you look at the &#8220;toDo&#8221; project you will notice that it only contains<br \/>\n    the <code>.cc<\/code> files. This is because those are the only files listed<br \/>\n    in the <code>CMakeLists.txt<\/code> for the toDo target. If you were to<br \/>\n    add <code>ToDo.h<\/code> to the toDo target it would appear in the &#8220;toDo&#8221;<br \/>\n    project in Visual Studio.\n  <\/p>\n<p>\n    Let&#8217;s try and build and see what happens.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/visualStudio\/build.png\" alt=\"[Visual Studio build]\" \/><\/p>\n<p>\n    I used the &#8220;Start Debugging&#8221; button on the toolbar which tried to debug the<br \/>\n    &#8220;ALL_BUILD&#8221; project. So while it successfully built toDo.exe it was not run<br \/>\n    since &#8220;ALL_BUILD&#8221; does not produce any outputs, much less an executable. So if<br \/>\n    you want to actually debug &#8220;toDo&#8221; you will have to explicitly pick that<br \/>\n    project. If we explicitly debug the &#8220;toDo&#8221; project we get what we were<br \/>\n    expecting.\n  <\/p>\n<p class=\"note\">\n    <em class=\"call-out\">Note:<\/em> If you set the project you want to debug as<br \/>\n    the &#8220;StartUp&#8221; project Visual Studio will debug it when you click the &#8220;Start<br \/>\n    Debugging&#8221; button. You can recognize the &#8220;StartUp&#8221; project as its name will<br \/>\n    be bold. To do this right click on the project and pick &#8220;Set as StartUp<br \/>\n    Project&#8221;.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/visualStudio\/build2.png\" alt=\"[Visual Studio build, second try]\" \/><\/p>\n<p>\n    Unfortunately our program is run in a command window that closes as soon as<br \/>\n    our program completes, so we don&#8217;t get to see its output. However the Output<br \/>\n    Window in Visual Studio shows that toDo exited with a code of 0 which means<br \/>\n    our test still passes. So everything works fine in Visual Studio.\n  <\/p>\n<p>\n    If you need to be able to build from the command line either because you<br \/>\n    prefer to or for an automated build process you can use<br \/>\n    the <code>MSBuild<\/code> command.\n  <\/p>\n<p class=\"note\">\n    <em class=\"call-out\">Note:<\/em> <code>MSBuild<\/code> does not appear to be<br \/>\n    included with Visual Studio Express, but only Visual Studio Professional.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd visualStudio\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> MSBuild ALL_BUILD.vcxproj\nMicrosoft (R) Build Engine Version 4.0.30319.1\n[Microsoft .NET Framework, Version 4.0.30319.269]\nCopyright (C) Microsoft Corporation 2007. All rights reserved.\nBuild started 7\/22\/2012 1:18:41 AM.\nProject &quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\ALL_BUILD.vcxproj&quot; on node 1 (default targets).\nProject &quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\ALL_BUILD.vcxproj&quot; (1) is building &quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\ZERO_CHECK.vcxproj&quot; (2) on node 1 (default targets).\nPrepareForBuild:\n  Creating directory &quot;Win32\\Debug\\ZERO_CHECK\\&quot;.\n  Creating directory &quot;Debug\\&quot;.\nInitializeBuildStatus:\n  Creating &quot;Win32\\Debug\\ZERO_CHECK\\ZERO_CHECK.unsuccessfulbuild&quot; because &quot;AlwaysCreate&quot; was specified.\nCustomBuild:\n  Checking Build System\n  CMake does not need to re-run because M:\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/visualStudio\/CMakeFiles\/generate.stamp is up-to-date.\nFinalizeBuildStatus:\n  Deleting file &quot;Win32\\Debug\\ZERO_CHECK\\ZERO_CHECK.unsuccessfulbuild&quot;.\n  Touching &quot;Win32\\Debug\\ZERO_CHECK\\ZERO_CHECK.lastbuildstate&quot;.\nDone Building Project &quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\ZERO_CHECK.vcxproj&quot; (default targets).\nProject &quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\ALL_BUILD.vcxproj&quot; (1) is building &quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj&quot; (3) on node 1 (default targets).\nPrepareForBuild:\n  Creating directory &quot;toDo.dir\\Debug\\&quot;.\nInitializeBuildStatus:\n  Creating &quot;toDo.dir\\Debug\\toDo.unsuccessfulbuild&quot; because &quot;AlwaysCreate&quot; was specified.\nCustomBuild:\n  Building Custom Rule M:\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/CMakeLists.txt\n  CMake does not need to re-run because M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\CMakeFiles\\generate.stamp is up-to-date.\nClCompile:\n  C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\CL.exe \/c \/Zi \/nologo \/W3 \/WX- \/Od \/Ob0 \/Oy- \/D WIN32 \/D _WINDOWS \/D _DEBUG \/D &quot;CMAKE_INTDIR=\\&quot;Debug\\&quot;&quot; \/D _MBCS \/Gm- \/MDd \/GS \/fp:precise \/Zc:wchar_t \/Zc:forScope \/GR \/Fo&quot;toDo.dir\\Debug\\\\&quot; \/Fd&quot;M:\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/visualStudio\/Debug\/toDo.pdb&quot; \/Gd \/TP \/analyze- \/errorReport:queue &quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\main.cc&quot; &quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\ToDo.cc&quot;  \/Zm1000 \/GX \/GZ\ncl : Command line warning D9035: option 'GX' has been deprecated and will be removed in a future release [M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj]\ncl : Command line warning D9036: use 'EHsc' instead of 'GX' [M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj]\ncl : Command line warning D9035: option 'GZ' has been deprecated and will be removed in a future release [M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj]\ncl : Command line warning D9036: use 'RTC1' instead of 'GZ' [M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj]\n  main.cc\n  ToDo.cc\n  Generating Code...\nManifestResourceCompile:\n  C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\bin\\rc.exe \/nologo \/fo&quot;toDo.dir\\Debug\\toDo.exe.embed.manifest.res&quot; toDo.dir\\Debug\\toDo_manifest.rc\nLink:\n  C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\link.exe \/ERRORREPORT:QUEUE \/OUT:&quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\Debug\\toDo.exe&quot; \/INCREMENTAL \/NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib \/MANIFEST \/ManifestFile:&quot;toDo.dir\\Debug\\toDo.exe.intermediate.manifest&quot; \/MANIFESTUAC:&quot;level='asInvoker' uiAccess='false'&quot; \/DEBUG \/PDB:&quot;M:\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/visualStudio\/Debug\/toDo.pdb&quot; \/SUBSYSTEM:CONSOLE \/STACK:&quot;10000000&quot; \/TLBID:1 \/DYNAMICBASE \/NXCOMPAT \/IMPLIB:&quot;M:\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/visualStudio\/Debug\/toDo.lib&quot; \/MACHINE:X86 toDo.dir\\Debug\\toDo.exe.embed.manifest.res\n  toDo.dir\\Debug\\main.obj\n  toDo.dir\\Debug\\ToDo.obj  \/machine:X86 \/debug\nManifest:\n  C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\bin\\mt.exe \/nologo \/verbose \/out:&quot;toDo.dir\\Debug\\toDo.exe.embed.manifest&quot; \/manifest toDo.dir\\Debug\\toDo.exe.intermediate.manifest\n  C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\bin\\rc.exe \/nologo \/fo&quot;toDo.dir\\Debug\\toDo.exe.embed.manifest.res&quot; toDo.dir\\Debug\\toDo_manifest.rc\nLinkEmbedManifest:\n  C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\link.exe \/ERRORREPORT:QUEUE \/OUT:&quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\Debug\\toDo.exe&quot; \/INCREMENTAL \/NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib \/MANIFEST \/ManifestFile:&quot;toDo.dir\\Debug\\toDo.exe.intermediate.manifest&quot; \/MANIFESTUAC:&quot;level='asInvoker' uiAccess='false'&quot; \/DEBUG \/PDB:&quot;M:\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/visualStudio\/Debug\/toDo.pdb&quot; \/SUBSYSTEM:CONSOLE \/STACK:&quot;10000000&quot; \/TLBID:1 \/DYNAMICBASE \/NXCOMPAT \/IMPLIB:&quot;M:\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/visualStudio\/Debug\/toDo.lib&quot; \/MACHINE:X86 toDo.dir\\Debug\\toDo.exe.embed.manifest.res\n  toDo.dir\\Debug\\main.obj\n  toDo.dir\\Debug\\ToDo.obj  \/machine:X86 \/debug\n  toDo.vcxproj -&gt; M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\Debug\\toDo.exe\nFinalizeBuildStatus:\n  Deleting file &quot;toDo.dir\\Debug\\toDo.unsuccessfulbuild&quot;.\n  Touching &quot;toDo.dir\\Debug\\toDo.lastbuildstate&quot;.\nDone Building Project &quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj&quot; (default targets).\nPrepareForBuild:\n  Creating directory &quot;Win32\\Debug\\ALL_BUILD\\&quot;.\nInitializeBuildStatus:\n  Creating &quot;Win32\\Debug\\ALL_BUILD\\ALL_BUILD.unsuccessfulbuild&quot; because &quot;AlwaysCreate&quot; was specified.\nCustomBuild:\n  Building Custom Rule M:\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/CMakeLists.txt\n  CMake does not need to re-run because M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\CMakeFiles\\generate.stamp is up-to-date.\n  Build all projects\nFinalizeBuildStatus:\n  Deleting file &quot;Win32\\Debug\\ALL_BUILD\\ALL_BUILD.unsuccessfulbuild&quot;.\n  Touching &quot;Win32\\Debug\\ALL_BUILD\\ALL_BUILD.lastbuildstate&quot;.\nDone Building Project &quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\ALL_BUILD.vcxproj&quot; (default targets).\nBuild succeeded.\n&quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\ALL_BUILD.vcxproj&quot; (default target) (1) -&gt;\n&quot;M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj&quot; (default target) (3) -&gt;\n(ClCompile target) -&gt;\n  cl : Command line warning D9035: option 'GX' has been deprecated and will be removed in a future release [M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj]\n  cl : Command line warning D9036: use 'EHsc' instead of 'GX' [M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj]\n  cl : Command line warning D9035: option 'GZ' has been deprecated and will be removed in a future release [M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj]\n  cl : Command line warning D9036: use 'RTC1' instead of 'GZ' [M:\\Programming\\C++\\CMake Tutorial\\flavors\\part1_step2\\visualStudio\\toDo.vcxproj]\n    4 Warning(s)\n    0 Error(s)\nTime Elapsed 00:00:05.49\n<\/pre>\n<\/section>\n<dl>\n<dt><kbd>MSBuild ALL_BUILD.vcxproj<\/kbd><\/dt>\n<dd>\n      The <code>MSBuild<\/code> tool requires the project to build as a command<br \/>\n      line argument. In this case I built everything. As you can see its output<br \/>\n      is rather verbose. <span class=\"subtle\">(Also it seems the projects<br \/>\n      created by CMake could use some updating.)<\/span><br \/>\n      <br \/>\n      <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/0k6kkbsd.aspx\">reference<\/a>,      <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms164311.aspx\">command line reference<\/a>      <time class=\"access\">(2012-07-22)<\/time>\n    <\/dd>\n<\/dl>\n<\/section>\n<section>\n<h1 id=\"section-Xcode\">Xcode<\/h1>\n<h2 id=\"section-MacOsX\">Mac OS X<\/h2>\n<p class=\"subtle\">\n    Xcode Version 4.1 Build 4B110 was used.\n  <\/p>\n<p>\n    Generating an Xcode project is very similar to generating any other project:\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> mkdir xcode\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd xcode\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cmake -G &quot;Xcode&quot; ..\n-- The C compiler identification is GNU 4.2.1\n-- The CXX compiler identification is GNU 4.2.1\n-- Checking whether C compiler has -isysroot\n-- Checking whether C compiler has -isysroot - yes\n-- Checking whether C compiler supports OSX deployment target flag\n-- Checking whether C compiler supports OSX deployment target flag - yes\n-- Check for working C compiler using: Xcode\n-- Check for working C compiler using: Xcode -- works\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - done\n-- Checking whether CXX compiler has -isysroot\n-- Checking whether CXX compiler has -isysroot - yes\n-- Checking whether CXX compiler supports OSX deployment target flag\n-- Checking whether CXX compiler supports OSX deployment target flag - yes\n-- Check for working CXX compiler using: Xcode\n-- Check for working CXX compiler using: Xcode -- works\n-- Detecting CXX compiler ABI info\n-- Detecting CXX compiler ABI info - done\n-- Configuring done\n-- Generating done\n-- Build files have been written to: \/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\n<\/pre>\n<\/section>\n<p>\n    If you look closely you will notice that most of CMake&#8217;s output looks the<br \/>\n    same as it did when we<br \/>\n    <a href=\"https:\/\/www.johnlamp.net\/cmake-tutorial-1-getting-started.html#Step1Output\">first<\/a>    ran it. In fact the only major difference is that CMake doesn&#8217;t directly<br \/>\n    interact with the compiler, it uses Xcode instead.  We are still doing an<br \/>\n    out-of-source build so even the Xcode project won&#8217;t clutter your source<br \/>\n    tree. CMake created the following files:\n  <\/p>\n<p>  <img class=\"screenshot-osX\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/xcode\/files.png\" alt=\"[generated files]\" \/><\/p>\n<p>\n    Most of these files will look familiar if you had looked at what files CMake<br \/>\n    generated before.  The most important file is <code>To Do<br \/>\n    List.xcodeproj<\/code>. Note that the project file is named after the project<br \/>\n    command in <code>CMakeLists.txt<\/code>. If spaces in file names cause<br \/>\n    trouble in your environment then you will want to ensure your project names<br \/>\n    have no spaces. Now let&#8217;s take a look at the project CMake created for us.\n  <\/p>\n<p>  <img class=\"screenshot-osX\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/xcode\/project.png\" alt=\"[Xcode project window]\" \/><\/p>\n<p>\n    The project is not as neat as one you would have made by hand. Most<br \/>\n    conspicuously <code>ToDo.h<\/code> is missing. This is because CMake doesn&#8217;t<br \/>\n    actually know about it. However because it is in the same directory<br \/>\n    as <code>ToDo.cc<\/code> the compiler will still find it. If you were to<br \/>\n    include <code>ToDo.h<\/code> in the <code>add_executable()<\/code> command<br \/>\n    then it would be included in the Xcode project. Both Xcode and CMake know<br \/>\n    not to compile header files so there would be no actual effect on the build.\n  <\/p>\n<p>\n    You will notice the extra folders &#8220;ALL_BUILD&#8221; and &#8220;ZERO_CHECK&#8221;, these<br \/>\n    actually correspond to particular Xcode targets created by CMake. These are<br \/>\n    the targets created by CMake:\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/xcode\/targets.png\" alt=\"[Xcode targets]\" \/><\/p>\n<dl>\n<dt>ZERO_CHECK<\/dt>\n<dd>\n      This oddly named target checks your <code>CMakeLists.txt<\/code> and<br \/>\n      updates your project as needed. Just as with the generated Makefile.\n    <\/dd>\n<dt>toDo<\/dt>\n<dd>\n      This is our executable as specified by the <code>add_executable()<\/code><br \/>\n      command. This will build our little command line tool.\n    <\/dd>\n<dt>RUN_TESTS<\/dt>\n<dd>\n      This runs CTest just as <kbd>make test<\/kbd> did before. It produces the<br \/>\n      same output files as before, too. CTest&#8217;s output, however, is not<br \/>\n      displayed, but it can be found using the Log Navigator. Also as before it<br \/>\n      does not depend on any other targets, e.g. &#8220;toDo,&#8221; even if a test does.\n    <\/dd>\n<dt>ALL_BUILD<\/dt>\n<dd>\n      This builds all targets except &#8220;RUN_TESTS&#8221; just as <kbd>make<\/kbd> did<br \/>\n      before. Since we only specified one target, &#8220;toDo,&#8221; this target is<br \/>\n      redundant, but if we had specified other targets, say another executable,<br \/>\n      this would build them all.\n    <\/dd>\n<\/dl>\n<p>\n    Let&#8217;s build toDo and see what output Xcode produces.\n  <\/p>\n<p>  <img class=\"screenshot-osX\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/xcode\/build.png\" alt=\"[Xcode build]\" \/><\/p>\n<p>\n    The &#8220;Run&#8221; button in Xcode builds and then runs the target. The build<br \/>\n    succeeded and the test still passes; so far everything works fine in<br \/>\n    Xcode. You will notice, though, that we now have a warning. If you were to<br \/>\n    look in Xcode you will find<br \/>\n    that <code>-Wmost<\/code>, <code>-Wno-four-char-constants<\/code>,<br \/>\n    and <code>-Wno-unknown-pragmas<\/code> are passed to gcc by<br \/>\n    Xcode. Our <code>CMakeLists.txt<\/code> doesn&#8217;t pass any additional options<br \/>\n    to the compiler so when we were using the Makefile generator we were using<br \/>\n    gcc&#8217;s default settings. For now don&#8217;t worry about the warning, we will get<br \/>\n    to that in<br \/>\n    <a href=\"https:\/\/www.johnlamp.net\/cmake-tutorial-3-gui-tool.html#section-FirstFixAWarning\">chapter 3<\/a>.  <\/p>\n<p>\n    Now if you prefer to work from the command line but must use Xcode you can<br \/>\n    use the <code>xcodebuild<\/code> tool provided by Apple.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd xcode\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> xcodebuild -list\nInformation about project &quot;To Do List&quot;:\n    Targets:\n        ALL_BUILD\n        RUN_TESTS\n        ZERO_CHECK\n        toDo\n    Build Configurations:\n        Debug\n        Release\n        MinSizeRel\n        RelWithDebInfo\n    If no build configuration is specified &quot;Debug&quot; is used.\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> xcodebuild\n=== BUILD AGGREGATE TARGET ZERO_CHECK OF PROJECT To Do List WITH THE DEFAULT CONFIGURATION (Debug) ===\nCheck dependencies\nPhaseScriptExecution &quot;CMake Rules&quot; &quot;xcode\/To Do List.build\/Debug\/ZERO_CHECK.build\/Script-1D0B6873874D4ED8AF14DE31.sh&quot;\n    cd &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2&quot;\n    \/bin\/sh -c &quot;\\&quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/To Do List.build\/Debug\/ZERO_CHECK.build\/Script-1D0B6873874D4ED8AF14DE31.sh\\&quot;&quot;\necho &quot;&quot;\nmake -f \/Volumes\/Documents\/Programming\/C++\/CMake\\ Tutorial\/flavors\/part1_step2\/xcode\/CMakeScripts\/ReRunCMake.make\nmake[1]: `CMakeFiles\/cmake.check_cache' is up to date.\n=== BUILD NATIVE TARGET toDo OF PROJECT To Do List WITH THE DEFAULT CONFIGURATION (Debug) ===\nCheck dependencies\nCompileC &quot;xcode\/To Do List.build\/Debug\/toDo.build\/Objects-normal\/x86_64\/ToDo.o&quot; ToDo.cc normal x86_64 c++ com.apple.compilers.llvmgcc42\n    cd &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2&quot;\n    setenv LANG en_US.US-ASCII\n    \/Developer\/usr\/bin\/llvm-gcc-4.2 -x c++ -arch x86_64 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 &quot;-DCMAKE_INTDIR=\\&quot;Debug\\&quot;&quot; -isysroot \/Developer\/SDKs\/MacOSX10.7.sdk -fasm-blocks -mmacosx-version-min=10.7 -gdwarf-2 &quot;-I\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/Debug\/include&quot; &quot;-I\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/To Do List.build\/Debug\/toDo.build\/DerivedSources\/x86_64&quot; &quot;-I\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/To Do List.build\/Debug\/toDo.build\/DerivedSources&quot; -Wmost -Wno-four-char-constants -Wno-unknown-pragmas &quot;-F\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/Debug&quot; -c &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/ToDo.cc&quot; -o &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/To Do List.build\/Debug\/toDo.build\/Objects-normal\/x86_64\/ToDo.o&quot;\nCompileC &quot;xcode\/To Do List.build\/Debug\/toDo.build\/Objects-normal\/x86_64\/main.o&quot; main.cc normal x86_64 c++ com.apple.compilers.llvmgcc42\n    cd &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2&quot;\n    setenv LANG en_US.US-ASCII\n    \/Developer\/usr\/bin\/llvm-gcc-4.2 -x c++ -arch x86_64 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 &quot;-DCMAKE_INTDIR=\\&quot;Debug\\&quot;&quot; -isysroot \/Developer\/SDKs\/MacOSX10.7.sdk -fasm-blocks -mmacosx-version-min=10.7 -gdwarf-2 &quot;-I\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/Debug\/include&quot; &quot;-I\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/To Do List.build\/Debug\/toDo.build\/DerivedSources\/x86_64&quot; &quot;-I\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/To Do List.build\/Debug\/toDo.build\/DerivedSources&quot; -Wmost -Wno-four-char-constants -Wno-unknown-pragmas &quot;-F\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/Debug&quot; -c &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/main.cc&quot; -o &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/To Do List.build\/Debug\/toDo.build\/Objects-normal\/x86_64\/main.o&quot;\n\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/main.cc: In function 'int equalityTest(T1, T2, const char*, const char*, const char*, int) [with T1 = long unsigned int, T2 = int]':\n\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/main.cc:34:   instantiated from here\n\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/main.cc:58: warning: comparison between signed and unsigned integer expressions\nLd xcode\/Debug\/toDo normal x86_64\n    cd &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2&quot;\n    setenv MACOSX_DEPLOYMENT_TARGET 10.7\n    \/Developer\/usr\/bin\/llvm-g++-4.2 -arch x86_64 -isysroot \/Developer\/SDKs\/MacOSX10.7.sdk &quot;-L\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/Debug&quot; &quot;-F\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/Debug&quot; -filelist &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/To Do List.build\/Debug\/toDo.build\/Objects-normal\/x86_64\/toDo.LinkFileList&quot; -mmacosx-version-min=10.7 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -o &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/Debug\/toDo&quot;\nPhaseScriptExecution &quot;CMake PostBuild Rules&quot; &quot;xcode\/To Do List.build\/Debug\/toDo.build\/Script-01429AA71A364B6AAE9CB89B.sh&quot;\n    cd &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2&quot;\n    \/bin\/sh -c &quot;\\&quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/To Do List.build\/Debug\/toDo.build\/Script-01429AA71A364B6AAE9CB89B.sh\\&quot;&quot;\necho &quot;Depend check for xcode&quot;\nDepend check for xcode\ncd \/Volumes\/Documents\/Programming\/C++\/CMake\\ Tutorial\/flavors\/part1_step2\/xcode &amp;&amp; make -C \/Volumes\/Documents\/Programming\/C++\/CMake\\ Tutorial\/flavors\/part1_step2\/xcode -f \/Volumes\/Documents\/Programming\/C++\/CMake\\ Tutorial\/flavors\/part1_step2\/xcode\/CMakeScripts\/XCODE_DEPEND_HELPER.make PostBuild.toDo.Debug\nmake[1]: Nothing to be done for `PostBuild.toDo.Debug'.\n=== BUILD AGGREGATE TARGET ALL_BUILD OF PROJECT To Do List WITH THE DEFAULT CONFIGURATION (Debug) ===\nCheck dependencies\nPhaseScriptExecution &quot;CMake Rules&quot; &quot;xcode\/To Do List.build\/Debug\/ALL_BUILD.build\/Script-48A6EF12B1004D59A240CCC6.sh&quot;\n    cd &quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2&quot;\n    \/bin\/sh -c &quot;\\&quot;\/Volumes\/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/xcode\/To Do List.build\/Debug\/ALL_BUILD.build\/Script-48A6EF12B1004D59A240CCC6.sh\\&quot;&quot;\necho &quot;&quot;\necho Build\\ all\\ projects\nBuild all projects\n** BUILD SUCCEEDED **\n<\/pre>\n<\/section>\n<dl>\n<dt><kbd>xcodebuild -list<\/kbd><\/dt>\n<dd>\n      This lists all the targets and all the build configurations set up in the<br \/>\n      Xcode project. Xcode, by default, uses the <code>xcodeproj<\/code> file in<br \/>\n      the current directory if there is only one, which is the case when using<br \/>\n      CMake.<br \/>\n      (<a href=\"https:\/\/developer.apple.com\/library\/mac\/#documentation\/Darwin\/Reference\/Manpages\/man1\/xcodebuild.1.html\">man page<\/a>      <time class=\"access\">2012-07-17<\/time>)\n    <\/dd>\n<dt><kbd>xcodebuild<\/kbd><\/dt>\n<dd>\n      <code>xcodebuild<\/code> assumes the first target if none is provided on<br \/>\n      the command line, much like <code>make<\/code>. Conveniently CMake<br \/>\n      made <code>ALL_BUILD<\/code> the first target. As you can see this builds<br \/>\n      everything and is a lot more verbose than the makefile created by CMake.\n    <\/dd>\n<\/dl>\n<h2 id=\"section-Ios\">iOS<\/h2>\n<p>\n    While cross-compiling will not be covered until later you can build for iOS<br \/>\n    using CMake and the Xcode generator. There is a Google Code Project<br \/>\n    specifically for this:<br \/>\n    <a href=\"http:\/\/code.google.com\/p\/ios-cmake\/\">ios-cmake<\/a>    <time class=\"access\">(2012-07-09)<\/time>.<br \/>\n<\/section>\n<section>\n<h1 id=\"section-EclipseCdt4\">Eclipse CDT4<\/h1>\n<p class=\"subtle\">\n    Eclipse Indigo Version 3.7.2 Build I20110613-1736 was used.\n  <\/p>\n<p>\n    If you want to use Eclipse you simply need to tell CMake so when you<br \/>\n    generate your project files.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> mkdir eclipse\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd eclipse\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cmake -G &quot;Eclipse CDT4 - Unix Makefiles&quot; ..\n-- The C compiler identification is GNU\n-- The CXX compiler identification is GNU\n-- Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.\n-- Check for working C compiler: \/usr\/bin\/gcc\n-- Check for working C compiler: \/usr\/bin\/gcc -- works\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - done\n-- 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\nCMake Warning in CMakeLists.txt:\n  The build directory is a subdirectory of the source directory.\n  This is not supported well by Eclipse.  It is strongly recommended to use a\n  build directory which is a sibling of the source directory.\n-- Generating done\n-- Build files have been written to: \/home\/john\/Desktop\/part1_step2\/eclipse\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> ls -A\nCMakeCache.txt  cmake_install.cmake  CTestTestfile.cmake  .project\n<span class=\"ansiBold ansiForeground-blue\">CMakeFiles<\/span>      .cproject            Makefile\n<\/pre>\n<\/section>\n<p>\n    Well perhaps it isn&#8217;t actually that simple. CMake warns us that Eclipse<br \/>\n    doesn&#8217;t like the build directory being a subdirectory of the source<br \/>\n    directory. As you can see it created the <code>.project<\/code><br \/>\n    and <code>.cproject<\/code> files required by Eclipse CDT.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/eclipse\/project.png\" alt=\"[Eclipse project window]\" \/>  <\/p>\n<p>\n    The project looks okay, however it isn&#8217;t. Certain aspects of the project<br \/>\n    will not function properly. So we will learn from our mistake and follow<br \/>\n    CMake&#8217;s advice.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd ..\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> mkdir eclipse\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd eclipse\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cmake -G &quot;Eclipse CDT4 - Unix Makefiles&quot; ..\/part1_step2\/\n-- The C compiler identification is GNU\n-- The CXX compiler identification is GNU\n-- Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.\n-- Check for working C compiler: \/usr\/bin\/gcc\n-- Check for working C compiler: \/usr\/bin\/gcc -- works\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - done\n-- 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: \/home\/john\/Desktop\/eclipse\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> ls -a\n<span class=\"ansiBold ansiForeground-blue\">.<\/span>   CMakeCache.txt  cmake_install.cmake  CTestTestfile.cmake  .project\n<span class=\"ansiBold ansiForeground-blue\">..<\/span>  <span class=\"ansiBold ansiForeground-blue\">CMakeFiles<\/span>      .cproject            Makefile\n<\/pre>\n<\/section>\n<p>\n    CMake&#8217;s output looks the same, save for the lack of a warning, and it also<br \/>\n    created the same files as before. The project should work fine this<br \/>\n    time. Let&#8217;s have a look.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/eclipse\/project2.png\" alt=\"[Eclipse project window, take 2]\" \/>  <\/p>\n<p>\n    The project looks a lot better this time. If you are familiar with Eclipse<br \/>\n    you may know that it only supports one target per project whereas CMake<br \/>\n    supports many. In fact managing builds of complex source trees is one of<br \/>\n    CMake&#8217;s strengths. These seem to be at odds with each other. If you looked<br \/>\n    closely before you would have noticed that CMake created a Makefile and<br \/>\n    created a Makefile project for Eclipse. This allows CMake to support<br \/>\n    multiple targets <i>and<\/i> work with Eclipse. The &#8220;[Subprojects]&#8221; folder<br \/>\n    lists every CMake project included, in our case there&#8217;s just one. Similarly<br \/>\n    the &#8220;[Targets]&#8221; folder lists all of the targets defined in<br \/>\n    your <code>CmakeLists.txt<\/code>. If you looked at any of the other IDE<br \/>\n    projects generated by CMake you may be surprised to see <code>ToDo.h<\/code><br \/>\n    included. That is because the Eclipse project includes some virtual folders<br \/>\n    which display whatever files happened to be in the corresponding directory.\n  <\/p>\n<p>\n    Let&#8217;s try building our project and see if it still works.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/eclipse\/build.png\" alt=\"[Eclipse build]\" \/>  <\/p>\n<p>\n    It still builds fine and as you can see Eclipse uses make to do the<br \/>\n    building. Conveniently the binary executable &#8220;toDo&#8221; is added to the project<br \/>\n    so it can easily be run or debugged from within Eclipse.\n  <\/p>\n<p>\n    Eclipse supports Makefiles rather well so you can get it to build any of the<br \/>\n    available targets. Eclipse provides a convenient list.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/eclipse\/targets.png\" alt=\"[Eclipse Makefile targets]\" \/>  <\/p>\n<p>\n    The default is, of course, to build all targets. &#8220;[exe] toDo&#8221; is, of course<br \/>\n    our tiny example program. However there is also &#8220;[exe] toDo\/fast&#8221; which has<br \/>\n    an intriguing name. The difference between the two is that the &#8220;fast&#8221;<br \/>\n    version doesn&#8217;t check if the <code>CmakeLists.txt<\/code> has changed or<br \/>\n    recalculate toDo&#8217;s dependencies. It also doesn&#8217;t calculate completion<br \/>\n    percentages. If you are sure that none of those have changed using a &#8220;fast&#8221;<br \/>\n    target can speed up your build a bit. However, the most interesting target<br \/>\n    here is &#8220;: test&#8221; which will run CTest just as <kbd>make test<\/kbd> did<br \/>\n    before. CTest&#8217;s output is displayed in the Build Console and the Testing<br \/>\n    directory is added to the project.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/eclipse\/test.png\" alt=\"[Eclipse make test]\" \/>  <\/p>\n<p>\n    As you can see the test still passes so everything works in Eclipse.\n  <\/p>\n<p>\n    If you desire to still build your project from the command line it is<br \/>\n    actually quite easy because CMake created Makefiles. So you can build just<br \/>\n    as you did before.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd ..\/eclipse\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> make\n[ 50%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/main.cc.o\n<\/span>[100%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/ToDo.cc.o\n<\/span><span class=\"ansiBold ansiForeground-red\">Linking CXX executable toDo\n<\/span>[100%] Built target toDo\n<\/pre>\n<\/section>\n<\/section>\n<section>\n<h1 id=\"section-Kdevelop\">KDevelop<\/h1>\n<p>\n    For KDevelop 3 CMake will generate a project for you to use. KDevelop 4,<br \/>\n    however, has native CMake support making that step unnecessary.\n  <\/p>\n<h2 id=\"section-Generated(Kdevelop3)\">Generated (KDevelop3)<\/h2>\n<p class=\"subtle\">\n    KDevelop Version 3.3.4 was used.\n  <\/p>\n<p>\n    If you want CMake to create a KDevelop project for you specify the<br \/>\n    &#8220;KDevelop3&#8221; generator. There is also a &#8220;KDevelop3 &#8211; Unix Makefiles&#8221; which<br \/>\n    generates the same exact files, so save yourself the typing.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> mkdir kdevelop\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd kdevelop\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cmake -G &quot;KDevelop3&quot; ..\n-- The C compiler identification is GNU\n-- The CXX compiler identification is GNU\n-- Check for working C compiler: \/usr\/bin\/gcc\n-- Check for working C compiler: \/usr\/bin\/gcc -- works\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - done\n-- 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: \/home\/john\/Desktop\/part1_step2\/kdevelop\n<\/pre>\n<\/section>\n<p>\n    The output looks similar to the first time we ran it. It produces a few<br \/>\n    extra files for KDevelop, though.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/kdevelop3\/files.png\" alt=\"[KDevelop 3 files]\" \/>  <\/p>\n<p>\n    The KDevelop 3 project file, <code>To Do List.kdevelop<\/code> is the most<br \/>\n    important of the new files. You will notice that CMake still created<br \/>\n    a <code>Makefile<\/code>. KDevelop&#8217;s Makefile support, however, is quite<br \/>\n    good. Let&#8217;s see the project.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/kdevelop3\/project.png\" alt=\"[KDevelop 3 project]\" \/>  <\/p>\n<p>\n    Oddly the &#8220;File List&#8221; only displays <code>ToDo.cc<\/code> even though we<br \/>\n    would expect it to also include <code>main.cc<\/code>. The &#8220;File Selector&#8221;<br \/>\n    shows all of the files in your source directory. Let&#8217;s see if we can still<br \/>\n    build.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/kdevelop3\/build.png\" alt=\"[KDevelop 3 build]\" \/>  <\/p>\n<p>\n    Of course it still builds. We are using the same <code>Makefile<\/code> as we<br \/>\n    originally did. The only difference this time is that KDevelop is running<br \/>\n    make for us. Thanks to KDevelop&#8217;s Makefile support we can actually build any<br \/>\n    target we want.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/kdevelop3\/targets.png\" alt=\"[KDevelop 3 targets]\" \/>  <\/p>\n<p>\n    By default KDevelop builds the target &#8220;all&#8221; which does exactly what you&#8217;d<br \/>\n    expect, it builds everything. There are a few targets that end with<br \/>\n    &#8220;\/fast&#8221;. These &#8220;fast&#8221; targets skip some steps to save time, so be careful<br \/>\n    when using them. Dependency calculation and checking<br \/>\n    the <code>CMakeLists.txt<\/code> file for changes are skipped; also<br \/>\n    completion percentages aren&#8217;t printed. While these will build faster than<br \/>\n    the regular targets if there are any changes that require dependencies to be<br \/>\n    recalculated or any <code>CMakeLists.txt<\/code> have been changed you<br \/>\n    results will not be what you expected.\n  <\/p>\n<p>\n    Currently the most interesting target is &#8220;test&#8221;. Building this target is, of<br \/>\n    course, the same as running <kbd>make test<\/kbd>.\n  <\/p>\n<p>  <img class=\"screenshot\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/kdevelop3\/test.png\" alt=\"[KDevelop 3 test]\" \/>  <\/p>\n<p>\n    Our test still passes. Don&#8217;t lie, I know you had doubts. CTest&#8217;s output is<br \/>\n    displayed in the Messages panel. Just as before CTest creates the same<br \/>\n    files, too.\n  <\/p>\n<p>\n    If you wanted to build from the command line it&#8217;s quite simple since we have<br \/>\n    a <code>Makefile<\/code> just as before.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd kdevelop\n<span class=\"ansiBold ansiForeground-red\"> <\/span><span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> make\n[ 50%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/main.cc.o\n<\/span>[100%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/ToDo.cc.o\n<\/span><span class=\"ansiBold ansiForeground-red\">Linking CXX executable toDo\n<\/span>[100%] Built target toDo\n<\/pre>\n<\/section>\n<h2 id=\"section-CmakeSupport(Kdevelop4)\">CMake Support (KDevelop4)<\/h2>\n<p class=\"subtle\">\n    KDevelop Version 4.3.1 was used.\n  <\/p>\n<p>\n    KDevelop 4 has built-in support for CMake projects. So rather than use a<br \/>\n    generator to make a new project file as was done in the previous examples we<br \/>\n    instead simply open the CMake project with KDevelop.\n  <\/p>\n<p>\n    After launching KDevelop 4 choose &#8220;Open \/ Import Project&#8230;&#8221; from the<br \/>\n    &#8220;Project Menu&#8221; and follow the steps of the import process. First you will<br \/>\n    have to find you <code>CmakeLists.txt<\/code> file. KDevelop will treat it as<br \/>\n    your project file. Next it will ask for a project name and build system. It<br \/>\n    will infer both and likely be correct. Lastly it will configure your build<br \/>\n    directory and CMake binary. Again the defaults are probably<br \/>\n    sufficient. After that you will get to see your project.\n  <\/p>\n<p>  <img class=\"screenshot-kde\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/kdevelop4\/project.png\" alt=\"[KDevelop 4 project]\" \/><\/p>\n<p>\n    The file list shows all files that are actually in the project<br \/>\n    directory. Conveniently this include <code>ToDo.h<\/code>. However you may<br \/>\n    also notice a <code>kdev4<\/code> project file. While KDevelop4 supports<br \/>\n    CMake, including out of source builds, it does put a project file in your<br \/>\n    source directory. Although since it is only one file it is easy to clean up<br \/>\n    <span class=\"subtle\">(or have git ignore)<\/span>.\n  <\/p>\n<p>\n    Building is, of course, as simple as clicking the &#8220;Build Selection&#8221;<br \/>\n    button.\n  <\/p>\n<p>  <img class=\"screenshot-kde\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/kdevelop4\/build.png\" alt=\"[KDevelop 4 build]\" \/><\/p>\n<p>\n    You will notice that KDevelop still uses make to build the project. The main<br \/>\n    difference here is that KDevelop also runs CMake for you. These are the<br \/>\n    files it created:\n  <\/p>\n<p>  <img class=\"screenshot-kde\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/kdevelop4\/files.png\" alt=\"[KDevelop 4 files]\" \/><\/p>\n<p>\n    Exactly the files you should have expected.\n  <\/p>\n<p>\n    Now if I wanted to run our little program the &#8220;Execute&#8221; button doesn&#8217;t seem<br \/>\n    to work, it merely displays an error. However if I right-click on the &#8220;toDo&#8221;<br \/>\n    entry under the project and pick &#8220;Execute As&#8230;&#8221; &gt; &#8220;Native Application&#8221;<br \/>\n    it runs fine.\n  <\/p>\n<p>  <img class=\"screenshot-kde\" src=\"https:\/\/www.johnlamp.net\/screenshots\/cmt-2\/kdevelop4\/run.png\" alt=\"[KDevelop 4 run]\" \/><\/p>\n<p>\n    Unfortunately I cannot find a way to run the tests from within KDevelop. As<br \/>\n    it does create a Makefile project the tests can be manually run from the<br \/>\n    command line. That seems like an ugly work-around, though.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n <span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd kdevelop\n <span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> make test\n<span class=\"ansiForeground-cyan\">Running tests...\n<\/span>Test project \/Documents\/Programming\/C++\/CMake Tutorial\/flavors\/part1_step2\/kdevelop\n    Start 1: toDoTest\n1\/1 Test #1: toDoTest .........................   Passed    0.01 sec\n100% tests passed, 0 tests failed out of 1\nTotal Test time (real) =   0.05 sec\n<\/pre>\n<\/section>\n<p>\n    Since this is a Makefile project you can easily build from the command line<br \/>\n    using <kbd>make<\/kbd>.\n  <\/p>\n<section class=\"terminal\">\n<pre>\n <span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> cd kdevelop\n <span class=\"ansiBold ansiForeground-blue\">&gt;<\/span> make\n[ 50%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/main.cc.o\n<\/span>[100%] <span class=\"ansiForeground-green\">Building CXX object CMakeFiles\/toDo.dir\/ToDo.cc.o\n<\/span><span class=\"ansiBold ansiForeground-red\">Linking CXX executable toDo\n<\/span>[100%] Built target toDo\n<\/pre>\n<\/section>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Now that we are familiar with CMake I will make good on CMake&#8217;s promise of<br \/>\n    flexibility. I said before that CMake could create projects for various<br \/>\n    IDE&#8217;s and in this chapter we will do so. This is one of CMake&#8217;s greatest<br \/>\n    strengths as it allows for very diverse development environments while<br \/>\n    working on the same &hellip;<br \/><a href=\"https:\/\/www.johnlamp.net\/?p=16\" rel=\"bookmark\">Continue reading &quot;CMake Tutorial &#8211; Chapter&#160;2: IDE Integration&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\/16"}],"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=16"}],"version-history":[{"count":0,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johnlamp.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}