@@ -445,6 +445,12 @@ add_option("experimental-decimal-support",
445445 nargs = '?' ,
446446)
447447
448+ add_option ("cxx-std" ,
449+ choices = ["11" , "14" ],
450+ default = "11" ,
451+ help = "Select the C++ langauge standard to build with" ,
452+ )
453+
448454def find_mongo_custom_variables ():
449455 files = []
450456 for path in sys .path :
@@ -1854,13 +1860,17 @@ def doConfigure(myenv):
18541860 conf .Finish ()
18551861
18561862 if not myenv .ToolchainIs ('msvc' ):
1857- if not AddToCXXFLAGSIfSupported (myenv , '-std=c++11' ):
1858- myenv .ConfError ('Compiler does not honor -std=c++11' )
1863+ if get_option ('cxx-std' ) == "11" :
1864+ if not AddToCXXFLAGSIfSupported (myenv , '-std=c++11' ):
1865+ myenv .ConfError ('Compiler does not honor -std=c++11' )
1866+ elif get_option ('cxx-std' ) == "14" :
1867+ if not AddToCXXFLAGSIfSupported (myenv , '-std=c++14' ):
1868+ myenv .ConfError ('Compiler does not honor -std=c++14' )
18591869 if not AddToCFLAGSIfSupported (myenv , '-std=c99' ):
18601870 myenv .ConfError ("C++11 mode selected for C++ files, but can't enable C99 for C files" )
18611871
18621872 if using_system_version_of_cxx_libraries ():
1863- print ( 'WARNING: System versions of C++ libraries must be compiled with C++11 support' )
1873+ print ( 'WARNING: System versions of C++ libraries must be compiled with C++11/14 support' )
18641874
18651875 # We appear to have C++11, or at least a flag to enable it. Check that the declared C++
18661876 # language level is not less than C++11, and that we can at least compile an 'auto'
@@ -1883,13 +1893,35 @@ def doConfigure(myenv):
18831893 context .Result (ret )
18841894 return ret
18851895
1896+ def CheckCxx14 (context ):
1897+ test_body = """
1898+ #ifndef _MSC_VER
1899+ #if __cplusplus < 201402L
1900+ #error
1901+ #endif
1902+ #endif
1903+ auto DeducedReturnTypesAreACXX14Feature() {
1904+ return 0;
1905+ }
1906+ """
1907+
1908+ context .Message ('Checking for C++14... ' )
1909+ ret = context .TryCompile (textwrap .dedent (test_body ), ".cpp" )
1910+ context .Result (ret )
1911+ return ret
1912+
18861913 conf = Configure (myenv , help = False , custom_tests = {
18871914 'CheckCxx11' : CheckCxx11 ,
1915+ 'CheckCxx14' : CheckCxx14 ,
18881916 })
18891917
18901918 if not conf .CheckCxx11 ():
18911919 myenv .ConfError ('C++11 support is required to build MongoDB' )
18921920
1921+ if get_option ('cxx-std' ) == "14" :
1922+ if not conf .CheckCxx14 ():
1923+ myenv .ConfError ('C++14 does not appear to work with the current toolchain' )
1924+
18931925 conf .Finish ()
18941926
18951927 def CheckMemset_s (context ):
0 commit comments