MCPcopy Create free account
hub / github.com/pybind/pybind11 / has_flag

Function has_flag

pybind11/setup_helpers.py:229–245  ·  view source on GitHub ↗

Return the flag if a flag name is supported on the specified compiler, otherwise None (can be used as a boolean). If multiple flags are passed, return the first that matches.

(compiler: Any, flag: str)

Source from the content-addressed store, hash-verified

227
228# cf http://bugs.python.org/issue26689
229def has_flag(compiler: Any, flag: str) -> bool:
230 """
231 Return the flag if a flag name is supported on the
232 specified compiler, otherwise None (can be used as a boolean).
233 If multiple flags are passed, return the first that matches.
234 """
235
236 with tmp_chdir():
237 fname = Path("flagcheck.cpp")
238 # Don't trigger -Wunused-parameter.
239 fname.write_text("int main (int, char **) { return 0; }", encoding="utf-8")
240
241 try:
242 compiler.compile([str(fname)], extra_postargs=[flag])
243 except distutils.errors.CompileError:
244 return False
245 return True
246
247
248# Every call will cache the result

Callers 1

auto_cpp_levelFunction · 0.85

Calls 2

tmp_chdirFunction · 0.85
strClass · 0.85

Tested by

no test coverage detected