setup_global.py.in 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Setup script for pybind11-global (in the sdist or in tools/setup_global.py in the repository)
  4. # This package is targeted for easy use from CMake.
  5. import contextlib
  6. import glob
  7. import os
  8. import re
  9. import shutil
  10. import subprocess
  11. import sys
  12. import tempfile
  13. # Setuptools has to be before distutils
  14. from setuptools import setup
  15. from distutils.command.install_headers import install_headers
  16. class InstallHeadersNested(install_headers):
  17. def run(self):
  18. headers = self.distribution.headers or []
  19. for header in headers:
  20. # Remove pybind11/include/
  21. short_header = header.split("/", 2)[-1]
  22. dst = os.path.join(self.install_dir, os.path.dirname(short_header))
  23. self.mkpath(dst)
  24. (out, _) = self.copy_file(header, dst)
  25. self.outfiles.append(out)
  26. main_headers = glob.glob("pybind11/include/pybind11/*.h")
  27. detail_headers = glob.glob("pybind11/include/pybind11/detail/*.h")
  28. stl_headers = glob.glob("pybind11/include/pybind11/stl/*.h")
  29. cmake_files = glob.glob("pybind11/share/cmake/pybind11/*.cmake")
  30. headers = main_headers + detail_headers + stl_headers
  31. cmdclass = {"install_headers": InstallHeadersNested}
  32. $extra_cmd
  33. # This will _not_ affect installing from wheels,
  34. # only building wheels or installing from SDist.
  35. # Primarily intended on Windows, where this is sometimes
  36. # customized (for example, conda-forge uses Library/)
  37. base = os.environ.get("PYBIND11_GLOBAL_PREFIX", "")
  38. # Must have a separator
  39. if base and not base.endswith("/"):
  40. base += "/"
  41. setup(
  42. name="pybind11_global",
  43. version="$version",
  44. packages=[],
  45. headers=headers,
  46. data_files=[
  47. (base + "share/cmake/pybind11", cmake_files),
  48. (base + "include/pybind11", main_headers),
  49. (base + "include/pybind11/detail", detail_headers),
  50. (base + "include/pybind11/stl", stl_headers),
  51. ],
  52. cmdclass=cmdclass,
  53. )