FindEigen3.cmake
Go to the documentation of this file.
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 #
18 # Modified by Andreas Schuh to add Eigen3_DIR/EIGEN3_DIR to the PATHS of
19 # the find_path command (instead of HINGS). Use further PATH_SUFFIXES.
20 # Also, removed the separate branches for whether or not EIGEN3_INCLUDE_DIR
21 # is set already. The find_path command will not repeat the search in
22 # this case anyway.
23 
24 if(NOT Eigen3_FIND_VERSION)
26  set(Eigen3_FIND_VERSION_MAJOR 2)
27  endif(NOT Eigen3_FIND_VERSION_MAJOR)
29  set(Eigen3_FIND_VERSION_MINOR 91)
30  endif(NOT Eigen3_FIND_VERSION_MINOR)
32  set(Eigen3_FIND_VERSION_PATCH 0)
33  endif(NOT Eigen3_FIND_VERSION_PATCH)
34 
35  set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
36 endif(NOT Eigen3_FIND_VERSION)
37 
38 macro(_eigen3_check_version)
39  file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
40 
41  string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
42  set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
43  string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
44  set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
45  string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
46  set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
47 
48  set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
49  if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
50  set(EIGEN3_VERSION_OK FALSE)
51  else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
52  set(EIGEN3_VERSION_OK TRUE)
53  endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
54 
55  if(NOT EIGEN3_VERSION_OK)
56  message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
57  "but at least version ${Eigen3_FIND_VERSION} is required")
58  endif(NOT EIGEN3_VERSION_OK)
59 endmacro(_eigen3_check_version)
60 
61 find_path(EIGEN3_INCLUDE_DIR
62  NAMES
63  signature_of_eigen3_matrix_library
64  PATHS
65  ${Eigen3_DIR}
66  ${EIGEN3_DIR}
67  ${CMAKE_INSTALL_PREFIX}
68  ${KDE4_INCLUDE_DIR}
69  PATH_SUFFIXES
70  include
71  include/eigen3
72  include/eigen
73  eigen3
74  eigen
75 )
76 
77 if (EIGEN3_INCLUDE_DIR)
78  _eigen3_check_version()
79 endif ()
80 
81 include(FindPackageHandleStandardArgs)
82 find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
83 
84 mark_as_advanced(EIGEN3_INCLUDE_DIR)
function is(in result, in expected, in name)
Test whether a given result is equal to the expected result.
cmake Eigen3_FIND_VERSION_MINOR
cmake Eigen3_FIND_VERSION_MAJOR
cmake Eigen3_FIND_VERSION_PATCH
cmake Eigen3_FIND_VERSION