-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
72 lines (59 loc) · 2.08 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
69
70
71
72
# !/usr/bin/env python
import os
from os.path import abspath, dirname, exists
import subprocess
import sys
from setuptools import (
Extension,
find_packages,
setup,
)
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
def __init__(self, name, cmake_lists_dir='.', sources=None, **kwargs):
Extension.__init__(self, name, sources=sources or [], **kwargs)
self.cmake_lists_dir = abspath(cmake_lists_dir)
class CMakeBuild(build_ext):
def build_extensions(self):
try:
subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError('Cannot find CMake executable')
for ext in self.extensions:
extdir = abspath(dirname(self.get_ext_fullpath(ext.name)))
cfg = os.environ.get('QB_BUILD_TYPE', 'Release')
cmake_args = [
'-DCMAKE_BUILD_TYPE=' + cfg,
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(
cfg.upper(), extdir,
),
'-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{}={}'.format(
cfg.upper(), self.build_temp,
),
'-DPYTHON_EXECUTABLE={}'.format(sys.executable),
'-DBUILD_TESTING=OFF',
]
if not exists(self.build_temp):
os.makedirs(self.build_temp)
# Config and build the extension
subprocess.check_call(
['cmake', ext.cmake_lists_dir, '-G', 'Ninja'] + cmake_args,
cwd=self.build_temp,
)
subprocess.check_call(
['cmake', '--build', '.', '--config', cfg],
cwd=self.build_temp,
)
ext_modules = [
CMakeExtension('quelling_blade.arena_allocatable'),
]
setup(
name='quelling-blade',
version='0.0.1',
description='Library for creating objects which can be arena allocated.',
author='Joe Jevnik',
author_email='[email protected]',
packages=find_packages(),
cmdclass={'build_ext': CMakeBuild},
ext_modules=ext_modules,
)