|
23 | 23 | from setuptools.command.test import test as TestCommand
|
24 | 24 | import sys
|
25 | 25 | import os
|
| 26 | +import subprocess |
26 | 27 | import platform
|
27 | 28 |
|
28 |
| - |
29 | 29 | link_args = ['-fopenmp']
|
30 | 30 | # Avoid compiling error with prange. Similar to http://stackoverflow.com/questions/36577182/unable-to-assign-value-to-array-in-prange
|
31 | 31 | compile_args = ['-fopenmp', '-fpermissive']
|
32 | 32 |
|
33 | 33 | if platform.system().lower() == 'darwin':
|
34 |
| - # clang on macOS does not work with OpenMP |
35 |
| - ccs = ["/usr/local/bin/g++-5", |
36 |
| - "/usr/local/bin/g++-6", |
37 |
| - "/usr/local/bin/g++-7", |
38 |
| - "/usr/local/opt/llvm/bin/clang"] |
39 |
| - cc = None |
40 |
| - for compiler in ccs: |
41 |
| - if os.path.isfile(compiler): |
42 |
| - cc = compiler |
43 |
| - if cc is None: |
44 |
| - raise ValueError("You must install clang-6.0 or gcc/g++. You can install with homebrew: brew install gcc or brew install llvm") |
45 |
| - if 'clang' in cc and os.path.isdir("/usr/local/opt/libomp")==False: |
46 |
| - raise ValueError("You must also install libomp. You can install with homebrew: brew install libomp") |
47 |
| - os.environ["CC"] = cc if 'clang' in cc else cc.replace("g++", "gcc") |
48 |
| - os.environ["CXX"] = cc |
| 34 | + # if a recent compiler on PATH (e.g. from anaconda) then let's use that |
| 35 | + gcc_out = subprocess.check_output(['gcc', '-v'], stderr=subprocess.STDOUT) |
| 36 | + if b'LLVM' in gcc_out: |
| 37 | + # clang on macOS does not work with OpenMP |
| 38 | + ccs = ["/usr/local/bin/g++-5", |
| 39 | + "/usr/local/bin/g++-6", |
| 40 | + "/usr/local/bin/g++-7", |
| 41 | + "/usr/local/opt/llvm/bin/clang"] |
| 42 | + cc = None |
| 43 | + for compiler in ccs: |
| 44 | + if os.path.isfile(compiler): |
| 45 | + cc = compiler |
| 46 | + if cc is None: |
| 47 | + raise ValueError("You must install clang-6.0 or gcc/g++. You can install with homebrew: brew install gcc or brew install llvm") |
| 48 | + if 'clang' in cc and os.path.isdir("/usr/local/opt/libomp")==False: |
| 49 | + raise ValueError("You must also install libomp. You can install with homebrew: brew install libomp") |
| 50 | + os.environ["CC"] = cc if 'clang' in cc else cc.replace("g++", "gcc") |
| 51 | + os.environ["CXX"] = cc |
| 52 | + if 'clang' in cc: |
| 53 | + link_args = ['-fopenmp=libomp'] |
| 54 | + |
49 | 55 | # not all OSX/clang compiler flags supported by GCC. For some reason
|
50 | 56 | # these sometimes are generated and used. Cython will still add more flags.
|
51 | 57 | os.environ["CFLAGS"] = "-fno-common -fno-strict-aliasing -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -g -fwrapv -Os"
|
52 | 58 |
|
53 |
| - if 'clang' in cc: |
54 |
| - link_args = ['-fopenmp=libomp'] |
55 | 59 | elif platform.system().lower() == 'windows':
|
56 | 60 | compile_args = ['/openmp']
|
57 | 61 | link_args = []
|
|
0 commit comments