How to identify compiler before defining cython extensions?
After posting on the cython forums and searching for related issues in distutils I found this post showing how to move the compiler arguments into the build_ext assignment. If I subsequently remove all compiler arguments from the extension class I can now lazy assign them inside the command class as I expected. I can also get install
and egg_info
command classes to call my new version of the build_ext as well.
from setuptools.command.build_ext import build_ext
BUILD_ARGS = defaultdict(lambda: ['-O3', '-g0'])
for compiler, args in [
('msvc', ['/EHsc', '/DHUNSPELL_STATIC']),
('gcc', ['-O3', '-g0'])]:
BUILD_ARGS[compiler] = args
class build_ext_compiler_check(build_ext):
def build_extensions(self):
compiler = self.compiler.compiler_type
args = BUILD_ARGS[compiler]
for ext in self.extensions:
ext.extra_compile_args = args
build_ext.build_extensions(self)
...
setup(
...
cmdclass={ 'build_ext': build_ext_compiler_check })