| 47 | self.build_extension(ext) |
| 48 | |
| 49 | def build_extension(self, ext): |
| 50 | extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) |
| 51 | bin_dir_windows = os.path.join(os.path.abspath(self.build_temp), "bin") |
| 52 | cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, |
| 53 | '-DPYTHON_EXECUTABLE=' + sys.executable] |
| 54 | |
| 55 | cfg = 'Debug' if self.debug else 'Release' |
| 56 | build_args = ['--config', cfg] |
| 57 | |
| 58 | # Add cmake command line arguments |
| 59 | if cmake_clargs is not None: |
| 60 | cmake_args += ['-D{}'.format(arg) for arg in cmake_clargs] |
| 61 | |
| 62 | if platform.system() == "Windows": |
| 63 | cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir), |
| 64 | '-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=' + bin_dir_windows, |
| 65 | '-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), bin_dir_windows)] |
| 66 | if sys.maxsize > 2**32: |
| 67 | cmake_args += ['-A', 'x64'] |
| 68 | build_args += ['--', '/m'] |
| 69 | else: |
| 70 | cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] |
| 71 | build_args += ['--', '-j{}'.format(mp.cpu_count())] |
| 72 | |
| 73 | env = os.environ.copy() |
| 74 | env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''), |
| 75 | self.distribution.get_version()) |
| 76 | |
| 77 | # Add position independent code flags if using gcc on linux probably |
| 78 | if platform.system() == "Linux": |
| 79 | cmake_args += ['-DCMAKE_CXX_FLAGS=-fPIC', '-DCMAKE_C_FLAGS=-fPIC'] |
| 80 | |
| 81 | # Using relative rpath messes up repairing the wheel file. The relative rpath is only necessary when |
| 82 | # building locally from source |
| 83 | if not args.manylinux_build: |
| 84 | cmake_args += ['-DCMAKE_INSTALL_RPATH={}'.format("$ORIGIN"), |
| 85 | '-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON', |
| 86 | '-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=OFF'] |
| 87 | |
| 88 | if not os.path.exists(self.build_temp): |
| 89 | os.makedirs(self.build_temp) |
| 90 | |
| 91 | if not args.manylinux_build: |
| 92 | subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) |
| 93 | subprocess.check_call(['cmake', '--build', '.', '--target', internal_name] + build_args, cwd=self.build_temp) |
| 94 | else: |
| 95 | subprocess.check_call(['cmake3', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) |
| 96 | subprocess.check_call(['cmake3', '--build', '.', '--target', internal_name] + build_args, cwd=self.build_temp) |
| 97 | |
| 98 | |
| 99 | # Get Readme text for long description |