-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
64 lines (53 loc) · 1.99 KB
/
setup.py
File metadata and controls
64 lines (53 loc) · 1.99 KB
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
import os
import subprocess
from pathlib import Path
from setuptools import setup, Extension, find_packages
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
super().__init__(name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
user_options = build_ext.user_options + [
('cmake-args=', None, 'Additional arguments for CMake')
]
def initialize_options(self):
super().initialize_options()
self.cmake_args = None
def finalize_options(self):
super().finalize_options()
self.cmake_args = self.cmake_args.split() if self.cmake_args else []
def build_extension(self, ext: CMakeExtension) -> None:
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
extdir = ext_fullpath.parent.resolve()
cfg = "Release" if not self.debug else "Debug"
build_temp = Path.cwd() / "build"
build_temp.mkdir(parents=True, exist_ok=True)
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
f"-DCMAKE_BUILD_TYPE={cfg}"
] + self.cmake_args
build_args = ["--config", cfg]
if not extdir.exists():
extdir.mkdir(parents=True)
subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=build_temp)
subprocess.check_call(["cmake", "--build", ".", "--target", ext.name] + build_args, cwd=build_temp)
setup(
name="ismpc",
version="0.1",
author="Flavio Maiorana",
author_email="97flavio.maiorana@gmail.com",
description="Cose",
long_description="Altre cose",
ext_modules=[CMakeExtension("ismpc", sourcedir=".")],
cmdclass={"build_ext": CMakeBuild},
zip_safe=False,
extras_require={"test": ["pytest>=6.0"]},
python_requires=">=3.8",
packages=find_packages(),
package_dir={"": "."},
package_data={
"ismpc": ["*.pyi"],
},
include_package_data=True,
)