You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.8 KiB

  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. # Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
  13. # Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
  14. # Redistribution and use is allowed according to the terms of the BSD license.
  15. if(NOT Eigen2_FIND_VERSION)
  16. if(NOT Eigen2_FIND_VERSION_MAJOR)
  17. set(Eigen2_FIND_VERSION_MAJOR 2)
  18. endif(NOT Eigen2_FIND_VERSION_MAJOR)
  19. if(NOT Eigen2_FIND_VERSION_MINOR)
  20. set(Eigen2_FIND_VERSION_MINOR 0)
  21. endif(NOT Eigen2_FIND_VERSION_MINOR)
  22. if(NOT Eigen2_FIND_VERSION_PATCH)
  23. set(Eigen2_FIND_VERSION_PATCH 0)
  24. endif(NOT Eigen2_FIND_VERSION_PATCH)
  25. set(Eigen2_FIND_VERSION "${Eigen2_FIND_VERSION_MAJOR}.${Eigen2_FIND_VERSION_MINOR}.${Eigen2_FIND_VERSION_PATCH}")
  26. endif(NOT Eigen2_FIND_VERSION)
  27. macro(_eigen2_check_version)
  28. file(READ "${EIGEN2_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen2_version_header)
  29. string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen2_world_version_match "${_eigen2_version_header}")
  30. set(EIGEN2_WORLD_VERSION "${CMAKE_MATCH_1}")
  31. string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen2_major_version_match "${_eigen2_version_header}")
  32. set(EIGEN2_MAJOR_VERSION "${CMAKE_MATCH_1}")
  33. string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen2_minor_version_match "${_eigen2_version_header}")
  34. set(EIGEN2_MINOR_VERSION "${CMAKE_MATCH_1}")
  35. set(EIGEN2_VERSION ${EIGEN2_WORLD_VERSION}.${EIGEN2_MAJOR_VERSION}.${EIGEN2_MINOR_VERSION})
  36. if((${EIGEN2_WORLD_VERSION} NOTEQUAL 2) OR (${EIGEN2_MAJOR_VERSION} GREATER 10) OR (${EIGEN2_VERSION} VERSION_LESS ${Eigen2_FIND_VERSION}))
  37. set(EIGEN2_VERSION_OK FALSE)
  38. else()
  39. set(EIGEN2_VERSION_OK TRUE)
  40. endif()
  41. if(NOT EIGEN2_VERSION_OK)
  42. message(STATUS "Eigen2 version ${EIGEN2_VERSION} found in ${EIGEN2_INCLUDE_DIR}, "
  43. "but at least version ${Eigen2_FIND_VERSION} is required")
  44. endif(NOT EIGEN2_VERSION_OK)
  45. endmacro(_eigen2_check_version)
  46. if (EIGEN2_INCLUDE_DIR)
  47. # in cache already
  48. _eigen2_check_version()
  49. set(EIGEN2_FOUND ${EIGEN2_VERSION_OK})
  50. else (EIGEN2_INCLUDE_DIR)
  51. find_path(EIGEN2_INCLUDE_DIR NAMES Eigen/Core
  52. PATHS
  53. ${INCLUDE_INSTALL_DIR}
  54. ${KDE4_INCLUDE_DIR}
  55. PATH_SUFFIXES eigen2
  56. )
  57. if(EIGEN2_INCLUDE_DIR)
  58. _eigen2_check_version()
  59. endif(EIGEN2_INCLUDE_DIR)
  60. include(FindPackageHandleStandardArgs)
  61. find_package_handle_standard_args(Eigen2 DEFAULT_MSG EIGEN2_INCLUDE_DIR EIGEN2_VERSION_OK)
  62. mark_as_advanced(EIGEN2_INCLUDE_DIR)
  63. endif(EIGEN2_INCLUDE_DIR)