title: Converting a Makefile project to Cmake
body: <p>I'm learning how to use cmake for this class but the documentation is extremely verbose and dense. A lot of the tutorials are either too simple to be useful (cmake with just one file) or too complicated.</p>
  
  <p>the original Makefile for the project looks like: </p>
  
  <pre><code># Some optimization settings
  # see: http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
  
  # Standard all target
  all: hw1_p2
  
  # Simple program to do brute-force k-nearest neighbor searches against a signature file
  hw1_p2: prob2.o ParseRecord.o Sorter.o Timing.o
          g++ -o hw1_p2 prob2.o ParseRecord.o Sorter.o Timing.o
  
  prob2.o: prob2.cpp utility_templates.hpp
          g++ -Wall -c prob2.cpp
  
  ParseRecord.o: ParseRecord.cpp ParseRecord.hpp utility_templates.hpp
          g++ -Wall -c ParseRecord.cpp
  
  Sorter.o: Sorter.cpp Sorter.hpp
          g++ -Wall -c Sorter.cpp
  
  # Timing class
  Timing.o: Timing.hpp Timing.cpp
          g++ -Wall -c Timing.cpp
  
  # Clean code-derived files
  clean:
          rm -f *.o hw1_p2 
  </code></pre>
  
  <p>The project is organized like this </p>
  
  <ul>
  <li>cmakelearn 
  <ul>
  <li>CMakeLists.txt</li>
  <li>build   </li>
  <li>src 
  <ul>
  <li>CMakeLists.txt        </li>
  <li>ParseRecord.hpp       </li>
  <li>Timing.cpp            </li>
  <li>small.dat</li>
  <li>Makefile              </li>
  <li>Sorter.cpp            </li>
  <li>Timing.hpp            </li>
  <li>utility_templates.hpp</li>
  <li>ParseRecord.cpp       </li>
  <li>Sorter.hpp            </li>
  <li>prob2.cpp</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>So far, from the reading that I've done I understand that you need a CMakelists.txt file in every directory. 
  The build folder is there so that I can go into it and run cmake ..</p>
  
  <p>In the top-level CMakelists.txt file I have </p>
  
  <pre><code>cmake_minimum_required (VERSION 2.6)
  project (CMAKETEST)
  add_subdirectory(src)
  </code></pre>
  
  <p>and in the src dir CMakelist.txt here is my attempt: </p>
  
  <pre><code>include_directories(${CMAKETEST_SOURCE_DIR}/src)
  link_directories(${CMAKETEST_BINARY_DIR}/src)
  
  add_executable(hw1_p2 prob2.cpp ParseRecord.cpp Sorter.cpp Timing.cpp)
  </code></pre>
  
  <p>I don't even really know where to begin other than that. 
  This comment from a tutorial pretty much sums up my thoughts about cmake and the documentation right now: </p>
  
  <blockquote>
    <p>Not nearly detailed enough to be useful. Having said that, I don’t like CMake much
    anyway; too many separate, arbitrary Things you Just Have to Know. At
    least that’s my impression. Like, ‘add_definitions(-std=c99)’. Really?
    Does that name jump out at you as how to add flags to a compiler? And
    is ‘set(VAR a b c)’ any more intuitive than VAR=a b c or some such?
    Beh on the article, and on CMake. Yet I know CMake is taking the
    build-world by storm.</p>
  </blockquote>
  
  <p>Still, I really want to learn and figure this out so any help that you can provide will be much appreciated and helpful. Thanks in advance.</p>