From 39eb1c0bc4361b66dd41f9b361ea8b26ee1ecf46 Mon Sep 17 00:00:00 2001 From: Applin Date: Sun, 7 Apr 2024 14:46:55 +0100 Subject: [PATCH] Simplify compile flags --- setup.py | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/setup.py b/setup.py index bfa169c..3a1b5c4 100644 --- a/setup.py +++ b/setup.py @@ -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 @@ -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]: """