| 19 | |
| 20 | |
| 21 | class CMakeBuild(build_ext): |
| 22 | def run(self): |
| 23 | try: |
| 24 | out = subprocess.check_output(['cmake', '--version']) |
| 25 | except OSError: |
| 26 | raise RuntimeError("CMake must be installed to build the following extensions: " + |
| 27 | ", ".join(e.name for e in self.extensions)) |
| 28 | |
| 29 | if platform.system() == "Windows": |
| 30 | cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.decode()).group(1)) |
| 31 | if cmake_version < '3.1.0': |
| 32 | raise RuntimeError("CMake >= 3.1.0 is required on Windows") |
| 33 | |
| 34 | for ext in self.extensions: |
| 35 | self.build_extension(ext) |
| 36 | |
| 37 | def build_extension(self, ext): |
| 38 | extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) |
| 39 | # required for auto-detection of auxiliary "native" libs |
| 40 | if not extdir.endswith(os.path.sep): |
| 41 | extdir += os.path.sep |
| 42 | |
| 43 | cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, |
| 44 | '-DPYTHON_EXECUTABLE=' + sys.executable] |
| 45 | |
| 46 | cfg = 'Debug' if self.debug else 'Release' |
| 47 | build_args = ['--config', cfg] |
| 48 | |
| 49 | if platform.system() == "Windows": |
| 50 | cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)] |
| 51 | if sys.maxsize > 2 ** 32: |
| 52 | cmake_args += ['-A', 'x64'] |
| 53 | build_args += ['--', '/m'] |
| 54 | else: |
| 55 | cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] |
| 56 | build_args += ['--', '-j8'] |
| 57 | |
| 58 | env = os.environ.copy() |
| 59 | env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''), self.distribution.get_version()) |
| 60 | if not os.path.exists(self.build_temp): |
| 61 | os.makedirs(self.build_temp) |
| 62 | subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) |
| 63 | subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp) |
| 64 | |
| 65 | |
| 66 | setup( |
nothing calls this directly
no outgoing calls
no test coverage detected