Compiling with Cmake and using a header only libra

2019-08-14 12:22发布

问题:

The question is a continuation/repeated one to a previous question, which didn't resolve the issue i'm running into.

Using Eigen with Cmake

Compiling Eigen with make file is one step task. But in Cmake, how do you add a header only library (basically i am using only the Eigen folder from the extracted archive folder in the Eigen website, and disregarding the rest.) Note: Eigen folder has its own CMakeLists.txt

回答1:

You can use the FindEigen3.cmake. Put it into cmake/Modules folder and add the following lines to your CmakeLists.txt

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})

You can find FindEigen3.cmake in the source of the Eigen library in cmake/FindEigen3.cmake

https://bitbucket.org/eigen/eigen/src/971445a0e8ec311b4b663242b1f0ac668a9753ca/cmake/FindEigen3.cmake?at=default