Skip to content
Snippets Groups Projects
Commit e8343fea authored by acrovato's avatar acrovato
Browse files

Add Eigen version check to Cmake

parent 7ad50d31
No related branches found
No related tags found
1 merge request!52Feature eigen
Pipeline #1105 passed
......@@ -12,11 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# FindEIGEN.cmake - try to find Eigen headers
# FindEIGEN.cmake - try to find Eigen 3 headers
# The logic that checks the version comes from FindEigen3.cmake (source dir)
# ----------------------------------------------------------------------------
# output:
# EIGEN_FOUND : TRUE/FALSE
# EIGEN_INCLUDE_DIRS : where the Eigen/*.h are [cached]
# EIGEN_VERSION : version number of Eigen
# ----------------------------------------------------------------------------
# autodetection:
# utiliser "CMAKE_PREFIX_PATH=c:\local"
......@@ -24,12 +26,53 @@
# ou "INCLUDE=c:\local\include"
# ----------------------------------------------------------------------------
# Check version (only for Eigen 3)
macro(_eigen3_check_version)
file(READ "${EIGEN_INCLUDE_DIRS}/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(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}")
set(EIGEN_VERSION ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})
if(${EIGEN_VERSION} VERSION_LESS ${EIGEN_FIND_VERSION})
message(FATAL_ERROR "Eigen version ${EIGEN_VERSION} found in ${EIGEN_INCLUDE_DIRS}, but at least version ${EIGEN_FIND_VERSION} is required!")
endif()
endmacro()
# Set a dummy version if not provided
if(NOT EIGEN_FIND_VERSION)
if(NOT EIGEN_FIND_VERSION_MAJOR)
set(EIGEN_FIND_VERSION_MAJOR 3)
endif()
if(NOT EIGEN_FIND_VERSION_MINOR)
set(EIGEN_FIND_VERSION_MINOR 3)
endif()
if(NOT EIGEN_FIND_VERSION_PATCH)
set(EIGEN_FIND_VERSION_PATCH 4)
endif()
set(EIGEN_FIND_VERSION "${EIGEN_FIND_VERSION_MAJOR}.${EIGEN_FIND_VERSION_MINOR}.${EIGEN_FIND_VERSION_PATCH}")
endif()
# Find the header and check the version
find_path(EIGEN_INCLUDE_DIRS "Eigen/Dense" PATHS "/usr/include/eigen3")
if (EIGEN_INCLUDE_DIRS)
_eigen3_check_version()
else()
message(FATAL_ERROR "Eigen3 headers not found! Define the path in the INCLUDE environment variable.")
endif()
# handle the QUIETLY and REQUIRED arguments and set EIGEN_FOUND to TRUE
# if all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(EIGEN DEFAULT_MSG
EIGEN_INCLUDE_DIRS)
find_package_handle_standard_args(EIGEN
FOUND_VAR EIGEN_FOUND
REQUIRED_VARS EIGEN_INCLUDE_DIRS
VERSION_VAR EIGEN_VERSION)
#MESSAGE(STATUS "EIGEN_FOUND = ${EIGEN_FOUND}")
......@@ -17,4 +17,3 @@
SET(CMAKE_GENERATOR "MSYS Makefiles" CACHE INTERNAL "" FORCE)
SET(WAVES_USE_MKL OFF CACHE BOOL "" FORCE)
SET(WAVES_USE_MUMPS OFF CACHE BOOL "" FORCE)
INCLUDE(disable-trilinos)
......@@ -69,7 +69,7 @@ ELSE()
ENDIF()
# -- Eigen --
FIND_PACKAGE(EIGEN REQUIRED)
FIND_PACKAGE(EIGEN 3.3.4 REQUIRED)
TARGET_INCLUDE_DIRECTORIES(tbox PUBLIC ${EIGEN_INCLUDE_DIRS} ${LAPACK_INCLUDE_DIRS})
TARGET_COMPILE_DEFINITIONS(tbox PUBLIC EIGEN_DONT_PARALLELIZE)
IF(FOUND_MKL)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment