2020-10-07 00:10:06 +08:00
###############################################################################
# Option for using system Eigen or GTSAM-bundled Eigen
2022-10-26 05:37:29 +08:00
option ( GTSAM_USE_SYSTEM_EIGEN "Find and use system-installed Eigen. If 'off', use the one bundled with GTSAM" OFF )
2020-10-07 04:58:42 +08:00
if ( NOT GTSAM_USE_SYSTEM_EIGEN )
# This option only makes sense if using the embedded copy of Eigen, it is
# used to decide whether to *install* the "unsupported" module:
option ( GTSAM_WITH_EIGEN_UNSUPPORTED "Install Eigen's unsupported modules" OFF )
endif ( )
2020-10-07 00:10:06 +08:00
# Switch for using system Eigen or GTSAM-bundled Eigen
if ( GTSAM_USE_SYSTEM_EIGEN )
2022-10-08 00:52:10 +08:00
# Since Eigen 3.3.0 a Eigen3Config.cmake is available so use it.
find_package ( Eigen3 CONFIG REQUIRED ) # need to find again as REQUIRED
2022-10-06 02:15:39 +08:00
2020-10-07 00:10:06 +08:00
# check if MKL is also enabled - can have one or the other, but not both!
# Note: Eigen >= v3.2.5 includes our patches
if ( EIGEN_USE_MKL_ALL AND ( EIGEN3_VERSION VERSION_LESS 3.2.5 ) )
message ( FATAL_ERROR "MKL requires at least Eigen 3.2.5, and your system appears to have an older version. Disable GTSAM_USE_SYSTEM_EIGEN to use GTSAM's copy of Eigen, or disable GTSAM_WITH_EIGEN_MKL" )
endif ( )
# Check for Eigen version which doesn't work with MKL
# See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1527 for details.
if ( EIGEN_USE_MKL_ALL AND ( EIGEN3_VERSION VERSION_EQUAL 3.3.4 ) )
message ( FATAL_ERROR "MKL does not work with Eigen 3.3.4 because of a bug in Eigen. See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1527. Disable GTSAM_USE_SYSTEM_EIGEN to use GTSAM's copy of Eigen, disable GTSAM_WITH_EIGEN_MKL, or upgrade/patch your installation of Eigen." )
endif ( )
2025-01-07 20:52:59 +08:00
set ( GTSAM_EIGEN_VERSION "${EIGEN3_VERSION}" )
2020-10-07 00:10:06 +08:00
else ( )
# Use bundled Eigen include path.
# Clear any variables set by FindEigen3
if ( EIGEN3_INCLUDE_DIR )
set ( EIGEN3_INCLUDE_DIR NOTFOUND CACHE STRING "" FORCE )
endif ( )
# set full path to be used by external projects
# this will be added to GTSAM_INCLUDE_DIR by gtsam_extra.cmake.in
set ( GTSAM_EIGEN_INCLUDE_FOR_INSTALL "include/gtsam/3rdparty/Eigen/" )
# The actual include directory (for BUILD cmake target interface):
2022-10-26 05:37:29 +08:00
set ( GTSAM_EIGEN_INCLUDE_FOR_BUILD "${GTSAM_SOURCE_DIR}/gtsam/3rdparty/Eigen" )
2022-10-06 02:15:39 +08:00
add_library ( gtsam_eigen3 INTERFACE )
2025-01-07 20:52:59 +08:00
target_include_directories ( gtsam_eigen3 SYSTEM INTERFACE
2022-10-06 02:15:39 +08:00
$ < B U I L D _ I N T E R F A C E : $ { G T S A M _ E I G E N _ I N C L U D E _ F O R _ B U I L D } >
$ < I N S T A L L _ I N T E R F A C E : $ { G T S A M _ E I G E N _ I N C L U D E _ F O R _ I N S T A L L } >
)
add_library ( Eigen3::Eigen ALIAS gtsam_eigen3 )
install ( TARGETS gtsam_eigen3 EXPORT GTSAM-exports PUBLIC_HEADER DESTINATION ${ CMAKE_INSTALL_INCLUDEDIR } )
list ( APPEND GTSAM_EXPORTED_TARGETS gtsam_eigen3 )
2022-10-26 05:37:29 +08:00
set ( GTSAM_EXPORTED_TARGETS "${GTSAM_EXPORTED_TARGETS}" )
2025-01-07 20:52:59 +08:00
# Detect Eigen version:
set ( EIGEN_VER_H "${GTSAM_EIGEN_INCLUDE_FOR_BUILD}/Eigen/src/Core/util/Macros.h" )
2020-10-07 00:10:06 +08:00
file ( READ "${EIGEN_VER_H}" STR_EIGEN_VERSION )
# Extract the Eigen version from the Macros.h file, lines "#define EIGEN_WORLD_VERSION XX", etc...
string ( REGEX MATCH "EIGEN_WORLD_VERSION[ ]+[0-9]+" GTSAM_EIGEN_VERSION_WORLD "${STR_EIGEN_VERSION}" )
string ( REGEX MATCH "[0-9]+" GTSAM_EIGEN_VERSION_WORLD "${GTSAM_EIGEN_VERSION_WORLD}" )
string ( REGEX MATCH "EIGEN_MAJOR_VERSION[ ]+[0-9]+" GTSAM_EIGEN_VERSION_MAJOR "${STR_EIGEN_VERSION}" )
string ( REGEX MATCH "[0-9]+" GTSAM_EIGEN_VERSION_MAJOR "${GTSAM_EIGEN_VERSION_MAJOR}" )
string ( REGEX MATCH "EIGEN_MINOR_VERSION[ ]+[0-9]+" GTSAM_EIGEN_VERSION_MINOR "${STR_EIGEN_VERSION}" )
string ( REGEX MATCH "[0-9]+" GTSAM_EIGEN_VERSION_MINOR "${GTSAM_EIGEN_VERSION_MINOR}" )
set ( GTSAM_EIGEN_VERSION "${GTSAM_EIGEN_VERSION_WORLD}.${GTSAM_EIGEN_VERSION_MAJOR}.${GTSAM_EIGEN_VERSION_MINOR}" )
2025-01-07 20:52:59 +08:00
endif ( )
2020-10-07 00:10:06 +08:00
2025-01-07 20:52:59 +08:00
message ( STATUS "Found Eigen version: ${GTSAM_EIGEN_VERSION}" )
2020-10-07 00:10:06 +08:00
if ( MSVC )
2023-02-13 05:39:39 +08:00
if ( GTSAM_SHARED_LIB )
2020-10-07 00:10:06 +08:00
# mute eigen static assert to avoid errors in shared lib
list_append_cache ( GTSAM_COMPILE_DEFINITIONS_PUBLIC EIGEN_NO_STATIC_ASSERT )
endif ( )
list_append_cache ( GTSAM_COMPILE_OPTIONS_PRIVATE "/wd4244" ) # Disable loss of precision which is thrown all over our Eigen
endif ( )