1

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

Community
  • 1
  • 1
Sam Gomari
  • 733
  • 4
  • 13
  • 37

2 Answers2

1

I ran into the same problem today when I wanted to use the stb_image.h library. I solved it this way:

Define the library with the header as input file:

add_library(stb_image SHARED stb_image.h)

As the file does not have a recognized file ending, you have to tell cmake which language the file is in (in this case, C):

set_target_properties(stb_image PROPERTIES LINKER_LANGUAGE C)

Finally, stb_image needs me to define STB_IMAGE_IMPLEMENTATION to enable compilation of the library:

target_compile_definitions(stb_image PRIVATE STB_IMAGE_IMPLEMENTATION)
alex
  • 11
  • 3
0

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

ipa
  • 1,496
  • 1
  • 17
  • 36