FindEigen.cmake 2.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#-----------------------------------------------------------------------------
# Set min version to find if not set
#-----------------------------------------------------------------------------
if(NOT Eigen_FIND_VERSION)
  if(NOT Eigen_FIND_VERSION_MAJOR)
    set(Eigen_FIND_VERSION_MAJOR 3)
  endif()
  if(NOT Eigen_FIND_VERSION_MINOR)
    set(Eigen_FIND_VERSION_MINOR 0)
  endif()
  if(NOT Eigen_FIND_VERSION_PATCH)
    set(Eigen_FIND_VERSION_PATCH 0)
  endif()

  set(Eigen_FIND_VERSION "${Eigen_FIND_VERSION_MAJOR}.${Eigen_FIND_VERSION_MINOR}.${Eigen_FIND_VERSION_PATCH}")
endif()

#-----------------------------------------------------------------------------
# Find path
#-----------------------------------------------------------------------------
21 22 23 24 25
find_path(Eigen_INCLUDE_DIR
  NAMES
    eigen/Eigen
    Eigen
    )
26
mark_as_advanced(Eigen_INCLUDE_DIR)
27
#message(STATUS "Eigen_INCLUDE_DIR : ${Eigen_INCLUDE_DIR}")
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

#-----------------------------------------------------------------------------
# Macro checking version
#-----------------------------------------------------------------------------
file(READ "${Eigen_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header)

string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}")
set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}")
set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}")
set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}")

set(Eigen_VERSION ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})
if(${Eigen_VERSION} VERSION_LESS ${Eigen_FIND_VERSION})
  set(Eigen_VERSION_OK FALSE)
else(${Eigen_VERSION} VERSION_LESS ${Eigen_FIND_VERSION})
  set(Eigen_VERSION_OK TRUE)
endif(${Eigen_VERSION} VERSION_LESS ${Eigen_FIND_VERSION})

if(NOT Eigen_VERSION_OK)
  message(STATUS "Eigen version ${Eigen_VERSION} found in ${Eigen_INCLUDE_DIR},"
    "but at least version ${Eigen_FIND_VERSION} is required")
endif(NOT Eigen_VERSION_OK)

#-----------------------------------------------------------------------------
# Find package
#-----------------------------------------------------------------------------
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Eigen
  REQUIRED_VARS
    Eigen_INCLUDE_DIR
    Eigen_VERSION_OK)

#-----------------------------------------------------------------------------
# If missing target, create it
#-----------------------------------------------------------------------------
65
if(Eigen_FOUND AND NOT TARGET Eigen)
66 67 68 69 70 71
  add_library(Eigen INTERFACE IMPORTED)
  set_target_properties(Eigen PROPERTIES
    INTERFACE_LINK_LIBRARIES "${Eigen_LIBRARY}"
    INTERFACE_INCLUDE_DIRECTORIES "${Eigen_INCLUDE_DIR}"
  )
endif()