Skip to content

Commit 999a98e

Browse files
committed
More robust way of checking whether the compiler is clang
1 parent 8d7355c commit 999a98e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

setup.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ def compiler_has_flag(compiler, flagname):
234234
return True
235235

236236

237+
# Test whether the compiler is clang, allowing for the fact that it's name might be gcc...
238+
def compiler_is_clang(compiler):
239+
# Test whether the compiler is clang by running the compiler with the --version flag and checking whether the output contains "clang"
240+
try:
241+
output = subprocess.check_output(
242+
[compiler.compiler[0], "--version"], stderr=subprocess.STDOUT
243+
)
244+
except (OSError, subprocess.CalledProcessError):
245+
return False
246+
return b"clang" in output
247+
248+
237249
# Now need to subclass BuildExt to access the compiler used and check flags
238250
class BuildExt(build_ext):
239251
def build_extensions(self):
@@ -246,7 +258,8 @@ def build_extensions(self):
246258
for flag in ext.extra_compile_args:
247259
if compiler_has_flag(self.compiler, flag):
248260
extra_compile_args.append(flag)
249-
elif "clang" in self.compiler.compiler[0] and flag == "-fopenmp":
261+
elif compiler_is_clang(self.compiler) and flag == "-fopenmp":
262+
print("Here")
250263
# clang does not support -fopenmp, but does support -Xclang -fopenmp
251264
extra_compile_args.append("-Xclang")
252265
extra_compile_args.append("-fopenmp")

0 commit comments

Comments
 (0)