-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAINT: Update vendored uarray version
The also moves the compile flag detection code from fft._pocketfft into _build_utils as it is now needed to build uarray as well.
- Loading branch information
1 parent
6a3afbc
commit 27c0be4
Showing
6 changed files
with
1,288 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
Helpers for detection of compiler features | ||
""" | ||
import tempfile | ||
import os | ||
|
||
def try_compile(compiler, code=None, flags=[], ext=None): | ||
"""Returns True if the compiler is able to compile the given code""" | ||
from distutils.errors import CompileError | ||
|
||
code = code or 'int main (int argc, char **argv) { return 0; }' | ||
ext = ext or compiler.src_extensions[0] | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
fname = os.path.join(temp_dir, 'main'+ext) | ||
with open(fname, 'w') as f: | ||
f.write(code) | ||
|
||
try: | ||
compiler.compile([fname], extra_postargs=flags) | ||
except CompileError: | ||
return False | ||
return True | ||
|
||
|
||
def has_flag(compiler, flag, ext=None): | ||
"""Returns True if the compiler supports the given flag""" | ||
return try_compile(compiler, flags=[flag], ext=ext) | ||
|
||
|
||
def get_cxx_std_flag(compiler): | ||
"""Detects compiler flag for c++14, c++11 or None if not detected""" | ||
gnu_flags = ['--std=c++14', '--std=c++11'] | ||
flags_by_cc = { | ||
'msvc': ['/std:c++14', None], | ||
'intelw': ['/Qstd=c++14', '/Qstd=c++11'] | ||
} | ||
flags = flags_by_cc.get(compiler.compiler_type, gnu_flags) | ||
|
||
for flag in flags: | ||
if flag is None: | ||
return None | ||
|
||
if has_flag(compiler, flag): | ||
return flag | ||
|
||
from numpy.distutils import log | ||
log.warn('Could not detect c++ standard flag') | ||
return None | ||
|
||
|
||
def try_add_flag(args, compiler, flag, ext=None): | ||
"""Appends flag to the list of arguments if supported by the compiler""" | ||
if try_compile(compiler, flags=args+[flag], ext=ext): | ||
args.append(flag) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.