title: cmake - adding a submodule
body: <p>I am trying to build a test project with a "submodule/subproject".</p>
  
  <p>The compilation fails with:</p>
  
  <pre><code>example_01/src/main.cpp:2:10: fatal error: inc/foo2.hpp: No such file or directory
  #include "inc/foo2.hpp" // #include "submodule/inc/foo2.hpp"
            ^~~~~~~~~~~~~~
  compilation terminated.
  make[2]: *** [CMakeFiles/hello_world.dir/build.make:63: CMakeFiles/hello_world.dir/src/main.cpp.o] Error 1
  make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/hello_world.dir/all] Error 2
  make: *** [Makefile:84: all] Error 2
  </code></pre>
  
  <p>My files:</p>
  
  <h3>main CMakeLists.txt</h3>
  
  <pre><code>cmake_minimum_required(VERSION 3.12)
  project(hello_world)
  
  set(CMAKE_CXX_STANDARD 14)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
  set(CMAKE_CXX_EXTENSIONS OFF)
  
  include_directories(${PROJECT_SOURCE_DIR})
  add_subdirectory("submodule")
  add_executable(${PROJECT_NAME} 
  src/main.cpp 
  src/foo.cpp)
  </code></pre>
  
  <h3>main.cpp</h3>
  
  <pre><code>#include "inc/foo.hpp"
  #include "inc/foo2.hpp" // #include "submodule/inc/foo2.hpp"
  
  int main()
  {
      foo();
      foo2();
  
      return 0;
  }
  </code></pre>
  
  <h3>foo.cpp</h3>
  
  <pre><code>#include &lt;iostream&gt;
  #include "inc/foo.hpp"
  
  void foo()
  {
      std::cout &lt;&lt; "Hello World!\n";
  }
  </code></pre>
  
  <h3>foo.hpp</h3>
  
  <pre><code>void foo();
  </code></pre>
  
  <h3>submodule cmakelist</h3>
  
  <pre><code>project(submodule_dummy1)
  add_executable(${PROJECT_NAME} src/foo2.cpp)
  </code></pre>
  
  <h3>foo2.cpp</h3>
  
  <pre><code>#include &lt;iostream&gt;
  #include "inc/foo2.hpp"
  
  void foo2()
  {
      std::cout &lt;&lt; "FuuTwo\n";
  }
  </code></pre>
  
  <h3>foo2.hpp</h3>
  
  <pre><code>void foo2();
  </code></pre>
  
  <p>Is there something else I need to declare so it can "see" the submodule header?</p>
  
  <h1>UPDATE</h1>
  
  <h2>Tree</h2>
  
  <pre><code>.
  ├── build
  ├── CMakeLists.txt
  ├── inc
  │   └── foo.hpp
  ├── readme.md
  ├── src
  │   ├── foo.cpp
  │   └── main.cpp
  └── submodule
      ├── CMakeLists.txt
      ├── inc
      │   └── foo2.hpp
      └── src
          └── foo2.cpp
  </code></pre>
  
  <h2>New main cmakelist</h2>
  
  <pre><code>cmake_minimum_required(VERSION 3.12)
  project(hello_world)
  
  set(CMAKE_CXX_STANDARD 14)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
  set(CMAKE_CXX_EXTENSIONS OFF)
  
  include_directories(${PROJECT_SOURCE_DIR})
  include_directories(${PROJECT_SOURCE_DIR}/submodule)
  
  add_subdirectory("submodule")
  add_executable(${PROJECT_NAME} 
      src/main.cpp 
      src/foo.cpp)
  </code></pre>
  
  <h2>new error message</h2>
  
  <pre><code>Scanning dependencies of target hello_world
  [ 20%] Building CXX object CMakeFiles/hello_world.dir/src/main.cpp.o
  [ 40%] Linking CXX executable hello_world
  /usr/bin/ld: CMakeFiles/hello_world.dir/src/main.cpp.o: in function `main':
  main.cpp:(.text+0xa): undefined reference to `foo2()'
  collect2: error: ld returned 1 exit status
  make[2]: *** [CMakeFiles/hello_world.dir/build.make:99: hello_world] Error 1
  make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/hello_world.dir/all] Error 2
  make: *** [Makefile:84: all] Error 2
  </code></pre>