FindEigen3.cmake 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. # Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
  13. # Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
  14. # Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
  15. # Redistribution and use is allowed according to the terms of the 2-clause BSD license.
  16. if(NOT Eigen3_FIND_VERSION)
  17. if(NOT Eigen3_FIND_VERSION_MAJOR)
  18. set(Eigen3_FIND_VERSION_MAJOR 2)
  19. endif(NOT Eigen3_FIND_VERSION_MAJOR)
  20. if(NOT Eigen3_FIND_VERSION_MINOR)
  21. set(Eigen3_FIND_VERSION_MINOR 91)
  22. endif(NOT Eigen3_FIND_VERSION_MINOR)
  23. if(NOT Eigen3_FIND_VERSION_PATCH)
  24. set(Eigen3_FIND_VERSION_PATCH 0)
  25. endif(NOT Eigen3_FIND_VERSION_PATCH)
  26. set(Eigen3_FIND_VERSION
  27. "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
  28. endif(NOT Eigen3_FIND_VERSION)
  29. macro(_eigen3_check_version)
  30. file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
  31. string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match
  32. "${_eigen3_version_header}")
  33. set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
  34. string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match
  35. "${_eigen3_version_header}")
  36. set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
  37. string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match
  38. "${_eigen3_version_header}")
  39. set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
  40. set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
  41. if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
  42. set(EIGEN3_VERSION_OK FALSE)
  43. else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
  44. set(EIGEN3_VERSION_OK TRUE)
  45. endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
  46. if(NOT EIGEN3_VERSION_OK)
  47. message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
  48. "but at least version ${Eigen3_FIND_VERSION} is required")
  49. endif(NOT EIGEN3_VERSION_OK)
  50. endmacro(_eigen3_check_version)
  51. if(EIGEN3_INCLUDE_DIR)
  52. # in cache already
  53. _eigen3_check_version()
  54. set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
  55. else(EIGEN3_INCLUDE_DIR)
  56. if(NOT DEFINED KDE4_INCLUDE_DIR)
  57. set(KDE4_INCLUDE_DIR "")
  58. endif()
  59. find_path(
  60. EIGEN3_INCLUDE_DIR
  61. NAMES signature_of_eigen3_matrix_library
  62. PATHS ${CMAKE_INSTALL_PREFIX}/include ${KDE4_INCLUDE_DIR}
  63. PATH_SUFFIXES eigen3 eigen)
  64. if(EIGEN3_INCLUDE_DIR)
  65. _eigen3_check_version()
  66. endif(EIGEN3_INCLUDE_DIR)
  67. include(FindPackageHandleStandardArgs)
  68. find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
  69. mark_as_advanced(EIGEN3_INCLUDE_DIR)
  70. endif(EIGEN3_INCLUDE_DIR)