1# - Try to find Eigen2 lib 2# 3# This module supports requiring a minimum version, e.g. you can do 4# find_package(Eigen2 2.0.3) 5# to require version 2.0.3 to newer of Eigen2. 6# 7# Once done this will define 8# 9# EIGEN2_FOUND - system has eigen lib with correct version 10# EIGEN2_INCLUDE_DIR - the eigen include directory 11# EIGEN2_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# Redistribution and use is allowed according to the terms of the BSD license. 16 17if(NOT Eigen2_FIND_VERSION) 18 if(NOT Eigen2_FIND_VERSION_MAJOR) 19 set(Eigen2_FIND_VERSION_MAJOR 2) 20 endif(NOT Eigen2_FIND_VERSION_MAJOR) 21 if(NOT Eigen2_FIND_VERSION_MINOR) 22 set(Eigen2_FIND_VERSION_MINOR 0) 23 endif(NOT Eigen2_FIND_VERSION_MINOR) 24 if(NOT Eigen2_FIND_VERSION_PATCH) 25 set(Eigen2_FIND_VERSION_PATCH 0) 26 endif(NOT Eigen2_FIND_VERSION_PATCH) 27 28 set(Eigen2_FIND_VERSION "${Eigen2_FIND_VERSION_MAJOR}.${Eigen2_FIND_VERSION_MINOR}.${Eigen2_FIND_VERSION_PATCH}") 29endif(NOT Eigen2_FIND_VERSION) 30 31macro(_eigen2_check_version) 32 file(READ "${EIGEN2_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen2_version_header) 33 34 string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen2_world_version_match "${_eigen2_version_header}") 35 set(EIGEN2_WORLD_VERSION "${CMAKE_MATCH_1}") 36 string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen2_major_version_match "${_eigen2_version_header}") 37 set(EIGEN2_MAJOR_VERSION "${CMAKE_MATCH_1}") 38 string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen2_minor_version_match "${_eigen2_version_header}") 39 set(EIGEN2_MINOR_VERSION "${CMAKE_MATCH_1}") 40 41 set(EIGEN2_VERSION ${EIGEN2_WORLD_VERSION}.${EIGEN2_MAJOR_VERSION}.${EIGEN2_MINOR_VERSION}) 42 if((${EIGEN2_WORLD_VERSION} NOTEQUAL 2) OR (${EIGEN2_MAJOR_VERSION} GREATER 10) OR (${EIGEN2_VERSION} VERSION_LESS ${Eigen2_FIND_VERSION})) 43 set(EIGEN2_VERSION_OK FALSE) 44 else() 45 set(EIGEN2_VERSION_OK TRUE) 46 endif() 47 48 if(NOT EIGEN2_VERSION_OK) 49 50 message(STATUS "Eigen2 version ${EIGEN2_VERSION} found in ${EIGEN2_INCLUDE_DIR}, " 51 "but at least version ${Eigen2_FIND_VERSION} is required") 52 endif(NOT EIGEN2_VERSION_OK) 53endmacro(_eigen2_check_version) 54 55if (EIGEN2_INCLUDE_DIR) 56 57 # in cache already 58 _eigen2_check_version() 59 set(EIGEN2_FOUND ${EIGEN2_VERSION_OK}) 60 61else (EIGEN2_INCLUDE_DIR) 62 63find_path(EIGEN2_INCLUDE_DIR NAMES Eigen/Core 64 PATHS 65 ${INCLUDE_INSTALL_DIR} 66 ${KDE4_INCLUDE_DIR} 67 PATH_SUFFIXES eigen2 68 ) 69 70if(EIGEN2_INCLUDE_DIR) 71 _eigen2_check_version() 72endif(EIGEN2_INCLUDE_DIR) 73 74include(FindPackageHandleStandardArgs) 75find_package_handle_standard_args(Eigen2 DEFAULT_MSG EIGEN2_INCLUDE_DIR EIGEN2_VERSION_OK) 76 77mark_as_advanced(EIGEN2_INCLUDE_DIR) 78 79endif(EIGEN2_INCLUDE_DIR) 80 81