Skip to content

Commit 6aa630f

Browse files
committed
build: detect TR1 or C++11 with automake macros.
Used in fastx-collapser, should ease compilation on newer systems.
1 parent 0c78199 commit 6aa630f

File tree

4 files changed

+155
-4
lines changed

4 files changed

+155
-4
lines changed

configure.ac

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010

1111
AC_INIT([FASTX Toolkit],
12-
[0.0.14-rc1],
12+
[0.0.14-rc2],
1313
[Assaf Gordon [email protected]],
1414
[fastx_toolkit])
1515
AC_CONFIG_AUX_DIR(config)
@@ -22,9 +22,11 @@ AC_PROG_CXX
2222
AC_PROG_LIBTOOL
2323
AX_C_LONG_LONG
2424
AX_CXX_HEADER_STDCXX_TR1
25-
if test "$ax_cv_cxx_stdcxx_tr1" != yes; then
26-
AC_MSG_ERROR([Your version of gcc does not support the 'std::tr1' standard. Recommended gcc version is 4.1.2 or later. Please use a newer gcc version, or try to download the pre-compiled binaries from the fastx-toolkit website.])
27-
fi
25+
AX_CXX_COMPILE_STDCXX_11([noext],[optional])
26+
27+
dnl if test "$ax_cv_cxx_stdcxx_tr1" != yes; then
28+
dnl AC_MSG_ERROR([Your version of gcc does not support the 'std::tr1' standard. Recommended gcc version is 4.1.2 or later. Please use a newer gcc version, or try to download the pre-compiled binaries from the fastx-toolkit website.])
29+
dnl fi
2830

2931
PKG_CHECK_MODULES([GTEXTUTILS],[gtextutils])
3032

m4/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ m4datadir = $(datadir)/aclocal
1313

1414
# List your m4 macros here
1515
m4macros = ax_c_long_long.m4 \
16+
ax_cxx_compile_stdcxx_11.m4 \
1617
ax_cxx_header_stdcxx_tr1.m4
1718

1819
# The following is boilerplate

m4/ax_cxx_compile_stdcxx_11.m4

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# ============================================================================
2+
# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
3+
# ============================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
8+
#
9+
# DESCRIPTION
10+
#
11+
# Check for baseline language coverage in the compiler for the C++11
12+
# standard; if necessary, add switches to CXXFLAGS to enable support.
13+
#
14+
# The first argument, if specified, indicates whether you insist on an
15+
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
16+
# -std=c++11). If neither is specified, you get whatever works, with
17+
# preference for an extended mode.
18+
#
19+
# The second argument, if specified 'mandatory' or if left unspecified,
20+
# indicates that baseline C++11 support is required and that the macro
21+
# should error out if no mode with that support is found. If specified
22+
# 'optional', then configuration proceeds regardless, after defining
23+
# HAVE_CXX11 if and only if a supporting mode is found.
24+
#
25+
# LICENSE
26+
#
27+
# Copyright (c) 2008 Benjamin Kosnik <[email protected]>
28+
# Copyright (c) 2012 Zack Weinberg <[email protected]>
29+
# Copyright (c) 2013 Roy Stogner <[email protected]>
30+
#
31+
# Copying and distribution of this file, with or without modification, are
32+
# permitted in any medium without royalty provided the copyright notice
33+
# and this notice are preserved. This file is offered as-is, without any
34+
# warranty.
35+
36+
#serial 3
37+
38+
m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [
39+
template <typename T>
40+
struct check
41+
{
42+
static_assert(sizeof(int) <= sizeof(T), "not big enough");
43+
};
44+
45+
typedef check<check<bool>> right_angle_brackets;
46+
47+
int a;
48+
decltype(a) b;
49+
50+
typedef check<int> check_type;
51+
check_type c;
52+
check_type&& cr = static_cast<check_type&&>(c);
53+
54+
auto d = a;
55+
])
56+
57+
AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
58+
m4_if([$1], [], [],
59+
[$1], [ext], [],
60+
[$1], [noext], [],
61+
[m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
62+
m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
63+
[$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
64+
[$2], [optional], [ax_cxx_compile_cxx11_required=false],
65+
[m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])dnl
66+
AC_LANG_PUSH([C++])dnl
67+
ac_success=no
68+
AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
69+
ax_cv_cxx_compile_cxx11,
70+
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
71+
[ax_cv_cxx_compile_cxx11=yes],
72+
[ax_cv_cxx_compile_cxx11=no])])
73+
if test x$ax_cv_cxx_compile_cxx11 = xyes; then
74+
ac_success=yes
75+
fi
76+
77+
m4_if([$1], [noext], [], [dnl
78+
if test x$ac_success = xno; then
79+
for switch in -std=gnu++11 -std=gnu++0x; do
80+
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
81+
AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
82+
$cachevar,
83+
[ac_save_CXXFLAGS="$CXXFLAGS"
84+
CXXFLAGS="$CXXFLAGS $switch"
85+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
86+
[eval $cachevar=yes],
87+
[eval $cachevar=no])
88+
CXXFLAGS="$ac_save_CXXFLAGS"])
89+
if eval test x\$$cachevar = xyes; then
90+
CXXFLAGS="$CXXFLAGS $switch"
91+
ac_success=yes
92+
break
93+
fi
94+
done
95+
fi])
96+
97+
m4_if([$1], [ext], [], [dnl
98+
if test x$ac_success = xno; then
99+
for switch in -std=c++11 -std=c++0x; do
100+
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
101+
AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
102+
$cachevar,
103+
[ac_save_CXXFLAGS="$CXXFLAGS"
104+
CXXFLAGS="$CXXFLAGS $switch"
105+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
106+
[eval $cachevar=yes],
107+
[eval $cachevar=no])
108+
CXXFLAGS="$ac_save_CXXFLAGS"])
109+
if eval test x\$$cachevar = xyes; then
110+
CXXFLAGS="$CXXFLAGS $switch"
111+
ac_success=yes
112+
break
113+
fi
114+
done
115+
fi])
116+
AC_LANG_POP([C++])
117+
if test x$ax_cxx_compile_cxx11_required = xtrue; then
118+
if test x$ac_success = xno; then
119+
AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
120+
fi
121+
else
122+
if test x$ac_success = xno; then
123+
HAVE_CXX11=0
124+
AC_MSG_NOTICE([No compiler with C++11 support was found])
125+
else
126+
HAVE_CXX11=1
127+
AC_DEFINE(HAVE_CXX11,1,
128+
[define if the compiler supports basic C++11 syntax])
129+
fi
130+
131+
AC_SUBST(HAVE_CXX11)
132+
fi
133+
])

src/fastx_collapser/fastx_collapser.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,23 @@ const char* usage=
4747
"\n";
4848

4949
FASTX fastx;
50+
51+
#if HAVE_CXX11 == 1
52+
/* compiler supports -std=cxx11 - use <unordered_map> */
53+
#include <unordered_map>
54+
std::unordered_map<string,size_t> collapsed_sequences;
55+
#else
56+
#ifdef STDCXX_TR1_HEADERS
57+
/* fallback - compiler suppots 'tr1' headers - use them */
5058
#include <tr1/unordered_map>
5159
std::tr1::unordered_map<string,size_t> collapsed_sequences;
60+
#else
61+
/* Worse fallback - use map instead of unordered_map */
62+
#include <map>
63+
std::map<string,size_t> collapsed_sequences;
64+
#endif
65+
#endif
66+
5267
std::list< pair<string,size_t> > sorted_collapsed_sequences ;
5368

5469
struct PrintCollapsedSequence

0 commit comments

Comments
 (0)