title: The right way to structure my c++ project with cmake?
body: <p>I have been struggling with this for quite a while, and my adventures with cmake have only resulted in hackish solutions that I am pretty sure are not correct.</p>
  
  <p>I created a library that consists of several files, as follows:</p>
  
  <pre><code>-libfolder
    -codepart1folder
      -CMakeLists.txt
      -codepart1.cpp
      -codepart1.hpp
    -codepart2folder
    -codepart3folder
    -lib.cpp
    -lib.hpp
    -CMakeLists.txt
  </code></pre>
  
  <p>I wrote a CMakeLists file to compile the library (after some experimentation), and I can generate a lib.a file. Now I would like to include this code as a library in other projects, and access it through the interface in lib.hpp. What is the best way to do this, in terms of directory structure, and what I need to put into CMakeLists.txt in my root project?</p>
  
  <p>My current attempt has been to add -libfolder as a subfolder to my current project, and add the commands:</p>
  
  <pre><code>include_directories(${PROJECT_SOURCE_DIR}/libfolder)
  link_directories(${PROJECT_BINARY_DIR}/libfolder)
  add_subdirectory(libfolder)
  target_link_libraries(project lib)
  </code></pre>
  
  <p>When I run make, the library compiles fine, but when project.cpp compiles, it complains that it cannot find codepart1.hpp (which is included in lib.hpp, included from project.cpp).</p>
  
  <p>I suspect that this is the wrong way about doing this, but I cannot wade through the CMake documentation and find a good tutorial on setting up projects like this. Please help, CMake gurus!</p>