Skip to content

Commit

Permalink
Add conditional standard flags
Browse files Browse the repository at this point in the history
  • Loading branch information
jcapriot committed Mar 15, 2023
1 parent 18e9799 commit 5687398
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
metadata["install_requires"] = install_requires
else:
from setuptools.extension import Extension
from setuptools.command.build_ext import build_ext
from Cython.Build import cythonize
import numpy as np

Expand All @@ -93,7 +94,7 @@
"discretize._extensions.tree_ext",
["discretize/_extensions/tree_ext.pyx", "discretize/_extensions/tree.cpp"],
include_dirs=[np.get_include()],
extra_compile_args=["-std:c++17", "-std=c++17"],
#extra_compile_args=["-std:c++17", "-std=c++17"],
**ext_kwargs
),
Extension(
Expand All @@ -104,6 +105,23 @@
),
]

class build_ext_cpp_standard(build_ext):
# add compiler specific standard argument specifier
def build_extension(self, ext):
# This module requires c++17 standard
if ext.name == "discretize._extensions.tree_ext":
comp_type = self.compiler.compiler_type
if comp_type == 'msvc':
std_arg = "\std:c++17"
elif comp_type == 'bcpp':
raise Exception('Must use cpp compiler that support C++17 standard.')
else:
std_arg = "-std=c++17"
ext.extra_compile_args = [std_arg,]
super().build_extension(ext)


metadata["ext_modules"] = cythonize(extensions)
metadata["cmdclass"] = {"build_ext":build_ext_cpp_standard}

setup(**metadata)

0 comments on commit 5687398

Please sign in to comment.