title: CMake: Include vs add_subdirectory: Relative header file path
body: <p>I have a c++ project with several subdirectories, e.g.</p>
  
  <pre><code>src/
    CMakeLists.txt
    main.cpp
    module1/
       CMakeLists.txt
       code.cpp
       code.h
    module2/
       CMakeLists.txt
       code2.cpp
  </code></pre>
  
  <p>It seems that the two ways to deal with this in cmake is to either use <code>add_subdirectory(module1)</code> or <code>include(module1)</code> in my <code>src/CMakeLists.txt</code>. Somewhere I read, that the <code>include</code> use is regarded legacy/deprecated. My <code>src/module1/CMakeLists.txt</code> looks like this:</p>
  
  <pre><code>include_directories(${CMAKE_CURRENT_LIST_DIR})
  
  set( SRCS
      ${SRCS}
      ${CMAKE_CURRENT_LIST_DIR}/code.cpp
     )
  
  set( QT_FILE_HEADERS 
      ${QT_FILE_HEADERS} code.h
     )
  </code></pre>
  
  <p>If I try to use the <code>add_subdirectory</code> method and want to use<code>code.h</code> in <code>main.cpp</code> I have to write <code>#include "module1/code.h"</code>. If I do the <code>include</code> method of adding module1,  I can simply write <code>#include "code.h"</code>. I would prefer not to specify the relative path of the include files when I use them somewhere else, is there a way to achieve this using the <code>add_subdirectory</code> method? I thought the <code>include_directories</code> line should have taken care of that.</p>