source: trunk/m4/yat_cxx11.m4 @ 3591

Last change on this file since 3591 was 3591, checked in by Peter, 6 years ago

fixes #877

Generalize YAT_CXX_RVALUE into YAT_CXX_TRY_CXX11 and use that to
implement new macro YAT_CXX_ATOMIC. Use this macro in configure.ac and
use std::atomic<> conditoionally in RNG singleton.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 3.5 KB
Line 
1## $Id: yat_cxx11.m4 3591 2017-01-20 02:19:49Z peter $
2#
3# serial 2  (yat 0.15)
4#
5# see http://www.gnu.org/software/automake/manual/automake.html#Serials
6#
7# SYNOPSIS
8#
9#   YAT_CXX_ATOMIC([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
10#   YAT_CXX_RVALUE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
11#
12# DESCRIPTION
13#
14#   Test whether $CXX supports rvalues
15#
16# LAST MODIFICATION
17#
18#   $Date: 2017-01-20 02:19:49 +0000 (Fri, 20 Jan 2017) $
19#
20# COPYLEFT
21#
22#   Copyright (C) 2017 Peter Johansson
23#
24#   This file is part of the yat library, http://dev.thep.lu.se/yat
25#
26#   The yat library is free software; you can redistribute it and/or
27#   modify it under the terms of the GNU General Public License as
28#   published by the Free Software Foundation; either version 3 of the
29#   License, or (at your option) any later version.
30#
31#   The yat library is distributed in the hope that it will be useful,
32#   but WITHOUT ANY WARRANTY; without even the implied warranty of
33#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
34#   General Public License for more details.
35#
36#   You should have received a copy of the GNU General Public License
37#   along with yat. If not, see <http://www.gnu.org/licenses/>.
38#
39
40# YAT_CXX_ATOMIC([action-if-found], [action-if-not-found])
41#
42# Test whether $CXX supports std::atomic. If not, try turning on
43# support with a number of different switches. If a successful switch
44# is found invoke shell action-if-found; else issue
45# action-if-not-found.
46AC_DEFUN([YAT_CXX_ATOMIC],
47[
48YAT_CXX_TRY_CXX11([atomic],
49  [@%:@include <atomic>],
50  [std::atomic<bool> ready(false);],
51  [$1], [$2])
52])
53
54
55# YAT_CXX_RVALUE([action-if-found], [action-if-not-found])
56#
57# Test whether $CXX supports rvalue. If not, try turning on support
58# with a number of different switches. If a successful switch is found
59# invoke shell action-if-found; else issue action-if-not-found.
60AC_DEFUN([YAT_CXX_RVALUE],
61[
62YAT_CXX_TRY_CXX11([rvalue], [ dnl header
63  @%:@include <utility>
64
65  class MyClass
66  {
67  public:
68    MyClass(void);
69    MyClass(const MyClass&); // copy constructor
70    MyClass(MyClass&&); // move constructor
71    MyClass& operator=(const MyClass&); // copy assignment
72    MyClass& operator=(MyClass&&); // move assignment
73  };
74  ],[ dnl body
75  MyClass mc;
76  MyClass mc2 = std::move(mc);
77  ], [# action
78  $1
79  ], [ # action if not found
80  $2
81  ])
82]) # YAT_CXX_RVALUE
83
84# YAT_CXX_TRY_CXX11([feature], [header], [body], [action-if-found],
85#                   [action-if-not-found])
86#
87AC_DEFUN([YAT_CXX_TRY_CXX11],
88[AS_VAR_PUSHDEF([my_CACHE], [yat_cv_cxx_$1])dnl
89AC_CACHE_CHECK([for $CXX option to enable $1],
90  [my_CACHE],
91  [my_CACHE=no
92   AS_VAR_PUSHDEF([my_save_CXX], [yat_cxx_$1_save_CXX])dnl
93   my_save_CXX="$CXX"
94# From autoconf 'c.m4' we have
95# GCC -std=c++11 -std=c++0x
96# IBM XL C -qlanglvl=stdcxx11
97# HP aC++ -AA
98# INTEL -std=c++11 -std=c++0x
99# from ax_cxx_compile_stdcxx.m4 we have
100# HP's aCC needs +std=c++11
101# Cray's crayCC '-h std=c++11'
102# but first we try with empty string, hoping compiler is modern.
103   for yat_arg in '' -std=c++11 -std=c++0x -qlanglvl=stdcxx11 -AA +std=c++11 "-h std=c++11" ; do
104     CXX="$my_save_CXX $yat_arg"
105     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
106                       [my_CACHE="$yat_arg"],
107                       [])
108     AS_VAR_IF([my_CACHE], [no], [], [break])
109   done
110   # restore CXX
111   CXX="$my_save_CXX"
112
113   AS_CASE([x"$my_CACHE"],
114           [x], [my_CACHE="none needed"],
115           [x"no"], [my_CACHE=unsupported])
116
117   AS_VAR_POPDEF([my_save_CXX])
118  ])
119
120AS_CASE([$my_CACHE],
121        ["none needed"], [$4],
122        [unsupported], [$5],
123        [CXX="$CXX $my_CACHE"
124         $4])
125AS_VAR_POPDEF([my_CACHE])
126])
Note: See TracBrowser for help on using the repository browser.