-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsetup.py
144 lines (118 loc) · 4.11 KB
/
setup.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import os
from subprocess import check_output
import sys
# Numpy/mpi4py must be installed prior to installing
import numpy
import mpi4py
# Import distutils
from setuptools import setup, find_packages
from distutils.core import Extension as Ext
from Cython.Build import cythonize
from Cython.Compiler import Options
Options.docstrings = True
# Convert from local to absolute directories
def get_global_dir(files):
tmr_root = os.path.abspath(os.path.dirname(__file__))
new = []
for f in files:
new.append(os.path.join(tmr_root, f))
return new
def get_mpi_flags():
# Split the output from the mpicxx command
args = check_output(["mpicxx", "-show"]).decode("utf-8").split()
# Determine whether the output is an include/link/lib command
inc_dirs, lib_dirs, libs = [], [], []
for flag in args:
if flag[:2] == "-I":
inc_dirs.append(flag[2:])
elif flag[:2] == "-L":
lib_dirs.append(flag[2:])
elif flag[:2] == "-l":
libs.append(flag[2:])
return inc_dirs, lib_dirs, libs
inc_dirs, lib_dirs, libs = get_mpi_flags()
# Relative paths for the include/library directories
rel_inc_dirs = ["src", "src/interfaces", "src/topology"]
rel_lib_dirs = ["lib"]
libs.extend(["tmr"])
# Convert from relative to absolute directories
inc_dirs.extend(get_global_dir(rel_inc_dirs))
lib_dirs.extend(get_global_dir(rel_lib_dirs))
# Add the include directories from OpenCascade
for sufix in ["include/opencascade", "include/oce", "inc", "include"]:
cas_inc = os.path.join(os.environ["CASROOT"], sufix)
if os.path.isdir(cas_inc):
inc_dirs.append(cas_inc)
break
# This should be made more general so that you can specify
# alternate locations for the installation of AMD/METIS
default_ext_inc = ["extern/blossom5-v2.05.src"]
inc_dirs.extend(get_global_dir(default_ext_inc))
# Add the numpy/mpi4py/tacs/paropt include directories
inc_dirs.extend([numpy.get_include(), mpi4py.get_include()])
# Add tmr/lib as a runtime directory
runtime_lib_dirs = get_global_dir(["lib"])
# Add the TACS libraries
import tacs
if "tacs" in sys.modules:
inc_dirs.extend(tacs.get_include())
inc_dirs.extend(tacs.get_cython_include())
inc_dirs.append(os.path.split(tacs.get_cython_include()[0])[0])
tacs_lib_dirs, tacs_libs = tacs.get_libraries()
lib_dirs.extend(tacs_lib_dirs)
libs.extend(tacs_libs)
runtime_lib_dirs.extend(tacs_lib_dirs)
# Add the ParOpt libraries
import paropt
if "paropt" in sys.modules:
inc_dirs.extend(paropt.get_include())
inc_dirs.extend(paropt.get_cython_include())
inc_dirs.append(os.path.split(paropt.get_cython_include()[0])[0])
paropt_lib_dirs, paropt_libs = paropt.get_libraries()
lib_dirs.extend(paropt_lib_dirs)
libs.extend(paropt_libs)
runtime_lib_dirs.extend(paropt_lib_dirs)
# Add the egads4py libraries
import egads4py
if "egads4py" in sys.modules:
inc_dirs.extend(egads4py.get_include())
inc_dirs.extend(egads4py.get_cython_include())
inc_dirs.append(os.path.split(egads4py.get_cython_include()[0])[0])
egads4py_lib_dirs, egads4py_libs = egads4py.get_libraries()
lib_dirs.extend(egads4py_lib_dirs)
libs.extend(egads4py_libs)
runtime_lib_dirs.extend(egads4py_lib_dirs)
exts = []
mod = "TMR"
exts.append(
Ext(
"tmr.%s" % (mod),
sources=["tmr/%s.pyx" % (mod)],
include_dirs=inc_dirs,
libraries=libs,
library_dirs=lib_dirs,
runtime_library_dirs=runtime_lib_dirs,
extra_compile_args=["-std=c++11"],
extra_link_args=["-std=c++11"],
define_macros=[
("math_Memory_HeaderFile", "1"),
("TMR_HAS_OPENCASCADE", "1"),
("TMR_HAS_EGADS", "1"),
("TMR_HAS_PAROPT", "1"),
],
)
)
for e in exts:
e.cython_directives = {
"embedsignature": True,
"binding": True,
}
setup(
name="tmr",
version=1.0,
description="Parallel mesh generation utilities",
author="Graeme J. Kennedy",
author_email="graeme.kennedy@ae.gatech.edu",
packages=find_packages(include=["tmr*"]),
ext_modules=cythonize(exts, include_path=inc_dirs),
)