aboutsummaryrefslogtreecommitdiffstats
path: root/testing/libtorrent-rasterbar/cxx14.patch
blob: 49a6633805c8563efc321a50e43564e8a9e4a553 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
From 3276484d3310e69d032602634afbc1b126112d2d Mon Sep 17 00:00:00 2001
From: Nam Nguyen <namn@berkeley.edu>
Date: Thu, 14 Jan 2021 21:27:14 +0000
Subject: [PATCH] add --with-cxx-standard=14 configure switch C++ standard is
 specified by 11, 14 or 17. Either AX_CXX_COMPILE_STDCXX_11 or
 AX_CXX_COMPILE_STDCXX are called appropriately.

---
 configure.ac | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 0b9b0c446b..3fa925b1fa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -144,7 +144,49 @@ AS_ECHO "Checking for boost libraries:"
 
 AX_BOOST_BASE([1.58])
 
-AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])
+AC_ARG_WITH(
+  [cxx-standard],
+  [AS_HELP_STRING(
+    [--with-cxx-standard[=ARG]],
+    [specify C++ standard (e.g., 11, 14 or 17) [default=11]])],
+  [[ARG_CXX_STANDARD=$withval]],
+  [[ARG_CXX_STANDARD=default]]
+)
+
+AC_MSG_CHECKING([which c++ standard to use])
+if test "x${ARG_CXX_STANDARD}" = "x17" ; then
+  AX_CXX_COMPILE_STDCXX(17, [noext], [mandatory])
+elif test "x${ARG_CXX_STANDARD}" = "x14" ; then
+  AX_CXX_COMPILE_STDCXX(14, [noext], [mandatory])
+elif test "x${ARG_CXX_STANDARD}" = "x11" ; then
+  AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])
+elif test "x${ARG_CXX_STANDARD}" != "xdefault" -a "${ARG_CXX_STANDARD}" -lt "11" ; then
+  dnl force 11 if user specified out of bounds, regardless of compiler default
+  ARG_CXX_STANDARD="11"
+  AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])
+elif test "x${ARG_CXX_STANDARD}" != "xdefault" -a "${ARG_CXX_STANDARD}" -gt "17" ; then
+  dnl force 11 if user specified out of bounds, regardless of compiler default
+  ARG_CXX_STANDARD="11"
+  AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])
+else
+  dnl nothing specified so use compiler default
+
+  echo '#include <iostream>' > cpp_standard.cpp
+  echo 'using std::cout; using std::endl; int main() { switch (__cplusplus) { case 201103L: cout << 11 << endl; break; case 201402L: cout << 14 << endl; break; case 201703L: cout << 17 << endl; break; default: cout << 1 << endl; } }' >> cpp_standard.cpp
+  ${CXX} cpp_standard.cpp -o cpp_standard
+  DEFAULT_CXX_STANDARD=`./cpp_standard`
+  echo $DEFAULT_CXX_STANDARD
+  if test "x${DEFAULT_CXX_STANDARD}" = "x17" ; then
+    ARG_CXX_STANDARD="17"
+    AX_CXX_COMPILE_STDCXX(17, [noext], [mandatory])
+  elif test "x${DEFAULT_CXX_STANDARD}" = "x14" ; then
+    ARG_CXX_STANDARD="14"
+    AX_CXX_COMPILE_STDCXX(14, [noext], [mandatory])
+  else
+    ARG_CXX_STANDARD="11"
+    AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])
+  fi
+fi
 
 AX_BOOST_SYSTEM()
 AS_IF([test -z "$BOOST_SYSTEM_LIB"],
@@ -590,6 +632,7 @@ Build options:
   debug build:          ${ARG_ENABLE_DEBUG:-no}
   invariant checks:     ${ARG_ENABLE_INVARIANT:-no}
   logging support:      ${ARG_ENABLE_LOGGING:-yes}
+  cxx standard:         ${ARG_CXX_STANDARD:-default}
 
 Features:
   encryption support:   ${ARG_ENABLE_ENCRYPTION:-yes}