diff options
author | Matthew Brett <matthew.brett@gmail.com> | 2021-10-23 16:14:43 +0100 |
---|---|---|
committer | Matthew Brett <matthew.brett@gmail.com> | 2021-10-23 18:33:16 +0100 |
commit | 07778e58fbb5bd0e5172a9c1a99c391144ed41de (patch) | |
tree | 404f6243cf10b9e0a9f6ee0786962eaf76061c33 /numpy/distutils/command/build_clib.py | |
parent | 6409a721c17aae94cfd55ccbcf26a95494dd1cf8 (diff) | |
download | numpy-07778e58fbb5bd0e5172a9c1a99c391144ed41de.tar.gz |
Allow clib callable build flags
At the moment, we are guessing whether we have the MSVC compiler, by
looking at what Python was originally compiled for. That works only if
we are using the same compiler, but this is not the case when we compile
with e.g. mingw-w64 using Python.org Python.
Unfortunately, at the time we are specifying build flags, we don't know
what compiler we are using.
Allow build flags to clib to be callables that return lists of strings,
instead of strings, where the callables can do work like inspecting the
compiler, at build time.
Use this to check for MSVC at build time, when specifying the
`/GL-` flag.
See gh-9977 for a related discussion about these flags.
Diffstat (limited to 'numpy/distutils/command/build_clib.py')
-rw-r--r-- | numpy/distutils/command/build_clib.py | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/numpy/distutils/command/build_clib.py b/numpy/distutils/command/build_clib.py index a481758c1..45201f98f 100644 --- a/numpy/distutils/command/build_clib.py +++ b/numpy/distutils/command/build_clib.py @@ -185,6 +185,30 @@ class build_clib(old_build_clib): for (lib_name, build_info) in libraries: self.build_a_library(build_info, lib_name, libraries) + def assemble_flags(self, in_flags): + """ Assemble flags from flag list + + Parameters + ---------- + in_flags : None or sequence + None corresponds to empty list. Sequence elements can be strings + or callables that return lists of strings. Callable takes `self` as + single parameter. + + Returns + ------- + out_flags : list + """ + if in_flags is None: + return [] + out_flags = [] + for in_flag in in_flags: + if callable(in_flag): + out_flags += in_flag(self) + else: + out_flags.append(in_flag) + return out_flags + def build_a_library(self, build_info, lib_name, libraries): # default compilers compiler = self.compiler @@ -263,9 +287,13 @@ class build_clib(old_build_clib): include_dirs = build_info.get('include_dirs') if include_dirs is None: include_dirs = [] - extra_postargs = build_info.get('extra_compiler_args') or [] - extra_cflags = build_info.get('extra_cflags') or [] - extra_cxxflags = build_info.get('extra_cxxflags') or [] + # Flags can be strings, or callables that return a list of strings. + extra_postargs = self.assemble_flags( + build_info.get('extra_compiler_args')) + extra_cflags = self.assemble_flags( + build_info.get('extra_cflags')) + extra_cxxflags = self.assemble_flags( + build_info.get('extra_cxxflags')) include_dirs.extend(get_numpy_include_dirs()) # where compiled F90 module files are: |