Changeset 3666


Ignore:
Timestamp:
Jul 25, 2017, 10:09:23 AM (10 months ago)
Author:
peter
Message:

configure.ac: add --disable-cxx11 in --help output

Change default behaviour of configure. If neither --enable-cxx11 nor
--disable-cxx11 is given, try c++11 features with CXX but if it
doesn't work, don't try with list of compiler options (as is behaviour
with --enable-cxx11).

README: update text to match behaviour

yat/utility/config_public.h.in: extend docs

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/README

    r3661 r3666  
    155155
    156156If enabled, yat uses C++11 features such as rvalues and std::atomic,
    157 which make the library faster and safer. To turn on these features you
    158 need to configure yat with option
     157which make the library faster and safer. You can turn off these
     158features with option
     159
     160  #> ./configure --disable-cxx11
     161
     162Otherwise the configure script will check if compiler supports rvalue
     163and other features and #define macros as appropriate. In addition, if
     164you run configure with option
    159165
    160166  #> ./configure --enable-cxx11
    161167
    162 This will make the configure script test if the compiler supports
    163 these features, and, if nessecary, add options such as -std=cxx11. If
    164 the search is sucessful corresponding macro is defined in file
    165 'yat/utility/config_public.h'. If you want to use these features in
    166 your own code, you need turn them on by setting preproccessor
    167 definition YAT_WITH_CXX11 (and of course make sure the compiler
    168 supports them).
     168the script will first try the features by default, and if not working
     169try a list of different options, such as '-std=cxx11' to turn on
     170support, and if any of them work, #define macros as appropriate in
     171file 'yat/utility/config_public.h' and save compiler option to $CXX,
     172so the library is built with this option.
     173
     174If you want to use these features in your own code, you need turn them
     175on by #defining YAT_WITH_CXX11 (and make sure the compiler supports
     176them). Please see file 'yat/utility/config_public.h.in' for more
     177discussion how to use macros YAT_WITH_CXX11 and YAT_WITHOUT_CXX11.
    169178
    170179=== Doxygen ===
  • trunk/configure.ac

    r3641 r3666  
    8888
    8989AC_ARG_ENABLE([cxx11],
    90               [AS_HELP_STRING([--enable-cxx11],
    91                               [build with C++11 support (if available)])],
    92             [],
    93             [enable_cxx11=no])
    94 
    95 # if CXX11 is wanted look for rvalue support
     90  [AS_HELP_STRING([--enable-cxx11],
     91                  [search for compiler options to build with C++11 support])
     92AS_HELP_STRING([--disable-cxx11],
     93               [turn off C++11 support])],
     94  # disallow --enable-cxx11=foo (only yes or no)
     95  [AS_CASE([$enable_cxx11],
     96           [yes|no], [],
     97           [AC_MSG_ERROR([invalid argument for --enable-cxx11: $enable_cxx11])])
     98  ],
     99  #default
     100  [enable_cxx11=maybe])
     101
    96102yat_have_rvalue=no
    97103yat_have_atomic=no
    98104yat_have_log2=no
    99 AS_VAR_IF([enable_cxx11], [yes], [
     105AS_VAR_IF([enable_cxx11], [no], [], [
     106# if CXX11 is wanted look for rvalue support
    100107  YAT_CXX_RVALUE([yat_have_rvalue=yes
    101108                  AC_DEFINE([YAT_HAVE_RVALUE], [1],
    102                             [Define if compiler support rvalues])])
     109                            [Define if compiler supports rvalues])],
     110                 [], [$enable_cxx11])
     111
    103112  YAT_CXX_ATOMIC([yat_have_atomic=yes
    104113                  AC_DEFINE([YAT_HAVE_ATOMIC], [1],
    105                             [Define if compiler support std::atomic])])
     114                            [Define if compiler supports std::atomic])],
     115                 [], [$enable_cxx11])
     116
    106117  YAT_CXX_LOG2([yat_have_log2=yes
    107118                AC_DEFINE([YAT_HAVE_LOG2], [1],
    108                           [Define if std::log2 exists])])
     119                          [Define if std::log2 exists])],
     120               [], [$enable_cxx11])
     121
     122  # Unless --disable-cxx11, #define YAT_WITH_CXX11 in 'config.h'. The
     123  # private 'config.h' is #included first in every source file
     124  # (i.e. before 'config_public.h') and thereby YAT_HAVE_CXX11__ is
     125  # #defined and cxx11 features compiled into libyat (if available).
     126  AC_DEFINE([YAT_WITH_CXX11], [1], [Define if cxx11 is wanted])
    109127])
    110128
  • trunk/m4/yat_cxx11.m4

    r3640 r3666  
    11## $Id$
    22#
    3 # serial 3  (yat 0.15)
     3# serial 4  (yat 0.15)
    44#
    55# see http://www.gnu.org/software/automake/manual/automake.html#Serials
     
    99#   YAT_CXX_ATOMIC([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
    1010#   YAT_CXX_RVALUE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
     11#   YAT_CXX_LOG2([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
    1112#
    1213# DESCRIPTION
     
    3839#
    3940
    40 # YAT_CXX_ATOMIC([action-if-found], [action-if-not-found])
     41# YAT_CXX_ATOMIC([action-if-found], [action-if-not-found], [search-options])
    4142#
    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.
     43# Test whether $CXX supports std::atomic. If not and search-options is
     44# 'yes', try turning on support with a number of different
     45# switches. If a successful switch is found invoke shell
     46# action-if-found; else issue action-if-not-found.
    4647AC_DEFUN([YAT_CXX_ATOMIC],
    4748[
     
    4950  [@%:@include <atomic>],
    5051  [std::atomic<bool> ready(false);],
    51   [$1], [$2])
     52  [$1], [$2], [$3])
    5253])
    5354
    5455
    55 # YAT_CXX_RVALUE([action-if-found], [action-if-not-found])
     56# YAT_CXX_RVALUE([action-if-found], [action-if-not-found], [search-options])
    5657#
    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.
     58# Test whether $CXX supports rvalue. If not and search-options is
     59# 'yes', try turning on support with a number of different
     60# switches. If a successful switch is found invoke shell
     61# action-if-found; else issue action-if-not-found.
    6062AC_DEFUN([YAT_CXX_RVALUE],
    6163[
     
    7577  MyClass mc;
    7678  MyClass mc2 = std::move(mc);
    77   ], [# action
    78   $1
    79   ], [ # action if not found
    80   $2
    81   ])
    82 ]) # YAT_CXX_RVALUE
     79  ], [$1], [$2], [$3])
     80])
    8381
    8482
    85 # YAT_CXX_LOG2([action-if-found], [action-if-not-found])
     83# YAT_CXX_LOG2([action-if-found], [action-if-not-found], [search-options])
    8684#
    87 # Test whether $CXX supports std::log2. If not, try turning on support
    88 # with a number of different switches. If a successful switch is found
    89 # invoke shell action-if-found; else issue action-if-not-found.
     85# Test whether $CXX supports std::log2. If not and search-options is
     86# 'yes', try turning on support with a number of different
     87# switches. If a successful switch is found invoke shell
     88# action-if-found; else issue action-if-not-found.
    9089AC_DEFUN([YAT_CXX_LOG2],
    9190[
     
    9695  double x = std::log2(3.14);
    9796  foo(x);
    98   ], [# action
    99   $1
    100   ], [ # action if not found
    101   $2
    102   ])
    103 ]) # YAT_CXX_RVALUE
     97  ], [$1], [$2], [$3])
     98])
    10499
    105100
    106 # YAT_CXX_TRY_CXX11([feature], [header], [body], [action-if-found],
    107 #                   [action-if-not-found])
     101# YAT_CXX_TRY_CXX11(feature, prologue, body, [action-if-success],
     102#                   [action-if-failed], [search-options])
    108103#
     104# Try c++11 feature, feature, by using code with prologue and body. If
     105# successful, issue shell code action-if-success, otherwise if
     106# search-options is 'yes' retry with different CXX options as detailed
     107# in YAT_CXX_SEARCH_CXX11; if none works, issue shell code action-if-failed.
    109108AC_DEFUN([YAT_CXX_TRY_CXX11],
    110 [AS_VAR_PUSHDEF([my_CACHE], [yat_cv_cxx_$1])dnl
     109[
     110AS_IF([test x"$6" = x"yes"], [
     111  YAT_CXX_SEARCH_CXX11([$1], [$2], [$3], [$4], [$5])
     112], [
     113  AS_VAR_PUSHDEF([my_CACHE], [yat_cv_cxx_try_$1])dnl
     114  AC_CACHE_CHECK([if $CXX supports $1],
     115    [my_CACHE],
     116    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
     117                       [my_CACHE=yes],
     118                       [my_CACHE=no])])
     119  AS_VAR_IF([my_CACHE], [yes], [$4], [$5])
     120  AS_VAR_POPDEF([my_CACHE])
     121])
     122]) #YAT_CXX_TRY_CXX11
     123
     124
     125# YAT_CXX_SEARCH_CXX11([feature], [prologue], [body], [action-if-found],
     126#                      [action-if-not-found])
     127#
     128# Try feature by using code with prologue and body, first with CXX and
     129# then by adding switches to CXX. If a switch is found with which code
     130# compiles, issue action-if-found; otherwise issue
     131# action-if-not-found.
     132AC_DEFUN([YAT_CXX_SEARCH_CXX11],
     133[
     134AS_VAR_PUSHDEF([my_CACHE], [yat_cv_cxx_search_$1])dnl
    111135AC_CACHE_CHECK([for $CXX option to enable $1],
    112136  [my_CACHE],
  • trunk/yat/utility/config_public.h.in

    r3642 r3666  
    5656#undef YAT_HAVE_BOOST_CONCEPT_WITH_CONSTRUCTOR
    5757
    58 /// Let the user turn on/off c++11 features with YAT_WITH_CXX11 and
    59 /// YAT_WITHOUT_CXX11, respectively.
     58// User can enable/disable cxx11 features with public macros
     59// YAT_WITH_CXX11 and YAT_WITHOUT_CXX11.
     60//
     61// If user want to disable all cxx11 features, they should #define
     62// YAT_WITHOUT_CXX11; if cxx11 features are desired, user should
     63// #define YAT_WITH_CXX11 and cxx11 features will be enabled if found
     64// when building yat (see comment below).
    6065#ifndef YAT_WITH_CXX11
    6166#  ifndef YAT_WITHOUT_CXX11
    62 #    define YAT_HAVE_CXX11__ 0 // default is off for now
     67#    /// default behaviour is that cxx11 features are disabled; this is
     68#    /// likely to change in future versions
     69#    define YAT_HAVE_CXX11__ 0
    6370#  else
    64 // YAT_WITHOUT_CXX11 defined by user, turn off features
     71#    /// YAT_WITHOUT_CXX11 defined by user, turn off features
    6572#    define YAT_HAVE_CXX11__ 0
    6673#  endif
     
    6976#    error "cannot set both YAT_WITH_CXX11 and YAT_WITHOUT_CXX11"
    7077#  endif
    71 // YAT_WITH_CXX11 defined by user, turn on features
     78#  /// YAT_WITH_CXX11 defined by user, turn on features
    7279#  define YAT_HAVE_CXX11__ 1
    7380#endif
    7481
    7582
    76 // Depending on whether YAT_WITH_CXX11 and YAT_WITHOUT_CXX11 are
    77 // defined (see logic above), define specific features if found during
    78 // configuration.
     83// See comment and logic above for how to use public macros
     84// YAT_WITH_CXX11 and YAT_WITHOUT_CXX11 to affect whether
     85// YAT_HAVE_CXX11__ is defined.
    7986#if YAT_HAVE_CXX11__
     87// Defines below are defined depending on tests performed during
     88// configure step when building yat. The results can be affected by
     89// installer via configure options --enable-cxx11 and --disable-cxx11
     90// (see README).
     91//
    8092/// Define if compiler supports rvalues */
    8193#undef YAT_HAVE_RVALUE
Note: See TracChangeset for help on using the changeset viewer.