Distutils - way to check validity of compiler flag?
![](https://secure.gravatar.com/avatar/b4929294417e9ac44c17967baae75a36.jpg?s=120&d=mm&r=g)
Hi, I'm sorry to ask this, I guess I should know - but is there any way in disutils or numpy distutils to check whether a compiler flag is valid before doing extension building? I'm thinking of something like this, to check whether the compiler can handle '-fopenmp': have_openmp = check_compiler_flag('-fopenmp') flags = ['-fopenmp'] if have_openmp else [] ext = Extension('myext', ['myext.c'], extra_compile_args = flags, extra_link_args = flags]) I guess this would have to go somewhere in the main setup() call in order to pick up custom compilers on the command line and such? Cheers, Matthew
![](https://secure.gravatar.com/avatar/9cf3859e4f8d4e422f242a842a6e301c.jpg?s=120&d=mm&r=g)
In a couple of my projects, we check for flags by compiling little test files -- autotools style -- to check for SSE, OpenMP, etc. See e.g. https://github.com/rmcgibbo/mdtraj/blob/master/setup.py#L215 If anyone has a better solution, I'm all ears. -Robert On Mon, May 12, 2014 at 12:24 PM, Matthew Brett <matthew.brett@gmail.com>wrote:
![](https://secure.gravatar.com/avatar/b4929294417e9ac44c17967baae75a36.jpg?s=120&d=mm&r=g)
Hi, On Mon, May 12, 2014 at 12:50 PM, Robert McGibbon <rmcgibbo@gmail.com> wrote:
Thanks a lot for the reply. Your code is nice and clean, but I think that it won't pick up custom compilers such as python setup.py build --compiler=mingw32 or similar? I ended up going for an approach suggested by Min RK of IPython fame - code here: https://github.com/nipy/dipy/pull/371/files The basic idea is to wait until the last distutils moment after the compiler has been configured, and then test with that exact compiler setup. It's a little ugly and not too general as it stands, but I'm posting in case someone runs into the same thing. Cheers, Matthew
![](https://secure.gravatar.com/avatar/9cf3859e4f8d4e422f242a842a6e301c.jpg?s=120&d=mm&r=g)
In a couple of my projects, we check for flags by compiling little test files -- autotools style -- to check for SSE, OpenMP, etc. See e.g. https://github.com/rmcgibbo/mdtraj/blob/master/setup.py#L215 If anyone has a better solution, I'm all ears. -Robert On Mon, May 12, 2014 at 12:24 PM, Matthew Brett <matthew.brett@gmail.com>wrote:
![](https://secure.gravatar.com/avatar/b4929294417e9ac44c17967baae75a36.jpg?s=120&d=mm&r=g)
Hi, On Mon, May 12, 2014 at 12:50 PM, Robert McGibbon <rmcgibbo@gmail.com> wrote:
Thanks a lot for the reply. Your code is nice and clean, but I think that it won't pick up custom compilers such as python setup.py build --compiler=mingw32 or similar? I ended up going for an approach suggested by Min RK of IPython fame - code here: https://github.com/nipy/dipy/pull/371/files The basic idea is to wait until the last distutils moment after the compiler has been configured, and then test with that exact compiler setup. It's a little ugly and not too general as it stands, but I'm posting in case someone runs into the same thing. Cheers, Matthew
participants (2)
-
Matthew Brett
-
Robert McGibbon