Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 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 |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame^] | 12 | # |
| 13 | # This module reads hints about search locations from |
| 14 | # the following enviroment variables: |
| 15 | # |
| 16 | # EIGEN3_ROOT |
| 17 | # EIGEN3_ROOT_DIR |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 18 | |
| 19 | # Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org> |
| 20 | # Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr> |
| 21 | # Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> |
| 22 | # Redistribution and use is allowed according to the terms of the 2-clause BSD license. |
| 23 | |
| 24 | if(NOT Eigen3_FIND_VERSION) |
| 25 | if(NOT Eigen3_FIND_VERSION_MAJOR) |
| 26 | set(Eigen3_FIND_VERSION_MAJOR 2) |
| 27 | endif(NOT Eigen3_FIND_VERSION_MAJOR) |
| 28 | if(NOT Eigen3_FIND_VERSION_MINOR) |
| 29 | set(Eigen3_FIND_VERSION_MINOR 91) |
| 30 | endif(NOT Eigen3_FIND_VERSION_MINOR) |
| 31 | if(NOT Eigen3_FIND_VERSION_PATCH) |
| 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 | |
| 57 | message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " |
| 58 | "but at least version ${Eigen3_FIND_VERSION} is required") |
| 59 | endif(NOT EIGEN3_VERSION_OK) |
| 60 | endmacro(_eigen3_check_version) |
| 61 | |
| 62 | if (EIGEN3_INCLUDE_DIR) |
| 63 | |
| 64 | # in cache already |
| 65 | _eigen3_check_version() |
| 66 | set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) |
| 67 | |
| 68 | else (EIGEN3_INCLUDE_DIR) |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame^] | 69 | |
| 70 | # search first if an Eigen3Config.cmake is available in the system, |
| 71 | # if successful this would set EIGEN3_INCLUDE_DIR and the rest of |
| 72 | # the script will work as usual |
| 73 | find_package(Eigen3 ${Eigen3_FIND_VERSION} NO_MODULE QUIET) |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 74 | |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame^] | 75 | if(NOT EIGEN3_INCLUDE_DIR) |
| 76 | find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library |
| 77 | HINTS |
| 78 | ENV EIGEN3_ROOT |
| 79 | ENV EIGEN3_ROOT_DIR |
| 80 | PATHS |
| 81 | ${CMAKE_INSTALL_PREFIX}/include |
| 82 | ${KDE4_INCLUDE_DIR} |
| 83 | PATH_SUFFIXES eigen3 eigen |
| 84 | ) |
| 85 | endif(NOT EIGEN3_INCLUDE_DIR) |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 86 | |
| 87 | if(EIGEN3_INCLUDE_DIR) |
| 88 | _eigen3_check_version() |
| 89 | endif(EIGEN3_INCLUDE_DIR) |
| 90 | |
| 91 | include(FindPackageHandleStandardArgs) |
| 92 | find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) |
| 93 | |
| 94 | mark_as_advanced(EIGEN3_INCLUDE_DIR) |
| 95 | |
| 96 | endif(EIGEN3_INCLUDE_DIR) |
| 97 | |