summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorserge-sans-paille <serge.guelton@telecom-bretagne.eu>2022-04-07 07:55:46 +0200
committerserge-sans-paille <serge.guelton@telecom-bretagne.eu>2022-04-08 10:02:41 +0200
commitc91a7d0c5691c9d78bd75284777fda73f225155d (patch)
tree667b576e0f0a3618a970d4443c4c7f5fd79d1d1e /numpy
parentca85c17e712c93717abb5c2b921393c3ecfc47c4 (diff)
downloadnumpy-c91a7d0c5691c9d78bd75284777fda73f225155d.tar.gz
Introduce numpy.core.setup_common.NPY_CXX_FLAGS
Group all C++ flags in one location. This avoids redundancy and makes sure we test the flags we use, and use the flags we test. Fix #21302
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/setup.py14
-rw-r--r--numpy/distutils/ccompiler_opt.py8
-rw-r--r--numpy/linalg/setup.py6
3 files changed, 19 insertions, 9 deletions
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index ce037308e..c632d60e8 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -469,6 +469,7 @@ def configuration(parent_package='',top_path=None):
exec_mod_from_location)
from numpy.distutils.system_info import (get_info, blas_opt_info,
lapack_opt_info)
+ from numpy.distutils.ccompiler_opt import NPY_CXX_FLAGS
from numpy.version import release as is_released
config = Configuration('core', parent_package, top_path)
@@ -737,11 +738,17 @@ def configuration(parent_package='',top_path=None):
):
is_cpp = lang == 'c++'
if is_cpp:
- # this a workround to get rid of invalid c++ flags
+ # this a workaround to get rid of invalid c++ flags
# without doing big changes to config.
# c tested first, compiler should be here
bk_c = config_cmd.compiler
config_cmd.compiler = bk_c.cxx_compiler()
+
+ # Check that Linux compiler actually support the default flags
+ if hasattr(config_cmd.compiler, 'compiler'):
+ config_cmd.compiler.compiler.extend(NPY_CXX_FLAGS)
+ config_cmd.compiler.compiler_so.extend(NPY_CXX_FLAGS)
+
st = config_cmd.try_link(test_code, lang=lang)
if not st:
# rerun the failing command in verbose mode
@@ -1120,10 +1127,7 @@ def configuration(parent_package='',top_path=None):
libraries=['npymath'],
extra_objects=svml_objs,
extra_info=extra_info,
- extra_cxx_compile_args=['-std=c++11',
- '-D__STDC_VERSION__=0',
- '-fno-exceptions',
- '-fno-rtti'])
+ extra_cxx_compile_args=NPY_CXX_FLAGS)
#######################################################################
# umath_tests module #
diff --git a/numpy/distutils/ccompiler_opt.py b/numpy/distutils/ccompiler_opt.py
index 6d2114c95..886066a61 100644
--- a/numpy/distutils/ccompiler_opt.py
+++ b/numpy/distutils/ccompiler_opt.py
@@ -16,6 +16,14 @@ import re
import subprocess
import textwrap
+# These flags are used to compile any C++ source within Numpy.
+# They are chosen to have very few runtime dependencies.
+NPY_CXX_FLAGS = [
+ '-std=c++11', # Minimal standard version
+ '-D__STDC_VERSION__=0', # for compatibility with C headers
+ '-fno-exceptions', # no exception support
+ '-fno-rtti'] # no runtime type information
+
class _Config:
"""An abstract class holds all configurable attributes of `CCompilerOpt`,
diff --git a/numpy/linalg/setup.py b/numpy/linalg/setup.py
index 82c688d91..dc62dff8f 100644
--- a/numpy/linalg/setup.py
+++ b/numpy/linalg/setup.py
@@ -3,6 +3,7 @@ import sys
def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
+ from numpy.distutils.ccompiler_opt import NPY_CXX_FLAGS
from numpy.distutils.system_info import get_info, system_info
config = Configuration('linalg', parent_package, top_path)
@@ -72,10 +73,7 @@ def configuration(parent_package='', top_path=None):
sources=['umath_linalg.cpp', get_lapack_lite_sources],
depends=['lapack_lite/f2c.h'],
extra_info=lapack_info,
- extra_cxx_compile_args=['-std=c++11',
- '-D__STDC_VERSION__=0',
- '-fno-exceptions',
- '-fno-rtti'],
+ extra_cxx_compile_args=NPY_CXX_FLAGS,
libraries=['npymath'],
)
config.add_data_files('*.pyi')