3581 |
19 Jan 17 |
peter |
## $Id$ |
3581 |
19 Jan 17 |
peter |
2 |
# |
4101 |
22 Sep 21 |
peter |
# serial 7 (yat 0.20) |
3581 |
19 Jan 17 |
peter |
4 |
# |
3581 |
19 Jan 17 |
peter |
# see http://www.gnu.org/software/automake/manual/automake.html#Serials |
3581 |
19 Jan 17 |
peter |
6 |
# |
3581 |
19 Jan 17 |
peter |
# SYNOPSIS |
3581 |
19 Jan 17 |
peter |
8 |
# |
3937 |
16 Jul 20 |
peter |
# YAT_CXX11([search], [action-if-found], [action-if-not-found]) |
3591 |
20 Jan 17 |
peter |
# YAT_CXX_ATOMIC([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
3581 |
19 Jan 17 |
peter |
# YAT_CXX_RVALUE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
3666 |
25 Jul 17 |
peter |
# YAT_CXX_LOG2([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
3581 |
19 Jan 17 |
peter |
13 |
# |
3581 |
19 Jan 17 |
peter |
# DESCRIPTION |
3581 |
19 Jan 17 |
peter |
15 |
# |
3937 |
16 Jul 20 |
peter |
# Test whether $CXX supports cxx11 features |
3581 |
19 Jan 17 |
peter |
17 |
# |
3581 |
19 Jan 17 |
peter |
# LAST MODIFICATION |
3581 |
19 Jan 17 |
peter |
19 |
# |
3581 |
19 Jan 17 |
peter |
# $Date$ |
3581 |
19 Jan 17 |
peter |
21 |
# |
3581 |
19 Jan 17 |
peter |
# COPYLEFT |
3581 |
19 Jan 17 |
peter |
23 |
# |
4207 |
26 Aug 22 |
peter |
# Copyright (C) 2017, 2018, 2019, 2020, 2021 Peter Johansson |
3581 |
19 Jan 17 |
peter |
25 |
# |
3581 |
19 Jan 17 |
peter |
# This file is part of the yat library, http://dev.thep.lu.se/yat |
3581 |
19 Jan 17 |
peter |
27 |
# |
3581 |
19 Jan 17 |
peter |
# The yat library is free software; you can redistribute it and/or |
3581 |
19 Jan 17 |
peter |
# modify it under the terms of the GNU General Public License as |
3581 |
19 Jan 17 |
peter |
# published by the Free Software Foundation; either version 3 of the |
3581 |
19 Jan 17 |
peter |
# License, or (at your option) any later version. |
3581 |
19 Jan 17 |
peter |
32 |
# |
3581 |
19 Jan 17 |
peter |
# The yat library is distributed in the hope that it will be useful, |
3581 |
19 Jan 17 |
peter |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
3581 |
19 Jan 17 |
peter |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3581 |
19 Jan 17 |
peter |
# General Public License for more details. |
3581 |
19 Jan 17 |
peter |
37 |
# |
3581 |
19 Jan 17 |
peter |
# You should have received a copy of the GNU General Public License |
3581 |
19 Jan 17 |
peter |
# along with yat. If not, see <http://www.gnu.org/licenses/>. |
3581 |
19 Jan 17 |
peter |
40 |
# |
3581 |
19 Jan 17 |
peter |
41 |
|
3937 |
16 Jul 20 |
peter |
# YAT_CXX11([search], [action-if-found], [action-if-not-found]) |
3937 |
16 Jul 20 |
peter |
43 |
# |
3937 |
16 Jul 20 |
peter |
# Test whether $CXX is a C++11 compliant compiler. If not and search |
3937 |
16 Jul 20 |
peter |
# is 'yes', then search different switches to $CXX to see if |
3937 |
16 Jul 20 |
peter |
# compliance can be turned on. If a C++11 compliant compiler is found, |
3937 |
16 Jul 20 |
peter |
# AC_DEFINE HAVE_CXX11, set shell variable HAVE_CXX11 to 1 and |
3937 |
16 Jul 20 |
peter |
# AC_SUBST it. Otherwise set HAVE_CXX11 to 0 and execute |
3937 |
16 Jul 20 |
peter |
# action-if-not-found. |
3937 |
16 Jul 20 |
peter |
50 |
AC_DEFUN([YAT_CXX11], [ |
3937 |
16 Jul 20 |
peter |
51 |
|
3937 |
16 Jul 20 |
peter |
52 |
AC_MSG_CHECKING([whether $CXX supports C++11 features]) |
3937 |
16 Jul 20 |
peter |
53 |
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_11])], [ |
3937 |
16 Jul 20 |
peter |
54 |
AC_MSG_RESULT([yes]) |
3937 |
16 Jul 20 |
peter |
55 |
HAVE_CXX11=1 |
3937 |
16 Jul 20 |
peter |
56 |
AC_DEFINE([HAVE_CXX11], [1], [define if the compiler supports C++11 syntax]) |
3937 |
16 Jul 20 |
peter |
57 |
], [ |
3937 |
16 Jul 20 |
peter |
58 |
AC_MSG_RESULT([no]) |
3937 |
16 Jul 20 |
peter |
59 |
HAVE_CXX11=0 |
3937 |
16 Jul 20 |
peter |
60 |
AS_IF([test x"$1" = x"yes"], [ |
3937 |
16 Jul 20 |
peter |
# This macro sets HAVE_CXX11=1 if successful and AC_DEFINE |
4101 |
22 Sep 21 |
peter |
62 |
AX_CXX_COMPILE_STDCXX([11], [noext], [optional]) |
3937 |
16 Jul 20 |
peter |
63 |
]) |
3937 |
16 Jul 20 |
peter |
64 |
]) |
3937 |
16 Jul 20 |
peter |
65 |
AC_SUBST([HAVE_CXX11]) |
3937 |
16 Jul 20 |
peter |
# ACTION |
3937 |
16 Jul 20 |
peter |
67 |
AS_VAR_IF([HAVE_CXX11], [1], [$2], [$3]) |
3937 |
16 Jul 20 |
peter |
68 |
|
3937 |
16 Jul 20 |
peter |
69 |
]) # end of YAT_CXX11 |
3937 |
16 Jul 20 |
peter |
70 |
|
3937 |
16 Jul 20 |
peter |
71 |
|
3666 |
25 Jul 17 |
peter |
# YAT_CXX_ATOMIC([action-if-found], [action-if-not-found], [search-options]) |
3591 |
20 Jan 17 |
peter |
73 |
# |
3666 |
25 Jul 17 |
peter |
# Test whether $CXX supports std::atomic. If not and search-options is |
3666 |
25 Jul 17 |
peter |
# 'yes', try turning on support with a number of different |
3666 |
25 Jul 17 |
peter |
# switches. If a successful switch is found invoke shell |
3666 |
25 Jul 17 |
peter |
# action-if-found; else issue action-if-not-found. |
3591 |
20 Jan 17 |
peter |
78 |
AC_DEFUN([YAT_CXX_ATOMIC], |
3591 |
20 Jan 17 |
peter |
79 |
[ |
3591 |
20 Jan 17 |
peter |
80 |
YAT_CXX_TRY_CXX11([atomic], |
3591 |
20 Jan 17 |
peter |
81 |
[@%:@include <atomic>], |
3591 |
20 Jan 17 |
peter |
82 |
[std::atomic<bool> ready(false);], |
3666 |
25 Jul 17 |
peter |
83 |
[$1], [$2], [$3]) |
3591 |
20 Jan 17 |
peter |
84 |
]) |
3591 |
20 Jan 17 |
peter |
85 |
|
3591 |
20 Jan 17 |
peter |
86 |
|
3666 |
25 Jul 17 |
peter |
# YAT_CXX_RVALUE([action-if-found], [action-if-not-found], [search-options]) |
3591 |
20 Jan 17 |
peter |
88 |
# |
3666 |
25 Jul 17 |
peter |
# Test whether $CXX supports rvalue. If not and search-options is |
3666 |
25 Jul 17 |
peter |
# 'yes', try turning on support with a number of different |
3666 |
25 Jul 17 |
peter |
# switches. If a successful switch is found invoke shell |
3666 |
25 Jul 17 |
peter |
# action-if-found; else issue action-if-not-found. |
3581 |
19 Jan 17 |
peter |
93 |
AC_DEFUN([YAT_CXX_RVALUE], |
3591 |
20 Jan 17 |
peter |
94 |
[ |
3591 |
20 Jan 17 |
peter |
95 |
YAT_CXX_TRY_CXX11([rvalue], [ dnl header |
3591 |
20 Jan 17 |
peter |
96 |
@%:@include <utility> |
3591 |
20 Jan 17 |
peter |
97 |
|
3591 |
20 Jan 17 |
peter |
98 |
class MyClass |
3591 |
20 Jan 17 |
peter |
99 |
{ |
3591 |
20 Jan 17 |
peter |
100 |
public: |
3591 |
20 Jan 17 |
peter |
101 |
MyClass(void); |
3591 |
20 Jan 17 |
peter |
102 |
MyClass(const MyClass&); // copy constructor |
3591 |
20 Jan 17 |
peter |
103 |
MyClass(MyClass&&); // move constructor |
3591 |
20 Jan 17 |
peter |
104 |
MyClass& operator=(const MyClass&); // copy assignment |
3591 |
20 Jan 17 |
peter |
105 |
MyClass& operator=(MyClass&&); // move assignment |
3591 |
20 Jan 17 |
peter |
106 |
}; |
3591 |
20 Jan 17 |
peter |
107 |
],[ dnl body |
3591 |
20 Jan 17 |
peter |
108 |
MyClass mc; |
3591 |
20 Jan 17 |
peter |
109 |
MyClass mc2 = std::move(mc); |
3666 |
25 Jul 17 |
peter |
110 |
], [$1], [$2], [$3]) |
3666 |
25 Jul 17 |
peter |
111 |
]) |
3591 |
20 Jan 17 |
peter |
112 |
|
3640 |
03 May 17 |
peter |
113 |
|
3666 |
25 Jul 17 |
peter |
# YAT_CXX_LOG2([action-if-found], [action-if-not-found], [search-options]) |
3640 |
03 May 17 |
peter |
115 |
# |
3666 |
25 Jul 17 |
peter |
# Test whether $CXX supports std::log2. If not and search-options is |
3666 |
25 Jul 17 |
peter |
# 'yes', try turning on support with a number of different |
3666 |
25 Jul 17 |
peter |
# switches. If a successful switch is found invoke shell |
3666 |
25 Jul 17 |
peter |
# action-if-found; else issue action-if-not-found. |
3640 |
03 May 17 |
peter |
120 |
AC_DEFUN([YAT_CXX_LOG2], |
3640 |
03 May 17 |
peter |
121 |
[ |
3640 |
03 May 17 |
peter |
122 |
YAT_CXX_TRY_CXX11([log2], [ dnl header |
3640 |
03 May 17 |
peter |
123 |
@%:@include <cmath> |
3640 |
03 May 17 |
peter |
124 |
void foo(double x); |
3640 |
03 May 17 |
peter |
125 |
],[ dnl body |
3640 |
03 May 17 |
peter |
126 |
double x = std::log2(3.14); |
3640 |
03 May 17 |
peter |
127 |
foo(x); |
3666 |
25 Jul 17 |
peter |
128 |
], [$1], [$2], [$3]) |
3666 |
25 Jul 17 |
peter |
129 |
]) |
3640 |
03 May 17 |
peter |
130 |
|
3640 |
03 May 17 |
peter |
131 |
|
3730 |
10 Apr 18 |
peter |
# YAT_CXX_THROW_IF_NESTED([action-if-found], [action-if-not-found], |
3730 |
10 Apr 18 |
peter |
# [search-options]) |
3730 |
10 Apr 18 |
peter |
134 |
# |
3730 |
10 Apr 18 |
peter |
# Test whether $CXX supports std::nested_exception. If not and |
3730 |
10 Apr 18 |
peter |
# search-options is 'yes', try turning on support with a number of |
3730 |
10 Apr 18 |
peter |
# different switches. If a successful switch is found invoke shell |
3730 |
10 Apr 18 |
peter |
# action-if-found; else issue action-if-not-found. |
3730 |
10 Apr 18 |
peter |
139 |
AC_DEFUN([YAT_CXX_THROW_IF_NESTED], |
3730 |
10 Apr 18 |
peter |
140 |
[ |
3730 |
10 Apr 18 |
peter |
141 |
YAT_CXX_TRY_CXX11([throw_if_nested], [ dnl header |
3730 |
10 Apr 18 |
peter |
142 |
@%:@include <exception> |
3786 |
29 Jan 19 |
peter |
143 |
@%:@include <stdexcept> |
3730 |
10 Apr 18 |
peter |
144 |
void foo(void); |
3730 |
10 Apr 18 |
peter |
145 |
],[ dnl body |
3730 |
10 Apr 18 |
peter |
146 |
try { |
3730 |
10 Apr 18 |
peter |
147 |
foo(); |
3730 |
10 Apr 18 |
peter |
148 |
} |
3730 |
10 Apr 18 |
peter |
149 |
catch (std::runtime_error& e) { |
3786 |
29 Jan 19 |
peter |
150 |
std::throw_with_nested(std::runtime_error("foo")); |
3730 |
10 Apr 18 |
peter |
151 |
} |
3730 |
10 Apr 18 |
peter |
152 |
catch (std::exception& e) { |
3730 |
10 Apr 18 |
peter |
153 |
std::rethrow_if_nested(e); |
3730 |
10 Apr 18 |
peter |
154 |
} |
3730 |
10 Apr 18 |
peter |
155 |
], [$1], [$2], [$3]) |
3730 |
10 Apr 18 |
peter |
156 |
]) |
3730 |
10 Apr 18 |
peter |
157 |
|
3730 |
10 Apr 18 |
peter |
158 |
|
3666 |
25 Jul 17 |
peter |
# YAT_CXX_TRY_CXX11(feature, prologue, body, [action-if-success], |
3666 |
25 Jul 17 |
peter |
# [action-if-failed], [search-options]) |
3591 |
20 Jan 17 |
peter |
161 |
# |
3666 |
25 Jul 17 |
peter |
# Try c++11 feature, feature, by using code with prologue and body. If |
3666 |
25 Jul 17 |
peter |
# successful, issue shell code action-if-success, otherwise if |
3666 |
25 Jul 17 |
peter |
# search-options is 'yes' retry with different CXX options as detailed |
3666 |
25 Jul 17 |
peter |
# in YAT_CXX_SEARCH_CXX11; if none works, issue shell code action-if-failed. |
3591 |
20 Jan 17 |
peter |
166 |
AC_DEFUN([YAT_CXX_TRY_CXX11], |
3666 |
25 Jul 17 |
peter |
167 |
[ |
3666 |
25 Jul 17 |
peter |
168 |
AS_IF([test x"$6" = x"yes"], [ |
3666 |
25 Jul 17 |
peter |
169 |
YAT_CXX_SEARCH_CXX11([$1], [$2], [$3], [$4], [$5]) |
3666 |
25 Jul 17 |
peter |
170 |
], [ |
3666 |
25 Jul 17 |
peter |
171 |
AS_VAR_PUSHDEF([my_CACHE], [yat_cv_cxx_try_$1])dnl |
3666 |
25 Jul 17 |
peter |
172 |
AC_CACHE_CHECK([if $CXX supports $1], |
3666 |
25 Jul 17 |
peter |
173 |
[my_CACHE], |
3666 |
25 Jul 17 |
peter |
174 |
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$2], [$3])], |
3666 |
25 Jul 17 |
peter |
175 |
[my_CACHE=yes], |
3666 |
25 Jul 17 |
peter |
176 |
[my_CACHE=no])]) |
3666 |
25 Jul 17 |
peter |
177 |
AS_VAR_IF([my_CACHE], [yes], [$4], [$5]) |
3666 |
25 Jul 17 |
peter |
178 |
AS_VAR_POPDEF([my_CACHE]) |
3666 |
25 Jul 17 |
peter |
179 |
]) |
3666 |
25 Jul 17 |
peter |
180 |
]) #YAT_CXX_TRY_CXX11 |
3666 |
25 Jul 17 |
peter |
181 |
|
3666 |
25 Jul 17 |
peter |
182 |
|
3666 |
25 Jul 17 |
peter |
# YAT_CXX_SEARCH_CXX11([feature], [prologue], [body], [action-if-found], |
3666 |
25 Jul 17 |
peter |
# [action-if-not-found]) |
3666 |
25 Jul 17 |
peter |
185 |
# |
3666 |
25 Jul 17 |
peter |
# Try feature by using code with prologue and body, first with CXX and |
3666 |
25 Jul 17 |
peter |
# then by adding switches to CXX. If a switch is found with which code |
3666 |
25 Jul 17 |
peter |
# compiles, issue action-if-found; otherwise issue |
3666 |
25 Jul 17 |
peter |
# action-if-not-found. |
3666 |
25 Jul 17 |
peter |
190 |
AC_DEFUN([YAT_CXX_SEARCH_CXX11], |
3666 |
25 Jul 17 |
peter |
191 |
[ |
3666 |
25 Jul 17 |
peter |
192 |
AS_VAR_PUSHDEF([my_CACHE], [yat_cv_cxx_search_$1])dnl |
3591 |
20 Jan 17 |
peter |
193 |
AC_CACHE_CHECK([for $CXX option to enable $1], |
3591 |
20 Jan 17 |
peter |
194 |
[my_CACHE], |
3591 |
20 Jan 17 |
peter |
195 |
[my_CACHE=no |
3591 |
20 Jan 17 |
peter |
196 |
AS_VAR_PUSHDEF([my_save_CXX], [yat_cxx_$1_save_CXX])dnl |
3591 |
20 Jan 17 |
peter |
197 |
my_save_CXX="$CXX" |
3581 |
19 Jan 17 |
peter |
# From autoconf 'c.m4' we have |
3581 |
19 Jan 17 |
peter |
# GCC -std=c++11 -std=c++0x |
3581 |
19 Jan 17 |
peter |
# IBM XL C -qlanglvl=stdcxx11 |
3581 |
19 Jan 17 |
peter |
# HP aC++ -AA |
3581 |
19 Jan 17 |
peter |
# INTEL -std=c++11 -std=c++0x |
3581 |
19 Jan 17 |
peter |
# from ax_cxx_compile_stdcxx.m4 we have |
3581 |
19 Jan 17 |
peter |
# HP's aCC needs +std=c++11 |
3581 |
19 Jan 17 |
peter |
# Cray's crayCC '-h std=c++11' |
3581 |
19 Jan 17 |
peter |
# but first we try with empty string, hoping compiler is modern. |
3581 |
19 Jan 17 |
peter |
207 |
for yat_arg in '' -std=c++11 -std=c++0x -qlanglvl=stdcxx11 -AA +std=c++11 "-h std=c++11" ; do |
3591 |
20 Jan 17 |
peter |
208 |
CXX="$my_save_CXX $yat_arg" |
3591 |
20 Jan 17 |
peter |
209 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$2], [$3])], |
3591 |
20 Jan 17 |
peter |
210 |
[my_CACHE="$yat_arg"], |
3581 |
19 Jan 17 |
peter |
211 |
[]) |
3591 |
20 Jan 17 |
peter |
212 |
AS_VAR_IF([my_CACHE], [no], [], [break]) |
3581 |
19 Jan 17 |
peter |
213 |
done |
3591 |
20 Jan 17 |
peter |
# restore CXX |
3591 |
20 Jan 17 |
peter |
215 |
CXX="$my_save_CXX" |
3581 |
19 Jan 17 |
peter |
216 |
|
3591 |
20 Jan 17 |
peter |
217 |
AS_CASE([x"$my_CACHE"], |
3591 |
20 Jan 17 |
peter |
218 |
[x], [my_CACHE="none needed"], |
3591 |
20 Jan 17 |
peter |
219 |
[x"no"], [my_CACHE=unsupported]) |
3581 |
19 Jan 17 |
peter |
220 |
|
3591 |
20 Jan 17 |
peter |
221 |
AS_VAR_POPDEF([my_save_CXX]) |
3591 |
20 Jan 17 |
peter |
222 |
]) |
3581 |
19 Jan 17 |
peter |
223 |
|
3591 |
20 Jan 17 |
peter |
224 |
AS_CASE([$my_CACHE], |
3591 |
20 Jan 17 |
peter |
225 |
["none needed"], [$4], |
3591 |
20 Jan 17 |
peter |
226 |
[unsupported], [$5], |
3591 |
20 Jan 17 |
peter |
227 |
[CXX="$CXX $my_CACHE" |
3591 |
20 Jan 17 |
peter |
228 |
$4]) |
3591 |
20 Jan 17 |
peter |
229 |
AS_VAR_POPDEF([my_CACHE]) |
3581 |
19 Jan 17 |
peter |
230 |
]) |