-
Notifications
You must be signed in to change notification settings - Fork 3
/
acsm_cxx_compiler_standard.m4
167 lines (154 loc) · 6.67 KB
/
acsm_cxx_compiler_standard.m4
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# SYNOPSIS
#
# ACSM_CXX_COMPILER_STANDARD([MIN_VERSION], [MAX_VERSION], [ext|noext])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for a
# version of the C++ standard in between the specified MIN_VERSION
# (which defaults to 2011) and MAX_VERSION (which defaults to 2017).
#
# These defaults may be updated by --cxx-std-min, --cxx-std-max, or
# --cxx-std (to set both) options to configure.
#
# Setting a MAX_VERSION below a compiler default standard does not
# currently override that standard.
#
# Currently this macro is capable of searching for C++11, C++14,
# and/or C++17 support.
#
# The third argument, if specified, indicates whether you insist on
# extended modes (e.g. -std=gnu++14) or strict conformance modes
# (e.g. -std=c++14). If neither is specified, you get whatever
# works, with preference for an extended mode.
#
# If necessary, add switches to CXX and CXXCPP to enable support for
# a detected standard. If no acceptable standard is detected, error
# out.
#
# This macro makes "callbacks" to a user macro, ACSM_TEST_CXX_ALL,
# which can be used to add additional C++ required-feature tests.
# The user implementation of ACSM_TEST_CXX_ALL should set
# have_cxx_all=yes if no tests fail, or have_cxx_all=no otherwise.
#
# LICENSE
#
# Copyright (c) 2021 Roy Stogner <[email protected]>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
AC_DEFUN([ACSM_CXX_COMPILER_STANDARD], [dnl
acsm_CXX_STD_MIN="$1"
m4_if([$1], [], [acsm_CXX_STD_MIN=2011])
acsm_CXX_STD_MAX="$2"
m4_if([$2], [], [acsm_CXX_STD_MAX=2017])
m4_if([$3], [], [],
[$3], [ext], [],
[$3], [noext], [],
[m4_fatal([invalid third argument `$3' to ACSM_CXX_COMPILER_STANDARD])])dnl
# --------------------------------------------------------------
# How new a C++ standard should we ask for?
# --------------------------------------------------------------
AC_ARG_WITH([cxx-std-max],
AS_HELP_STRING([--with-cxx-std-max@<:@=ARG@:>@],
[Maximum C++ standard year to request, 2011+; this does not override your compiler default]),
[
AS_IF([test "$withval" -ge 2011],
[acsm_CXX_STD_MAX="$withval"],
[AC_MSG_ERROR(${withval} for --with-cxx-std-max must be an integer >= 2011)])
])
# --------------------------------------------------------------
# How new a C++ standard should we insist upon?
# --------------------------------------------------------------
AC_ARG_WITH([cxx-std-min],
AS_HELP_STRING([--with-cxx-std-min@<:@=ARG@:>@],
[Minimum C++ standard year to require; default 2011]),
[
AS_IF([test "$withval" -ge 2011],
[acsm_CXX_STD_MIN="$withval"],
[AC_MSG_ERROR(${withval} for --with-cxx-std-min must be an integer >= 2011)])
AS_IF([test "$withval" -gt 2017],
[AC_MSG_ERROR(${withval} for --with-cxx-std-min must be an integer <= 2017)])
])
# --------------------------------------------------------------
# Semantic sugar to insist upon a specific standard easily
# --------------------------------------------------------------
AC_ARG_WITH([cxx-std],
AS_HELP_STRING([--with-cxx-std@<:@=ARG@:>@],
[Exact C++ standard year to require]),
[
AS_IF([test "$withval" -ge 2011],
[acsm_CXX_STD_MAX="$withval"
acsm_CXX_STD_MIN="$withval"],
[AC_MSG_ERROR(${withval} for --with-cxx-std must be an integer >= 2011)])
])
AS_IF([test "$acsm_CXX_STD_MAX" -ge "$acsm_CXX_STD_MIN"],
[AC_MSG_NOTICE([Seeking a C++ standard between "$acsm_CXX_STD_MIN" and "$acsm_CXX_STD_MAX"])],
[AC_MSG_ERROR(Maximum C++ standard "$acsm_CXX_STD_MAX" must be at least minimum "$acsm_CXX_STD_MIN")])
acsm_found_cxx=0
acsm_cxx_version=0
acsm_backup_CXX="$CXX"
acsm_backup_CXXCPP="$CXXCPP"
dnl We test for every standard in our range, so that later standards
dnl still "count" as earlier standards too.
AS_IF([test 2017 -le "$acsm_CXX_STD_MAX"],
[
AS_IF([test 2017 -gt "$acsm_CXX_STD_MIN"],
[AX_CXX_COMPILE_STDCXX([17],[$3],[optional])],
[AX_CXX_COMPILE_STDCXX([17],[$3],[mandatory])])
AS_IF([test "$HAVE_CXX17" = "1" -a $acsm_found_cxx -eq 0],
[ACSM_TEST_CXX_ALL])
AS_IF([test "$HAVE_CXX17" = "1" -a "x$have_cxx_all" = xyes],
[
AC_MSG_NOTICE([Found C++17 standard support])
AS_IF([test $acsm_found_cxx -eq 0],
[acsm_cxx_version=17])
acsm_found_cxx=1],
[CXX="$acsm_backup_CXX"
CXXCPP="$acsm_backup_CXXCPP"
AS_IF([test "$HAVE_CXX17" = "0"],
[AC_MSG_NOTICE([Did not find C++17 standard support])])])
])
AS_IF([test 2014 -le "$acsm_CXX_STD_MAX"],
[
AS_IF([test 2014 -gt "$acsm_CXX_STD_MIN"],
[AX_CXX_COMPILE_STDCXX([14],[$3],[optional])],
[AX_CXX_COMPILE_STDCXX([14],[$3],[mandatory])])
AS_IF([test "$HAVE_CXX14" = "1" -a $acsm_found_cxx -eq 0],
[ACSM_TEST_CXX_ALL])
AS_IF([test "$HAVE_CXX14" = "1" -a "x$have_cxx_all" = xyes],
[
AC_MSG_NOTICE([Found C++14 standard support])
AS_IF([test $acsm_found_cxx -eq 0],
[acsm_cxx_version=14])
acsm_found_cxx=1],
[CXX="$acsm_backup_CXX"
CXXCPP="$acsm_backup_CXXCPP"
AS_IF([test "$HAVE_CXX14" = "0"],
[AC_MSG_NOTICE([Did not find C++14 standard support])])])
])
AS_IF([test 2011 -le "$acsm_CXX_STD_MAX"],
[
AS_IF([test 2011 -gt "$acsm_CXX_STD_MIN"],
[AX_CXX_COMPILE_STDCXX([11],[$3],[optional])],
[AX_CXX_COMPILE_STDCXX([11],[$3],[mandatory])])
AS_IF([test "$HAVE_CXX11" = "1" -a $acsm_found_cxx -eq 0],
[ACSM_TEST_CXX_ALL])
AS_IF([test "$HAVE_CXX11" = "1" -a "x$have_cxx_all" = xyes],
[
AC_MSG_NOTICE([Found C++11 standard support])
AS_IF([test $acsm_found_cxx -eq 0],
[acsm_cxx_version=11])
acsm_found_cxx=1],
[CXX="$acsm_backup_CXX"
CXXCPP="$acsm_backup_CXXCPP"
AS_IF([test "$HAVE_CXX11" = "0"],
[AC_MSG_NOTICE([Did not find C++11 standard support])])])
])
AS_IF([test "$acsm_found_cxx" = "1"],
[AC_MSG_NOTICE([Using support for C++$acsm_cxx_version standard])],
[AC_MSG_ERROR([Could not find support for an acceptable C++ standard])])
])