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 | # |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 13 | # and the following imported target: |
| 14 | # |
| 15 | # Eigen3::Eigen - The header-only Eigen library |
| 16 | # |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame] | 17 | # This module reads hints about search locations from |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 18 | # the following environment variables: |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame] | 19 | # |
| 20 | # EIGEN3_ROOT |
| 21 | # EIGEN3_ROOT_DIR |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 22 | |
| 23 | # Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org> |
| 24 | # Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr> |
| 25 | # Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> |
| 26 | # Redistribution and use is allowed according to the terms of the 2-clause BSD license. |
| 27 | |
| 28 | if(NOT Eigen3_FIND_VERSION) |
| 29 | if(NOT Eigen3_FIND_VERSION_MAJOR) |
| 30 | set(Eigen3_FIND_VERSION_MAJOR 2) |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 31 | endif() |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 32 | if(NOT Eigen3_FIND_VERSION_MINOR) |
| 33 | set(Eigen3_FIND_VERSION_MINOR 91) |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 34 | endif() |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 35 | if(NOT Eigen3_FIND_VERSION_PATCH) |
| 36 | set(Eigen3_FIND_VERSION_PATCH 0) |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 37 | endif() |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 38 | |
| 39 | set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}") |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 40 | endif() |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 41 | |
| 42 | macro(_eigen3_check_version) |
| 43 | file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) |
| 44 | |
| 45 | string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") |
| 46 | set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") |
| 47 | string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") |
| 48 | set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") |
| 49 | string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") |
| 50 | set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") |
| 51 | |
| 52 | set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) |
| 53 | if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) |
| 54 | set(EIGEN3_VERSION_OK FALSE) |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 55 | else() |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 56 | set(EIGEN3_VERSION_OK TRUE) |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 57 | endif() |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 58 | |
| 59 | if(NOT EIGEN3_VERSION_OK) |
| 60 | |
| 61 | message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " |
| 62 | "but at least version ${Eigen3_FIND_VERSION} is required") |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 63 | endif() |
| 64 | endmacro() |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 65 | |
| 66 | if (EIGEN3_INCLUDE_DIR) |
| 67 | |
| 68 | # in cache already |
| 69 | _eigen3_check_version() |
| 70 | set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 71 | set(Eigen3_FOUND ${EIGEN3_VERSION_OK}) |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 72 | |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 73 | else () |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame] | 74 | |
| 75 | # search first if an Eigen3Config.cmake is available in the system, |
| 76 | # if successful this would set EIGEN3_INCLUDE_DIR and the rest of |
| 77 | # the script will work as usual |
| 78 | find_package(Eigen3 ${Eigen3_FIND_VERSION} NO_MODULE QUIET) |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 79 | |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame] | 80 | if(NOT EIGEN3_INCLUDE_DIR) |
| 81 | find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library |
| 82 | HINTS |
| 83 | ENV EIGEN3_ROOT |
| 84 | ENV EIGEN3_ROOT_DIR |
| 85 | PATHS |
| 86 | ${CMAKE_INSTALL_PREFIX}/include |
| 87 | ${KDE4_INCLUDE_DIR} |
| 88 | PATH_SUFFIXES eigen3 eigen |
| 89 | ) |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 90 | endif() |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 91 | |
| 92 | if(EIGEN3_INCLUDE_DIR) |
| 93 | _eigen3_check_version() |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 94 | endif() |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 95 | |
| 96 | include(FindPackageHandleStandardArgs) |
| 97 | find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) |
| 98 | |
| 99 | mark_as_advanced(EIGEN3_INCLUDE_DIR) |
| 100 | |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 101 | endif() |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 102 | |
Austin Schuh | c55b017 | 2022-02-20 17:52:35 -0800 | [diff] [blame^] | 103 | if(EIGEN3_FOUND AND NOT TARGET Eigen3::Eigen) |
| 104 | add_library(Eigen3::Eigen INTERFACE IMPORTED) |
| 105 | set_target_properties(Eigen3::Eigen PROPERTIES |
| 106 | INTERFACE_INCLUDE_DIRECTORIES "${EIGEN3_INCLUDE_DIR}") |
| 107 | endif() |