Skip to content

Commit

Permalink
Simplify compile flags
Browse files Browse the repository at this point in the history
  • Loading branch information
robertapplin committed Apr 7, 2024
1 parent f7c11fc commit 39eb1c0
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
"""
from os import environ
from pathlib import PurePosixPath
from subprocess import STDOUT, check_output
# Importing setuptools modifies the behaviour of setup from distutils
# to support building wheels. It will be marked as unused by IDEs/static analysis.
import setuptools
import sys
from typing import Sequence, Tuple
from typing import Sequence

from numpy.distutils.core import (Extension as FortranExtension, setup)
from numpy.distutils.command.build_ext import build_ext as _build_ext
Expand All @@ -24,36 +23,26 @@ def create_fortran_extension(fq_name: str, sources: Sequence[str]) -> FortranExt
:param sources: List of relative paths from this file to the sources
:return: An Extension class to be built
"""
extra_compile_args, extra_link_args, extra_f90_compile_args = compiler_flags()
_remove_environment_compiler_flags()
return FortranExtension(name=fq_name,
sources=sources,
extra_f90_compile_args=extra_f90_compile_args,
extra_link_args=extra_link_args,
extra_compile_args=extra_compile_args)
extra_f90_compile_args=["-O1", "-std=legacy"],
extra_link_args=["-static", "-static-libgfortran", "-static-libgcc"]
if sys.platform == "win32" else [])


def compiler_flags() -> Tuple[Sequence[str], Sequence[str]]:
def _remove_environment_compiler_flags() -> None:
"""
:return: The compiler flags appropriate for this platform
Using the 'gfortran_linux-64' and 'gfortran_osx-64' conda packages gives poor fit results by default
because they set several optimization compiler flags which alter the operation of the Fortran code. We
must therefore remove these flags from the 'FFLAGS' environment variable before performing the compilation.
"""
extra_compile_args = []
extra_link_args = []
if sys.platform == "win32":
extra_link_args = ["-static", "-static-libgfortran", "-static-libgcc"]
elif sys.platform == "darwin":
extra_compile_args = ["-Wno-argument-mismatch"]
extra_link_args = ["-static", "-static-libgfortran", "-static-libgcc"]

fflags_value = environ.get('FFLAGS')
if isinstance(fflags_value, str):
fflags_value = fflags_value.replace("-fstack-protector ", "")
fflags_value = fflags_value.replace("-fstack-protector-strong ", "")
environ['FFLAGS'] = fflags_value

extra_f90_compile_args = ["-O1", "-std=legacy"]

return extra_compile_args, extra_link_args, extra_f90_compile_args


def source_paths(dirname: PurePosixPath, filenames: Sequence[str]) -> Sequence[str]:
"""
Expand Down

0 comments on commit 39eb1c0

Please sign in to comment.