mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-11-21 03:11:25 +08:00
* add a FindEigen2.cmake file for reference
* parse the version number from the Macro.h header file
This commit is contained in:
parent
b83d9b48fa
commit
56aad5aafb
@ -1,19 +1,29 @@
|
|||||||
project(Eigen)
|
project(Eigen)
|
||||||
set(EIGEN_VERSION_NUMBER "2.0.52-unstable")
|
|
||||||
|
|
||||||
#if the svnversion program is absent, this will leave the SVN_REVISION string empty,
|
# automatically parse the version number
|
||||||
#but won't stop CMake.
|
file(READ "${CMAKE_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen2_version_header LIMIT 5000 OFFSET 1000)
|
||||||
execute_process(COMMAND svnversion -n ${CMAKE_SOURCE_DIR}
|
string(REGEX MATCH "define *EIGEN_WORLD_VERSION ([0-9]*)" _eigen2_world_version_match "${_eigen2_version_header}")
|
||||||
OUTPUT_VARIABLE EIGEN_SVNVERSION_OUTPUT)
|
set(EIGEN2_WORLD_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
string(REGEX MATCH "define *EIGEN_MAJOR_VERSION ([0-9]*)" _eigen2_major_version_match "${_eigen2_version_header}")
|
||||||
|
set(EIGEN2_MAJOR_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
string(REGEX MATCH "define *EIGEN_MINOR_VERSION ([0-9]*)" _eigen2_minor_version_match "${_eigen2_version_header}")
|
||||||
|
set(EIGEN2_MINOR_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
# TODO find a way to automatically remove the unstable suffix
|
||||||
|
set(EIGEN_VERSION_NUMBER ${EIGEN2_WORLD_VERSION}.${EIGEN2_MAJOR_VERSION}.${EIGEN2_MINOR_VERSION}-unstable)
|
||||||
|
|
||||||
#we only want EIGEN_SVN_REVISION if it is an actual revision number, not a string like "exported"
|
# if the mercurial program is absent, this will leave the EIGEN_HG_REVISION string empty,
|
||||||
string(REGEX MATCH "^[0-9]+.*" EIGEN_SVN_REVISION "${EIGEN_SVNVERSION_OUTPUT}")
|
# but won't stop CMake.
|
||||||
|
execute_process(COMMAND hg tip -R ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE EIGEN_HGTIP_OUTPUT)
|
||||||
|
|
||||||
if(EIGEN_SVN_REVISION)
|
# extract the mercurial revision number from the hg tip output
|
||||||
set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (SVN revision ${EIGEN_SVN_REVISION})")
|
string(REGEX MATCH "^changeset: *[0-9]*:([0-9;a-f]+).*" EIGEN_HG_REVISION_MATCH "${EIGEN_HGTIP_OUTPUT}")
|
||||||
else(EIGEN_SVN_REVISION)
|
set(EIGEN_HG_REVISION "${CMAKE_MATCH_1}")
|
||||||
|
|
||||||
|
if(EIGEN_HG_REVISION)
|
||||||
|
set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (mercurial revision ${EIGEN_HG_REVISION})")
|
||||||
|
else(EIGEN_HG_REVISION)
|
||||||
set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}")
|
set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}")
|
||||||
endif(EIGEN_SVN_REVISION)
|
endif(EIGEN_HG_REVISION)
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.6.2)
|
cmake_minimum_required(VERSION 2.6.2)
|
||||||
|
|
||||||
|
73
cmake/FindEigen2.cmake
Normal file
73
cmake/FindEigen2.cmake
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
# - Try to find Eigen2 lib
|
||||||
|
# Once done this will define
|
||||||
|
#
|
||||||
|
# EIGEN2_FOUND - system has eigen lib with correct version
|
||||||
|
# EIGEN2_INCLUDE_DIR - the eigen include directory
|
||||||
|
# EIGEN2_VERSION - eigen version
|
||||||
|
|
||||||
|
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
|
||||||
|
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
|
||||||
|
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||||
|
|
||||||
|
include(MacroEnsureVersion)
|
||||||
|
|
||||||
|
if(NOT EIGEN2_MIN_VERSION)
|
||||||
|
if(NOT Eigen2_FIND_VERSION_MAJOR)
|
||||||
|
set(Eigen2_FIND_VERSION_MAJOR 2)
|
||||||
|
endif(NOT Eigen2_FIND_VERSION_MAJOR)
|
||||||
|
if(NOT Eigen2_FIND_VERSION_MINOR)
|
||||||
|
set(Eigen2_FIND_VERSION_MINOR 0)
|
||||||
|
endif(NOT Eigen2_FIND_VERSION_MINOR)
|
||||||
|
if(NOT Eigen2_FIND_VERSION_PATCH)
|
||||||
|
set(Eigen2_FIND_VERSION_PATCH 0)
|
||||||
|
endif(NOT Eigen2_FIND_VERSION_PATCH)
|
||||||
|
|
||||||
|
set(EIGEN2_MIN_VERSION "${Eigen2_FIND_VERSION_MAJOR}.${Eigen2_FIND_VERSION_MINOR}.${Eigen2_FIND_VERSION_PATCH}")
|
||||||
|
endif(NOT EIGEN2_MIN_VERSION)
|
||||||
|
|
||||||
|
macro(_eigen2_check_version)
|
||||||
|
file(READ "${EIGEN2_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen2_version_header LIMIT 5000 OFFSET 1000)
|
||||||
|
|
||||||
|
string(REGEX MATCH "define *EIGEN_WORLD_VERSION ([0-9]*)" _eigen2_world_version_match "${_eigen2_version_header}")
|
||||||
|
set(EIGEN2_WORLD_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
string(REGEX MATCH "define *EIGEN_MAJOR_VERSION ([0-9]*)" _eigen2_major_version_match "${_eigen2_version_header}")
|
||||||
|
set(EIGEN2_MAJOR_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
string(REGEX MATCH "define *EIGEN_MINOR_VERSION ([0-9]*)" _eigen2_minor_version_match "${_eigen2_version_header}")
|
||||||
|
set(EIGEN2_MINOR_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
|
||||||
|
set(EIGEN2_VERSION ${EIGEN2_WORLD_VERSION}.${EIGEN2_MAJOR_VERSION}.${EIGEN2_MINOR_VERSION})
|
||||||
|
MACRO_ENSURE_VERSION( ${EIGEN2_MIN_VERSION} ${EIGEN2_VERSION} EIGEN2_VERSION_OK)
|
||||||
|
|
||||||
|
if(NOT EIGEN2_VERSION_OK)
|
||||||
|
|
||||||
|
message(STATUS "Eigen2 version ${EIGEN2_VERSION} found in ${EIGEN2_INCLUDE_DIR}, "
|
||||||
|
"but at least version ${EIGEN2_MIN_VERSION} is required")
|
||||||
|
endif(NOT EIGEN2_VERSION_OK)
|
||||||
|
endmacro(_eigen2_check_version)
|
||||||
|
|
||||||
|
if (EIGEN2_INCLUDE_DIR)
|
||||||
|
|
||||||
|
# in cache already
|
||||||
|
_eigen2_check_version()
|
||||||
|
set(EIGEN2_FOUND ${EIGEN2_VERSION_OK})
|
||||||
|
|
||||||
|
else (EIGEN2_INCLUDE_DIR)
|
||||||
|
|
||||||
|
find_path(EIGEN2_INCLUDE_DIR NAMES Eigen/Core
|
||||||
|
PATHS
|
||||||
|
${INCLUDE_INSTALL_DIR}
|
||||||
|
${KDE4_INCLUDE_DIR}
|
||||||
|
PATH_SUFFIXES eigen2
|
||||||
|
)
|
||||||
|
|
||||||
|
if(EIGEN2_INCLUDE_DIR)
|
||||||
|
_eigen2_check_version()
|
||||||
|
endif(EIGEN2_INCLUDE_DIR)
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(Eigen2 DEFAULT_MSG EIGEN2_INCLUDE_DIR EIGEN2_VERSION_OK)
|
||||||
|
|
||||||
|
mark_as_advanced(EIGEN2_INCLUDE_DIR)
|
||||||
|
|
||||||
|
endif(EIGEN2_INCLUDE_DIR)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user