title: How to use CMake with Catch2?
body: <p>From <a href="https://github.com/catchorg/Catch2/blob/master/docs/tutorial.md#writing-tests" rel="noreferrer">Catch2's example</a>, I tried to run this example with <code>cmake</code> where structure of my project is like this:</p>
  
  <pre><code>/factorial
      +-- CMakeLists.txt
      +-- /bin
      +-- /include
      |     +-- catch.hpp
      |     +-- fact.hpp 
      +-- /src
      |     +-- CMakeLists.txt
      |    +-- fact.cpp
      +-- /test
           +-- CMakeLists.txt
           +-- test_fact.cpp
  </code></pre>
  
  <p><code>fact.cpp</code>:</p>
  
  <pre><code>unsigned int factorial( unsigned int number ) {
      return number &lt;= 1 ? number : factorial(number-1)*number;
  }
  </code></pre>
  
  <p><code>fact.hpp</code>:</p>
  
  <pre><code>#ifndef FACT_H
  #define FACT_H
  
  unsigned int factorial(unsigned int);
  
  #endif
  </code></pre>
  
  <p><code>test_fact.cpp</code>:</p>
  
  <pre><code>#define CATCH_CONFIG_MAIN
  #include "catch.hpp"
  #include "fact.hpp"
  
  TEST_CASE( "factorials are computed", "[factorial]" ) {
      REQUIRE( factorial(1) == 1 );
      REQUIRE( factorial(2) == 2 );
      REQUIRE( factorial(3) == 6 );
      REQUIRE( factorial(10) == 3628800 );
  }
  </code></pre>
  
  <p>I tried several ways already to build this project with <code>cmake</code> but it's failed. Sometimes I got an error:</p>
  
  <pre><code>cpp:X:XX: fatal error: 'fact.hpp' file not found
  ...
  </code></pre>
  
  <p>and sometimes I got:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "_main", referenced from:
  ...
  </code></pre>
  
  <p>when I run <code>make</code>.</p>
  
  <p>What should I have in <code>factorial/CMakeLists.txt</code>,<code>factorial/src/CMakeLists.txt</code> and <code>factorial/test/CMakeLists.txt</code>, if I want to have my execution files in <code>factorial/bin</code>?</p>
  
  <p>Additional:
  This is my CMakeLists.txts (I think they are completely wrong).</p>
  
  <p><code>factorial/CMakeLists.txt</code>:</p>
  
  <pre><code>project(factorial)
  cmake_minimum_required(VERSION 2.8.12)
  
  add_definitions("-std=c++11")
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
  
  add_subdirectory(src)
  add_subdirectory(test)
  </code></pre>
  
  <p><code>factorial/src/CMakeLists.txt</code>:</p>
  
  <pre><code>project(factorial)
  cmake_minimum_required(VERSION 2.8.12)
  
  add_executable(fact fact.cpp)
  </code></pre>
  
  <p><code>factorial/test/CMakeLists.txt</code>:</p>
  
  <pre><code>project(factorial)
  cmake_minimum_required(VERSION 2.8.12)
  
  add_executable(test_fact test_fact.cpp)
  target_include_directories(test_fact PRIVATE ${CMAKE_SOURCE_DIR}/include)
  </code></pre>