cudaslicer/setup.py
2026-09-26 14:25:36 +03:00

62 lines
2.2 KiB
Python

import os
import sys
import platform
import subprocess
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DPython3_EXECUTABLE={sys.executable}",
]
cfg = "Debug" if self.debug else "Release"
build_args = ["--config", cfg]
if platform.system() == "Windows":
cmake_args += [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}",
"-A", "x64"
]
else:
cmake_args += [f"-DCMAKE_BUILD_TYPE={cfg}"]
build_args += ["--", f"-j{os.cpu_count() or 4}"]
build_temp = os.path.join(self.build_temp, ext.name)
os.makedirs(build_temp, exist_ok=True)
subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=build_temp)
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=build_temp)
setup(
name="cudaslicer",
version="1.1.0",
author="CUDA Slicer Team",
description="GPU-Accelerated 2D/3D Slicing & Polygon Offsetting Library",
long_description=open("README.md").read() if os.path.exists("README.md") else "",
long_description_content_type="text/markdown",
package_dir={"": "python"},
packages=find_packages(where="python"),
ext_modules=[CMakeExtension("cudaslicer._cudaslicer_backend")],
cmdclass={"build_ext": CMakeBuild},
python_requires=">=3.8",
install_requires=[
"numpy>=1.20.0",
],
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: C++",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Topic :: Scientific/Engineering",
],
)