@@ -70,21 +70,21 @@ def all_files_from(dir, ext=''):
7070shared_data = all_files_from ('share' )
7171
7272copt = {
73- 'gcc' : ['-O2' ,'-std=c++11 ' ,'-fvisibility=hidden' ,'-fopenmp' ],
74- 'gcc w/ GPU' : ['-O2' ,'-std=c++11 ' ,'-fvisibility=hidden' ,'-fopenmp' ,'-foffload=nvptx-none' ,'-DGALSIM_USE_GPU' ],
75- 'icc' : ['-O2' ,'-vec-report0' ,'-std=c++11 ' ,'-openmp' ],
76- 'clang' : ['-O2' ,'-std=c++11 ' ,
73+ 'gcc' : ['-O2' ,'-std=c++14 ' ,'-fvisibility=hidden' ,'-fopenmp' ],
74+ 'gcc w/ GPU' : ['-O2' ,'-std=c++14 ' ,'-fvisibility=hidden' ,'-fopenmp' ,'-foffload=nvptx-none' ,'-DGALSIM_USE_GPU' ],
75+ 'icc' : ['-O2' ,'-vec-report0' ,'-std=c++14 ' ,'-openmp' ],
76+ 'clang' : ['-O2' ,'-std=c++14 ' ,
7777 '-Wno-shorten-64-to-32' ,'-fvisibility=hidden' ,'-stdlib=libc++' ],
78- 'clang w/ OpenMP' : ['-O2' ,'-std=c++11 ' ,'-fopenmp' ,
78+ 'clang w/ OpenMP' : ['-O2' ,'-std=c++14 ' ,'-fopenmp' ,
7979 '-Wno-shorten-64-to-32' ,'-fvisibility=hidden' ,'-stdlib=libc++' ],
80- 'clang w/ Intel OpenMP' : ['-O2' ,'-std=c++11 ' ,'-Xpreprocessor' ,'-fopenmp' ,
80+ 'clang w/ Intel OpenMP' : ['-O2' ,'-std=c++14 ' ,'-Xpreprocessor' ,'-fopenmp' ,
8181 '-Wno-shorten-64-to-32' ,'-fvisibility=hidden' ,'-stdlib=libc++' ],
82- 'clang w/ manual OpenMP' : ['-O2' ,'-std=c++11 ' ,'-Xpreprocessor' ,'-fopenmp' ,
82+ 'clang w/ manual OpenMP' : ['-O2' ,'-std=c++14 ' ,'-Xpreprocessor' ,'-fopenmp' ,
8383 '-Wno-shorten-64-to-32' ,'-fvisibility=hidden' ,'-stdlib=libc++' ],
84- 'clang w/ GPU' : ['-O2' ,'-msse2' ,'-std=c++11 ' ,'-fopenmp' ,'-fopenmp-targets=nvptx64-nvidia-cuda' ,
84+ 'clang w/ GPU' : ['-O2' ,'-msse2' ,'-std=c++14 ' ,'-fopenmp' ,'-fopenmp-targets=nvptx64-nvidia-cuda' ,
8585 '-Wno-openmp-mapping' ,'-Wno-unknown-cuda-version' ,
8686 '-Wno-shorten-64-to-32' ,'-fvisibility=hidden' , '-DGALSIM_USE_GPU' ],
87- 'nvc++' : ['-O2' ,'-std=c++11 ' ,'-mp=gpu' ,'-DGALSIM_USE_GPU' ],
87+ 'nvc++' : ['-O2' ,'-std=c++14 ' ,'-mp=gpu' ,'-DGALSIM_USE_GPU' ],
8888 'unknown' : [],
8989}
9090lopt = {
@@ -684,17 +684,29 @@ def try_cpp(compiler, cflags=[], lflags=[], prepend=None):
684684 """ )
685685 return try_compile (cpp_code , compiler , cflags , lflags , prepend = prepend )
686686
687- def try_cpp11 (compiler , cflags = [], lflags = [], check_warning = False ):
688- """Check if compiling c++11 code with the given compiler works properly.
687+ def try_cpp14 (compiler , cflags = [], lflags = [], check_warning = False ):
688+ """Check if compiling c++14 code with the given compiler works properly.
689689 """
690690 from textwrap import dedent
691691 cpp_code = dedent ("""
692692 #include <iostream>
693- #include <forward_list>
693+ #include <forward_list> // c++11 feature
694694 #include <cmath>
695+ #include <memory>
695696
696697 int main(void) {
698+ // c++11 feature
697699 std::cout << std::tgamma(1.3) << std::endl;
700+
701+ // c++14 feature
702+ auto func = [](int i) { return i + 5; };
703+ std::cout << "Result of func(3): " << func(3) << std::endl;
704+
705+ // A more sophisticated c++14 feature
706+ std::unique_ptr<int> ptr(new int(10));
707+ auto lambda = [value = std::move(ptr)]() { if (value) return *value; };
708+ std::cout << "Value from lambda(): " << lambda() << std::endl;
709+
698710 return 0;
699711 }
700712 """ )
@@ -822,7 +834,7 @@ def fix_compiler(compiler, njobs):
822834 extra_cflags = copt [comp_type ]
823835 extra_lflags = lopt [comp_type ]
824836
825- success = try_cpp11 (compiler , extra_cflags , extra_lflags )
837+ success = try_cpp14 (compiler , extra_cflags , extra_lflags )
826838 if not success :
827839 # In case libc++ doesn't work, try letting the system use the default stdlib
828840 try :
@@ -831,16 +843,16 @@ def fix_compiler(compiler, njobs):
831843 except (AttributeError , ValueError ):
832844 pass
833845 else :
834- success = try_cpp11 (compiler , extra_cflags , extra_lflags )
846+ success = try_cpp14 (compiler , extra_cflags , extra_lflags )
835847 if not success :
836- print ('The compiler %s with flags %s did not successfully compile C++11 code' %
848+ print ('The compiler %s with flags %s did not successfully compile C++14 code' %
837849 (cc , ' ' .join (extra_cflags )))
838- raise OSError ("Compiler is not C++-11 compatible" )
850+ raise OSError ("Compiler is not C++-14 compatible" )
839851
840852 # Also see if adding -msse2 works (and doesn't give a warning)
841853 if '-msse2' not in extra_cflags :
842854 extra_cflags .append ('-msse2' )
843- if try_cpp11 (compiler , extra_cflags , extra_lflags , check_warning = True ):
855+ if try_cpp14 (compiler , extra_cflags , extra_lflags , check_warning = True ):
844856 print ('Using cflag -msse2' )
845857 else :
846858 print ('warning with -msse2.' )
0 commit comments