19 from setuptools
import setup, Extension
20 from setuptools.command.build_ext
import build_ext
21 from distutils.version
import LooseVersion
26 Extension.__init__(self, name, sources=[])
33 out = subprocess.check_output([
'cmake',
'--version'])
35 raise RuntimeError(
"CMake must be installed to build the following extensions: " +
36 ", ".join(e.name
for e
in self.extensions))
38 if platform.system() ==
"Windows":
39 cmake_version = LooseVersion(re.search(
r'version\s*([\d.]+)', out.decode()).group(1))
40 if cmake_version <
'3.1.0':
41 raise RuntimeError(
"CMake >= 3.1.0 is required on Windows")
43 for ext
in self.extensions:
47 extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
48 cmake_args = [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
49 '-DPYTHON_EXECUTABLE=' + sys.executable,
50 '-DBUILD_ESTIMATION_PROJECTS=OFF',
51 '-DBUILD_OPENCV_PROJECTS=OFF',
52 '-DBUILD_PYTHON_BINDINGS=ON']
54 cfg =
'Debug' if self.debug
else 'Release' 55 build_args = [
'--config', cfg]
57 if platform.system() ==
"Windows":
58 cmake_args += [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)]
59 if sys.maxsize > 2**32:
60 cmake_args += [
'-A',
'x64']
61 build_args += [
'--',
'/m']
63 cmake_args += [
'-DCMAKE_BUILD_TYPE=' + cfg]
64 build_args += [
'--',
'-j2']
66 env = os.environ.copy()
67 env[
'CXXFLAGS'] =
'{} -DVERSION_INFO=\\"{}\\"'.format(env.get(
'CXXFLAGS',
''),
68 self.distribution.get_version())
69 if not os.path.exists(self.build_temp):
70 os.makedirs(self.build_temp)
71 subprocess.check_call([
'cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
72 subprocess.check_call([
'cmake',
'--build',
'.'] + build_args, cwd=self.build_temp)
77 author=
'Luiz Marques',
78 author_email=
'lccmarques@gmail.com',
79 description=
'A test project using pybind11 and CMake',
82 cmdclass=dict(build_ext=CMakeBuild),
def __init__(self, name, sourcedir='..')
def build_extension(self, ext)