summaryrefslogtreecommitdiff
path: root/setup.py
blob: f243f62191b6d78c839cee18709725c4b331fa9d (plain)
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
import os
import pathlib

from setuptools import setup
from setuptools import Extension
from setuptools.command.build_ext import build_ext


class CMakeExtension(Extension):
	def __init__(self, name):
		super().__init__(name, sources=[])


class CMakeBuild(build_ext):
	def run(self):
		for ext in self.extensions:
			self.build_cmake(ext)
		super().run()

	def build_cmake(self, ext):
		cwd = pathlib.Path().absolute()
		build_temp = pathlib.Path(self.build_temp)
		extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
		for dir in (build_temp, extdir):
			dir.mkdir(parents=True, exist_ok=True)
		cmake_args = [
			f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir.parent.absolute()}",
		]
		os.chdir(str(build_temp))
		self.spawn(["cmake", str(cwd)] + cmake_args)
		if not self.dry_run:
			self.spawn(["cmake", "--build", "."])
		os.chdir(str(cwd))


setup(
	name="hwd",
	ext_modules=[
		CMakeExtension("hwd.gpio"),
		CMakeExtension("hwd.memory"),
	],
	cmdclass={"build_ext": CMakeBuild},
)