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