diff options
Diffstat (limited to 'var/spack/repos/builtin/packages/cxx')
5 files changed, 82 insertions, 0 deletions
diff --git a/var/spack/repos/builtin/packages/cxx/package.py b/var/spack/repos/builtin/packages/cxx/package.py new file mode 100644 index 0000000000..0be36c3ae5 --- /dev/null +++ b/var/spack/repos/builtin/packages/cxx/package.py @@ -0,0 +1,38 @@ +# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +import os + + +class Cxx(Package): + """Virtual package for the C++ language.""" + homepage = 'https://isocpp.org/std/the-standard' + virtual = True + + def test(self): + test_source = self.test_suite.current_test_data_dir + + for test in os.listdir(test_source): + filepath = os.path.join(test_source, test) + exe_name = '%s.exe' % test + + cxx_exe = os.environ['CXX'] + + # standard options + # Hack to get compiler attributes + # TODO: remove this when compilers are dependencies + c_name = clang if self.spec.satisfies('llvm+clang') else self.name + c_spec = spack.spec.CompilerSpec(c_name, self.spec.version) + c_cls = spack.compilers.class_for_compiler_name(c_name) + compiler = c_cls(c_spec, None, None, ['fakecc', 'fakecxx']) + + cxx_opts = [compiler.cxx11_flag] if 'c++11' in test else [] + + cxx_opts += ['-o', exe_name, filepath] + compiled = self.run_test(cxx_exe, options=cxx_opts, installed=True) + + if compiled: + expected = ['Hello world', 'YES!'] + self.run_test(exe_name, expected=expected) diff --git a/var/spack/repos/builtin/packages/cxx/test/hello.c++ b/var/spack/repos/builtin/packages/cxx/test/hello.c++ new file mode 100644 index 0000000000..f0ad7caffb --- /dev/null +++ b/var/spack/repos/builtin/packages/cxx/test/hello.c++ @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main() +{ + printf ("Hello world from C++\n"); + printf ("YES!"); + + return 0; +} diff --git a/var/spack/repos/builtin/packages/cxx/test/hello.cc b/var/spack/repos/builtin/packages/cxx/test/hello.cc new file mode 100644 index 0000000000..2a85869996 --- /dev/null +++ b/var/spack/repos/builtin/packages/cxx/test/hello.cc @@ -0,0 +1,9 @@ +#include <iostream> +using namespace std; + +int main() +{ + cout << "Hello world from C++!" << endl; + cout << "YES!" << endl; + return (0); +} diff --git a/var/spack/repos/builtin/packages/cxx/test/hello.cpp b/var/spack/repos/builtin/packages/cxx/test/hello.cpp new file mode 100644 index 0000000000..b49db59f4a --- /dev/null +++ b/var/spack/repos/builtin/packages/cxx/test/hello.cpp @@ -0,0 +1,9 @@ +#include <iostream> +using namespace std; + +int main() +{ + cout << "Hello world from C++!" << endl; + cout << "YES!" << endl; + return (0); +} diff --git a/var/spack/repos/builtin/packages/cxx/test/hello_c++11.cc b/var/spack/repos/builtin/packages/cxx/test/hello_c++11.cc new file mode 100644 index 0000000000..10f57c3f75 --- /dev/null +++ b/var/spack/repos/builtin/packages/cxx/test/hello_c++11.cc @@ -0,0 +1,17 @@ +#include <iostream> +#include <regex> + +using namespace std; + +int main() +{ + auto func = [] () { cout << "Hello world from C++11" << endl; }; + func(); // now call the function + + std::regex r("st|mt|tr"); + std::cout << "std::regex r(\"st|mt|tr\")" << " match tr? "; + if (std::regex_match("tr", r) == 0) + std::cout << "NO!\n ==> Using pre g++ 4.9.2 libstdc++ which doesn't implement regex properly" << std::endl; + else + std::cout << "YES!\n ==> Correct libstdc++11 implementation of regex (4.9.2 or later)" << std::endl; +} |