From c964d558175ea49c51efb9d7e71e413032955f4a Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Tue, 20 Aug 2013 20:35:24 +0200 Subject: [PATCH 1/7] Add Eigen3 CMake find module Imported from cmake/FindEigen3.cmake in Eigen 3.1. It is licensed under the 2-clause BSD, which should be compatible with GPL as long as the build system is distributed as source. --- cmake/Modules/FindEigen3.cmake | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 cmake/Modules/FindEigen3.cmake diff --git a/cmake/Modules/FindEigen3.cmake b/cmake/Modules/FindEigen3.cmake new file mode 100644 index 00000000..9c546a05 --- /dev/null +++ b/cmake/Modules/FindEigen3.cmake @@ -0,0 +1,81 @@ +# - Try to find Eigen3 lib +# +# This module supports requiring a minimum version, e.g. you can do +# find_package(Eigen3 3.1.2) +# to require version 3.1.2 or newer of Eigen3. +# +# Once done this will define +# +# EIGEN3_FOUND - system has eigen lib with correct version +# EIGEN3_INCLUDE_DIR - the eigen include directory +# EIGEN3_VERSION - eigen version + +# Copyright (c) 2006, 2007 Montel Laurent, +# Copyright (c) 2008, 2009 Gael Guennebaud, +# Copyright (c) 2009 Benoit Jacob +# Redistribution and use is allowed according to the terms of the 2-clause BSD license. + +if(NOT Eigen3_FIND_VERSION) + if(NOT Eigen3_FIND_VERSION_MAJOR) + set(Eigen3_FIND_VERSION_MAJOR 2) + endif(NOT Eigen3_FIND_VERSION_MAJOR) + if(NOT Eigen3_FIND_VERSION_MINOR) + set(Eigen3_FIND_VERSION_MINOR 91) + endif(NOT Eigen3_FIND_VERSION_MINOR) + if(NOT Eigen3_FIND_VERSION_PATCH) + set(Eigen3_FIND_VERSION_PATCH 0) + endif(NOT Eigen3_FIND_VERSION_PATCH) + + set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}") +endif(NOT Eigen3_FIND_VERSION) + +macro(_eigen3_check_version) + file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) + + string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") + set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") + set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") + set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") + + set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) + if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + set(EIGEN3_VERSION_OK FALSE) + else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + set(EIGEN3_VERSION_OK TRUE) + endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + + if(NOT EIGEN3_VERSION_OK) + + message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " + "but at least version ${Eigen3_FIND_VERSION} is required") + endif(NOT EIGEN3_VERSION_OK) +endmacro(_eigen3_check_version) + +if (EIGEN3_INCLUDE_DIR) + + # in cache already + _eigen3_check_version() + set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) + +else (EIGEN3_INCLUDE_DIR) + + find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library + PATHS + ${CMAKE_INSTALL_PREFIX}/include + ${KDE4_INCLUDE_DIR} + PATH_SUFFIXES eigen3 eigen + ) + + if(EIGEN3_INCLUDE_DIR) + _eigen3_check_version() + endif(EIGEN3_INCLUDE_DIR) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) + + mark_as_advanced(EIGEN3_INCLUDE_DIR) + +endif(EIGEN3_INCLUDE_DIR) + From b848d37d2f50cf5899d13095826556594ccc7f50 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Tue, 25 Jun 2013 14:30:24 +0200 Subject: [PATCH 2/7] Allow user to specify path to Eigen3 library By setting EIGEN3_ROOT, we can point directly to the path of the library checkout we want to use. No other searching will then take place. Notice that if you have found an Eigen3 installation in a previous configure, it will not find a new version even if you introduce the EIGEN3_ROOT variable! --- cmake/Modules/FindEigen3.cmake | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/FindEigen3.cmake b/cmake/Modules/FindEigen3.cmake index 9c546a05..a5386848 100644 --- a/cmake/Modules/FindEigen3.cmake +++ b/cmake/Modules/FindEigen3.cmake @@ -61,12 +61,23 @@ if (EIGEN3_INCLUDE_DIR) else (EIGEN3_INCLUDE_DIR) - find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library + # if the _ROOT is specified, then look *only* there; don't allow any + # other version to be swapped in to substitute; if not specified, then + # go search usual locations + if (EIGEN3_ROOT) + find_path (EIGEN3_INCLUDE_DIR + NAMES signature_of_eigen3_matrix_library + PATHS ${EIGEN3_ROOT} + NO_DEFAULT_PATH + ) + else (EIGEN3_ROOT) + find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library PATHS ${CMAKE_INSTALL_PREFIX}/include ${KDE4_INCLUDE_DIR} PATH_SUFFIXES eigen3 eigen ) + endif (EIGEN3_ROOT) if(EIGEN3_INCLUDE_DIR) _eigen3_check_version() From b8ba56de280630f6026af0579fab78b87a995d3d Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Tue, 25 Jun 2013 14:35:23 +0200 Subject: [PATCH 3/7] Allow mixed case name in variable (as for package) Since the package is named Eigen3 (in mixed case), we should allow for the variable to be named this way, too. --- cmake/Modules/FindEigen3.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/Modules/FindEigen3.cmake b/cmake/Modules/FindEigen3.cmake index a5386848..43964344 100644 --- a/cmake/Modules/FindEigen3.cmake +++ b/cmake/Modules/FindEigen3.cmake @@ -61,6 +61,11 @@ if (EIGEN3_INCLUDE_DIR) else (EIGEN3_INCLUDE_DIR) + # allow Eigen3_ROOT to be used in addition to EIGEN3_ROOT + if (Eigen3_ROOT) + set (EIGEN3_ROOT "${Eigen3_ROOT}") + endif (Eigen3_ROOT) + # if the _ROOT is specified, then look *only* there; don't allow any # other version to be swapped in to substitute; if not specified, then # go search usual locations From fb1eed622671ca956d23dd321b0277772d15e559 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Tue, 25 Jun 2013 14:45:35 +0200 Subject: [PATCH 4/7] Use standard code to handle not found case Instead of setting EIGEN3_FOUND ourselves, rely on the standard method to check arguments and raise an error if not found. --- cmake/Modules/FindEigen3.cmake | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cmake/Modules/FindEigen3.cmake b/cmake/Modules/FindEigen3.cmake index 43964344..5169e615 100644 --- a/cmake/Modules/FindEigen3.cmake +++ b/cmake/Modules/FindEigen3.cmake @@ -53,13 +53,8 @@ macro(_eigen3_check_version) endif(NOT EIGEN3_VERSION_OK) endmacro(_eigen3_check_version) -if (EIGEN3_INCLUDE_DIR) - - # in cache already - _eigen3_check_version() - set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) - -else (EIGEN3_INCLUDE_DIR) +# only probe if we haven't a path in our cache +if (NOT EIGEN3_INCLUDE_DIR) # allow Eigen3_ROOT to be used in addition to EIGEN3_ROOT if (Eigen3_ROOT) @@ -83,6 +78,7 @@ else (EIGEN3_INCLUDE_DIR) PATH_SUFFIXES eigen3 eigen ) endif (EIGEN3_ROOT) +endif (NOT EIGEN3_INCLUDE_DIR) if(EIGEN3_INCLUDE_DIR) _eigen3_check_version() @@ -93,5 +89,4 @@ else (EIGEN3_INCLUDE_DIR) mark_as_advanced(EIGEN3_INCLUDE_DIR) -endif(EIGEN3_INCLUDE_DIR) From db7cb6a5afda120a0ea1cee56c0b04f050bdc74d Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Tue, 25 Jun 2013 14:54:22 +0200 Subject: [PATCH 5/7] Search common suffixes for include files This allows us to set e.g. -DEIGEN3_ROOT=/usr/local, and have the files actually be located in /usr/local/include/eigen3 --- cmake/Modules/FindEigen3.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/Modules/FindEigen3.cmake b/cmake/Modules/FindEigen3.cmake index 5169e615..014b5907 100644 --- a/cmake/Modules/FindEigen3.cmake +++ b/cmake/Modules/FindEigen3.cmake @@ -68,6 +68,7 @@ if (NOT EIGEN3_INCLUDE_DIR) find_path (EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library PATHS ${EIGEN3_ROOT} + PATH_SUFFIXES eigen3 include/eigen3 eigen include/eigen NO_DEFAULT_PATH ) else (EIGEN3_ROOT) From ee05e73c618f2bd559574128d334d5797b5dd77c Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Sat, 17 Aug 2013 00:04:05 +0200 Subject: [PATCH 6/7] Require the newer 3.1 version of Eigen --- cmake/Modules/opm-autodiff-prereqs.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/opm-autodiff-prereqs.cmake b/cmake/Modules/opm-autodiff-prereqs.cmake index d2b44bf5..6399259c 100644 --- a/cmake/Modules/opm-autodiff-prereqs.cmake +++ b/cmake/Modules/opm-autodiff-prereqs.cmake @@ -19,5 +19,5 @@ set (opm-autodiff_DEPS dune-istl REQUIRED; opm-core REQUIRED" # Eigen - "Eigen3 REQUIRED" + "Eigen3 3.1 REQUIRED" ) From 953080a31ee2b5c374d174805e0559de6041440e Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Tue, 20 Aug 2013 20:46:13 +0200 Subject: [PATCH 7/7] Add support for Eigen3 in Autotools compatibility layer --- cmake/Scripts/configure | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/Scripts/configure b/cmake/Scripts/configure index 468aa17d..b59832e6 100755 --- a/cmake/Scripts/configure +++ b/cmake/Scripts/configure @@ -192,6 +192,7 @@ for OPT in "$@"; do ;; alugrid |\ boost |\ + eigen3 |\ ert |\ metis |\ superlu |\