This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Using Eigen Lib in my Cmake project?

Tags: None
(comma "," separated)
warrior
Registered Member
Posts
1
Karma
0
I am working on an application that is part of a bigger application. My application needs to use Eigen, so i downloaded the zip file, but i took only the Eigen Folder from the rest (the rest being e.g. demo, test folder etc...). So, Eigen need not be installed , i'd like it to be part of the build.
I've been trying to do it, but since i'm new to CMake , i am having difficulty including a header only library. Help would be immensely appreciated.

Note that Eigen has a CmakeLists.txt in Eigen folder, and it has /src folder having (*.h and *.cpp) related to Matrix operation etc...

The structure of my program is as follow

Myproject (folder) is composed of :
+ CmakeLists.txt
+ /Build
+ /Source

The Source folder has bunch of my files (*.h and *.cpp) and the /Eigen (folder).

what i did is :

Code: Select all
FIND_PACKAGE(PkgConfig REQUIRED)
PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0)
LIST(APPEND CMAKE_CXX_FLAGS
    "-std=c++0x
     -pthread
     ${CMAKE_CXX_FLAGS}
     -g
    -Wall -Wextra ")

ADD_LIBRARY(Eigen ${CMAKE_SOURCE_DIR}/Eigen)
TARGET_INCLUDE_DIRECTORIES(Eigen INTERFACE
 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
 $<INSTALL_INTERFACE:include/Eigen>
)

INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS})
ADD_DEFINITIONS(${GTK3_CFLAGS_OTHERS})
INCLUDE_DIRECTORIES(include)
ADD_LIBRARY(RTT
        Def.cpp
        Def.h       
        krnel.cpp
        krnel.h
        Mesh.cpp
        Mesh.h
        Mcom.cpp
        Mcom.h
        timer.h
        Identifier.h)       

ADD_EXECUTABLE(Rdrtst main.cpp)
TARGET_LINK_LIBRARIES(Rdrtst RTT ${GTK3_LIBRARIES} Eigen)


When i cd to /Build and type (Cmake ../Source )

I get the following :

Code: Select all
[/../Build]$ cmake ../Source
-- Configuring done
CMake Error: Cannot determine link language for target "Eigen".
CMake Error: CMake can not determine linker language for target:Eigen
-- Generating done
-- Build files have been written to: /../../MyProject/Build




The CMakeLists.txt of the Eigen folder is :


Code: Select all
include(RegexUtils)
test_escape_string_as_regex()

file(GLOB Eigen_directory_files "*")

escape_string_as_regex(ESCAPED_CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

foreach(f ${Eigen_directory_files})
  if(NOT f MATCHES "\\.txt" AND NOT f MATCHES "${ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/[.].+" AND NOT f MATCHES "${ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/src")
    list(APPEND Eigen_directory_files_to_install ${f})
  endif()
endforeach(f ${Eigen_directory_files})

install(FILES
  ${Eigen_directory_files_to_install}
  DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen COMPONENT Devel
  )

add_subdirectory(src)
aluaces
Registered Member
Posts
13
Karma
0
OS
Eigen is a header-only library, so you do not directly compile it, but copy it along your sources and then just include its headers.

There is nothing to be done with respect to CMake, unless you need to use any INCLUDE_DIRECTORIES command.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]