From 4ac64e6cd88bc0216c6c77e0d50d56287300f7da Mon Sep 17 00:00:00 2001 From: Justin S <3630356+codeandkey@users.noreply.github.com> Date: Wed, 5 Jun 2019 04:43:11 -0500 Subject: [PATCH] add C standard flags to compiler classes (#11618) * add c99_flag, c11_flag to compiler class * implement c99_flag, c11_flag for gcc * implement c99_flag, c11_flag for arm * implement c99_flag for cce * implement c99_flag, c11_flag for clang * implement c99_flag, c11_flag for intel * implement c99_flag, c11_flag for xl --- lib/spack/spack/compiler.py | 18 ++++++++++++++++++ lib/spack/spack/compilers/arm.py | 8 ++++++++ lib/spack/spack/compilers/cce.py | 4 ++++ lib/spack/spack/compilers/clang.py | 14 ++++++++++++++ lib/spack/spack/compilers/gcc.py | 18 ++++++++++++++++++ lib/spack/spack/compilers/intel.py | 20 ++++++++++++++++++++ lib/spack/spack/compilers/xl.py | 8 ++++++++ 7 files changed, 90 insertions(+) diff --git a/lib/spack/spack/compiler.py b/lib/spack/spack/compiler.py index d5cb2cc47d..37d36166ec 100644 --- a/lib/spack/spack/compiler.py +++ b/lib/spack/spack/compiler.py @@ -195,6 +195,24 @@ def cxx17_flag(self): "the C++17 standard", "cxx17_flag") + # This property should be overridden in the compiler subclass if + # C99 is supported by that compiler + @property + def c99_flag(self): + # If it is not overridden, assume it is not supported and warn the user + raise UnsupportedCompilerFlag(self, + "the C99 standard", + "c99_flag") + + # This property should be overridden in the compiler subclass if + # C11 is supported by that compiler + @property + def c11_flag(self): + # If it is not overridden, assume it is not supported and warn the user + raise UnsupportedCompilerFlag(self, + "the C11 standard", + "c11_flag") + # # Compiler classes have methods for querying the version of # specific compiler executables. This is used when discovering compilers. diff --git a/lib/spack/spack/compilers/arm.py b/lib/spack/spack/compilers/arm.py index 4b3aa70f2b..4892c5a63d 100644 --- a/lib/spack/spack/compilers/arm.py +++ b/lib/spack/spack/compilers/arm.py @@ -53,6 +53,14 @@ def cxx14_flag(self): def cxx17_flag(self): return "-std=c++1z" + @property + def c99_flag(self): + return "-std=c99" + + @property + def c11_flag(self): + return "-std=c11" + @property def pic_flag(self): return "-fPIC" diff --git a/lib/spack/spack/compilers/cce.py b/lib/spack/spack/compilers/cce.py index 2941ed2c11..349ed394d7 100644 --- a/lib/spack/spack/compilers/cce.py +++ b/lib/spack/spack/compilers/cce.py @@ -42,6 +42,10 @@ def openmp_flag(self): def cxx11_flag(self): return "-h std=c++11" + @property + def c99_flag(self): + return "-h c99" + @property def pic_flag(self): return "-h PIC" diff --git a/lib/spack/spack/compilers/clang.py b/lib/spack/spack/compilers/clang.py index 811e465ad3..658884b5de 100644 --- a/lib/spack/spack/compilers/clang.py +++ b/lib/spack/spack/compilers/clang.py @@ -157,6 +157,20 @@ def cxx17_flag(self): else: return "-std=c++17" + @property + def c99_flag(self): + return '-std=c99' + + @property + def c11_flag(self): + if self.version < ver('6.1.0'): + raise UnsupportedCompilerFlag(self, + "the C11 standard", + "c11_flag", + "< 3.3") + else: + return "-std=c11" + @property def pic_flag(self): return "-fPIC" diff --git a/lib/spack/spack/compilers/gcc.py b/lib/spack/spack/compilers/gcc.py index 5dc0b514b7..4d3c319c85 100644 --- a/lib/spack/spack/compilers/gcc.py +++ b/lib/spack/spack/compilers/gcc.py @@ -87,6 +87,24 @@ def cxx17_flag(self): else: return "-std=c++17" + @property + def c99_flag(self): + if self.version < ver('4.5'): + raise UnsupportedCompilerFlag(self, + "the C99 standard", + "c99_flag", + "< 4.5") + return "-std=c99" + + @property + def c11_flag(self): + if self.version < ver('4.7'): + raise UnsupportedCompilerFlag(self, + "the C11 standard", + "c11_flag", + "< 4.7") + return "-std=c11" + @property def pic_flag(self): return "-fPIC" diff --git a/lib/spack/spack/compilers/intel.py b/lib/spack/spack/compilers/intel.py index 7485471241..c0fb5ebe51 100644 --- a/lib/spack/spack/compilers/intel.py +++ b/lib/spack/spack/compilers/intel.py @@ -65,6 +65,26 @@ def cxx14_flag(self): else: return "-std=c++14" + @property + def c99_flag(self): + if self.version < ver('12'): + raise UnsupportedCompilerFlag(self, + "the C99 standard", + "c99_flag", + "< 12") + else: + return "-std=c99" + + @property + def c11_flag(self): + if self.version < ver('16'): + raise UnsupportedCompilerFlag(self, + "the C11 standard", + "c11_flag", + "< 16") + else: + return "-std=c1x" + @property def pic_flag(self): return "-fPIC" diff --git a/lib/spack/spack/compilers/xl.py b/lib/spack/spack/compilers/xl.py index acedd2fdb8..6e33075408 100644 --- a/lib/spack/spack/compilers/xl.py +++ b/lib/spack/spack/compilers/xl.py @@ -43,6 +43,14 @@ def cxx11_flag(self): else: return "-qlanglvl=extended0x" + @property + def c99_flag(self): + return '-std=c99' + + @property + def c11_flag(self): + return '-std=c11' + @property def pic_flag(self): return "-qpic"