Skip to content

Commit

Permalink
#16: bindings: Continue cmake build backend for setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrepebay committed Nov 7, 2023
1 parent 9060ddb commit fdd191b
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import os
import re
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import subprocess
import os
import sys
from setuptools import setup, Extension, find_packages
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 run(self):
try:
out = subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError("CMake must be installed to build the following extensions: " +
", ".join(e.name for e in self.extensions))
raise RuntimeError('CMake must be installed to build the following extensions: ' +
', '.join(e.name for e in self.extensions))

for ext in self.extensions:
self.build_extension(ext)
Expand All @@ -31,11 +28,13 @@ def build_extension(self, ext):
cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]

if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)

subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp)
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
# Assuming the CMakeLists.txt is in the root of the project directory
os.chdir(ext.sourcedir)
self.spawn(['cmake', ext.sourcedir] + cmake_args)
if not self.dry_run:
self.spawn(['cmake', '--build', '.', '--target', ext.name] + build_args)
# Returning to the previous directory
os.chdir(self.distribution.get_fullname())


setup(
Expand All @@ -46,10 +45,7 @@ def build_extension(self, ext):
url='https://github.com/DARMA-tasking/vt-tv',
description='Virtual Transport Task Visualizer',
long_description='',
ext_modules=ext_modules,
setup_requires=['nanobind>=1.3.2', 'cmake>=3.17.0'],
packages=find_packages(),
ext_modules=[CMakeExtension('vttv', 'bindings/python')],
ext_modules=[CMakeExtension('vttv', sourcedir='.')],
cmdclass=dict(build_ext=CMakeBuild),
zip_safe=False,
)

0 comments on commit fdd191b

Please sign in to comment.