Permalink
Browse files

ENH: Introduce new options extra_f77_compile_args and extra_f90_compi…

…le_args to

Configuration.add_extension. Configuration.add_library, and Extension. These options
allow specifying extra compile options for compiling Fortran sources within a
setup.py file.
  • Loading branch information...
1 parent ea529d4 commit a90754d673aa4af4d605a657134d76422c390510 @pearu pearu committed with charris Aug 16, 2011
View
@@ -226,7 +226,8 @@ in writing setup scripts:
``define_macros``, ``undef_macros``, ``library_dirs``, ``libraries``,
``runtime_library_dirs``, ``extra_objects``, ``extra_compile_args``,
``extra_link_args``, ``export_symbols``, ``swig_opts``, ``depends``,
- ``language``, ``f2py_options``, ``module_dirs``, ``extra_info``.
+ ``language``, ``f2py_options``, ``module_dirs``, ``extra_info``,
+ ``extra_f77_compile_args``, ``extra_compile_f90_args``.
Note that ``config.paths`` method is applied to all lists that
may contain paths. ``extra_info`` is a dictionary or a list
@@ -261,11 +262,12 @@ in writing setup scripts:
The second argument gives a path to a build directory that must
be used when creating files to a disk.
-+ ``config.add_library(name, sources, **build_info)`` --- add
- a library to ``libraries`` list. Allowed keywords arguments
- are ``depends``, ``macros``, ``include_dirs``,
- ``extra_compiler_args``, ``f2py_options``. See ``.add_extension()``
- method for more information on arguments.
++ ``config.add_library(name, sources, **build_info)`` --- add a
+ library to ``libraries`` list. Allowed keywords arguments are
+ ``depends``, ``macros``, ``include_dirs``, ``extra_compiler_args``,
+ ``f2py_options``, ``extra_f77_compile_args``,
+ ``extra_compile_f90_args``. See ``.add_extension()`` method for
+ more information on arguments.
+ ``config.have_f77c()`` --- return True if Fortran 77 compiler is
available (read: a simple Fortran 77 code compiled succesfully).
@@ -177,6 +177,10 @@ def build_a_library(self, build_info, lib_name, libraries):
raise DistutilsError("library %s has Fortran sources"\
" but no Fortran compiler found" % (lib_name))
+ if fcompiler is not None:
+ fcompiler.extra_f77_compile_args = build_info.get('extra_f77_compile_args') or []
+ fcompiler.extra_f90_compile_args = build_info.get('extra_f90_compile_args') or []
+
macros = build_info.get('macros')
include_dirs = build_info.get('include_dirs')
if include_dirs is None:
@@ -299,6 +299,9 @@ def build_extension(self, ext):
fcompiler = self._f77_compiler
else: # in case ext.language is c++, for instance
fcompiler = self._f90_compiler or self._f77_compiler
+ if fcompiler is not None:
+ fcompiler.extra_f77_compile_args = ext.extra_f77_compile_args or []
+ fcompiler.extra_f90_compile_args = ext.extra_f90_compile_args or []
cxx_compiler = self._cxx_compiler
# check for the availability of required compilers
@@ -31,6 +31,8 @@ def __init__ (self, name, sources,
language=None,
f2py_options=None,
module_dirs=None,
+ extra_f77_compile_args=None,
+ extra_f90_compile_args=None,
):
old_Extension.__init__(self,name, [],
include_dirs,
@@ -63,7 +65,9 @@ def __init__ (self, name, sources,
# numpy_distutils features
self.f2py_options = f2py_options or []
self.module_dirs = module_dirs or []
-
+ self.extra_f77_compile_args = extra_f77_compile_args or []
+ self.extra_f90_compile_args = extra_f90_compile_args or []
+
return
def has_cxx_sources(self):
@@ -213,6 +213,10 @@ class FCompiler(CCompiler):
# command/{build_ext.py, build_clib.py, config.py} files.
c_compiler = None
+ # extra_{f77,f90}_compile_args are set by build_ext.build_extension method
+ extra_f77_compile_args = []
+ extra_f90_compile_args = []
+
def __init__(self, *args, **kw):
CCompiler.__init__(self, *args, **kw)
self.distutils_vars = self.distutils_vars.clone(self._environment_hook)
@@ -560,18 +564,21 @@ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
flavor = ':f77'
compiler = self.compiler_f77
src_flags = get_f77flags(src)
+ extra_compile_args = self.extra_f77_compile_args or []
elif is_free_format(src):
flavor = ':f90'
compiler = self.compiler_f90
if compiler is None:
raise DistutilsExecError('f90 not supported by %s needed for %s'\
% (self.__class__.__name__,src))
+ extra_compile_args = self.extra_f90_compile_args or []
else:
flavor = ':fix'
compiler = self.compiler_fix
if compiler is None:
raise DistutilsExecError('f90 (fixed) not supported by %s needed for %s'\
% (self.__class__.__name__,src))
+ extra_compile_args = self.extra_f90_compile_args or []
if self.object_switch[-1]==' ':
o_args = [self.object_switch.strip(),obj]
else:
@@ -580,13 +587,17 @@ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
assert self.compile_switch.strip()
s_args = [self.compile_switch, src]
+ if extra_compile_args:
+ log.info('extra %s options: %r' \
+ % (flavor[1:], ' '.join(extra_compile_args)))
+
extra_flags = src_flags.get(self.compiler_type,[])
if extra_flags:
log.info('using compile options from source: %r' \
% ' '.join(extra_flags))
command = compiler + cc_args + extra_flags + s_args + o_args \
- + extra_postargs
+ + extra_postargs + extra_compile_args
display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,
src)
@@ -961,5 +972,7 @@ def get_f77flags(src):
f.close()
return flags
+# TODO: implement get_f90flags and use it in _compile similarly to get_f77flags
+
if __name__ == '__main__':
show_fcompilers()
@@ -1403,6 +1403,8 @@ def add_extension(self,name,sources,**kw):
extra_objects:
extra_compile_args:
extra_link_args:
+ extra_f77_compile_args:
+ extra_f90_compile_args:
export_symbols:
swig_opts:
depends:
@@ -1497,6 +1499,8 @@ def add_library(self,name,sources,**build_info):
* macros
* include_dirs
* extra_compiler_args
+ * extra_f77_compiler_args
+ * extra_f90_compiler_args
* f2py_options
* language
@@ -1548,6 +1552,8 @@ def add_installed_library(self, name, sources, install_dir, build_info=None):
* macros
* include_dirs
* extra_compiler_args
+ * extra_f77_compiler_args
+ * extra_f90_compiler_args
* f2py_options
* language

0 comments on commit a90754d

Please sign in to comment.