1# - Try to find Eigen3 lib
2#
3# This module supports requiring a minimum version, e.g. you can do
4#   find_package(Eigen3 3.1.2)
5# to require version 3.1.2 or newer of Eigen3.
6#
7# Once done this will define
8#
9#  EIGEN3_FOUND - system has eigen lib with correct version
10#  EIGEN3_INCLUDE_DIR - the eigen include directory
11#  EIGEN3_VERSION - eigen version
12
13# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
14# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
15# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
16# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
17
18if(NOT Eigen3_FIND_VERSION)
19  if(NOT Eigen3_FIND_VERSION_MAJOR)
20    set(Eigen3_FIND_VERSION_MAJOR 2)
21  endif(NOT Eigen3_FIND_VERSION_MAJOR)
22  if(NOT Eigen3_FIND_VERSION_MINOR)
23    set(Eigen3_FIND_VERSION_MINOR 91)
24  endif(NOT Eigen3_FIND_VERSION_MINOR)
25  if(NOT Eigen3_FIND_VERSION_PATCH)
26    set(Eigen3_FIND_VERSION_PATCH 0)
27  endif(NOT Eigen3_FIND_VERSION_PATCH)
28
29  set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
30endif(NOT Eigen3_FIND_VERSION)
31
32macro(_eigen3_check_version)
33  file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
34
35  string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
36  set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
37  string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
38  set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
39  string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
40  set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
41
42  set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
43  if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
44    set(EIGEN3_VERSION_OK FALSE)
45  else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
46    set(EIGEN3_VERSION_OK TRUE)
47  endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
48
49  if(NOT EIGEN3_VERSION_OK)
50
51    message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
52                   "but at least version ${Eigen3_FIND_VERSION} is required")
53  endif(NOT EIGEN3_VERSION_OK)
54endmacro(_eigen3_check_version)
55
56if (EIGEN3_INCLUDE_DIR)
57
58  # in cache already
59  _eigen3_check_version()
60  set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
61
62else (EIGEN3_INCLUDE_DIR)
63
64  find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
65      PATHS
66      ${CMAKE_INSTALL_PREFIX}/include
67      ${KDE4_INCLUDE_DIR}
68      PATH_SUFFIXES eigen3 eigen
69    )
70
71  if(EIGEN3_INCLUDE_DIR)
72    _eigen3_check_version()
73  endif(EIGEN3_INCLUDE_DIR)
74
75  include(FindPackageHandleStandardArgs)
76  find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
77
78  mark_as_advanced(EIGEN3_INCLUDE_DIR)
79
80endif(EIGEN3_INCLUDE_DIR)
81
82