11import os
2- import sys
3-
4- import setuptools
5- from setuptools import Extension , setup
6- from setuptools .command .build_ext import build_ext
7-
8-
9- # <https://github.com/pybind/python_example/blob/master/setup.py>
10- class get_pybind_include (object ):
11- """Helper class to determine the pybind11 include path
12- The purpose of this class is to postpone importing pybind11
13- until it is actually installed, so that the ``get_include()``
14- method can be invoked."""
15-
16- def __str__ (self ):
17- import pybind11
18-
19- return pybind11 .get_include ()
20-
21-
22- # cf http://bugs.python.org/issue26689
23- def has_flag (compiler , flagname ):
24- """Return a boolean indicating whether a flag name is supported on
25- the specified compiler.
26- """
27- import os
28- import tempfile
29-
30- with tempfile .NamedTemporaryFile ("w" , suffix = ".cpp" , delete = False ) as f :
31- f .write ("int main (int argc, char **argv) { return 0; }" )
32- fname = f .name
33- try :
34- compiler .compile ([fname ], extra_postargs = [flagname ])
35- except setuptools .distutils .errors .CompileError :
36- return False
37- finally :
38- try :
39- os .remove (fname )
40- except OSError :
41- pass
42- return True
43-
44-
45- def cpp_flag (compiler ):
46- """Return the -std=c++[11/14/17] compiler flag.
47- The newer version is prefered over c++11 (when it is available).
48- """
49- flags = ["-std=c++17" , "-std=c++14" , "-std=c++11" ]
50-
51- for flag in flags :
52- if has_flag (compiler , flag ):
53- return flag
54-
55- raise RuntimeError ("Unsupported compiler -- at least C++11 support " "is needed!" )
56-
57-
58- class BuildExt (build_ext ):
59- """A custom build extension for adding compiler-specific options."""
60-
61- c_opts = {
62- "msvc" : ["/EHsc" ],
63- "unix" : [],
64- }
65- l_opts = {
66- "msvc" : [],
67- "unix" : [],
68- }
69-
70- if sys .platform == "darwin" :
71- darwin_opts = ["-stdlib=libc++" , "-mmacosx-version-min=10.7" ]
72- c_opts ["unix" ] += darwin_opts
73- l_opts ["unix" ] += darwin_opts
74-
75- def build_extensions (self ):
76- ct = self .compiler .compiler_type
77- opts = self .c_opts .get (ct , [])
78- link_opts = self .l_opts .get (ct , [])
79- if ct == "unix" :
80- opts .append (cpp_flag (self .compiler ))
81- if has_flag (self .compiler , "-fvisibility=hidden" ):
82- opts .append ("-fvisibility=hidden" )
83-
84- for ext in self .extensions :
85- ext .define_macros = [
86- ("VERSION_INFO" , '"{}"' .format (self .distribution .get_version ()))
87- ]
88- ext .extra_compile_args = opts
89- ext .extra_link_args = link_opts
90- build_ext .build_extensions (self )
912
3+ from pybind11 .setup_helpers import Pybind11Extension , build_ext
4+ from setuptools import setup
925
6+ # https://github.com/pybind/python_example/
937ext_modules = [
94- Extension (
8+ Pybind11Extension (
959 "_pygalmesh" ,
9610 # Sort input source files to ensure bit-for-bit reproducible builds
9711 # (https://github.com/pybind/python_example/pull/53)
@@ -107,20 +21,15 @@ def build_extensions(self):
10721 "src/pybind11.cpp" ,
10822 ]
10923 ),
110- include_dirs = [
111- os .environ .get ("EIGEN_INCLUDE_DIR" , "/usr/include/eigen3/" ),
112- # Path to pybind11 headers
113- get_pybind_include (),
114- ],
115- language = "c++" ,
24+ include_dirs = [os .environ .get ("EIGEN_INCLUDE_DIR" , "/usr/include/eigen3/" )],
11625 # no CGAL libraries necessary from CGAL 5.0 onwards
11726 libraries = ["gmp" , "mpfr" ],
11827 )
11928]
12029
12130if __name__ == "__main__" :
12231 setup (
123- cmdclass = {"build_ext" : BuildExt },
32+ cmdclass = {"build_ext" : build_ext },
12433 ext_modules = ext_modules ,
12534 zip_safe = False ,
12635 )
0 commit comments