@@ -180,7 +180,7 @@ def __init__(self):
180180 """
181181
182182 fields = {'cc' , 'ld' }
183- _cpp = False
183+ default_cpp = False
184184
185185 def __init__ (self , ** kwargs ):
186186 _name = kwargs .pop ('name' , self .__class__ .__name__ )
@@ -191,6 +191,7 @@ def __init__(self, **kwargs):
191191 super ().__init__ (** kwargs )
192192
193193 self .__lookup_cmds__ ()
194+ self ._cpp = kwargs .get ('cpp' , self .default_cpp )
194195
195196 self .suffix = kwargs .get ('suffix' )
196197 if not kwargs .get ('mpi' ):
@@ -200,7 +201,7 @@ def __init__(self, **kwargs):
200201 self .cc = self .MPICC if self ._cpp is False else self .MPICXX
201202 self .ld = self .cc # Wanted by the superclass
202203
203- self .cflags = ['-O3' , '-g' , '-fPIC' , '-Wall' , '-std=c99 ' ]
204+ self .cflags = ['-O3' , '-g' , '-fPIC' , '-Wall' , f '-std={ self . std } ' ]
204205 self .ldflags = ['-shared' ]
205206
206207 self .include_dirs = []
@@ -252,6 +253,10 @@ def version(self):
252253
253254 return version
254255
256+ @property
257+ def std (self ):
258+ return 'c++14' if self ._cpp else 'c99'
259+
255260 def get_version (self ):
256261 result , stdout , stderr = call_capture_output ((self .cc , "--version" ))
257262 if result != 0 :
@@ -486,16 +491,16 @@ def __init_finalize__(self, **kwargs):
486491 language = kwargs .pop ('language' , configuration ['language' ])
487492 platform = kwargs .pop ('platform' , configuration ['platform' ])
488493
489- if isinstance ( platform , NvidiaDevice ) :
490- self .cflags .remove ('-std=c99 ' )
494+ if platform is NVIDIAX :
495+ self .cflags .remove (f '-std={ self . std } ' )
491496 # Add flags for OpenMP offloading
492497 if language in ['C' , 'openmp' ]:
493498 cc = get_nvidia_cc ()
494499 if cc :
495500 self .cflags += ['-Xopenmp-target' , f'-march=sm_{ cc } ' ]
496501 self .ldflags += ['-fopenmp' , '-fopenmp-targets=nvptx64-nvidia-cuda' ]
497502 elif platform is AMDGPUX :
498- self .cflags .remove ('-std=c99 ' )
503+ self .cflags .remove (f '-std={ self . std } ' )
499504 # Add flags for OpenMP offloading
500505 if language in ['C' , 'openmp' ]:
501506 self .ldflags += ['-target' , 'x86_64-pc-linux-gnu' ]
@@ -558,9 +563,9 @@ def __init_finalize__(self, **kwargs):
558563 self .ldflags += ['-fopenmp' ]
559564
560565 if isinstance (platform , NvidiaDevice ):
561- self .cflags .remove ('-std=c99 ' )
566+ self .cflags .remove (f '-std={ self . std } ' )
562567 elif platform is AMDGPUX :
563- self .cflags .remove ('-std=c99 ' )
568+ self .cflags .remove (f '-std={ self . std } ' )
564569 # Add flags for OpenMP offloading
565570 if language in ['C' , 'openmp' ]:
566571 self .ldflags += ['-target' , 'x86_64-pc-linux-gnu' ]
@@ -595,15 +600,15 @@ def __lookup_cmds__(self):
595600
596601class PGICompiler (Compiler ):
597602
598- _cpp = True
603+ default_cpp = True
599604
600605 def __init_finalize__ (self , ** kwargs ):
601606
602- self .cflags .remove ('-std=c99 ' )
607+ self .cflags .remove (f '-std={ self . std } ' )
603608 self .cflags .remove ('-O3' )
604609 self .cflags .remove ('-Wall' )
605610
606- self .cflags .append ('-std=c++14 ' )
611+ self .cflags .append (f '-std={ self . std } ' )
607612
608613 language = kwargs .pop ('language' , configuration ['language' ])
609614 platform = kwargs .pop ('platform' , configuration ['platform' ])
@@ -648,14 +653,14 @@ def __lookup_cmds__(self):
648653
649654class CudaCompiler (Compiler ):
650655
651- _cpp = True
656+ default_cpp = True
652657
653658 def __init_finalize__ (self , ** kwargs ):
654659
655- self .cflags .remove ('-std=c99 ' )
660+ self .cflags .remove (f '-std={ self . std } ' )
656661 self .cflags .remove ('-Wall' )
657662 self .cflags .remove ('-fPIC' )
658- self .cflags .extend (['-std=c++14 ' , '-Xcompiler' , '-fPIC' ])
663+ self .cflags .extend ([f '-std={ self . std } ' , '-Xcompiler' , '-fPIC' ])
659664
660665 if configuration ['mpi' ]:
661666 # We rather use `nvcc` to compile MPI, but for this we have to
@@ -722,14 +727,14 @@ def __lookup_cmds__(self):
722727
723728class HipCompiler (Compiler ):
724729
725- _cpp = True
730+ default_cpp = True
726731
727732 def __init_finalize__ (self , ** kwargs ):
728733
729- self .cflags .remove ('-std=c99 ' )
734+ self .cflags .remove (f '-std={ self . std } ' )
730735 self .cflags .remove ('-Wall' )
731736 self .cflags .remove ('-fPIC' )
732- self .cflags .extend (['-std=c++14 ' , '-fPIC' ])
737+ self .cflags .extend ([f '-std={ self . std } ' , '-fPIC' ])
733738
734739 if configuration ['mpi' ]:
735740 # We rather use `hipcc` to compile MPI, but for this we have to
@@ -883,7 +888,7 @@ def __lookup_cmds__(self):
883888
884889class SyclCompiler (OneapiCompiler ):
885890
886- _cpp = True
891+ default_cpp = True
887892
888893 def __init_finalize__ (self , ** kwargs ):
889894 IntelCompiler .__init_finalize__ (self , ** kwargs )
@@ -894,7 +899,7 @@ def __init_finalize__(self, **kwargs):
894899 if language != 'sycl' :
895900 warning ("Expected language sycl with SyclCompiler" )
896901
897- self .cflags .remove ('-std=c99 ' )
902+ self .cflags .remove (f '-std={ self . std } ' )
898903 self .cflags .append ('-fsycl' )
899904
900905 self .cflags .remove ('-g' ) # -g disables some optimizations in IGC
@@ -950,7 +955,7 @@ def __new__(cls, *args, **kwargs):
950955 obj = super ().__new__ (cls )
951956 # Keep base to initialize accordingly
952957 obj ._base = kwargs .pop ('base' , _base )
953- obj ._cpp = obj ._base ._cpp
958+ obj .default_cpp = obj ._base .default_cpp
954959
955960 return obj
956961
0 commit comments