From 5530575ae0ad939e17f08d6bd49978acea388ab7 Mon Sep 17 00:00:00 2001 From: Paul Baltescu Date: Mon, 28 Jan 2013 11:56:31 +0000 Subject: Initial working commit. --- m4/boost.m4 | 2 +- m4/misc.m4 | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 m4/misc.m4 (limited to 'm4') diff --git a/m4/boost.m4 b/m4/boost.m4 index 7e0ed075..ca8a08e8 100644 --- a/m4/boost.m4 +++ b/m4/boost.m4 @@ -395,7 +395,7 @@ dnl generated only once above (before we start the for loops). LDFLAGS=$boost_save_LDFLAGS LIBS=$boost_save_LIBS if test x"$Boost_lib" = xyes; then - Boost_lib_LDFLAGS="-L$boost_ldpath -R$boost_ldpath" + Boost_lib_LDFLAGS="-L$boost_ldpath -I$boost_ldpath" break 6 else boost_failed_libs="$boost_failed_libs@$boost_lib@" diff --git a/m4/misc.m4 b/m4/misc.m4 new file mode 100644 index 00000000..d4aab47b --- /dev/null +++ b/m4/misc.m4 @@ -0,0 +1,110 @@ +dnl @synopsis AX_CXX_CHECK_LIB(libname, functioname, action-if, action-if-not) +dnl +dnl The standard AC_CHECK_LIB can not test functions in namespaces. +dnl Therefore AC_CHECK_LIB(cgicc, cgicc::Cgicc::getVersion) will always +dnl fail. We need to decompose the functionname into a series of namespaces +dnl where it gets declared so that it can be used for a link test. +dnl +dnl In the first version I did allow namespace::functionname to be a +dnl reference to a void-argument global functionname (just wrapped in a +dnl namespace) like its C counterparts would be - but in reality such +dnl thing does not exist. The only global / static functions are always +dnl made const-functions which is an attribute mangled along into the +dnl library function export name. +dnl +dnl The normal usage will ask for a test of a class-member function which +dnl should be presented with a full function spec with arguments given in +dnl parentheses following the function name - if the function to test for +dnl does expect arguments then you should add default initial values in the +dnl prototype (even if they do not exist originally, these are used only +dnl locally to build a correct function call in the configure test script). +dnl +dnl In the current version if you do omit the parenthesis from the macro +dnl argument then the macro will assume that you want to check for the +dnl class name - which is really to check for default constructor being +dnl exported from the given library name. +dnl +dnl EXAMPLE: +dnl AX_CXX_CHECK_LIB(cgicc, [cgicc::HTTPCookie]) +dnl AX_CXX_CHECK_LIB(cgicc, [cgicc::Cgicc::getVersion () const], +dnl AX_CXX_CHECK_LIB(boost_regex, [boost::RegEx::Position (int i = 0) const]) +dnl +dnl Result: +dnl Just as the usual AX_CXX_CHECK_LIB - defines HAVE_LIBCGICC +dnl and adds the libraries to the default library path (and +dnl uses internally the normal ac_check_lib cache symbol +dnl like ac_cv_lib_cgicc_cgicc__Cgicc) +dnl +dnl Footnote: The C++ language is not good at creating stable library +dnl interfaces at the binary level - a lot of functionality is usually being +dnl given as inline functions plus there is hardly a chance to create opaque +dnl types. Therefore most C++ library tests will only do compile tests using +dnl the header files. Doing a check_lib is however good to check the link +dnl dependency before hitting it as an error in the build later. +dnl +dnl @category C++ +dnl @author Guido U. Draheim +dnl @vesion 2006-12-18 + +AC_DEFUN([AX_CXX_CHECK_LIB], +[m4_ifval([$3], , [AH_CHECK_LIB([$1])])dnl +AS_LITERAL_IF([$1], + [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])], + [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1''_$2])])dnl +AC_CACHE_CHECK([for $2 in -l$1], ac_Lib, +[ac_check_lib_save_LIBS=$LIBS +LIBS="-l$1 $5 $LIBS" +case "$2" +in *::*::*\(*) +AC_LINK_IFELSE([AC_LANG_PROGRAM([ + namespace `echo "$2" | sed -e "s/::.*//"` + { class `echo "$2" | sed -e "s/.*::\\(.*\\)::.*/\\1/" -e "s/(.*//"` + { public: int `echo "$2" | sed -e "s/.*:://" -e "/(/!s/..*/&()/"`; + }; + } +],[`echo "$2" | sed -e "s/(.*//" -e "s/\\(.*\\)::\\(.*\\)/((\\1*)(0))->\\2/g"`()])], + [AS_VAR_SET(ac_Lib, yes)], + [AS_VAR_SET(ac_Lib, no)]) +;; *::*::*) +AC_LINK_IFELSE([AC_LANG_PROGRAM([ + namespace `echo "$2" | sed -e "s/::.*//"` + { namespace `echo "$2" | sed -e "s/.*::\\(.*\\)::.*/\\1/"` + { class `echo "$2" | sed -e "s/.*:://"` + { public: `echo "$2" | sed -e "s/.*:://"` (); + }; + } + } +],[new $2()])], + [AS_VAR_SET(ac_Lib, yes)], + [AS_VAR_SET(ac_Lib, no)]) +;; *::*\(*) +AC_LINK_IFELSE([AC_LANG_PROGRAM([ + class `echo "$2" | sed -e "s/\\(.*\\)::.*/\\1/" -e "s/(.*//"` + { public: int `echo "$2" | sed -e "s/.*:://" -e "/(/!s/..*/&()/"`; + }; +],[`echo "$2" | sed -e "s/(.*//" -e "s/\\(.*\\)::\\(.*\\)/((\\1*)(0))->\\2/g"`()])], + [AS_VAR_SET(ac_Lib, yes)], + [AS_VAR_SET(ac_Lib, no)]) +;; *::*) +AC_LINK_IFELSE([AC_LANG_PROGRAM([ + namespace `echo "$2" | sed -e "s/::.*//"` + { class `echo "$2" | sed -e "s/.*:://"` + { public: `echo "$2" | sed -e "s/.*:://"` (); + }; + } +],[new $2()])], + [AS_VAR_SET(ac_Lib, yes)], + [AS_VAR_SET(ac_Lib, no)]) +;; *) +AC_LINK_IFELSE([AC_LANG_CALL([], [$2])], + [AS_VAR_SET(ac_Lib, yes)], + [AS_VAR_SET(ac_Lib, no)]) +;; esac +LIBS=$ac_check_lib_save_LIBS]) +AS_IF([test AS_VAR_GET(ac_Lib) = yes], + [m4_default([$3], [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1)) + LIBS="-l$1 $LIBS" +])], + [$4])dnl +AS_VAR_POPDEF([ac_Lib])dnl +])# AC_CHECK_LIB -- cgit v1.2.3 From bf10ad9d1d3a17ae82804f947616db89f41d4f28 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Tue, 23 Apr 2013 23:59:02 -0400 Subject: configure c++11 if available --- configure.ac | 1 + m4/ax_cxx_compile_stdcxx_11.m4 | 135 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 m4/ax_cxx_compile_stdcxx_11.m4 (limited to 'm4') diff --git a/configure.ac b/configure.ac index eb09676e..8cbdb4fa 100644 --- a/configure.ac +++ b/configure.ac @@ -10,6 +10,7 @@ esac # CPPFLAGS="$CPPFLAGS -std=c++0x" AC_PROG_CC AC_PROG_CXX +AX_CXX_COMPILE_STDCXX_11 AC_LANG_CPLUSPLUS AC_OPENMP BOOST_REQUIRE([1.44]) diff --git a/m4/ax_cxx_compile_stdcxx_11.m4 b/m4/ax_cxx_compile_stdcxx_11.m4 new file mode 100644 index 00000000..1bc31128 --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx_11.m4 @@ -0,0 +1,135 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++11 +# standard; if necessary, add switches to CXXFLAGS to enable support. +# +# The first argument, if specified, indicates whether you insist on an +# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. +# -std=c++11). If neither is specified, you get whatever works, with +# preference for an extended mode. +# +# The second argument, if specified 'mandatory' or if left unspecified, +# indicates that baseline C++11 support is required and that the macro +# should error out if no mode with that support is found. If specified +# 'optional', then configuration proceeds regardless, after defining +# HAVE_CXX11 if and only if a supporting mode is found. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2013 Roy Stogner +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 3 + +m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c); + + auto d = a; +]) + +AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl + m4_if([$1], [], [], + [$1], [ext], [], + [$1], [noext], [], + [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl + m4_if([$2], [], [ax_cxx_compile_cxx11_required=true], + [$2], [mandatory], [ax_cxx_compile_cxx11_required=true], + [$2], [optional], [ax_cxx_compile_cxx11_required=false], + [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])dnl + AC_LANG_PUSH([C++])dnl + ac_success=no + AC_CACHE_CHECK(whether $CXX supports C++11 features by default, + ax_cv_cxx_compile_cxx11, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [ax_cv_cxx_compile_cxx11=yes], + [ax_cv_cxx_compile_cxx11=no])]) + if test x$ax_cv_cxx_compile_cxx11 = xyes; then + ac_success=yes + fi + + m4_if([$1], [noext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=gnu++11 -std=gnu++0x; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + ac_success=yes + break + fi + done + fi]) + + m4_if([$1], [ext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=c++11 -std=c++0x; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + ac_success=yes + break + fi + done + fi]) + AC_LANG_POP([C++]) + if test x$ax_cxx_compile_cxx11_required = xtrue; then + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) + fi + else + if test x$ac_success = xno; then + HAVE_CXX11=0 + AC_MSG_NOTICE([No compiler with C++11 support was found]) + else + HAVE_CXX11=1 + AC_DEFINE(HAVE_CXX11,1, + [define if the compiler supports basic C++11 syntax]) + fi + AM_CONDITIONAL([HAVE_CXX11],[test "x$HAVE_CXX11" = "x1"]) + + AC_SUBST(HAVE_CXX11) + fi +]) + -- cgit v1.2.3 From df3b23968d5bda4050b7f7a002a7e5a1d7a48a74 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Thu, 25 Apr 2013 23:32:02 -0400 Subject: only turn on c++11 for extractor --- extractor/Makefile.am | 2 +- m4/ax_cxx_compile_stdcxx_11.m4 | 9 +++++++-- utils/filelib.h | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'm4') diff --git a/extractor/Makefile.am b/extractor/Makefile.am index d8239b7d..fc799f74 100644 --- a/extractor/Makefile.am +++ b/extractor/Makefile.am @@ -145,5 +145,5 @@ libextractor_a_SOURCES = \ translation_table.cc \ vocabulary.cc -AM_CPPFLAGS = -W -Wall -Wno-sign-compare -std=c++0x -fopenmp $(GTEST_CPPFLAGS) $(GMOCK_CPPFLAGS) +AM_CPPFLAGS = -W -Wall -Wno-sign-compare $(CXX11_SWITCH) -fopenmp $(GTEST_CPPFLAGS) $(GMOCK_CPPFLAGS) AM_LDFLAGS = -fopenmp diff --git a/m4/ax_cxx_compile_stdcxx_11.m4 b/m4/ax_cxx_compile_stdcxx_11.m4 index 1bc31128..f6cf4a15 100644 --- a/m4/ax_cxx_compile_stdcxx_11.m4 +++ b/m4/ax_cxx_compile_stdcxx_11.m4 @@ -74,6 +74,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl ac_success=yes fi + restore_it="$CXXFLAGS" m4_if([$1], [noext], [], [dnl if test x$ac_success = xno; then for switch in -std=gnu++11 -std=gnu++0x; do @@ -87,7 +88,8 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl [eval $cachevar=no]) CXXFLAGS="$ac_save_CXXFLAGS"]) if eval test x\$$cachevar = xyes; then - CXXFLAGS="$CXXFLAGS $switch" + CXXFLAGS="$CXXFLAGS" + c11switch="$switch" ac_success=yes break fi @@ -107,12 +109,15 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl [eval $cachevar=no]) CXXFLAGS="$ac_save_CXXFLAGS"]) if eval test x\$$cachevar = xyes; then - CXXFLAGS="$CXXFLAGS $switch" + CXXFLAGS="$CXXFLAGS" + c11switch="$switch" ac_success=yes break fi done fi]) + CXXFLAGS="$restore_it" + AC_SUBST([CXX11_SWITCH], ["$c11switch"]) AC_LANG_POP([C++]) if test x$ax_cxx_compile_cxx11_required = xtrue; then if test x$ac_success = xno; then diff --git a/utils/filelib.h b/utils/filelib.h index bb6e7415..b9ea3940 100644 --- a/utils/filelib.h +++ b/utils/filelib.h @@ -27,7 +27,7 @@ struct BaseFile { } bool is_null() const { return !ps_; } operator bool() const { - return ps_; + return ps_.get(); } S* stream() { return ps_.get(); } S* operator->() { return ps_.get(); } // compat with old ReadFile * -> new Readfile. remove? -- cgit v1.2.3