-
Notifications
You must be signed in to change notification settings - Fork 92
/
setup.py
68 lines (57 loc) · 2.26 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
import os
import sys
from pathlib import Path
import platform
import cmake_build_extension
import setuptools
# Extra options passed to the CI/CD pipeline that uses cibuildwheel
CIBW_CMAKE_OPTIONS = []
if "CIBUILDWHEEL" in os.environ and os.environ["CIBUILDWHEEL"] == "1":
# The manylinux variant runs in Debian Stretch and it uses lib64 folder
if sys.platform == "linux":
CIBW_CMAKE_OPTIONS += ["-DCMAKE_INSTALL_LIBDIR=lib"]
# Set Cmake options
if "CMAKE_ARGS" in os.environ:
cmake_args = [m for m in os.environ["CMAKE_ARGS"].split()]
user_flag = True
else:
user_flag = False
cmake_args = []
# Always build shared libraries
cmake_args += [f"-DPython3_ROOT_DIR={Path(sys.prefix)}",
"-DCALL_FROM_SETUP_PY:BOOL=ON",
"-DBUILD_SHARED_LIBS=ON"]
# Append fortran flags
if not user_flag or "-DCMAKE_Fortran_FLAGS" not in os.environ["CMAKE_ARGS"]:
cmake_args += ['-DCMAKE_Fortran_FLAGS=-ffree-line-length-0']
else:
for im, m in enumerate(cmake_args):
if m.find("-DCMAKE_Fortran_FLAGS") >= 0:
cmake_args[im] += ' -ffree-line-length-0'
# Set if unset
#if not user_flag or "-DCMAKE_INSTALL_PREFIX" not in os.environ["CMAKE_ARGS"]:
# cmake_args += [f'-DCMAKE_INSTALL_PREFIX={this_directory}/rosco']
# Set if unset
#if not user_flag or "-DCMAKE_PREFIX_PATH" not in os.environ["CMAKE_ARGS"]:
# python_root = os.path.dirname( os.path.dirname( sysconfig.get_path('stdlib') ) )
# cmake_args += [f'-DCMAKE_PREFIX_PATH={python_root}']
if platform.system() == 'Windows':
if "FC" not in os.environ:
os.environ["FC"] = "gfortran"
#if "gfortran" in os.environ["FC"].lower():
# cmake_args += ['-G', 'MinGW Makefiles']
#else:
# cmake_args += ['-DCMAKE_GENERATOR_PLATFORM=x64']
setuptools.setup(
ext_modules=[
cmake_build_extension.CMakeExtension(
# This could be anything you like, it is used to create build folders
name="rosco",
install_prefix="rosco",
# Selects the folder where the main CMakeLists.txt is stored
source_dir=os.path.join('rosco','controller'),
cmake_configure_options=cmake_args + CIBW_CMAKE_OPTIONS,
),
],
cmdclass={'build_ext': cmake_build_extension.BuildExtension},
)