0

I just recently learning cmake and trying to use eigen library in my project. I included eigen headers directly under my src folder. Then I tried to cmake, but it failed. I learned that if we want to build target against Eigen, we need the Eigen3Config.cmake file. But for the eigen folder under src, it does not have it. So how can I write the CMakeList.txt?

I checked following answers, but those are all talking Eigen installed in the system:
CMake find eigen incorrect results
Find package Eigen3 for CMake

What I want to implement is NOT depending on Eigen installed in system but just the Eigen in my src.

The following is my current CMakeList.txt and project structure

project(eigen_test)

cmake_minimum_required (VERSION 3.1)

add_definitions(-std=c++11)

find_package (Eigen3 3.3 REQUIRED NO_MODULE)


set(sources src/main.cpp src/other.cpp)

add_executable(eigen_test ${sources})

target_link_libraries (eigen_test Eigen3::Eigen)

Project Structure:

  
project_folder
|--CMakeLists.txt
|--src/
    |---- Eigen/
    |---- main.cpp
    |---- other.cpp

Thank you!

  • If you manually obtained all required files, then `find_package(Eigen)` is not needed. Just specify proper include directories for your executable. For that purpose you can use `target_include_directories` command. See the [duplicate question](https://stackoverflow.com/questions/28267104/using-eigen-lib-in-my-cmake-project) and its answers for more info. – Tsyvarev Mar 10 '21 at 21:32
  • @Tsyvarev Thank you for sharing the thoughts and links. target_include_directories works for me. For the use of target_include_directories, we can refer to https://cmake.org/cmake/help/latest/command/target_include_directories.html – cvkfmpc Mar 11 '21 at 03:38

0 Answers0