-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathacsm_cxx_compiler_standard.m4
More file actions
136 lines (125 loc) · 5.75 KB
/
acsm_cxx_compiler_standard.m4
File metadata and controls
136 lines (125 loc) · 5.75 KB
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
# 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 2023).
#
# 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.
#
# 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-2026 Roy Stogner <Roy.Stogner@inl.gov>
#
# 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=2023])
m4_if([$3], [], [],
[$3], [ext], [],
[$3], [noext], [],
[$3], [defaultnoext], [],
[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 2023],
[AC_MSG_ERROR(${withval} for --with-cxx-std-min must be an integer <= 2023)])
])
# --------------------------------------------------------------
# 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.
m4_foreach_w([cxx_year], [23 20 17 14 11], [
CXX_YEAR=cxx_year
AS_IF([test "20$CXX_YEAR" -le "$acsm_CXX_STD_MAX"],
[AS_IF([test $acsm_found_cxx -eq 0],
[AS_IF([test "20$CXX_YEAR" -gt "$acsm_CXX_STD_MIN"],
[AX_CXX_COMPILE_STDCXX(cxx_year,[$3],[optional])],
[AX_CXX_COMPILE_STDCXX(cxx_year,[$3],[mandatory])])
eval "HAVE_TESTED_CXX=\${HAVE_CXX$CXX_YEAR}"
AS_IF([test "$HAVE_TESTED_CXX" = "1" -a $acsm_found_cxx -eq 0],
[ACSM_TEST_CXX_ALL])
AS_IF([test "$HAVE_TESTED_CXX" = "1" -a "x$have_cxx_all" = xyes],
[AC_MSG_NOTICE([Found C++$CXX_YEAR standard support])
AS_IF([test $acsm_found_cxx -eq 0],
[acsm_cxx_version=$CXX_YEAR])
acsm_found_cxx=1],
[CXX="$acsm_backup_CXX"
CXXCPP="$acsm_backup_CXXCPP"
AS_IF([test "$HAVE_CXX$CXX_YEAR" = "0"],
[AC_MSG_NOTICE([Did not find C++$CXX_YEAR standard support])])])
],
dnl If we support a newer C++ standard, we basically support the older ones.
[eval "HAVE_CXX$CXX_YEAR=1"
AC_SUBST([HAVE_CXX]cxx_year)
]
)
])
])
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])])
])