Compiling with Cmake and using a header only library
Asked Answered
S

2

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

Stacystadholder answered 3/2, 2015 at 19:1 Comment(0)
K
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)
Kohl answered 10/3, 2020 at 17:23 Comment(0)
H
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

Hendrick answered 11/5, 2015 at 23:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.