Skip to content

Commit

Permalink
using eigen3
Browse files Browse the repository at this point in the history
  • Loading branch information
mhekkel committed Dec 5, 2023
1 parent d91f8d0 commit 1e74f79
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,29 @@ endif()

find_package(ZLIB REQUIRED)

find_package(Eigen3 QUIET)
# Using Eigen3 is a bit of a thing. We don't want to build it completely since we
# only need a couple of header files. Nothing special. But often, eigen3 is already
# installed and then we prefer that.
find_package(Eigen3 3.4 QUIET)

if(NOT Eigen3_FOUND)
if(Eigen3_FOUND AND TARGET Eigen3::Eigen)
get_target_property(EIGEN_INCLUDE_DIR Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES)
else()

# Create a private copy of eigen3 and populate it only, no need to build
FetchContent_Declare(
Eigen3
my-eigen3
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0
)

FetchContent_GetProperties(Eigen3)
if(NOT Eigen3_POPULATED)
FetchContent_Populate(Eigen3)
add_subdirectory(${Eigen3_SOURCE_DIR} ${Eigen3_BINARY_DIR} EXCLUDE_FROM_ALL)
FetchContent_GetProperties(my-eigen3)

if(NOT my-eigen3_POPULATED)
FetchContent_Populate(my-eigen3)
endif()

set(EIGEN_INCLUDE_DIR ${my-eigen3_SOURCE_DIR})
endif()

include(FindFilesystem)
Expand Down Expand Up @@ -339,11 +348,11 @@ target_include_directories(cifpp
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
PRIVATE
"${BOOST_REGEX_INCLUDE_DIR}"
"${EIGEN_INCLUDE_DIR}"
)

target_link_libraries(cifpp
PUBLIC Threads::Threads ZLIB::ZLIB ${CIFPP_REQUIRED_LIBRARIES}
PRIVATE Eigen3::Eigen)
PUBLIC Threads::Threads ZLIB::ZLIB ${CIFPP_REQUIRED_LIBRARIES})

if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_link_options(cifpp PRIVATE -undefined dynamic_lookup)
Expand Down Expand Up @@ -539,7 +548,8 @@ if(BUILD_TESTING)

add_executable(${CIFPP_TEST} ${CIFPP_TEST_SOURCE} "${CMAKE_CURRENT_SOURCE_DIR}/test/test-main.cpp")

target_link_libraries(${CIFPP_TEST} PRIVATE Threads::Threads cifpp::cifpp Catch2::Catch2 Eigen3::Eigen)
target_link_libraries(${CIFPP_TEST} PRIVATE Threads::Threads cifpp::cifpp Catch2::Catch2)
target_include_directories(${CIFPP_TEST} PRIVATE "${EIGEN_INCLUDE_DIR}")

if(MSVC)
# Specify unwind semantics so that MSVC knowns how to handle exceptions
Expand Down

0 comments on commit 1e74f79

Please sign in to comment.