| 48 | self.build_extension(ext) |
| 49 | |
| 50 | def build_extension(self, ext): |
| 51 | extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) |
| 52 | bin_dir_windows = os.path.join(os.path.abspath(self.build_temp), "bin") |
| 53 | cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, |
| 54 | # '-DPYBIND11_PYTHON_VERSION=' + f"{sys.version_info.major}.{sys.version_info.minor}" |
| 55 | '-DPYBIND11_FINDPYTHON=On', |
| 56 | '-DPython_EXECUTABLE=' + sys.executable, |
| 57 | ] |
| 58 | |
| 59 | print(f"Using cmake args {cmake_args}") |
| 60 | print(f"Python version: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}") |
| 61 | |
| 62 | cfg = 'Debug' if self.debug else 'Release' |
| 63 | build_args = ['--config', cfg] |
| 64 | |
| 65 | # Determine if this is a manylinux (cibuildwheel) build: either explicit flag or CIBUILDWHEEL env var |
| 66 | is_manylinux = args.manylinux_build or os.environ.get('CIBUILDWHEEL') == '1' |
| 67 | |
| 68 | # Add cmake command line arguments from setup.py -D flags |
| 69 | if cmake_clargs is not None: |
| 70 | cmake_args += ['-D{}'.format(arg) for arg in cmake_clargs] |
| 71 | |
| 72 | # Add extra cmake defines from environment variable (e.g. provided by CI) |
| 73 | extra_env_defines = os.environ.get('EXTRA_CMAKE_DEFINES') |
| 74 | if extra_env_defines: |
| 75 | for token in shlex.split(extra_env_defines): |
| 76 | if not token: |
| 77 | continue |
| 78 | if token.startswith('-D'): |
| 79 | cmake_args.append(token) |
| 80 | else: |
| 81 | cmake_args.append(f'-D{token}') |
| 82 | |
| 83 | if platform.system() == "Windows": |
| 84 | cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir), |
| 85 | '-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=' + bin_dir_windows, |
| 86 | '-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), bin_dir_windows)] |
| 87 | if sys.maxsize > 2**32: |
| 88 | cmake_args += ['-A', 'x64'] |
| 89 | build_args += ['--', '/m'] |
| 90 | else: |
| 91 | cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] |
| 92 | build_args += ['--', '-j{}'.format(mp.cpu_count())] |
| 93 | |
| 94 | env = os.environ.copy() |
| 95 | env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''), |
| 96 | self.distribution.get_version()) |
| 97 | |
| 98 | # Add position independent code flags if using gcc on linux probably |
| 99 | if platform.system() == "Linux": |
| 100 | cmake_args += ['-DCMAKE_CXX_FLAGS=-fPIC', '-DCMAKE_C_FLAGS=-fPIC'] |
| 101 | |
| 102 | # Using relative rpath messes up repairing the wheel file. The relative rpath is only necessary when |
| 103 | # building locally from source |
| 104 | if not is_manylinux: |
| 105 | cmake_args += ['-DCMAKE_INSTALL_RPATH={}'.format("$ORIGIN"), |
| 106 | '-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON', |
| 107 | '-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=OFF'] |