13
13
14
14
15
15
# C++ is only supported on Python 3.6 and newer
16
- TEST_CPP = (sys .version_info >= (3 , 6 ))
16
+ TEST_CXX = (sys .version_info >= (3 , 6 ))
17
17
18
18
SRC_DIR = os .path .normpath (os .path .join (os .path .dirname (__file__ ), '..' ))
19
19
20
20
# Windows uses MSVC compiler
21
21
MSVC = (os .name == "nt" )
22
22
23
- # C compiler flags for GCC and clang
24
23
COMMON_FLAGS = [
25
- # Treat warnings as error
26
- '-Werror' ,
27
- # Enable all warnings
28
- '-Wall' , '-Wextra' ,
29
- # Extra warnings
30
- '-Wconversion' ,
31
- # /usr/lib64/pypy3.7/include/pyport.h:68:20: error: redefinition of typedef
32
- # 'Py_hash_t' is a C11 feature
33
- "-Wno-typedef-redefinition" ,
24
+ '-I' + SRC_DIR ,
34
25
]
35
- CFLAGS = COMMON_FLAGS + [
36
- # Use C99 for pythoncapi_compat.c which initializes PyModuleDef with a
37
- # mixture of designated and non-designated initializers
38
- '-std=c99' ,
39
- ]
40
- CPPFLAGS = list (COMMON_FLAGS )
41
- # FIXME: _Py_CAST() emits C++ compilers on Python 3.12.
42
- # See: https://github.com/python/cpython/issues/94731
43
- if 0 :
44
- CPPFLAGS .extend ((
45
- '-Wold-style-cast' ,
46
- '-Wzero-as-null-pointer-constant' ,
26
+ if not MSVC :
27
+ # C compiler flags for GCC and clang
28
+ COMMON_FLAGS .extend ((
29
+ # Treat warnings as error
30
+ '-Werror' ,
31
+ # Enable all warnings
32
+ '-Wall' , '-Wextra' ,
33
+ # Extra warnings
34
+ '-Wconversion' ,
35
+ # /usr/lib64/pypy3.7/include/pyport.h:68:20: error: redefinition of typedef
36
+ # 'Py_hash_t' is a C11 feature
37
+ "-Wno-typedef-redefinition" ,
38
+ ))
39
+ CFLAGS = COMMON_FLAGS + [
40
+ # Use C99 for pythoncapi_compat.c which initializes PyModuleDef with a
41
+ # mixture of designated and non-designated initializers
42
+ '-std=c99' ,
43
+ ]
44
+ else :
45
+ # C compiler flags for MSVC
46
+ COMMON_FLAGS .extend ((
47
+ # Treat all compiler warnings as compiler errors
48
+ '/WX' ,
47
49
))
50
+ CFLAGS = list (COMMON_FLAGS )
51
+ CXXFLAGS = list (COMMON_FLAGS )
48
52
49
53
50
54
def main ():
@@ -66,34 +70,31 @@ def main():
66
70
# CC env var overrides sysconfig CC variable in setuptools
67
71
os .environ ['CC' ] = cmd
68
72
69
- cflags = ['-I' + SRC_DIR ]
70
- cppflags = list (cflags )
71
- if not MSVC :
72
- cflags .extend (CFLAGS )
73
- cppflags .extend (CPPFLAGS )
74
-
75
73
# C extension
76
74
c_ext = Extension (
77
75
'test_pythoncapi_compat_cext' ,
78
76
sources = ['test_pythoncapi_compat_cext.c' ],
79
- extra_compile_args = cflags )
77
+ extra_compile_args = CFLAGS )
80
78
extensions = [c_ext ]
81
79
82
- if TEST_CPP :
80
+ if TEST_CXX :
83
81
# C++ extension
84
82
85
83
# MSVC has /std flag but doesn't support /std:c++11
86
84
if not MSVC :
87
85
versions = [
88
- ('test_pythoncapi_compat_cpp03ext' , '-std=c++03' ),
89
- ('test_pythoncapi_compat_cpp11ext' , '-std=c++11' ),
86
+ ('test_pythoncapi_compat_cpp03ext' , [ '-std=c++03' ] ),
87
+ ('test_pythoncapi_compat_cpp11ext' , [ '-std=c++11' ] ),
90
88
]
91
89
else :
92
- versions = [('test_pythoncapi_compat_cppext' , None )]
93
- for name , flag in versions :
94
- flags = list (cppflags )
95
- if flag is not None :
96
- flags .append (flag )
90
+ versions = [
91
+ ('test_pythoncapi_compat_cppext' , None ),
92
+ ('test_pythoncapi_compat_cpp14ext' , ['/std:c++14' , '/Zc:__cplusplus' ]),
93
+ ]
94
+ for name , std_flags in versions :
95
+ flags = list (CXXFLAGS )
96
+ if std_flags is not None :
97
+ flags .extend (std_flags )
97
98
cpp_ext = Extension (
98
99
name ,
99
100
sources = ['test_pythoncapi_compat_cppext.cpp' ],
0 commit comments