forked from claudioperez/OpenSeesRT
-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
executable file
·127 lines (103 loc) · 3.32 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
#!/usr/bin/env python
import os
import sys
from glob import glob
from pathlib import Path
import subprocess
from os.path import basename, splitext
import amoeba
import setuptools
#--------------------------------------------------
version = "0.1.5"
build_type = "local"
#--------------------------------------------------
options = {
"release": [
"-DCMAKE_BUILD_TYPE=RELEASE",
"-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=TRUE",
],
#
"local": [
"-DCMAKE_BUILD_TYPE=RELEASE",
"-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=FALSE",
# "-DProfileBuild:BOOL=TRUE",
],
"debug": [
"-DCMAKE_BUILD_TYPE=DEBUG",
"-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=FALSE",
],
"no-build": []
}
use_conan = False
if os.name == "nt":
EnvArgs = []
use_conan = True
elif "CONDA_PREFIX" in os.environ:
# Ensure that conda libraries and compilers are used
EnvArgs = [
"-DDependencies=Conda",
f"-DCMAKE_PREFIX_PATH:FILEPATH={os.environ['CONDA_PREFIX']}",
f"-DCMAKE_IGNORE_PATH:FILEPATH=/usr/lib/;/lib",
]
else:
EnvArgs = [
"-DDependencies=Unix",
]
try:
assert False
assert os.name != "nt"
import pybind11
OpenSeesPyRT_Target = ["--target", "OpenSeesPyRT"]
OpenSeesPyRT_Config = [
f"-Dpybind11_DIR:FILEPATH={pybind11.get_cmake_dir()}",
f"-DPYTHON_EXECUTABLE:FILEPATH={sys.executable}"
]
except (AssertionError,ImportError):
OpenSeesPyRT_Config = ["-DNoOpenSeesPyRT=True"]
OpenSeesPyRT_Target = []
if use_conan:
EnvArgs + ["-DCMAKE_TOOLCHAIN_FILE=conan/conan_toolchain.cmake"]
class BuildOpenSeesRT(amoeba.BuildExtension):
def build_extension(self, ext):
# Ensure Conan dependencies are installed using Conan 2.0 commands
if use_conan:
self.run_conan(ext)
super().build_extension(ext)
def run_conan(self, ext):
toolchain = str(Path(".").absolute()/"build"/"generators"/"conan_toolchain.cmake")
ext.cmake_configure_options.append(
f"-DCMAKE_TOOLCHAIN_FILE={toolchain}"
)
# Create the Conan profile and run the Conan install command
subprocess.run([
"conan", "install", ".",
"--build=missing",
])
# BuildOpenSeesRT = amoeba.BuildExtension
if __name__ == "__main__":
setuptools.setup(
data_files=[
('bin', [*map(str,Path("win32/").glob("*.*"))]),
] if os.name == "nt" else [],
cmdclass = {
"build_ext": BuildOpenSeesRT, # amoeba.BuildExtension,
"cmake": amoeba.CMakeCommand
} if build_type != "no-build" else {},
ext_modules = [
amoeba.CMakeExtension(
name = build_type,
install_prefix="opensees",
cmake_build_type=options[build_type][0].split("=")[-1],
cmake_configure_options = [
*EnvArgs,
*options[build_type],
f"-DOPENSEESRT_VERSION={version}",
*OpenSeesPyRT_Config,
],
cmake_build_options=["-j15",
"--target", "OpenSeesRT",
*OpenSeesPyRT_Target
]
)
] if build_type != "no-build" else []
)