-
Notifications
You must be signed in to change notification settings - Fork 1
/
eigen.py
71 lines (66 loc) · 1.93 KB
/
eigen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- python -*-
#
# Copyright Christoph Lassner 2014.
#
# Distributed under the Boost Software License, Version 1.0.
# (See http://www.boost.org/LICENSE_1_0.txt)
from __future__ import print_function
import sys
import os
from ._tools import _checkLibs, _setupPaths
from SCons.SConf import CheckContext
CheckContext.checkLibs = _checkLibs
_check_dict = {}
_eigen_option_dict = {'--eigen-dir':
{'dest':"eigen_prefix",
'type':"string",
'nargs':1,
'action':"store",
'metavar':"DIR",
'default':os.environ.get("EIGEN_ROOT"),
'help':"prefix for Eigen library; should have 'Eigen' and 'unsupported' subdirectories"}}
def CheckEigen(context):
eigen_source_file = r"""
#include <Eigen/Dense>
#include <iostream>
using namespace Eigen;
int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
Matrix2d n;
n << 3, -1,
2.5, 1.5;
return 1 - (m==n);
}
"""
context.Message('Check building with Eigen... ')
include_dir = context.env.GetOption("eigen_prefix")
try:
ex_include_dir = context.env.GetOption("eigen_include")
if not ex_include_dir is None:
include_dir = ex_include_dir
except:
pass
_setupPaths(context.env,
prefix = None,
include = include_dir,
lib = None
)
result = (context.checkLibs([], eigen_source_file))
if not result:
context.Result(0)
print("Cannot build with Eigen.")
return False
result, output = context.TryRun(eigen_source_file,'.cpp')
if not result:
context.Result(0)
print("Cannot run program built with Eigen.")
return False
context.Result(1)
return True
_check_dict['eigen'] = {'options': _eigen_option_dict,
'checks': [CheckEigen]}