title: C++ project source code layout
body: <p>One of the popular way to organize project directory is more or less like this:</p>
  
  <pre>
  MyLib
       +--mylib_class_a.h
          mylib_class_a.cpp
          mylib_library_private_helpers.h
          mylib_library_private_helpers.cpp
  
  MyApp
       +--other_class.h
          other_class.cpp
          app.cpp
  </pre>
  
  <p><code>app.cpp</code>:</p>
  
  <pre><code>#include "other_class.h"
  #include &lt;mylib_class_a.h&gt; // using library MyLib
  </code></pre>
  
  <p>All <code>.h</code> and <code>.cpp</code> files for the same library are in the same directory. To avoid name collision, file names are often prefix with company name and/or library name. MyLib will be in MyApp's header search path, etc. I'm not a fan of prefixing filenames, but I like the idea of looking at the <code>#include</code> and know exactly where that header file belongs. I don't hate this approach of organizing files, but I think there should be a better way.</p>
  
  <p>Since I'm starting a new project, I want to solicit some directory organization ideas. Currently I like this directory structure:</p>
  
  <pre>
  ProjA
      +--include
               +--ProjA
                      +--mylib
                             +--class_a.h
                      +--app
                             +--other_class.h
      +--src
           +--mylib
                  +--class_a.cpp
                     library_private_helpers.h
                     library_private_helpers.cpp
           +--app
                +--other_class.cpp
                   app.cpp
                   util.h
  </pre>
  
  <p><code>app.cpp</code>:</p>
  
  <pre><code>#include "util.h" // private util.h file
  #include &lt;ProjA/app/other_class.h&gt; // public header file
  #include &lt;ProjA/mylib/class_a.h&gt; // using class_a.h of mylib
  #include &lt;other3rdptylib/class_a.h&gt; // class_a.h of other3rdptylib, no name collision
  #include &lt;class_a.h&gt; // not ProjA/mylib/class_a.h
  #include &lt;ProjA/mylib/library_private_helpers.h&gt; // error can't find .h 
  </code></pre>
  
  <p><code>.cpp</code> files and private (only visible to immediate library) <code>.h</code> files are stored under the src directory (src is sometimes called lib). Public header files are organized into a project/lib directory structure and included via <code>&lt;ProjectName/LibraryName/headerName.h&gt;</code>. File names are not prefixed with anything. If I ever needed to package up MyLib to be used by other teams, I could simply change my makefile to copy the appropriate binary files and the whole include/ProjA directory.</p>
  
  <p>Once files are checked into source control and people start working on them it will be hard to change directory structure. It is better to get it right at the get-go. </p>
  
  <p>Anyone with experience organizing source code like this? Anything you don't like about it? If you have a better way to do it, I would very much like to hear about it.</p>