title: Adding Eigen library to c++ project using cmake
body: <p>Unfortunately, i have some problems adding the headers only <a href="http://eigen.tuxfamily.org/index.php?title=Main_Page" rel="nofollow noreferrer">Eigen 3.3.7 Library</a> to my Makefile with Cmake on my Ubuntu 18.04.4 LTS system.
  I can compile my code using the library by just copying the library folder in the include directory and using
  <code>include_directories(./include/eigen3)</code> in the CMakeLists.txt file. However, i would much prefer not having the library path hard-coded but being able set it dynamically in the CMakeLists.txt file to make sharing the project with other people easier. Unfortunately, none of the instructions i found worked for me.</p>
  <p>I prepared the following minimum code example:</p>
  <p>main.cpp:</p>
  <pre><code>#include &lt;eigen3/Eigen/Dense&gt;
  #include &lt;iostream&gt;
  
  int main()
  {  
      Eigen::Vector3d test_vec(1.0f, 2.0f, 3.0f);
      std::cout &lt;&lt; test_vec &lt;&lt; std::endl;
      return 0;
  } 
  </code></pre>
  <p>CMakeLists.txt:</p>
  <pre><code>cmake_minimum_required(VERSION 3.0)
  
  project(Eigen-Cmake-Test VERSION 1.0) # set the project name
  
  find_package (Eigen3 3.3 REQUIRED NO_MODULE)
  
  include_directories(${EIGEN_INCLUDE_DIR})
  
  # add the executable
  add_executable(&quot;${PROJECT_NAME}&quot; ./main.cpp) 
  
  target_link_libraries(&quot;${PROJECT_NAME}&quot; Eigen3::Eigen)
  </code></pre>
  <p>I downloaded the headers only <a href="http://eigen.tuxfamily.org/index.php?title=Main_Page" rel="nofollow noreferrer">Eigen 3.3.7 Library</a> and renamed the folder to eigen3. The folder was then moved to:
  <code>/usr/local/share/eigen3</code></p>
  <p>when i run <code>cmake CMakeLists.txt</code> i get the following error:</p>
  <pre><code>CMake Error at CMakeLists.txt:5 (find_package):
    Could not find a package configuration file provided by &quot;Eigen3&quot; (requested
    version 3.3) with any of the following names:
  
      Eigen3Config.cmake
      eigen3-config.cmake
  
    Add the installation prefix of &quot;Eigen3&quot; to CMAKE_PREFIX_PATH or set
    &quot;Eigen3_DIR&quot; to a directory containing one of the above files.  If &quot;Eigen3&quot;
    provides a separate development package or SDK, be sure it has been
    installed.
  
  
  -- Configuring incomplete, errors occurred!
  </code></pre>
  <p>As i checked the Eigen library folder i realized that <code>/usr/local/share/eigen3/cmake</code> only contained a file named Eigen3Config.cmake.in instead of Eigen3Config.cmake which was required. Why is this the case?</p>
  <p>I tried renaming the file to Eigen3Config.cmake. Here the error was the following:</p>
  <pre><code>CMake Error at CMakeLists.txt:5 (find_package):
    Could not find a configuration file for package &quot;Eigen3&quot; that is compatible
    with requested version &quot;3.3&quot;.
  
    The following configuration files were considered but not accepted:
  
      /usr/local/share/eigen3/cmake/Eigen3Config.cmake, version: unknown
  
  
  
  -- Configuring incomplete, errors occurred!
  </code></pre>
  <p>Furthermore, i also tried the solutions explained <a href="https://stackoverflow.com/questions/53991812/cmake-find-package-not-working-for-eigen">stackoverflow: CMake find_package not working for Eigen?</a> without success.</p>
  <p>How can i make this work properly? Also i think i do not quite understand the underlying system yet. Any explanation would be appreciated.</p>