How can I specify that I want C++0x in Makefile.am?

后端 未结 1 1943
终归单人心
终归单人心 2021-01-24 00:49

Currently my project has the following simple tree:

./Makefile.am
./configure.ac
./README
./src/main.cpp
./src/Makefile.am
./bin

I\'m trying to

相关标签:
1条回答
  • 2021-01-24 01:39

    If you're using gcc (looks like you are) then from the libstdc++ manual they have autoconf examples for checking c++ base language features:

    # AC_COMPILE_STDCXX_OX
    AC_DEFUN([AC_COMPILE_STDCXX_0X], [
      AC_CACHE_CHECK(if g++ supports C++0x features without additional flags,
      ac_cv_cxx_compile_cxx0x_native,
      [AC_LANG_SAVE
      AC_LANG_CPLUSPLUS
      AC_TRY_COMPILE([
      template <typename T>
        struct check
        {
          static_assert(sizeof(int) <= sizeof(T), "not big enough");
        };
    
        typedef check<check<bool>> right_angle_brackets;
    
        int a;
        decltype(a) b;
    
        typedef check<int> check_type;
        check_type c;
        check_type&& cr = c;],,
      ac_cv_cxx_compile_cxx0x_native=yes, ac_cv_cxx_compile_cxx0x_native=no)
      AC_LANG_RESTORE
      ])
    
      AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x,
      ac_cv_cxx_compile_cxx0x_cxx,
      [AC_LANG_SAVE
      AC_LANG_CPLUSPLUS
      ac_save_CXXFLAGS="$CXXFLAGS"
      CXXFLAGS="$CXXFLAGS -std=c++0x"
      AC_TRY_COMPILE([
      template <typename T>
        struct check
        {
          static_assert(sizeof(int) <= sizeof(T), "not big enough");
        };
    
        typedef check<check<bool>> right_angle_brackets;
    
        int a;
        decltype(a) b;
    
        typedef check<int> check_type;
        check_type c;
        check_type&& cr = c;],,
      ac_cv_cxx_compile_cxx0x_cxx=yes, ac_cv_cxx_compile_cxx0x_cxx=no)
      CXXFLAGS="$ac_save_CXXFLAGS"
      AC_LANG_RESTORE
      ])
    
      AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x,
      ac_cv_cxx_compile_cxx0x_gxx,
      [AC_LANG_SAVE
      AC_LANG_CPLUSPLUS
      ac_save_CXXFLAGS="$CXXFLAGS"
      CXXFLAGS="$CXXFLAGS -std=gnu++0x"
      AC_TRY_COMPILE([
      template <typename T>
        struct check
        {
          static_assert(sizeof(int) <= sizeof(T), "not big enough");
        };
    
        typedef check<check<bool>> right_angle_brackets;
    
        int a;
        decltype(a) b;
    
        typedef check<int> check_type;
        check_type c;
        check_type&& cr = c;],,
      ac_cv_cxx_compile_cxx0x_gxx=yes, ac_cv_cxx_compile_cxx0x_gxx=no)
      CXXFLAGS="$ac_save_CXXFLAGS"
      AC_LANG_RESTORE
      ])
    
      if test "$ac_cv_cxx_compile_cxx0x_native" = yes ||
         test "$ac_cv_cxx_compile_cxx0x_cxx" = yes ||
         test "$ac_cv_cxx_compile_cxx0x_gxx" = yes; then
        AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ])
      fi
    ])
    

    You could probably try to put a lambda in there if you wanted. Then with HAVE_STDCXX_0X in hand you could set --std=c++0x appropriately.

    0 讨论(0)
提交回复
热议问题