Fix build with GNU libstdc++ C++11 ABI

The GNU libstdc++ that ships witch gcc 5 can be used with the same ABI as
older versions, or with a new ABI which is conformant to the C++11 standard.
LyX did not build if the latter was used:
https://kojipkgs.fedoraproject.org//work/tasks/1267/9651267/build.log

This is now fixed by detecting the ABI version and disabling the wrong forward
declarations. At the same time, STD_STRING_USES_COW is switched off for the
C++11 ABI version, because the std::basic_string implementation is now C++11
conformant. Since the GNU libstdc++ can also used by other compilers such as
clang, we must not test for the compiler version.
This commit is contained in:
Georg Baum 2015-05-12 21:23:06 +02:00
parent eaed3b94cc
commit be41e2d16f
5 changed files with 109 additions and 35 deletions

View File

@ -120,37 +120,65 @@ done
])dnl
AC_DEFUN([LYX_PROG_CXX_WORKS],
[rm -f conftest.C
cat >conftest.C <<EOF
class foo {
// we require the mutable keyword
mutable int bar;
};
// we require namespace support
namespace baz {
int bar;
}
int main() {
return(0);
}
EOF
$CXX -c $CXXFLAGS $CPPFLAGS conftest.C >&5 || CXX=
rm -f conftest.C conftest.o conftest.obj || true
dnl Usage: LYX_PROG_CLANG: set lyx_cv_prog_clang to yes if the compiler is clang.
AC_DEFUN([LYX_PROG_CLANG],
[AC_CACHE_CHECK([whether the compiler is clang],
[lyx_cv_prog_clang],
[AC_TRY_COMPILE([], [
#ifndef __clang__
this is not clang
#endif
],
[lyx_cv_prog_clang=yes ; CLANG=yes], [lyx_cv_prog_clang=no ; CLANG=no])])
])
dnl Usage: LYX_LIB_STDCXX: set lyx_cv_lib_stdcxx to yes if the STL library is libstdc++.
AC_DEFUN([LYX_LIB_STDCXX],
[AC_CACHE_CHECK([whether STL is libstdc++],
[lyx_cv_lib_stdcxx],
[AC_TRY_COMPILE([#include<vector>], [
#if ! defined(__GLIBCXX__) && ! defined(__GLIBCPP__)
this is not libstdc++
#endif
],
[lyx_cv_lib_stdcxx=yes], [lyx_cv_lib_stdcxx=no])])
])
dnl Usage: LYX_LIB_STDCXX_CXX11_ABI: set lyx_cv_lib_stdcxx_cxx11_abi to yes
dnl if the STL library is GNU libstdc++ and the C++11 ABI is used.
AC_DEFUN([LYX_LIB_STDCXX_CXX11_ABI],
[AC_CACHE_CHECK([whether STL is libstdc++ using the C++11 ABI],
[lyx_cv_lib_stdcxx_cxx11_abi],
[AC_TRY_COMPILE([#include<vector>], [
#if ! defined(_GLIBCXX_USE_CXX11_ABI) || ! _GLIBCXX_USE_CXX11_ABI
this is not libstdc++ using the C++11 ABI
#endif
],
[lyx_cv_lib_stdcxx_cxx11_abi=yes], [lyx_cv_lib_stdcxx_cxx11_abi=no])])
])
AC_DEFUN([LYX_PROG_CXX],
[AC_MSG_CHECKING([for a good enough C++ compiler])
LYX_SEARCH_PROG(CXX, $CXX $CCC g++ gcc c++ CC cxx xlC cc++, [LYX_PROG_CXX_WORKS])
[AC_REQUIRE([AC_PROG_CXX])
AC_REQUIRE([AC_PROG_CXXCPP])
if test -z "$CXX" ; then
AC_MSG_ERROR([Unable to find a good enough C++ compiler])
AC_LANG_PUSH(C++)
LYX_PROG_CLANG
LYX_LIB_STDCXX
LYX_LIB_STDCXX_CXX11_ABI
AC_LANG_POP(C++)
if test $lyx_cv_lib_stdcxx = "yes" ; then
if test $lyx_cv_lib_stdcxx_cxx11_abi = "yes" ; then
AC_DEFINE(USE_GLIBCXX_CXX11_ABI, 1, [use GNU libstdc++ with C++11 ABI])
fi
else
if test $lyx_cv_prog_clang = "yes" ; then
AC_DEFINE(USE_LLVM_LIBCPP, 1, [use libc++ provided by llvm instead of GNU libstdc++])
fi
fi
AC_MSG_RESULT($CXX)
AC_PROG_CXX
AC_PROG_CXXCPP
### We might want to get or shut warnings.
AC_ARG_ENABLE(warnings,

View File

@ -112,3 +112,49 @@ check_cxx_source_compiles(
"
SIZEOF_WCHAR_T_IS_4)
# Check whether STL is libstdc++
check_cxx_source_compiles(
"
#include <vector>
int main() {
#if ! defined(__GLIBCXX__) && ! defined(__GLIBCPP__)
this is not libstdc++
#endif
return(0);
}
"
lyx_cv_lib_stdcxx)
# Check whether STL is libstdc++ with C++11 ABI
check_cxx_source_compiles(
"
#include <vector>
int main() {
#if ! defined(_GLIBCXX_USE_CXX11_ABI) || ! _GLIBCXX_USE_CXX11_ABI
this is not libstdc++ using the C++11 ABI
#endif
return(0);
}
"
USE_GLIBCXX_CXX11_ABI)
check_cxx_source_compiles(
"
#ifndef __clang__
this is not clang
#endif
int main() {
return(0);
}
"
lyx_cv_prog_clang)
set(USE_LLVM_LIBCPP)
set(USE_GLIBCXX_CXX11_ABI)
if(NOT lyx_cv_lib_stdcxx)
if(lyx_cv_prog_clang)
# use libc++ provided by llvm instead of GNU libstdc++
set(USE_LLVM_LIBCPP 1)
endif()
endif()

View File

@ -57,6 +57,9 @@
#cmakedefine LYX_USE_TR1 1
#cmakedefine LYX_USE_TR1_REGEX 1
// use GNU libstdc++ with C++11 ABI
#cmakedefine USE_GLIBCXX_CXX11_ABI 1
#cmakedefine Z_PREFIX 1
#cmakedefine ASPELL_FOUND 1

View File

@ -13,14 +13,6 @@
#ifndef STRFWD_H
#define STRFWD_H
// This includes does nothing but defining _LIBCPP_VERSION
// if libc++ is used (rather than libstdc++) - we first
// check if we have at least a c++03 standard before
// including the file
#if (__cplusplus > 19971L)
#include <ciso646>
#endif
#ifdef USE_WCHAR_T
// Prefer this if possible because GNU libstdc++ has usable
@ -36,8 +28,10 @@ namespace lyx { typedef boost::uint32_t char_type; }
#endif
// Forward definitions do not work with libc++
#ifdef _LIBCPP_VERSION
// For gcc5 with the new std::string ABI forward declarations would work in
// principle, but I am not sure whether we want non-standard
// "namespace __cxx11" in our sources.
#if defined(USE_LLVM_LIBCPP) || defined(USE_GLIBCXX_CXX11_ABI)
#include <string>
#else

View File

@ -231,3 +231,6 @@ What's new
- Add "Keywords" to lyx.desktop file (bug 9414).
- Fix several compilation warnings (bug 9488).
- Fix build with gcc 5.1 using libstdc++ with C++11 ABI.